Skip to content

Instantly share code, notes, and snippets.

@jdegoes
Last active December 18, 2015 22:18
Show Gist options
  • Save jdegoes/5853465 to your computer and use it in GitHub Desktop.
Save jdegoes/5853465 to your computer and use it in GitHub Desktop.
ANTLR4 EJSON Grammar
ejsonValue
: (ejsonLiteral
| ejsonUnorderedMap
| ejsonOrderedMap
| ejsonSet
| ejsonArray
| ejsonNumber
| ejsonString) ejsonMetadata?;
ejsonMetadata : '@' ejsonValue;
ejsonLiteral : EJSON_FALSE | EJSON_TRUE | EJSON_NULL;
ejsonNumber : EJSON_NUMBER;
ejsonString : EJSON_STRING;
ejsonUnorderedMap : '{' (ejsonMapping (',' ejsonMapping)*)? '}';
ejsonOrderedMap : '[' (ejsonMapping (',' ejsonMapping)*)? ']';
ejsonMapping : ejsonValue ':' ejsonValue;
ejsonSet : '{' (ejsonValue (',' ejsonValue)*)? '}';
ejsonArray : '['(ejsonValue (',' ejsonValue)*)? ']';
EJSON_FALSE : 'false';
EJSON_TRUE : 'true';
EJSON_NULL : 'null';
EJSON_NUMBER : '-'? ('0' | ( '1'..'9' EJSON_INT* )) ('.' EJSON_INT+)? EJSON_EXPONENT?;
EJSON_STRING : '"' ( EJSON_ESC_SEQ | ~('\\'|'"') )* '"';
fragment EJSON_INT : '0'..'9'+;
fragment EJSON_EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+;
fragment EJSON_HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F');
fragment EJSON_ESC_SEQ : '\\' ('\"'|'\\'|'/'|'b'|'f'|'n'|'r'|'t') | EJSON_UNICODE_ESC;
fragment EJSON_UNICODE_ESC : '\\' 'u' EJSON_HEX_DIGIT{4};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment