-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Using https://www.bottlecaps.de/ebnf-convert/ to convert https://github.com/harmonylang/harmony/blob/master/Harmony.g4 to an EBNF understood by https://github.com/GuntherRademacher/rr that generate a nice navigable railroad diagram (see bellow with instructions at the top).
//
// EBNF to be viewd at
// https://www.bottlecaps.de/rr/ui
//
// Copy and paste this at the url shown above in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//
/* converted on Mon Jul 14, 2025, 14:28 (UTC+02) by antlr_4-to-w3c v0.71 which is Copyright (c) 2011-2025 by Gunther Rademacher <grd@gmx.net> */
program ::= stmt* EOF
import_stmt
::= ( import_name | import_from ) ';'? NL
import_name
::= 'import' import_names_seq
import_from
::= 'from' NAME 'import' ( '*' | import_names_seq )
import_names_seq
::= NAME ( ',' NAME )*
tuple_bound
::= NAME
| '(' bound? ')'
| '[' bound? ']'
bound ::= tuple_bound ( ',' tuple_bound )*
arith_op ::= 'and'
| 'or'
| '&'
| '|'
| '^'
| '-'
| '+'
| '*'
| '//'
| '/'
| '%'
| 'mod'
| '**'
| '<<'
| '>>'
| '=='
| '!='
| '<'
| '<='
| '>'
| '>='
| '=>'
unary_op ::= '-'
| '~'
| '?'
| '!'
| 'abs'
| 'all'
| 'any'
| 'bin'
| 'choose'
| 'dict'
| 'get_context'
| 'get_ident'
| 'hash'
| 'hex'
| 'int'
| 'keys'
| 'len'
| 'list'
| 'max'
| 'min'
| 'not'
| 'oct'
| 'reversed'
| 'set'
| 'sorted'
| 'str'
| 'sum'
| 'type'
| 'zip'
basic_expr
::= INT
| BOOL
| ATOM
| NAME
| STRING
| 'None'
| '{' ( set_rule? ','? | ':' ) '}'
| '(' tuple_rule? ')'
| '[' tuple_rule? ']'
| 'lambda' bound ':' nary_expr 'end'
set_rule ::= nary_expr ( ':' nary_expr ( iter_parse | ( ',' nary_expr ':' nary_expr )* ) | iter_parse | '..' nary_expr | ( ',' nary_expr )* )
iter_parse
::= for_parse ( NL? ( for_parse | where_parse ) )*
for_parse
::= 'for' bound ( ':' bound )? 'in' nary_expr
where_parse
::= 'where' nary_expr
tuple_rule
::= nary_expr ( iter_parse | ( ',' nary_expr )* ','? )
nary_expr
::= expr_rule ( ( 'not'? 'in' | 'if' nary_expr 'else' ) expr_rule | ( arith_op expr_rule )* )
expr_rule
::= ( 'setintlevel' | 'save' | 'stop' | unary_op )* basic_expr ( ARROWID | basic_expr )*
expr ::= nary_expr
aug_assign_op
::= 'and='
| 'or='
| '=>='
| '&='
| '|='
| '^='
| '-='
| '+='
| '*='
| '/='
| '//='
| '%='
| 'mod='
| '**='
| '>>='
| '<<='
expr_stmt
::= expr_rule
assign_stmt
::= tuple_rule ( '=' tuple_rule )+
aug_assign_stmt
::= tuple_rule aug_assign_op tuple_rule
const_assign_stmt
::= 'const' bound '=' expr
assert_stmt
::= 'assert' expr ( ',' expr )?
await_stmt
::= 'await' expr
var_stmt ::= 'var' bound '=' tuple_rule
trap_stmt
::= 'trap' expr
return_stmt
::= 'return' expr
finally_stmt
::= 'finally' expr
invariant_stmt
::= 'invariant' expr
del_stmt ::= 'del' expr
spawn_stmt
::= 'spawn' 'eternal'? expr
go_stmt ::= 'go' expr expr
print_stmt
::= 'print' expr ( ',' expr )?
sequential_stmt
::= 'sequential' sequential_names_seq
global_stmt
::= 'global' expr ( ',' expr )*
builtin_stmt
::= 'builtin' NAME STRING
sequential_names_seq
::= NAME ( ',' NAME )*
atomic_block
::= 'atomically' ':' block
for_block
::= iter_parse ':' block
let_decl ::= 'let' bound '=' tuple_rule NL?
when_decl
::= 'when' ( 'exists' bound 'in' )? expr NL?
let_when_block
::= ( let_decl | when_decl )+ ':' block
opt_returns
::= 'returns' NAME
method_decl
::= 'def' NAME bound opt_returns? ':' block
while_block
::= 'while' expr ':' block
elif_block
::= 'elif' expr ':' block
else_block
::= 'else' ':' block
if_block ::= 'if' expr ':' block elif_block* else_block?
block_stmts
::= stmt+
block ::= normal_block
| one_line_stmt
normal_block
::= INDENT ( block_stmts | INDENT block ) DEDENT ( ';' NL )?
simple_stmt
::= 'atomically'? ( assign_stmt | const_assign_stmt | await_stmt | var_stmt | finally_stmt | invariant_stmt | del_stmt | spawn_stmt | trap_stmt | go_stmt | print_stmt | 'pass' | 'break' | 'continue' | return_stmt | sequential_stmt | global_stmt | builtin_stmt | assert_stmt | aug_assign_stmt | expr_stmt )
compound_stmt
::= 'atomically'? ( if_block | while_block | for_block | let_when_block | atomic_block | method_decl )
one_line_stmt
::= simple_stmt ( ';' simple_stmt )* ';'? NL
label ::= ( NAME ':' )+
stmt ::= ( label | ':' )? ( ';'* NL | one_line_stmt | compound_stmt | import_stmt )
| ( label | ':' ) normal_block
_ ::= WS
/* ws: definition */
<?TOKENS?>
NL ::= #xD? #xA ( ' '* | #x9+ )
WS ::= ' '+
| #x9+
| '\' NL
| COMMENT
COMMENT? ::= '(*' .* '*)'
| '#' [^#xd#xa#xc]*
BOOL ::= 'False'
| 'True'
INT ::= [0-9]+
| '0x' [0-9a-fA-F]+
| '0b' [0-1]+
| '0o' [0-7]+
NAME ::= [a-zA-Z_] [a-zA-Z_0-9]*
ATOM ::= '.' ( HEX_INTEGER | NAME )
ARROWID ::= '->' ' '* NAME
HEX_INTEGER
::= '0X' HEX_DIGIT+
HEX_DIGIT
::= [0-9a-fA-F]
STRING ::= SHORT_STRING
| LONG_STRING
SHORT_STRING
::= "'" ( STRING_ESCAPE_SEQ | [^\'#xd#xa#xc] )* "'"
| '"' ( STRING_ESCAPE_SEQ | [^\"#xd#xa#xc] )* '"'
LONG_STRING
::= "'''" LONG_STRING_ITEM* "'''"
| '"""' LONG_STRING_ITEM* '"""'
LONG_STRING_ITEM
::= LONG_STRING_CHAR
| STRING_ESCAPE_SEQ
LONG_STRING_CHAR
::= [^-]
STRING_ESCAPE_SEQ
::= '\' ( . | NL )
EOF ::= $
Metadata
Metadata
Assignees
Labels
No labels