LambdaGrammar

class LambdaGrammar : Grammar<ParsedLambda>

Grammar that parses a lambda expression.

A lambda has the form param1 param2?: body content, where the header (param1 param2?:) defines parameters and the body is everything after the delimiter.

Parameters are word-character identifiers, optionally suffixed with ? to mark them as optional. The delimiter is a colon (:).

If the header cannot be parsed (i.e. no valid parameter-delimiter sequence is found), the entire input is treated as a body with no parameters.

The grammar is context-aware: while parsing the header, normal tokens (parameter names, whitespace, etc.) are matched individually. Once the delimiter is matched, a stateful body token activates and captures the entire remaining input in one shot.

See also

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open val declaredParsers: Set<Parser<*>>
Link copied to clipboard
open override val rootParser: Parser<ParsedLambda>

Entry point: one or more whitespace-separated parameters, a delimiter, and the remaining body.

Link copied to clipboard
open val tokenizer: Tokenizer
Link copied to clipboard
open val tokens: List<Token>

Functions

Link copied to clipboard
override fun tryParse(tokens: TokenMatchesSequence, fromPosition: Int): ParseResult<ParsedLambda>