Pantagruel v0.0.5 Pantagruel.Parse View Source

The parser takes a binary representing a Pantagruel program and constructs an AST. It expects the binary to have been preprocessed by the Scan module.

Link to this section Summary

Types

t()

A Pantagruel AST consists of a list of section nodes, each of which represent one section of the program delimited by the ; separator

Functions

Parses the given binary as expression

Parses the given binary as program

Link to this section Types

Link to this type body_stmt() View Source
body_stmt() :: {:expr, keyword()} | comment()
Link to this type combinator_resp() View Source
combinator_resp() ::
  {:ok, t(), binary(), map(), {pos_integer(), pos_integer()}, pos_integer()}
Link to this type comment() View Source
comment() :: {:comment, [binary()]}
Link to this type head_stmt() View Source
head_stmt() :: {:decl, keyword()} | {:alias, keyword()} | comment()
Link to this type section() View Source
section() :: [head: [head_stmt()], body: [body_stmt()]]

A Pantagruel AST consists of a list of section nodes, each of which represent one section of the program delimited by the ; separator.

A section has two components: the head and the body. The head contains declarations, either function declarations or domain alias declarations. The body contains expressions which should evaluate to true propositions about the program being described.

A section must have at least one statement in its head. The body is optional.

Link to this section Functions

Link to this function expression(binary, opts \\ []) View Source
expression(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: pos_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses the given binary as expression.

Returns {:ok, [token], rest, context, line, byte_offset} or {:error, reason, rest, context, line, byte_offset}.

Options

  • :line - the initial line, defaults to 1
  • :byte_offset - the initial byte offset, defaults to 0
  • :context - the initial context value. It will be converted to a map
Link to this function program(binary, opts \\ []) View Source
program(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: pos_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses the given binary as program.

Returns {:ok, [token], rest, context, line, byte_offset} or {:error, reason, rest, context, line, byte_offset}.

Options

  • :line - the initial line, defaults to 1
  • :byte_offset - the initial byte offset, defaults to 0
  • :context - the initial context value. It will be converted to a map