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 { Intensity } from "./Intensity";
@ -21,4 +21,5 @@ export type Interval = {
export type Comment = {
offset: Duration;
text: string;
loc: SourceLocation;
};

View File

@ -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,
},

View File

@ -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 {