Struct leo_parser::parser::ParserContext[][src]

pub struct ParserContext { /* fields omitted */ }

Stores a program in tokenized format plus additional context. May be converted into a Program AST by parsing all tokens.

Implementations

impl ParserContext[src]

pub fn new(tokens: Vec<SpannedToken>) -> Self[src]

Returns a new ParserContext type given a vector of tokens.

pub fn eof(&self) -> SyntaxError[src]

Returns an unexpected end of function SyntaxError.

pub fn peek(&self) -> SyntaxResult<&SpannedToken>[src]

Returns a reference to the next token or error if it does not exist.

pub fn peek_token(&self) -> Cow<'_, Token>[src]

pub fn has_next(&self) -> bool[src]

Returns true if the next token exists.

pub fn eat(&mut self, token: Token) -> Option<SpannedToken>[src]

Removes the next token if it exists and returns it, or None if the next token does not exist.

pub fn backtrack(&mut self, token: SpannedToken)[src]

Appends a token to the back of the vector.

pub fn eat_identifier(&mut self) -> Option<Identifier>[src]

Removes the next token if it is a [Token::Ident(_)] and returns it, or None if the next token is not a [Token::Ident(_)] or if the next token does not exist.

pub fn eat_group_partial(
    &mut self
) -> Option<SyntaxResult<(GroupCoordinate, GroupCoordinate, Span)>>
[src]

Removes the next two tokens if they are a pair of GroupCoordinate and returns them, or None if the next token is not a GroupCoordinate.

pub fn eat_int(&mut self) -> Option<(PositiveNumber, Span)>[src]

Removes the next token if it is a [Token::Int(_)] and returns it, or None if the next token is not a [Token::Int(_)] or if the next token does not exist.

pub fn eat_any(&mut self, token: &[Token]) -> Option<SpannedToken>[src]

Removes the next token if it exists and returns it, or None if the next token does not exist.

pub fn expect(&mut self, token: Token) -> SyntaxResult<Span>[src]

Returns the span of the next token if it is equal to the given [Token], or error.

pub fn expect_oneof(&mut self, token: &[Token]) -> SyntaxResult<SpannedToken>[src]

Returns the span of the next token if it is equal to one of the given [Token]s, or error.

pub fn expect_loose_identifier(&mut self) -> SyntaxResult<Identifier>[src]

Returns the Identifier of the next token if it is a keyword, [Token::Int(_)], or an Identifier, or error.

pub fn expect_ident(&mut self) -> SyntaxResult<Identifier>[src]

Returns the Identifier of the next token if it is an Identifier, or error.

pub fn expect_any(&mut self) -> SyntaxResult<SpannedToken>[src]

Returns the next token if it exists or return end of function.

impl ParserContext[src]

pub fn parse_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next token is an expression. Includes circuit init expressions.

pub fn parse_conditional_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent a ternary expression. May or may not include circuit init expressions.

Otherwise, tries to parse the next token using [parse_disjunctive_expression].

pub fn parse_disjunctive_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent a binary or expression.

Otherwise, tries to parse the next token using [parse_conjunctive_expression].

pub fn parse_conjunctive_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent a binary and expression.

Otherwise, tries to parse the next token using [parse_bit_or_expression].

pub fn parse_equality_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent a binary bitwise or expression.

Otherwise, tries to parse the next token using [parse_bit_xor_expression].

Returns an Expression AST node if the next tokens represent a binary bitwise xor expression.

Otherwise, tries to parse the next token using [parse_bit_and_expression].

Returns an Expression AST node if the next tokens represent a binary bitwise and expression.

Otherwise, tries to parse the next token using [parse_equality_expression].

Returns an Expression AST node if the next tokens represent a binary equals or not equals expression.

Otherwise, tries to parse the next token using [parse_ordering_expression].

pub fn parse_ordering_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent a binary relational expression: less than, less than or equals, greater than, greater than or equals.

Otherwise, tries to parse the next token using [parse_shift_expression].

pub fn parse_additive_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent a binary shift expression.

Otherwise, tries to parse the next token using [parse_additive_expression].

Returns an Expression AST node if the next tokens represent a binary addition or subtraction expression.

Otherwise, tries to parse the next token using [parse_mul_div_pow_expression].

pub fn parse_multiplicative_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent a binary multiplication, division, or modulus expression.

Otherwise, tries to parse the next token using [parse_exponential_expression].

pub fn parse_exponential_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent a binary exponentiation expression.

Otherwise, tries to parse the next token using [parse_cast_expression].

pub fn parse_cast_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent a type cast expression.

Otherwise, tries to parse the next token using [parse_unary_expression].

pub fn parse_unary_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent a unary not, negate, or bitwise not expression.

Otherwise, tries to parse the next token using [parse_postfix_expression].

pub fn parse_postfix_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next tokens represent an array access, circuit member access, function call, or static function call expression.

Otherwise, tries to parse the next token using [parse_primary_expression].

pub fn parse_spread_or_expression(&mut self) -> SyntaxResult<SpreadOrExpression>[src]

Returns a SpreadOrExpression AST node if the next tokens represent an spread or expression.

This method should only be called in the context of an array access expression.

pub fn parse_circuit_expression(
    &mut self,
    identifier: Identifier
) -> SyntaxResult<Expression>
[src]

Returns an Expression AST node if the next tokens represent an circuit initialization expression.

pub fn parse_tuple_expression(
    &mut self,
    span: &Span
) -> SyntaxResult<Expression>
[src]

