Skip to content

Commit 8cdb073

Browse files
author
Jay Patel
committed
Implement workaround for URI parsing
1 parent 1284827 commit 8cdb073

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

grammar.abnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ infixAssertion = attributePath SP infixAssertionOperator SP infixAssertionValue
2222
infixAssertionOperator = "eq" / "ne" / "co" / "sw" / "ew" / "gt" / "lt" / "ge" / "le"
2323
infixAssertionValue = null / true / false / number / string
2424

25-
attributePath = [URI ":"] attributePathSegment *1("." attributePathSegment)
25+
attributePath = [URI "<"] attributePathSegment *1("." attributePathSegment)
2626
attributePathSegment = ALPHA *("-" / "_" / DIGIT / ALPHA)
2727

2828
; rfc7159

grammar.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Yard.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class TrackMap {
3737
infixAssertionValue = [] as (null | boolean | number | string)[];
3838
attributePath = [] as string[][];
3939
attributePathSegment = [] as string[];
40+
uri = [] as string[];
4041
}
4142

4243
class Stat {
@@ -57,6 +58,7 @@ class Stat {
5758
infixAssertionValue = 0 as number;
5859
attributePath = 0 as number;
5960
attributePathSegment = 0 as number;
61+
uri = 0 as number;
6062
}
6163

6264
class StatsMap {
@@ -77,6 +79,7 @@ class StatsMap {
7779
infixAssertionValue = [] as Stat[];
7880
attributePath = [] as Stat[];
7981
attributePathSegment = [] as Stat[];
82+
uri = [] as Stat[];
8083
}
8184

8285
export class Yard {

src/attributePath.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ export function attributePath(
1414
break;
1515

1616
case ids.SEM_POST:
17-
const { attributePathSegment } = yard.post("attributePath");
17+
const { attributePathSegment, uri } = yard.post("attributePath");
1818

1919
if (attributePathSegment.length < 1) {
2020
throw new Error(
2121
`INVARIANT: Expected 1 or more attributePathSegment, but got ${attributePathSegment.length};`
2222
);
2323
}
24-
25-
yard.tracks.attributePath.push(attributePathSegment.reverse());
24+
yard.tracks.attributePath.push([
25+
...uri,
26+
...attributePathSegment.reverse()
27+
]);
2628
break;
2729
}
2830

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { infixAssertionOperator } from "./infixAssertionOperator";
2020
import { infixAssertionValue } from "./infixAssertionValue";
2121
import { attributePath } from "./attributePath";
2222
import { attributePathSegment } from "./attributePathSegment";
23+
import { uri } from "./uri";
2324

2425
const grammar = new Grammar();
2526
const parser = new Parser();
@@ -54,7 +55,8 @@ parser.ast.callbacks = {
5455
infixAssertionOperator,
5556
infixAssertionValue,
5657
attributePath,
57-
attributePathSegment
58+
attributePathSegment,
59+
uri
5860
};
5961

6062
export function compilePath(input: string): SimplePath | FilterPath {

src/uri.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ids, utils } from "apg-lib";
2+
import { Yard } from "./Yard";
3+
4+
export function uri(
5+
state: typeof ids.SEM_PRE | typeof ids.SEM_POST,
6+
chars: number[],
7+
phraseIndex: number,
8+
phraseLength: number,
9+
yard: Yard
10+
): typeof ids.SEM_OK | typeof ids.SEM_SKIP {
11+
switch (state) {
12+
case ids.SEM_PRE:
13+
break;
14+
15+
case ids.SEM_POST:
16+
yard.tracks.uri.push(
17+
utils.charsToString(chars, phraseIndex, phraseLength)
18+
);
19+
break;
20+
}
21+
22+
return ids.SEM_OK;
23+
}

0 commit comments

Comments
 (0)