Skip to content

Commit

Permalink
Merge pull request #232 from Pat-Lafon/main
Browse files Browse the repository at this point in the history
Richer Source Positions
  • Loading branch information
sampsyo authored Jul 30, 2022
2 parents 2002252 + 6ce9589 commit 732f63f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions docs/lang/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ It also has the optional `args`, `funcs`, and `labels` fields.
Source Positions
----------------

Any syntax object may optionally have a `pos` field to reflect a source position:
Any syntax object may optionally have position fields to reflect a source position:

{ ..., "pos": {"row": <int>, "col": <int>} }
{ ..., "pos": {"row": <int>, "col": <int>},
"pos_end": {"row": <int>, "col": <int>}?,
"src": "<string>"? }

The `pos` object has two keys: `row` (the line number) and `col` (the column number within the line).
The `pos` and `pos_end` objects have two keys: `row` (the line number) and `col` (the column number within the line). The `src` object can optionally provide the absolute path to a file which is referenced to by the source position.
If `pos_end` is provided, it must be equal to or greater than `pos`.
Front-end compilers that generate Bril code may add this information to help with debugging.
The [text format parser](../tools/text.md), for example, can optionally add source positions.
However, tools can't require positions to exist, to consistently exist or not on all syntax objects in a program, or to follow any particular rules.

0 comments on commit 732f63f

Please sign in to comment.