Add source location data to comments

This commit is contained in:
Rene Saarsoo 2020-11-21 21:01:40 +02:00
parent 1a720c2b21
commit 2f7b11d4ac
3 changed files with 31 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import { IntervalType } from "./parser/tokenizer"; import { IntervalType, SourceLocation } from "./parser/tokenizer";
import { Duration } from "./Duration"; import { Duration } from "./Duration";
import { Intensity } from "./Intensity"; import { Intensity } from "./Intensity";
@ -21,4 +21,5 @@ export type Interval = {
export type Comment = { export type Comment = {
offset: Duration; offset: Duration;
text: string; text: string;
loc: SourceLocation;
}; };

View File

@ -458,30 +458,50 @@ Rest: 5:00 50%
"cadence": undefined, "cadence": undefined,
"comments": Array [ "comments": Array [
Object { Object {
"loc": Object {
"col": 4,
"row": 3,
},
"offset": Duration { "offset": Duration {
"seconds": 0, "seconds": 0,
}, },
"text": "Find your rythm.", "text": "Find your rythm.",
}, },
Object { Object {
"loc": Object {
"col": 4,
"row": 4,
},
"offset": Duration { "offset": Duration {
"seconds": 60, "seconds": 60,
}, },
"text": "Try to settle in for the effort", "text": "Try to settle in for the effort",
}, },
Object { Object {
"loc": Object {
"col": 4,
"row": 6,
},
"offset": Duration { "offset": Duration {
"seconds": 300, "seconds": 300,
}, },
"text": "Half way through", "text": "Half way through",
}, },
Object { Object {
"loc": Object {
"col": 4,
"row": 8,
},
"offset": Duration { "offset": Duration {
"seconds": 540, "seconds": 540,
}, },
"text": "Almost there", "text": "Almost there",
}, },
Object { Object {
"loc": Object {
"col": 4,
"row": 9,
},
"offset": Duration { "offset": Duration {
"seconds": 570, "seconds": 570,
}, },
@ -500,12 +520,20 @@ Rest: 5:00 50%
"cadence": undefined, "cadence": undefined,
"comments": Array [ "comments": Array [
Object { Object {
"loc": Object {
"col": 4,
"row": 12,
},
"offset": Duration { "offset": Duration {
"seconds": 0, "seconds": 0,
}, },
"text": "Great effort!", "text": "Great effort!",
}, },
Object { Object {
"loc": Object {
"col": 4,
"row": 13,
},
"offset": Duration { "offset": Duration {
"seconds": 30, "seconds": 30,
}, },

View File

@ -74,6 +74,7 @@ const parseIntervalComments = (tokens: Token[]): [Comment[], Token[]] => {
comments.push({ comments.push({
offset: new Duration(offset.value), offset: new Duration(offset.value),
text: text.value, text: text.value,
loc: offset.loc,
}); });
tokens = rest; tokens = rest;
} else { } else {