Open bloerwald opened 6 years ago
Here's my 20 minutes of effort as an ANTLR v4 combined grammar. It's missing some stuff:
COMMENT foo
I don't know where those are supposed to appear so I chose to ignore themPeople that actually write grammars will probably roll their eyes to the back of their skulls when they see the formatting but whatever.
I tried to make some tokens skipped but that just completely breaks everything.
grammar ExprLexer;
LAYOUT : 'LAYOUT' ;
COLUMNS : 'COLUMNS' ;
BUILD : 'BUILD' -> skip ;
TYPE : 'int' | 'float' | 'string' | 'locstring' ;
BUILD_NUMBER : [0-9]+.[0-9]+.[0-9]+.[0-9]+ ;
LAYOUT_HASH : [A-Fa-f0-9]+ ;
ANNOTATION : 'id' | 'relation' | 'noninline' ;
REFERENCE : '<' [A-Za-z0-9_]+ '::' [A-Za-z0-9_]+ '>';
IDENTIFIER : [a-zA-Z0-9_]+ ;
GUESSED : '?' ;
INLINE_COMMENT : '//' [ a-zA-Z0-9._()-]* ;
DASH : '-' -> skip;
COMMA : ',' -> skip;
DOLLAR : '$' ;
WS: [ \t\n\r\f]+ -> skip ;
COLON : ':' -> skip;
reference : REFERENCE;
column_definition : TYPE reference? IDENTIFIER GUESSED? INLINE_COMMENT?;
column_definitions : column_definition+;
size : '<' ('8' | '16' | '32' | '64' | 'u8' | 'u16' | 'u32' | 'u64') '>' ;
layout : LAYOUT (LAYOUT_HASH COMMA?)* ;
builds : (BUILD? (BUILD_NUMBER | (BUILD_NUMBER DASH BUILD_NUMBER)) COMMA?)* ;
annotation_list : DOLLAR (ANNOTATION COMMA?)* DOLLAR ;
column_reference : annotation_list? IDENTIFIER size? ;
structure_definition : layout? builds column_reference+ ;
file : COLUMNS column_definitions structure_definition+ EOF ;
py3 code has
dbd_grammar.py
which already dumps something EBNF-y based on the parser used, but that needs manual cleanup since it is kind of ugly, uses bad names and stuff.