Created
May 22, 2025 12:38
-
-
Save bbrowning/125765c6f0c4f35f0d0ba92ee0559e93 to your computer and use it in GitHub Desktop.
EBNF grammar (for use with Tatsu) for Llama 4 Pythonic tool calling parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@grammar::Llama4 | |
start | |
= | |
expression $ | |
; | |
expression | |
= | |
[ start_python_tag ] functions:function_list [ end_python_tag ] | |
; | |
start_python_tag | |
= | |
"<|python_start|>" | |
; | |
end_python_tag | |
= | |
"<|python_end|>" | |
; | |
function_list | |
= | |
[ "[" ] /(,|;)/%{ @+:function }+ [ "]" ] | |
; | |
function | |
= | |
name:function_name "(" ","%{ args+:( function_args | () ) }+ ")" | |
; | |
function_name | |
= | |
python_identifier | |
; | |
function_args | |
= | |
key:python_identifier "=" value:arg_value | |
; | |
arg_value | |
= | |
| bool:bool | |
| number:number | |
| string:string | |
| dict:python_dict | |
| list:python_list | |
| identifier:python_identifier | |
; | |
bool | |
= | |
| "True" | |
| "true" | |
| "False" | |
| "false" | |
; | |
number | |
= | |
/-?\d+\.?\d*/ | |
; | |
string | |
= | |
# strings like: "foobarbaz" | |
| '"' /[^"]*/ '"' | |
# strings like: 'Martha\'s Vineyard' | |
| "'" ( "\" "'" )%{ /[^'\\]+/ } "'" | |
# strings like: '\"cool units\"' | |
| "'" "\" '"' /[^'\\]+/ "\" '"' "'" | |
# strings like: 'foo\"bar\"baz' | |
| "'" ( "\" '"' )%{ /[^'\\]+/ } "'" | |
; | |
python_dict | |
= | |
"{" @:",".{ python_dict_kv } "}" | |
; | |
python_dict_kv | |
= | |
key:string ":" value:arg_value | |
; | |
python_list | |
= | |
"[" @:",".{ arg_value } "]" | |
; | |
python_identifier | |
= | |
/[a-zA-Z_][a-zA-Z_\-0-9]*/ | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment