Sammal v0.1.0 Sammal.Parser View Source
A simple recursive parser for a Scheme-ish language.
Link to this section Summary
Types
All the parse_* functions adhere to the following pattern: {AST, tokens} -> {:ok, {new AST, remaining tokens}} | {:error, error struct}
A form consists of a list of expressions
Functions
Parser entrypoint
Parse all parenthesis-enclosed expressions
Parse a single parenthesis-enclosed expression
Parse the next atom or expression
Parse up to (and including) the given lexeme
Link to this section Types
All the parse_* functions adhere to the following pattern: {AST, tokens} -> {:ok, {new AST, remaining tokens}} | {:error, error struct}
A form consists of a list of expressions.
Link to this section Functions
parse([Sammal.Expr]) :: {:ok, cursor} | {:error, Sammal.SammalError}
Parser entrypoint.
Example
iex> {:ok, tokens} = Sammal.Tokenizer.tokenize(“(define (x 10))”) iex> {:ok, {[[define, [_var, _val]]], []}} = Sammal.Parser.parse(tokens) iex> define %Sammal.Expr{ctx: “(define (x 10))”, lex: “define”, line: 0, row: 1, val: :define}
Parse all parenthesis-enclosed expressions.
Parse a single parenthesis-enclosed expression.
Parse the next atom or expression.
Parse up to (and including) the given lexeme.