Better HF grammar implementation (#4953)
This commit is contained in:
parent
aa200f8723
commit
12690d3ffc
19 changed files with 830 additions and 116 deletions
|
@ -1,7 +0,0 @@
|
|||
# A probably incorrect grammar for Japanese
|
||||
root ::= jp-char+ ([ \t\n] jp-char+)*
|
||||
jp-char ::= hiragana | katakana | punctuation | cjk
|
||||
hiragana ::= [ぁ-ゟ]
|
||||
katakana ::= [ァ-ヿ]
|
||||
punctuation ::= [、-〾]
|
||||
cjk ::= [一-鿿]
|
|
@ -1,25 +1,14 @@
|
|||
root ::= object
|
||||
|
||||
object ::= "{" ws ( string ":" ws value ("," ws string ":" ws value)* )? "}"
|
||||
|
||||
value ::= object | array | string | number | ("true" | "false" | "null") ws
|
||||
|
||||
object ::=
|
||||
"{" ws (
|
||||
string ":" ws value
|
||||
("," ws string ":" ws value)*
|
||||
)? "}" ws
|
||||
array ::= "[" ws ( value ("," ws value)* )? "]" ws
|
||||
|
||||
array ::=
|
||||
"[" ws (
|
||||
value
|
||||
("," ws value)*
|
||||
)? "]" ws
|
||||
|
||||
string ::=
|
||||
"\"" (
|
||||
[^"\\] |
|
||||
"\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]) # escapes
|
||||
)* "\"" ws
|
||||
string ::= "\"" ( [a-zA-Z0-9] )* "\"" ws
|
||||
|
||||
number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws
|
||||
|
||||
# Optional space: by convention, applied in this grammar after literal chars when allowed
|
||||
|
||||
ws ::= ([ \t\n] ws)?
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
# This is the same as json.gbnf but we restrict whitespaces at the end of the root array
|
||||
# Useful for generating JSON arrays
|
||||
|
||||
root ::= arr
|
||||
value ::= object | array | string | number | ("true" | "false" | "null") ws
|
||||
|
||||
arr ::=
|
||||
"[\n" ws (
|
||||
value
|
||||
(",\n" ws value)*
|
||||
)? "]"
|
||||
|
||||
object ::=
|
||||
"{" ws (
|
||||
string ":" ws value
|
||||
("," ws string ":" ws value)*
|
||||
)? "}" ws
|
||||
|
||||
array ::=
|
||||
"[" ws (
|
||||
value
|
||||
("," ws value)*
|
||||
)? "]" ws
|
||||
|
||||
string ::=
|
||||
"\"" (
|
||||
[^"\\] |
|
||||
"\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]) # escapes
|
||||
)* "\"" ws
|
||||
|
||||
number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws
|
||||
|
||||
# Optional space: by convention, applied in this grammar after literal chars when allowed
|
||||
ws ::= ([ \t\n] ws)?
|
14
grammars/json_w_trailing_space.gbnf
Normal file
14
grammars/json_w_trailing_space.gbnf
Normal file
|
@ -0,0 +1,14 @@
|
|||
root ::= object
|
||||
|
||||
object ::= "{" ws ( string ":" ws value ("," ws string ":" ws value)* )? "}" ws
|
||||
|
||||
value ::= object | array | string | number | ("true" | "false" | "null") ws
|
||||
|
||||
array ::= "[" ws ( value ("," ws value)* )? "]" ws
|
||||
|
||||
string ::= "\"" ( [a-zA-Z0-9] )* "\"" ws
|
||||
|
||||
number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws
|
||||
|
||||
|
||||
ws ::= ([ \t\n] ws)?
|
|
@ -1,4 +1,2 @@
|
|||
root ::= item+
|
||||
|
||||
# Excludes various line break characters
|
||||
item ::= "- " [^\r\n\x0b\x0c\x85\u2028\u2029]+ "\n"
|
||||
root ::= "1. " paragraph "\n" ([0-9] [0-9]? ". " paragraph "\n")+
|
||||
paragraph ::= [a-zA-Z'.,; ]+
|
7
grammars/simple_arithmetic.gbnf
Normal file
7
grammars/simple_arithmetic.gbnf
Normal file
|
@ -0,0 +1,7 @@
|
|||
root ::= (expr "=" ws term "\n")+
|
||||
expr ::= term ([-+*/] term)*
|
||||
term ::= num | "(" ws expr ")" ws
|
||||
num ::= [0-9]+ ws
|
||||
ws ::= [ \t\n]*
|
||||
# this is a comment
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue