From fa8f0c70ad5a35b8208bd32a4c823bf8b97a790a Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Mon, 21 Sep 2020 22:19:52 +0300 Subject: [PATCH] Add comments support to AST --- src/ast.ts | 6 ++++++ src/parser/parser.test.ts | 10 ++++++++++ src/parser/parser.ts | 1 + 3 files changed, 17 insertions(+) diff --git a/src/ast.ts b/src/ast.ts index d820f9a..5ae4a18 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -12,4 +12,10 @@ export type Interval = { duration: number; intensity: { from: number; to: number }; cadence?: number; + comments: Comment[]; +}; + +export type Comment = { + offset: number; + text: string; }; diff --git a/src/parser/parser.test.ts b/src/parser/parser.test.ts index 79c10ec..eda154e 100644 --- a/src/parser/parser.test.ts +++ b/src/parser/parser.test.ts @@ -61,6 +61,7 @@ Rest: 5:00 45% Array [ Object { "cadence": undefined, + "comments": Array [], "duration": 300, "intensity": Object { "from": 0.5, @@ -70,6 +71,7 @@ Rest: 5:00 45% }, Object { "cadence": 90, + "comments": Array [], "duration": 600, "intensity": Object { "from": 0.8, @@ -79,6 +81,7 @@ Rest: 5:00 45% }, Object { "cadence": undefined, + "comments": Array [], "duration": 300, "intensity": Object { "from": 0.45, @@ -102,6 +105,7 @@ Cooldown: 5:30 70%..45% Array [ Object { "cadence": 100, + "comments": Array [], "duration": 330, "intensity": Object { "from": 0.5, @@ -111,6 +115,7 @@ Cooldown: 5:30 70%..45% }, Object { "cadence": undefined, + "comments": Array [], "duration": 330, "intensity": Object { "from": 0.7, @@ -140,6 +145,7 @@ Cooldown: 5:30 70%..45% expect(parseInterval("Interval: 50% 00:10")).toMatchInlineSnapshot(` Object { "cadence": undefined, + "comments": Array [], "duration": 10, "intensity": Object { "from": 0.5, @@ -151,6 +157,7 @@ Cooldown: 5:30 70%..45% expect(parseInterval("Interval: 50% 100rpm 00:10")).toMatchInlineSnapshot(` Object { "cadence": 100, + "comments": Array [], "duration": 10, "intensity": Object { "from": 0.5, @@ -162,6 +169,7 @@ Cooldown: 5:30 70%..45% expect(parseInterval("Interval: 100rpm 00:10 50%")).toMatchInlineSnapshot(` Object { "cadence": 100, + "comments": Array [], "duration": 10, "intensity": Object { "from": 0.5, @@ -176,6 +184,7 @@ Cooldown: 5:30 70%..45% expect(parseInterval("Interval: 50% 00:10 100rpm")).toMatchInlineSnapshot(` Object { "cadence": 100, + "comments": Array [], "duration": 10, "intensity": Object { "from": 0.5, @@ -187,6 +196,7 @@ Cooldown: 5:30 70%..45% expect(parseInterval("Interval: \t 50% \t 00:10 \t\t 100rpm \t")).toMatchInlineSnapshot(` Object { "cadence": 100, + "comments": Array [], "duration": 10, "intensity": Object { "from": 0.5, diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 0d1d7b6..a736a4c 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -95,6 +95,7 @@ const parseIntervals = (tokens: Token[]): Interval[] => { duration, intensity, cadence, + comments: [], }); tokens = rest; } else if (token.type === "text" && token.value === "") {