Correct instance-identifier escaping
[yangtools.git] / xpath / yang-xpath-impl / src / main / antlr4 / org / opendaylight / yangtools / yang / xpath / antlr / instanceIdentifierLexer.g4
1 lexer grammar instanceIdentifierLexer;
2
3 /*
4  * YANG 1.1 instance-identifier grammar, as defined in
5  * https://tools.ietf.org/html/rfc7950#section-9.13
6  *
7  * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
8  *
9  * This program and the accompanying materials are made available under the
10  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
11  * and is available at http://www.eclipse.org/legal/epl-v10.html
12  */
13 COLON : ':' ;
14 DOT : '.' ;
15 EQ : '=' ;
16 LBRACKET : '[' ;
17 RBRACKET : ']' ;
18 SLASH : '/' ;
19
20 Identifier : [a-zA-Z][a-zA-Z0-9_\-.]*
21   ;
22
23 // Note: XPath elements are counted from 1, not from 0, as per
24 //       https://mailarchive.ietf.org/arch/msg/netmod/xSR_hu6ry4EWfrvIY5NqcmC7ZoM/
25 PositiveIntegerValue : [1-9][0-9]*
26   ;
27
28 WSP : [ \t]+
29   ;
30
31 // Double/single-quoted strings. We deal with these using specialized modes.
32 DQUOT_START : '"' -> pushMode(DQUOT_STRING_MODE), skip;
33 SQUOT_START : '\'' -> pushMode(SQUOT_STRING_MODE), skip;
34
35 //
36 // Double-quoted string lexing mode. We interpret \n, \t, \", \\ only, as per RFC7950.
37 //
38 mode DQUOT_STRING_MODE;
39 DQUOT_STRING : (YANGCHAR | '\'' | ('\\' [nt"\\]))+ ;
40 DQUOT_END : '"' -> popMode;
41
42 //
43 // Single-quoted string lexing mode. We do not interpret anything within single
44 // quotes.
45 //
46 mode SQUOT_STRING_MODE;
47 SQUOT_STRING : (YANGCHAR | '"' | '\\')+ ;
48 SQUOT_END : '\'' -> popMode;
49
50 fragment
51 YANGCHAR : '\t'..'\n'
52   | '\r'
53
54   // '\u0020'..'\uD7FF' without "'", '"' and '\'
55   | '\u0020'..'\u0021' // 0x22 = "
56   | '\u0023'..'\u0026' // 0x27 = '
57   | '\u0028'..'\u005B' // 0x5C = \
58   | '\u005D'..'\uD7FF'
59
60   | '\uE000'..'\uFDCF'
61   | '\uFDF0'..'\uFFFD'
62   | '\u{10000}'..'\u{1FFFD}'
63   | '\u{20000}'..'\u{2FFFD}'
64   | '\u{30000}'..'\u{3FFFD}'
65   | '\u{40000}'..'\u{4FFFD}'
66   | '\u{50000}'..'\u{5FFFD}'
67   | '\u{60000}'..'\u{6FFFD}'
68   | '\u{70000}'..'\u{7FFFD}'
69   | '\u{80000}'..'\u{8FFFD}'
70   | '\u{90000}'..'\u{9FFFD}'
71   | '\u{A0000}'..'\u{AFFFD}'
72   | '\u{B0000}'..'\u{BFFFD}'
73   | '\u{C0000}'..'\u{CFFFD}'
74   | '\u{D0000}'..'\u{DFFFD}'
75   | '\u{E0000}'..'\u{EFFFD}'
76   | '\u{F0000}'..'\u{FFFFD}'
77   | '\u{100000}'..'\u{10FFFD}'
78   ;
79