Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Better HF grammar implementation #4953

Merged
merged 3 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions grammars/japanese.gbnf

This file was deleted.

23 changes: 6 additions & 17 deletions grammars/json.gbnf
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
root ::= object
value ::= object | array | string | number | ("true" | "false" | "null") ws

object ::=
"{" ws (
string ":" ws value
("," ws string ":" ws value)*
)? "}" ws
object ::= "{" ws ( string ":" ws value ("," ws string ":" ws value)* )? "}"

value ::= object | array | string | number | ("true" | "false" | "null") 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)?
34 changes: 0 additions & 34 deletions grammars/json_arr.gbnf

This file was deleted.

14 changes: 14 additions & 0 deletions grammars/json_w_trailing_space.gbnf
Original file line number Diff line number Diff line change
@@ -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)?
6 changes: 2 additions & 4 deletions grammars/list.gbnf
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions grammars/simple_arithmetic.gbnf
Original file line number Diff line number Diff line change
@@ -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

33 changes: 0 additions & 33 deletions modules/grammar.py

This file was deleted.

Loading