Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
fix compass AST
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiazya committed Jun 30, 2021
1 parent 836b3ff commit dae89c2
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 226 deletions.
14 changes: 13 additions & 1 deletion grammar/dot.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ _subgraph
: { type: 'subgraph', body, location: location() };
}

_compass
_compass_keyword
= "n"
/ "ne"
/ "e"
Expand All @@ -167,6 +167,18 @@ _compass
/ "w"
/ "nw"

_compass
= v:(
value:_compass_keyword { return { value, quoted: false }; }
/ "\"" value:_compass_keyword "\"" { return { value, quoted: true }; }
) {
return {
type: 'literal',
...v,
location: location(),
};
}

_literal
= QUOTED_STRING
/ HTML_STRING
Expand Down
2 changes: 1 addition & 1 deletion src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export namespace AST {
type: typeof Types.NodeRef;
id: Literal;
port?: Literal;
commpass?: Literal<Compass>;
compass?: Literal<Compass>;
}

/** Edge AST object. */
Expand Down
4 changes: 2 additions & 2 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function applyStatements(cluster: ICluster, statements: AST.ClusterStatement[]):
case AST.Types.Edge:
commentHolder.apply(
cluster.edge(
stmt.targets.map((t) => ({ id: t.id.value, port: t.port?.value, compass: t.commpass?.value })),
stmt.targets.map((t) => ({ id: t.id.value, port: t.port?.value, compass: t.compass?.value })),
stmt.body.reduce((prev, curr) => ({ ...prev, [curr.key.value]: curr.value.value }), {}),
),
stmt.location,
Expand Down Expand Up @@ -103,7 +103,7 @@ export function convert(
return subgraph;
case AST.Types.Edge:
const edge = new Edge(
ast.targets.map((t) => ({ id: t.id.value, port: t.port?.value, compass: t.commpass?.value })),
ast.targets.map((t) => ({ id: t.id.value, port: t.port?.value, compass: t.compass?.value })),
ast.body.reduce((prev, curr) => ({ ...prev, [curr.key.value]: curr.value.value }), {}),
);
return edge;
Expand Down
Loading

0 comments on commit dae89c2

Please sign in to comment.