/
sequalize.bnf
42 lines (35 loc) · 1.43 KB
/
sequalize.bnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# After updating this file run:
# yarn run build-bnf
# or
# npx bnf-compile ./packages/core/src/utils/bnf/syntax.bnf
# To update the compiled artifacts
program ::= switcher+ ;
switcher ::= ( sw_attr | sw_json ) nl ;
sw_attr ::= "attr: " attribute ;
sw_json ::= "json: " partialJsonPath ;
nl ::= "\r\n" | "\n";
## Used when parsing the attribute
attribute ::= attributeBegin jsonAccess* transform* ;
attributeBegin ::= association | ...identifier ;
## Used when parsing a nested JSON path used inside of an attribute
## Difference with "attribute" is in the first part. Instead of accepting:
## $association.attribute$ & attribute
## It accepts:
## key, "quotedKey", and [0] (index access)
partialJsonPath ::= ...key jsonAccess* transform* ;
# Internals
identifier ::= ( "A"->"Z"+ | "a"->"z"+ | "0"->"9"+ | "_" )+ ;
digit ::= "0"->"9" ;
number ::= ...digit+ ;
association ::= %"$" ...identifier (%"." ...identifier)* %"$" ;
jsonAccess ::= indexAccess | keyAccess ;
indexAccess ::= %"[" ...number %"]" ;
keyAccess ::= %"." ...key ;
# path segments accept dashes without needing to be quoted
key ::= nonEmptyString | identifier ;
nonEmptyString ::= ...(%"\"" (anyExceptQuoteOrBackslash | escapedCharacter)+ %"\"") ;
escapedCharacter ::= %"\\" ( "\"" | "\\" );
anyExceptQuoteOrBackslash ::= !("\"" | "\\");
transform ::= cast | modifier ;
cast ::= %"::" ...identifier ;
modifier ::= %":" ...identifier ;