Skip to content

Commit

Permalink
removed badly formed sample files; tweaked gram-cli stat output to be…
Browse files Browse the repository at this point in the history
… a valid gram graph node
  • Loading branch information
akollegger committed May 6, 2024
1 parent 287d4fe commit f21f4ee
Show file tree
Hide file tree
Showing 21 changed files with 30 additions and 243 deletions.
21 changes: 19 additions & 2 deletions packages/gram/src/lib/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ export type GramCstRelationshipTypeTag =
"squiggle_left";


export type GramSemanticElementTypeTag = "node" | GramCstRelationshipTypeTag;
export type GramSemanticElementTypeTag =
"pattern" |
"node" |
"relationship" |
"record" |
"identifier" |
"labels" |
GramCstRelationshipTypeTag;

export type GramSyntaxElementTypeTag = GramSemanticElementTypeTag;

Expand All @@ -48,7 +55,11 @@ export interface GramSyntaxNode extends Parser.SyntaxNode {
export type GramStats = Partial<Record<GramSemanticElementTypeTag, number>>;

export const emptyStats:GramStats = {
// pattern: 0,
// relationship: 0,
// record: 0,
// node: 0,
// identifier: 0,
// single_undirected: 0,
// single_bidirectional: 0,
// single_right: 0,
Expand Down Expand Up @@ -78,7 +89,10 @@ export const isGramSemanticElement = (o:unknown):o is GramSyntaxNode => {
return false;
}
switch (o.type) {
case "pattern":
case "node":
case "relationship":
case "record":
case "single_undirected":
case "single_bidirectional":
case "single_right":
Expand All @@ -91,6 +105,8 @@ export const isGramSemanticElement = (o:unknown):o is GramSyntaxNode => {
case "squiggle_bidirectional":
case "squiggle_right":
case "squiggle_left":
case "labels":
case "identifier":
return true;
default:
return false;
Expand All @@ -103,7 +119,8 @@ export const stats = (cst:GramSyntaxNode) => reduce(cst, (cst, acc) => {
isGramSemanticElement(cst) ? Option.some(cst) : Option.none(),
Option.map((cst) => ({
...acc,
[cst.type]: (acc[cst.type] ?? 0) + 1,
[cst.type]: (acc[cst.type] ?? 0) +
((cst.type === "labels") ? cst.namedChildCount : 1)
})),
Option.getOrElse(() => acc)
)
Expand Down
3 changes: 0 additions & 3 deletions samples/double_arrows00.gram-e

This file was deleted.

20 changes: 0 additions & 20 deletions samples/double_arrows12.gram

This file was deleted.

9 changes: 0 additions & 9 deletions samples/empty_nodes03.gram

This file was deleted.

15 changes: 0 additions & 15 deletions samples/empty_relationships05.gram

This file was deleted.

14 changes: 0 additions & 14 deletions samples/gql_grqph_type02.gram

This file was deleted.

20 changes: 0 additions & 20 deletions samples/graph_shape04.gram

This file was deleted.

9 changes: 0 additions & 9 deletions samples/identifiers09.gram

This file was deleted.

7 changes: 0 additions & 7 deletions samples/labeled_nodes04.gram

This file was deleted.

12 changes: 0 additions & 12 deletions samples/labeled_relationships03.gram

This file was deleted.

15 changes: 0 additions & 15 deletions samples/number_graphs01.gram
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
---

(gram
(pattern
(relationship
(node (integer))
(single_right)
(node (integer))
)
)
)

==================
Number graph: 1 +1 = 2
==================

(1)-[`+1`]->(2)

12 changes: 0 additions & 12 deletions samples/number_graphs02.gram

This file was deleted.

7 changes: 0 additions & 7 deletions samples/number_values05.gram

This file was deleted.

9 changes: 0 additions & 9 deletions samples/records09.gram

This file was deleted.

17 changes: 0 additions & 17 deletions samples/series08.gram

This file was deleted.

20 changes: 0 additions & 20 deletions samples/single_arrows10.gram

This file was deleted.

20 changes: 0 additions & 20 deletions samples/squiggle_arrows11.gram

This file was deleted.

11 changes: 0 additions & 11 deletions samples/text_graphs04.gram

This file was deleted.

17 changes: 0 additions & 17 deletions samples/text_values09.gram

This file was deleted.

9 changes: 7 additions & 2 deletions tools/gram-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ nx run gram-cli:build
Then, run it directly:

```
node dist/tools/gram-cli/main.js --help
```

See stats for a gram file:

```
node dist/tools/gram-cli/main.js --help
```
node dist/tools/gram-cli/main.js stat <filenames>...
```

6 changes: 4 additions & 2 deletions tools/gram-cli/src/gram-stat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ const gramStats = (filename:string, verbose: boolean) => FileSystem.FileSystem.p
Effect.map((content) => parse(content)),
Effect.tap((cst) => (verbose) ? Effect.all([
Console.log("cst:"),
Console.log(cst.rootNode.toString())
Console.log(cst.rootNode.toString()),
Console.log("")
]) : Effect.void),
Effect.map((cst) => stats(cst.rootNode)),
Effect.flatMap((stats) => Console.log("stats:", stats))
Effect.map((stats) => ({ source: filename, ...stats })),
Effect.flatMap((stats) => Console.log("(:Stats ", stats, ")")),
)


Expand Down

0 comments on commit f21f4ee

Please sign in to comment.