Init Commit: Moved bproto to seperate repo
This commit is contained in:
39
bprotoV1.g4
Normal file
39
bprotoV1.g4
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
grammar bprotoV1;
|
||||
|
||||
protocol_defintion : protocol_header (message_def | enum_def | bit_field_def)+;
|
||||
|
||||
protocol_header : 'protocol' IDENTIFIER 'version' INT ;
|
||||
|
||||
// Protocol definitions
|
||||
message_def : 'message' message_id IDENTIFIER '{' (field ',')* (field ','?)? '}' ;
|
||||
message_id : '[' INT ']';
|
||||
enum_def : 'enum' IDENTIFIER enum_body;
|
||||
bit_field_def : 'bits' IDENTIFIER bitfield_body;
|
||||
|
||||
field : field_pos IDENTIFIER ':' dtype;
|
||||
field_pos : '[' INT ']';
|
||||
|
||||
dtype: type_standard | type_enum | type_bitfield;
|
||||
|
||||
type_standard : IDENTIFIER array_extension?;
|
||||
type_enum : 'enum' (enum_body | IDENTIFIER);
|
||||
type_bitfield : 'bits' (bitfield_body | IDENTIFIER);
|
||||
|
||||
array_extension: '[' INT ']';
|
||||
|
||||
// enum def
|
||||
enum_body : '{' (enum_field ',')* (enum_field ','?)? '}';
|
||||
enum_field: IDENTIFIER ('=' INT)? ;
|
||||
|
||||
// bit field def
|
||||
bitfield_body : '{' (bitfield_field ',')* (bitfield_field ','?)? '}';
|
||||
bitfield_field: IDENTIFIER (':' INT)?;
|
||||
|
||||
// Lexer rules
|
||||
INT : [0-9]+;
|
||||
IDENTIFIER : [a-zA-Z0-9_]+;
|
||||
|
||||
WS : [ \t\r\n]+ -> skip;
|
||||
COMMENT : '//' ~[\r\n]* -> skip;
|
||||
COMMENT_MULTILINE : '/*' .*? '*/' -> skip;
|
||||
Reference in New Issue
Block a user