From 2f7b11d4ac61f120823777a19af7a2bc4056a448 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Sat, 21 Nov 2020 21:01:40 +0200 Subject: [PATCH] Add source location data to comments --- src/ast.ts | 3 ++- src/parser/parser.test.ts | 28 ++++++++++++++++++++++++++++ src/parser/parser.ts | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ast.ts b/src/ast.ts index a72cdc3..716bec6 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1,4 +1,4 @@ -import { IntervalType } from "./parser/tokenizer"; +import { IntervalType, SourceLocation } from "./parser/tokenizer"; import { Duration } from "./Duration"; import { Intensity } from "./Intensity"; @@ -21,4 +21,5 @@ export type Interval = { export type Comment = { offset: Duration; text: string; + loc: SourceLocation; }; diff --git a/src/parser/parser.test.ts b/src/parser/parser.test.ts index 28a437e..c28e4a9 100644 --- a/src/parser/parser.test.ts +++ b/src/parser/parser.test.ts @@ -458,30 +458,50 @@ Rest: 5:00 50% "cadence": undefined, "comments": Array [ Object { + "loc": Object { + "col": 4, + "row": 3, + }, "offset": Duration { "seconds": 0, }, "text": "Find your rythm.", }, Object { + "loc": Object { + "col": 4, + "row": 4, + }, "offset": Duration { "seconds": 60, }, "text": "Try to settle in for the effort", }, Object { + "loc": Object { + "col": 4, + "row": 6, + }, "offset": Duration { "seconds": 300, }, "text": "Half way through", }, Object { + "loc": Object { + "col": 4, + "row": 8, + }, "offset": Duration { "seconds": 540, }, "text": "Almost there", }, Object { + "loc": Object { + "col": 4, + "row": 9, + }, "offset": Duration { "seconds": 570, }, @@ -500,12 +520,20 @@ Rest: 5:00 50% "cadence": undefined, "comments": Array [ Object { + "loc": Object { + "col": 4, + "row": 12, + }, "offset": Duration { "seconds": 0, }, "text": "Great effort!", }, Object { + "loc": Object { + "col": 4, + "row": 13, + }, "offset": Duration { "seconds": 30, }, diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 64ee767..4c9876f 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -74,6 +74,7 @@ const parseIntervalComments = (tokens: Token[]): [Comment[], Token[]] => { comments.push({ offset: new Duration(offset.value), text: text.value, + loc: offset.loc, }); tokens = rest; } else {