Yarnspinnex.Parser.Expression (yarnspinnex v0.3.0)

Copy Markdown View Source

Parses a Yarn expression (as found inside {...} interpolation, <<if ...>>, <<set ... = ...>>, and command arguments) into a small, plain data AST that Yarnspinnex.Interpreter evaluates against the cursor's variables. Tokenizing is delegated to Yarnspinnex.Parser.Lexer; this module only builds the AST from the resulting tokens.

Summary

Types

A bare number, string, or boolean evaluates to itself; everything else is a tagged tuple.

Functions

Parses expression source into an AST, raising on invalid syntax.

How tightly binary operator op binds: a higher number binds tighter.

ast and every expression nested inside it, outermost first.

Types

ast()

@type ast() ::
  number()
  | String.t()
  | boolean()
  | {:var, String.t()}
  | {:field, ast(), String.t()}
  | {:call, String.t(), [ast()]}
  | {:not, ast()}
  | {:neg, ast()}
  | {:binop, Yarnspinnex.Ops.operator(), ast(), ast()}

A bare number, string, or boolean evaluates to itself; everything else is a tagged tuple.

Functions

parse!(source)

@spec parse!(String.t()) :: ast()

Parses expression source into an AST, raising on invalid syntax.

precedence(op)

@spec precedence(Yarnspinnex.Ops.operator()) :: non_neg_integer()

How tightly binary operator op binds: a higher number binds tighter.

subexpressions(ast)

@spec subexpressions(ast()) :: [ast()]

ast and every expression nested inside it, outermost first.