class Drizzle::Parser
- Drizzle::Parser
- Reference
- Object
Overview
A Parser reads in the tokens generated by a Lexer and constructs an Abstract Syntax Tree (AST) built from what it finds.
Defined in:
drizzle/parser.crConstructors
Instance Method Summary
-
#current : Drizzle::Token
The token that is currently being inspected by the parser
-
#eat?(expected_type : TokenType) : Bool
"Eat" the
@peektoken if the expected type matches the type of@peek -
#eat_error(expected_type : TokenType)
Add an error when
#eat?gets an incorrect token type -
#errors : Array(String)
Maintain an array of errors that are generated during the parsing step
-
#initialise_parsers
Initialize parser methods for the parser to use when parsing expressions
-
#next_token
Update the
@currentand@peekpointers contained in the Parser instance to the next token generated from theLexer -
#parse_block_statement : AST::BlockStatement?
Attempt to parse a block statement found at the current token, returning the node if possible, or nil if not
-
#parse_boolean_literal : AST::Expression
Parse a boolean found at the current token
boolean -
#parse_call_arguments : Array(AST::Expression)
Parse an argument list for a call expression
(expression*) -
#parse_call_expression(left : AST::Expression) : AST::Expression
Parse a call expression found at the current token
identifier argument_list -
#parse_expression(precedence : Precedence) : AST::Expression?
Attempt to parse an expression.
-
#parse_expression_statement : AST::ExpressionStatement?
Attempt to parse an expression statement found at the current token, returning the node if possible, or nil if not
-
#parse_function : AST::Function?
Attempt to parse a function found at the current token, returning the node if possible, or nil if not
def name((name: type)*) -> type block -
#parse_function_parameters : Array(AST::TypedIdentifier)?
Parse the parameter list for a function and return an array of
AST::TypedIdentifierinstances representing the parameters -
#parse_grouped_expression : AST::Expression?
Parse a grouped expression found at the current token
(expression) -
#parse_identifier : AST::Expression
Parse an identifier found at the current token
name -
#parse_if_statement(check_alternatives : Bool = true) : AST::IfStatement?
Attempt to parse an 'if' statement found at the current token, returning the node if possible, or nil if not.
-
#parse_infix_expression(left : AST::Expression) : AST::Expression
Parse an infix expression found at the current token
expression operator expression -
#parse_integer_literal : AST::Expression
Parse an integer found at the current token
integer -
#parse_let_statement : AST::Let?
Attempt to parse a
letstatement found at the current token, returning the node if possible, or nil if not -
#parse_prefix_expression : AST::Expression
Parse a prefix expression found at the current token
operator expression -
#parse_program : AST::Program
Parse a program and build a program node from it, and return it
-
#parse_return_statement : AST::Return?
Attempt to parse a
returnstatement found at the current token, returning the node if possible, or nil if not -
#parse_statement : AST::Statement?
Parse a statement found at
@currentand return it, or nil if no statement can be parsed -
#parse_typed_identifier : AST::TypedIdentifier?
Parse a typed identifier found at the current token
name: datatype -
#peek : Drizzle::Token
A pointer to the next token coming up in the stream.
-
#register_infix(token_type : TokenType, func : InfixParser)
Register a TokenType with a parser function that is run when the TokenType is discovered in a spot for infix notation
-
#register_prefix(token_type : TokenType, func : PrefixParser)
Register a TokenType with a parser function that is run when the TokenType is discovered in a spot for prefix notation
Constructor Detail
Instance Method Detail
"Eat" the @peek token if the expected type matches the type of @peek
Eating a token involves passing in the type of token that @peek is expected to be.
If it is the expected type, this method will advance the parser to the next token
Add an error when #eat? gets an incorrect token type
Update the @current and @peek pointers contained in the Parser instance to the next token generated from the Lexer
Attempt to parse a block statement found at the current token, returning the node if possible, or nil if not
Parse an argument list for a call expression
(expression*)
Parse a call expression found at the current token
identifier argument_list
Attempt to parse an expression. This method is given a current precedence to compare against when necessary.
Attempt to parse an expression statement found at the current token, returning the node if possible, or nil if not
Attempt to parse a function found at the current token, returning the node if possible, or nil if not
def name((name: type)*) -> type block
Parse the parameter list for a function and return an array of AST::TypedIdentifier instances representing the parameters
Parse a grouped expression found at the current token
(expression)
Attempt to parse an 'if' statement found at the current token, returning the node if possible, or nil if not.
The check_alternatives flag states whether the current call should check for elsif and else tokens. We can use this to parse elsif blocks recursively.
Parse an infix expression found at the current token
expression operator expression
Attempt to parse a let statement found at the current token, returning the node if possible, or nil if not
Parse a prefix expression found at the current token
operator expression
Attempt to parse a return statement found at the current token, returning the node if possible, or nil if not
Parse a statement found at @current and return it, or nil if no statement can be parsed
Parse a typed identifier found at the current token
name: datatype
A pointer to the next token coming up in the stream.
This is used to help guide what kind of node will be built from @current
Register a TokenType with a parser function that is run when the TokenType is discovered in a spot for infix notation
Register a TokenType with a parser function that is run when the TokenType is discovered in a spot for prefix notation