Parser
An executable parser of Leo.
If you are looking for API functions for calling the Leo parser,
please see parser-interface. The following section describes
the process of parsing a list of tokens into a CST.
This is a fairly simple parser for the Leo syntactic grammar.
Efficiency is not the primary focus for now;
correctness and simplicity are.
In the future, we may optimize this parser,
or we may use APT to do so.
The parser consists of a collection of parsing functions
that operate on a sequence of tokens.
Most parsing functions take a lookahead token (an optional
ABNF tree) and a sequence of the remaining tokens (list of
ABNF trees).
Each ABNF tree in the sequence of tokens
(and the lookahead token) should have a rulename
from the right hand side of the ABNF rule for token
indicating the kind of token it is:
token = keyword
/ identifier
/ atomic-literal
/ numeral
/ annotation
/ symbol
All the parsing functions return, as first result,
an ABNF tree or list of trees
that represents the parsed input.
This is called a CST (Concrete Syntax Tree).
Almost all the parsing functions also return
the next unparsed token and the tokens that follow it.
That is, they prefetch the token, so it is ready for the next function.
If the end of the input is reached, the next token is nil
(and so is the list of tokens after it).
Subtopics
- Parse-symbol-among
- Parse a symbol among the ones in a specified list.
- Parse-keyword
- Parse a specified keyword.
- Parse-named-primitive-type
- Parse a named-primitive-type.
- Parse-rest-of-struct-component-expression
- Parse the rest of a struct-component-expression.
- Parse-rest-of-tuple-component-expression
- Parse the rest of a tuple-component-expression.
- Parse-transition-declaration
- Parse a transition-declaration.
- Parse-named-type-as-identifier-?-dot-record
- Parse the named-type alternative identifier [ "." %s"record" ].
- Parse-named-type-as-locator-?-dot-record
- Parse the named-type alternative locator [ "." %s"record" ].
- Parse-assert-not-equal-call
- Parse an assert-not-equal-call.
- Parse-symbol
- Parse a specified symbol.
- Parse-struct-component-declarations
- Parse a struct-component-declarations.
- Parse-assert-equal-call
- Parse an assert-equal-call.
- Parse-transition-or-function-declaration
- Parse either a transition-declaration or a function-declaration.
- Parse-string-literal
- Parse a string-literal.
- Parse-group-coordinate
- Parse a group-coordinate.
- Parse-function-declaration
- Parse a function-declaration.
- Parse-finalizer
- Parse a finalize block.
- Parse-*-comma-struct-component-declaration
- Parse a *( "," struct-component-declaration ).
- Parse-increment-statement
- Parse a increment-statement.
- Parse-function-parameter
- Parse a function-parameter.
- Parse-decrement-statement
- Parse a decrement-statement.
- Parse-struct-component-declaration
- Parse a struct-component-declaration.
- Parse-variable-declaration
- Parse a variable-declaration.
- Parse-mapping-declaration
- Parse a mapping-declaration.
- Parse-function-parameters
- Parse a function-parameters.
- Parse-constant-declaration
- Parse a constant-declaration.
- Parse-assert-call
- Parse an assert-call.
- Parse-*-comma-function-parameter
- Parse a *( "," function-parameter ).
- Parse-program-declaration
- Parse an program-declaration.
- Parse-affine-group-literal
- Parse an affine-group-literal.
- Parse-variable-or-free-constant
- Parse a variable-or-free-constant.
- Parse-struct-declaration
- Parse a struct-declaration.
- Parse-record-declaration
- Parse a record-declaration.
- Parse-finalize-statement
- Parse a finalize-statement.
- Parse-associated-constant
- Parse a associated-constant.
- Parse-numeral
- Parse a numeral token.
- Parse-import-declaration
- Parse an import-declaration.
- Parse-identifier
- Parse an identifier.
- Parse-console-statement
- Parse a console-statement.
- Parse-annotation
- Parse an annotation.
- Parse-return-statement
- Parse a return-statement.
- Parse-program-item
- Parse a program-item.
- Parse-assignment-operator
- Parse an assignment-operator.
- Parse-*-import-declaration
- Parse a *import-declaration.
- Parse-unit-expression
- Parse a unit-expression.
- Parse-named-type
- Parse a named-type.
- Parse-console-call
- Parse a console-call.
- Parse-*-comma-natural
- Parse a *( "," natural ).
- Parse-program-id
- Parse an program-id.
- Parse-atomic-literal
- Parse an atomic-literal.
- Parse-?-output-type
- Parse [ "->" type ].
- Parse-unit-type
- Parse a unit-type.
- Parse-*-program-item
- Parse a *program-item.
- Parse-locator
- Parse a locator.
- Parse-?-finalizer
- Parse a [ finalizer ].
- Parse-*-annotation
- Parse a *annotation.
- Parse-primary-expression
- Parse a primary-expression.
- Parse-literal
- Parse a literal.
- Parse-?-comma
- Parse a [ "," ].
- Parse-file
- Parse a file.
- Parsize
- Size of the parser input.
- Check-token-string
- Check if the given token is present
and has the given string as fringe.
- Check-token-root
- Check if the given token is present
and has the given rule name as root.
- Parse-postfix-expression-rest
- Parse the rest of a postfix-expression.
- Parse-postfix-expression
- Parse a postfix-expression.
- Parse-token
- Parse a token.
- Token-stringp
- Check if the given token has the given string as fringe.
- Token-rootp
- Check if the given token has the given rule name as root.
- Patbind-pok<
- b* binder for checking and propagating
error results of parsing functions and ensuring termination.
- Parse-rest-of-operator-call
- Parse the rest of an operator-call.
- Parse-exclusive-disjunctive-expression-rest
- Parse the rest of a exclusive-disjunctive-expression.
- Parse-conditional-disjunctive-expression-rest
- Parse the rest of a conditional-disjunctive-expression.
- Parse-conditional-conjunctive-expression-rest
- Parse the rest of a conditional-conjunctive-expression.
- Parse-shift-expression-rest
- Parse the rest of a shift-expression.
- Parse-multiplicative-expression-rest
- Parse the rest of a multiplicative-expression.
- Parse-disjunctive-expression-rest
- Parse the rest of a disjunctive-expression.
- Parse-conjunctive-expression-rest
- Parse the rest of a conjunctive-expression.
- Parse-additive-expression-rest
- Parse the rest of an additive-expression.
- Parse-*-statement
- Parse a *statement.
- Parse-*-comma-type
- Parse a *( "," type ).
- Parse-*-comma-struct-component-initializer
- Parse a *( "," struct-component-initializer ).
- Parse-*-comma-expression
- Parse a *( "," expression ).
- Parse-unary-expression
- Parse a unary-expression.
- Parse-tuple-expression
- Parse a tuple-expression.
- Parse-struct-expression
- Parse a struct-expression.
- Parse-struct-component-initializer
- Parse a struct-component-initializer.
- Parse-static-function-call
- Parse a static-function-call.
- Parse-shift-expression
- Parse a shift-expression.
- Parse-ordering-expression
- Parse an ordering-expression.
- Parse-multiplicative-expression
- Parse a multiplicative-expression.
- Parse-function-arguments
- Parse a function-arguments.
- Parse-free-function-call
- Parse a free-function-call.
- Parse-exponential-expression
- Parsen an exponential-expression.
- Parse-exclusive-disjunctive-expression
- Parse a exclusive-disjunctive-expression.
- Parse-equality-expression
- Parse an equality-expression.
- Parse-disjunctive-expression
- Parse a disjunctive-expression.
- Parse-conjunctive-expression
- Parse a conjunctive-expression.
- Parse-conditional-ternary-expression
- Parse a conditional-ternary-expression.
- Parse-conditional-statement
- Parse a conditional-statement.
- Parse-conditional-disjunctive-expression
- Parse a conditional-disjunctive-expression.
- Parse-conditional-conjunctive-expression
- Parse a conditional-conjunctive-expression.
- Parse-binary-expression
- Parse a binary-expression.
- Parse-additive-expression
- Parse an additive-expression.
- Parse-type
- Parse a type.
- Parse-tuple-type
- Parse a tuple-type.
- Parse-statement
- Parse a statement.
- Parse-loop-statement
- Parse a loop-statement.
- Parse-expression
- Parse an expression.
- Parse-branch
- Parse a branch.
- Parse-block
- Parse a block.
- Patbind-pok
- b* binder for checking and propagating
error results of parsing functions.
- Perr
- Returning a parsing error.