Skip to content

Instantly share code, notes, and snippets.

@dmj
Created September 1, 2013 08:39
Show Gist options
  • Save dmj/6403133 to your computer and use it in GitHub Desktop.
Save dmj/6403133 to your computer and use it in GitHub Desktop.
ANTLR4 grammer for PICA+ records
/* ANTLR4 Grammar for PICA+ records */
grammar PicaRecord ;
file : record ('\n' record)* ;
record : field+ ;
field : tag ' ' subfield+ '\u001e';
tag : FIELD_TAG ;
subfield : SUBFIELD ;
// Lexer rules
FIELD_TAG : DIGIT DIGIT DIGIT (UPPER | SYMBOL_AT) ('/' DIGIT DIGIT)?;
SUBFIELD : '\u001f' SUBFIELD_CODE SUBFIELD_VALUE* ;
SUBFIELD_CODE : ALNUM ;
SUBFIELD_VALUE : ~('\u001f' | '\u001e') ;
fragment ALNUM : DIGIT | LOWER | UPPER ;
fragment DIGIT : '0'..'9' ;
fragment LOWER : 'a'..'z' ;
fragment UPPER : 'A'..'Z' ;
fragment SYMBOL_AT : '@' ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment