OpenUI.Parser.Expression (OpenUI v0.1.1)

Copy Markdown View Source

Parses tokens into an expression tree (language.md, sections 1.5 and 1.6) by precedence climbing, and classifies statements (section 2.1).

Like the lexer, parsing never fails: a token that cannot start an operand reads as null, a missing closer is assumed, and tokens left after a complete expression are dropped.

Summary

Functions

Parses one expression from tokens.

Parses the source of one statement. Returns nil when the text does not have the name = expression shape.

Types

ast()

@type ast() ::
  {:string, String.t()}
  | {:number, number()}
  | {:boolean, boolean()}
  | :null
  | {:array, [ast()]}
  | {:object, [{String.t(), ast()}]}
  | {:ref, String.t()}
  | {:state, String.t()}
  | {:component, String.t(), [ast()]}
  | {:call, String.t(), [ast()]}
  | {:binary, String.t(), ast(), ast()}
  | {:unary, String.t(), ast()}
  | {:ternary, ast(), ast(), ast()}
  | {:member, ast(), String.t()}
  | {:index, ast(), ast()}
  | {:assign, String.t(), ast()}
  | {:unresolved, String.t()}
  | {:runtime_ref, String.t(), :query | :mutation}

Functions

parse(tokens)

@spec parse([OpenUI.Parser.Lexer.token()]) :: ast()

Parses one expression from tokens.

parse_statement(source)

@spec parse_statement(String.t()) :: OpenUI.Statement.t() | nil

Parses the source of one statement. Returns nil when the text does not have the name = expression shape.