From d65bc0e86215acac508080e8d69a9715b410518d Mon Sep 17 00:00:00 2001 From: Patrick LaFontaine <32135464+Pat-Lafon@users.noreply.github.com> Date: Tue, 26 Jul 2022 11:52:07 -0400 Subject: [PATCH 1/2] Richer Source Positions --- docs/lang/syntax.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/lang/syntax.md b/docs/lang/syntax.md index fd96691b4..b3171dbbe 100644 --- a/docs/lang/syntax.md +++ b/docs/lang/syntax.md @@ -124,11 +124,13 @@ 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": , "col": } } + { ..., "pos": {"row": , "col": }, + "end_pos": {"row": , "col": }?, + "src": ""? } -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. 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. From 6ce95893af7c9e803d271701acdbb6e52d30a14a Mon Sep 17 00:00:00 2001 From: Patrick LaFontaine <32135464+Pat-Lafon@users.noreply.github.com> Date: Tue, 26 Jul 2022 12:04:56 -0400 Subject: [PATCH 2/2] Add restriction on `pos_end` --- docs/lang/syntax.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/lang/syntax.md b/docs/lang/syntax.md index b3171dbbe..550e0a965 100644 --- a/docs/lang/syntax.md +++ b/docs/lang/syntax.md @@ -127,10 +127,11 @@ Source Positions Any syntax object may optionally have position fields to reflect a source position: { ..., "pos": {"row": , "col": }, - "end_pos": {"row": , "col": }?, + "pos_end": {"row": , "col": }?, "src": ""? } 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.