Skip to content

Commit

Permalink
references must be a key; keys may be symbols, string literals or int…
Browse files Browse the repository at this point in the history
…egers; parse result is nested string s-expressions
  • Loading branch information
akollegger committed Nov 19, 2024
1 parent 562a7a2 commit 00b954b
Show file tree
Hide file tree
Showing 9 changed files with 647 additions and 1,170 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ Thumbs.db

.nx/cache
.nx/workspace-data

vite.config.*.timestamp*
59 changes: 43 additions & 16 deletions gram.ne
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
@preprocessor typescript

Gram -> Record:? (Pattern _):+
Gram -> (Record _):? (Pattern _):*
{% ([record, patterns]) => `(gram ${record ? record : ""} ${patterns.filter(nonNull).join(",")})` %}

Pattern -> PatternElement (_ "," _ PatternElement):*
{% ([p1, ps]) => `(pattern ${p1})` %}

PatternElement -> (Annotation _):* (Subject | Path)
PatternElement -> (Annotation _):* (Subject | Path | Reference)
{% ([anno, el]) => `${anno.filter(nonNull).join("@")}${el}?` %}

Subject -> "[" _ Attributes _ Association:? "]"
{% () => `(subject)` %}

Association -> "|" (Labels:? Record:? _ "|"):? _ AssociationMember (_ "," _ AssociationMember):*

AssociationMember -> (PatternElement | Reference)
Association -> "|" (Labels:? Record:? _ "|"):? _ Pattern

Reference -> Identity
{% () => `(reference)` %}

Path ->
Node
| Relationship
Node {% () => `(node)` %}
| Relationship {% () => `(relationship)` %}

Node -> "(" _ Attributes _ ")"

Expand Down Expand Up @@ -52,15 +55,17 @@ QualifiedArrow ->

Attributes -> Identity:? Labels:? Record:?

Identity -> Value
Identity -> Key

Labels -> ( (Define | Declare | Annotate) Key):+
Labels -> ( (Define | Declare ) Key):+

Record ->
"{" _ "}"
| "{" _ Property ("," _ Property ):* "}"
{% (d) => `(record ${(d.length > 2) ? d[2] : ""})` %}

Property -> Key _ ( Define | Declare | Annotate ) _ Value
Property -> Key _ ( Define | Declare ) _ Value
{% ([key, _1, binder, _2, value]) => `(property ${key} ${value})` %}

# What something has
Define -> ":"
Expand All @@ -71,7 +76,7 @@ Declare -> "::"
# What it means
Annotate -> "@"

Key -> ( Symbol | StringLiteral )
Key -> ( Symbol | StringLiteral | Integer)

Value ->
Null
Expand All @@ -93,7 +98,8 @@ Null -> "null"

Boolean -> "true" | "false"

Symbol -> [a-zA-Z_] [0-9a-zA-Z_\-]:*
Symbol -> [a-zA-Z_] [0-9a-zA-Z_\-@]:*
{% (d) => `(symbol)` %}

Range ->
NumericLiteral ".." NumericLiteral
Expand All @@ -108,16 +114,18 @@ NumericLiteral ->
| Percentage

Integer -> ("-"|"+"):? [0-9]:+
{% (d) => `(integer)` %}

Decimal -> "-":? [0-9]:+ ("." [0-9]:+):? ([eE] [+-]:? [0-9]:+):?
Decimal -> "-":? [0-9]:+ ("." [0-9]:+) ([eE] [+-]:? [0-9]:+):?
{% (d) => `(decimal)` %}

Hexadecimal -> "-":? "0x" [0-9a-fA-F]:+

Octal -> "-":? "0" [0-7]:+

Measurement -> Decimal Symbol
Measurement -> NumericLiteral Symbol

Percentage -> Decimal "%"
Percentage -> NumericLiteral "%"

StringLiteral ->
DoubleQuotedLiteral
Expand Down Expand Up @@ -151,6 +159,25 @@ EscapedChars ->
| "u" [a-fA-F0-9] [a-fA-F0-9] [a-fA-F0-9] [a-fA-F0-9]

_ -> wschar:*
{% nothing %}
__ -> wschar:+
{% nothing %}

wschar -> [ \t\n\v\f]

@{%
const nothing = () => null;

const nonNull = (x) => (x !== null && x !== '')

const nonNullArray = (d) => {
let output = [d[2]];

for (let i in d[3]) {
output.push(d[3][i][3]);
}

return output;
}

wschar -> [ \t\n\v\f]
%}
Loading

0 comments on commit 00b954b

Please sign in to comment.