Rollex.Token protocol (Rollex v0.12.0)

View Source

Summary

Functions

Create a token from the passed-in string representing a roll expression. Returns a token and the number of bytes consumed in doing so.

The left binding power (lbp), or the precedence in infix form for operator precedence. Higher lbp takes precedence over lower

Left denotation (led): take action when this token is encountered within an expression, e.g. infix and postfix operations

Null denotation (nud): the action take when this token is at the start of an expression, e.g. prefix operations

Types

t()

@type t() :: term()

Functions

create(token, roll_expr, matches)

@spec create(Rollex.token(), roll_expr :: String.t(), matches :: [String.t()] | nil) ::
  {Rollex.token(), num_bytes_consumed :: integer()}

Create a token from the passed-in string representing a roll expression. Returns a token and the number of bytes consumed in doing so.

lbp(token)

@spec lbp(Rollex.token()) :: integer()

The left binding power (lbp), or the precedence in infix form for operator precedence. Higher lbp takes precedence over lower

led(token, left, rest)

@spec led(Rollex.token(), left :: Rollex.totals(), rest :: Rollex.tokens()) ::
  {:ok, Rollex.totals(), Rollex.tokens()} | {:error, reason :: String.t()}

Left denotation (led): take action when this token is encountered within an expression, e.g. infix and postfix operations

nud(token, rest)

@spec nud(Rollex.token(), rest :: Rollex.tokens()) ::
  {:ok, Rollex.totals(), Rollex.tokens()} | {:error, reason :: String.t()}

Null denotation (nud): the action take when this token is at the start of an expression, e.g. prefix operations