-
Notifications
You must be signed in to change notification settings - Fork 0
/
Overpass.g4
77 lines (62 loc) · 1.77 KB
/
Overpass.g4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
grammar Overpass;
// Lexer rules
WS: (' ' | '\t' | '\n' | '\r' | '\f') -> channel(HIDDEN);
SL_COMMENT: '//' .*? '\r'? '\n' -> channel(HIDDEN);
ML_COMMENT: '/*' .*? '*/' -> channel(HIDDEN);
INTEGER: [0-9]+;
FLOAT: '-'? INTEGER '.' INTEGER;
OPERATOR: '=' | '~=' | '=~' | '!=' | '!~' | '~';
NOT: '!';
UNQUOTED_STRING: [-_a-zA-Z0-9]+;
SIMPLE_QUOTE: '\'';
DOUBLE_QUOTE: '"';
SIMPLE_QUOTED_STRING:
SIMPLE_QUOTE (~['] | '\\' ['])* SIMPLE_QUOTE;
DOUBLE_QUOTED_STRING:
DOUBLE_QUOTE (~["] | '\\' ["])* DOUBLE_QUOTE;
ID: [a-zA-Z_] [-_a-zA-Z0-9]*;
DOT_ID: '.' ID;
// Parser rules
osm_id: INTEGER;
number: INTEGER | FLOAT;
token:
SIMPLE_QUOTED_STRING
| DOUBLE_QUOTED_STRING
| UNQUOTED_STRING
| number;
metadata:
'[' (out_json = 'out:json') ']' (
'[' 'timeout:' (timeout = number) ']'
)?;
selector:
'[' (
(NOT? key = token)
| (key = token OPERATOR value = token)
) ']';
filter_bbox: number ',' number ',' number ',' number;
filter_poly:
'poly:' (SIMPLE_QUOTED_STRING | DOUBLE_QUOTED_STRING);
filter_osm_id: osm_id;
filter_osm_ids: 'id:' osm_id (',' osm_id)*;
filter_area: 'area' DOT_ID;
filter_around: 'around' DOT_ID ':' number;
filter:
'(' (
filter_bbox
| filter_poly
| filter_osm_id
| filter_osm_ids
| filter_area
| filter_around
) ')';
asignation: '->' DOT_ID;
object_type: 'node' | 'way' | 'relation' | 'area' | 'nwr';
query_object: object_type DOT_ID? selector* filter* asignation?;
query_recurse: ('<' | '<<' | '>' | '>>') asignation?;
query: query_object | query_recurse;
query_union: ('(' (query_sequence ';')+ ')') asignation?;
query_sequence: query | query_union;
out_geom: 'geom' | 'center' | 'bb';
out_level_of_details: 'ids' | 'skel' | 'body' | 'tags' | 'meta';
out: 'out' out_geom? out_level_of_details?;
request: (metadata ';')? (query_sequence ';')+ (out ';')?;