Returns an Expression AST node if the next tokens represent an tuple initialization expression.

pub fn parse_array_expression(
    &mut self,
    span: &Span
) -> SyntaxResult<Expression>
[src]

Returns an Expression AST node if the next tokens represent an array initialization expression.

pub fn parse_primary_expression(&mut self) -> SyntaxResult<Expression>[src]

Returns an Expression AST node if the next token is a primary expression:

  • Literals: field, group, unsigned integer, signed integer, boolean, address
  • Aggregate types: array, tuple
  • Identifiers: variables, keywords
  • self

Returns an expression error if the token cannot be matched.

impl ParserContext[src]

pub fn parse_program(&mut self) -> SyntaxResult<Program>[src]

Returns a Program AST if all tokens can be consumed and represent a valid Leo program.

pub fn parse_annotation(&mut self) -> SyntaxResult<Annotation>[src]

Returns an Annotation AST node if the next tokens represent a supported annotation.

pub fn parse_package_accesses(&mut self) -> SyntaxResult<Vec<PackageAccess>>[src]

Returns a vector of PackageAccess AST nodes if the next tokens represent package access expressions within an import statement.

pub fn parse_package_access(&mut self) -> SyntaxResult<PackageAccess>[src]

Returns a PackageAccess AST node if the next tokens represent a package access expression within an import statement.

pub fn parse_package_name(&mut self) -> SyntaxResult<Identifier>[src]

Returns an Identifier AST node if the next tokens represent a valid package name.

pub fn parse_package_path(&mut self) -> SyntaxResult<PackageOrPackages>[src]

Returns a PackageOrPackages AST node if the next tokens represent a valid package import with accesses.

pub fn parse_import(&mut self) -> SyntaxResult<ImportStatement>[src]

Returns a ImportStatement AST node if the next tokens represent an import statement.

pub fn parse_circuit_member(&mut self) -> SyntaxResult<CircuitMember>[src]

Returns a CircuitMember AST node if the next tokens represent a circuit member variable or circuit member function.

pub fn parse_circuit(&mut self) -> SyntaxResult<(Identifier, Circuit)>[src]

Returns an [(Identifier, Circuit)] tuple of AST nodes if the next tokens represent a circuit name and definition statement.

pub fn parse_function_parameters(&mut self) -> SyntaxResult<FunctionInput>[src]

Returns a FunctionInput AST node if the next tokens represent a function parameter.

pub fn parse_function_declaration(
    &mut self
) -> SyntaxResult<(Identifier, Function)>
[src]

Returns an [(Identifier, Function)] AST node if the next tokens represent a function name and function definition.

impl ParserContext[src]

pub fn construct_assignee_access(
    expr: Expression,
    accesses: &mut Vec<AssigneeAccess>
) -> SyntaxResult<Identifier>
[src]

Returns an Identifier AST node if the given Expression AST node evaluates to an identifier access. The access is stored in the given accesses.

pub fn construct_assignee(expr: Expression) -> SyntaxResult<Assignee>[src]

Returns an Assignee AST node from the given Expression AST node with accesses.

pub fn parse_statement(&mut self) -> SyntaxResult<Statement>[src]

Returns a Statement AST node if the next tokens represent a statement.

pub fn parse_assign_statement(&mut self) -> SyntaxResult<Statement>[src]

Returns a Block AST node if the next tokens represent a assign, or expression statement.

pub fn parse_block(&mut self) -> SyntaxResult<Block>[src]

Returns a Block AST node if the next tokens represent a block of statements.

pub fn parse_return_statement(&mut self) -> SyntaxResult<ReturnStatement>[src]

Returns a ReturnStatement AST node if the next tokens represent a return statement.

pub fn parse_conditional_statement(
    &mut self
) -> SyntaxResult<ConditionalStatement>
[src]

Returns a ConditionalStatement AST node if the next tokens represent a conditional statement.

pub fn parse_loop_statement(&mut self) -> SyntaxResult<IterationStatement>[src]

Returns an IterationStatement AST node if the next tokens represent an iteration statement.

pub fn parse_formatted_string(&mut self) -> SyntaxResult<FormatString>[src]

Returns a FormatString AST node if the next tokens represent a formatted string.

pub fn parse_console_statement(&mut self) -> SyntaxResult<ConsoleStatement>[src]

Returns a ConsoleStatement AST node if the next tokens represent a console statement.

pub fn parse_variable_name(
    &mut self,
    span: &SpannedToken
) -> SyntaxResult<VariableName>
[src]

Returns a VariableName AST node if the next tokens represent a variable name with valid keywords.

pub fn parse_definition_statement(
    &mut self
) -> SyntaxResult<DefinitionStatement>
[src]

Returns a DefinitionStatement AST node if the next tokens represent a definition statement.

impl ParserContext[src]

pub fn token_to_int_type(token: Token) -> Option<IntegerType>[src]

Returns a IntegerType AST node if the given token is a supported integer type, or None.

pub fn parse_array_dimensions(&mut self) -> SyntaxResult<ArrayDimensions>[src]

Returns an ArrayDimensions AST node if the next tokens represent dimensions for an array type.

pub fn parse_type(&mut self) -> SyntaxResult<(Type, Span)>[src]

Returns a [(Type, Span)] tuple of AST nodes if the next token represents a type. Also returns the span of the parsed token.

Trait Implementations

impl Iterator for ParserContext[src]

type Item = SpannedToken

The type of the elements being iterated over.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.