Skip to content

Commit

Permalink
Implement workaround for URI parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Patel committed Mar 2, 2020
1 parent 1284827 commit 8cdb073
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion grammar.abnf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ infixAssertion = attributePath SP infixAssertionOperator SP infixAssertionValue
infixAssertionOperator = "eq" / "ne" / "co" / "sw" / "ew" / "gt" / "lt" / "ge" / "le"
infixAssertionValue = null / true / false / number / string

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

; rfc7159
Expand Down
4 changes: 2 additions & 2 deletions grammar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Yard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TrackMap {
infixAssertionValue = [] as (null | boolean | number | string)[];
attributePath = [] as string[][];
attributePathSegment = [] as string[];
uri = [] as string[];
}

class Stat {
Expand All @@ -57,6 +58,7 @@ class Stat {
infixAssertionValue = 0 as number;
attributePath = 0 as number;
attributePathSegment = 0 as number;
uri = 0 as number;
}

class StatsMap {
Expand All @@ -77,6 +79,7 @@ class StatsMap {
infixAssertionValue = [] as Stat[];
attributePath = [] as Stat[];
attributePathSegment = [] as Stat[];
uri = [] as Stat[];
}

export class Yard {
Expand Down
8 changes: 5 additions & 3 deletions src/attributePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ export function attributePath(
break;

case ids.SEM_POST:
const { attributePathSegment } = yard.post("attributePath");
const { attributePathSegment, uri } = yard.post("attributePath");

if (attributePathSegment.length < 1) {
throw new Error(
`INVARIANT: Expected 1 or more attributePathSegment, but got ${attributePathSegment.length};`
);
}

yard.tracks.attributePath.push(attributePathSegment.reverse());
yard.tracks.attributePath.push([
...uri,
...attributePathSegment.reverse()
]);
break;
}

Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { infixAssertionOperator } from "./infixAssertionOperator";
import { infixAssertionValue } from "./infixAssertionValue";
import { attributePath } from "./attributePath";
import { attributePathSegment } from "./attributePathSegment";
import { uri } from "./uri";

const grammar = new Grammar();
const parser = new Parser();
Expand Down Expand Up @@ -54,7 +55,8 @@ parser.ast.callbacks = {
infixAssertionOperator,
infixAssertionValue,
attributePath,
attributePathSegment
attributePathSegment,
uri
};

export function compilePath(input: string): SimplePath | FilterPath {
Expand Down
23 changes: 23 additions & 0 deletions src/uri.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ids, utils } from "apg-lib";
import { Yard } from "./Yard";

export function uri(
state: typeof ids.SEM_PRE | typeof ids.SEM_POST,
chars: number[],
phraseIndex: number,
phraseLength: number,
yard: Yard
): typeof ids.SEM_OK | typeof ids.SEM_SKIP {
switch (state) {
case ids.SEM_PRE:
break;

case ids.SEM_POST:
yard.tracks.uri.push(
utils.charsToString(chars, phraseIndex, phraseLength)
);
break;
}

return ids.SEM_OK;
}

0 comments on commit 8cdb073

Please sign in to comment.