Current section

Files

Jump to
ergo lib ergo AST.md
Raw

lib/ergo/AST.md

What happens to the AST
Ergo parsers get passed a `Context` structure and return a `Context` structure.
The `Context` manages quite a lot of information
* id: nil
* created_at: nil,
* status: :ok,
* serial: 0,
* input: "",
* consumed: "",
* index: 0,
* line: 1,
* col: 1,
* entry_points: [],
* data: %{},
* ast: nil,
* parser: nil,
* tracks: MapSet.new(),
* depth: 0,
* parsers: [],
* committed: false
Of particular importance to us are the `ast` and `index`, `line`, and `col`
fields.
As parsing goes forwards `index` (and consequently the `line` and `col`) will
increase. A parser backtracking will reset the `index` (`line` & `col`) to
earlier values.
Whenever a parser returns it sets the `ast` of the `Context` to the value it
wants to return or, potentially, to `nil` meaning (no value, the `ignore`
parser returns `nil` for example).
The different parsers take different approaches.
many
choice
sequence
ignore
optional