Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grammar.abnf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 *("." attributePathSegment)
attributePath = [URI "<"] attributePathSegment *1("." attributePathSegment)
attributePathSegment = ALPHA *("-" / "_" / DIGIT / ALPHA)

; rfc7159
Expand Down
6 changes: 3 additions & 3 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 @@ -24,6 +24,7 @@ class TrackMap {
infixAssertionValue = [] as (null | boolean | number | string)[];
attributePath = [] as string[][];
attributePathSegment = [] as string[];
uri = [] as string[];
}

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

class StatsMap {
Expand All @@ -62,6 +64,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
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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 All @@ -39,7 +40,8 @@ parser.ast.callbacks = {
infixAssertionOperator,
infixAssertionValue,
attributePath,
attributePathSegment
attributePathSegment,
uri
};

export function compileFilter(input: string): (data: any) => boolean {
Expand All @@ -63,6 +65,10 @@ export function compileFilter(input: string): (data: any) => boolean {
}

export function parseAttributePath(input: string): string[] {
// TODO -- sanitize `input` such that the last occurrence of ":" is replaced with a "<"
// e.g. "my:urn:here:some.attrPath" -> "my:urn:here<some.attrPath"
// This is hacky, but would allow us to support parsing URIs from attributePaths.

Copy link
Author

@jaylattice jaylattice Mar 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a temporary hacky fix until we figure out what's wrong with apg-lib, but I think there would need to be similar sanitizations for compileFilter, compilePatchPath, etc.

// Parse the attributePath
const parseResult = parser.parse(grammar, "attributePath", input);
if (!parseResult.success) {
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;
}