Browse Source

add parser + test

rtree
dkm 12 years ago
commit
5c30317be3
  1. 55
      grammar/OpenAir.g
  2. 23
      test-parser.py

55
grammar/OpenAir.g

@ -0,0 +1,55 @@
grammar OpenAir;
options {
language=Python;
}
tokens {
INCLUDE='INCLUDE';
TYPE='TYPE';
TITLE='TITLE';
TOPS='TOPS';
BASE='BASE';
POINT='POINT';
ANTICLOCKWISE='ANTI-CLOCKWISE';
CLOCKWISE='CLOCKWISE';
RADIUS='RADIUS';
CENTRE='CENTRE';
TO='TO';
EQ='=';
AGL='AGL';
AMSL='AMSL';
FL='FL';
SFC='SFC';
UNL='UNL';
CTACTR='CTA/CTR';
OTHER='OTHER';
PROHIBITED='PROHIBITED';
RESTRICTED='RESTRICTED';
YES='YES';
NO='NO';
}
file
: zone NEWLINE EOF
;
zone
: INCLUDE WS* EQ WS* (YES|NO) WS*
;
NEWLINE
: '\r'? '\n'
;
WS
: (' '|'\t'|'\n'|'\r')+ {skip();}
;
ZONE_TITLE
: ('a'..'z'|'A'..'Z'|'0'..'9'|'.'|' ')+'\r'? '\n'
;

23
test-parser.py

@ -0,0 +1,23 @@
#!/usr/bin/env python
import antlr3
from OpenAirLexer import OpenAirLexer
from OpenAirParser import OpenAirParser
import sys
fin = file(sys.argv[1])
s = ""
for i in fin.xreadlines():
s += i
char_stream = antlr3.ANTLRStringStream(s)
# or to parse a file:
# char_stream = antlr3.ANTLRFileStream(path_to_input)
# or to parse an opened file or any other file-like object:
# char_stream = antlr3.ANTLRInputStream(file)
lexer = OpenAirLexer(char_stream)
tokens = antlr3.CommonTokenStream(lexer)
parser = OpenAirParser(tokens)
parser.file()
Loading…
Cancel
Save