blob: 4f190b9934bb9d0232e4e74653b456f1d7ffde50 [file] [log] [blame]
Vidyashree Rama66bc5252016-02-05 22:32:34 +05301/*
Brian O'Connor72b2df22017-08-03 18:48:28 -07002 * Copyright 2016-present Open Networking Foundation
Vidyashree Rama66bc5252016-02-05 22:32:34 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * This is a YANG grammar for lexer based on which ANTLR will generate YANG lexer.
19 */
20
21lexer grammar YangLexer;
22
Gaurav Agrawalc34a3222017-03-01 13:18:38 +053023@header {
24package org.onosproject.yang.compiler.parser.antlrgencode;
25}
26
Vidyashree Rama66bc5252016-02-05 22:32:34 +053027 // Statements keywords
28 ANYXML_KEYWORD : 'anyxml';
29 ARGUMENT_KEYWORD : 'argument';
30 AUGMENT_KEYWORD : 'augment';
31 BASE_KEYWORD : 'base';
32 BELONGS_TO_KEYWORD : 'belongs-to';
33 BIT_KEYWORD : 'bit';
34 CASE_KEYWORD : 'case';
35 CHOICE_KEYWORD : 'choice';
36 CONFIG_KEYWORD : 'config';
37 CONTACT_KEYWORD : 'contact';
38 CONTAINER_KEYWORD : 'container';
39 DEFAULT_KEYWORD : 'default';
40 DESCRIPTION_KEYWORD : 'description';
41 ENUM_KEYWORD : 'enum';
42 ERROR_APP_TAG_KEYWORD : 'error-app-tag';
43 ERROR_MESSAGE_KEYWORD : 'error-message';
44 EXTENSION_KEYWORD : 'extension';
45 DEVIATION_KEYWORD : 'deviation';
46 DEVIATE_KEYWORD : 'deviate';
47 FEATURE_KEYWORD : 'feature';
48 FRACTION_DIGITS_KEYWORD : 'fraction-digits';
49 GROUPING_KEYWORD : 'grouping';
50 IDENTITY_KEYWORD : 'identity';
51 IF_FEATURE_KEYWORD : 'if-feature';
52 IMPORT_KEYWORD : 'import';
53 INCLUDE_KEYWORD : 'include';
54 INPUT_KEYWORD : 'input';
55 KEY_KEYWORD : 'key';
56 LEAF_KEYWORD : 'leaf';
57 LEAF_LIST_KEYWORD : 'leaf-list';
58 LENGTH_KEYWORD : 'length';
59 LIST_KEYWORD : 'list';
60 MANDATORY_KEYWORD : 'mandatory';
61 MAX_ELEMENTS_KEYWORD : 'max-elements';
62 MIN_ELEMENTS_KEYWORD : 'min-elements';
63 MODULE_KEYWORD : 'module';
64 MUST_KEYWORD : 'must';
65 NAMESPACE_KEYWORD : 'namespace';
66 NOTIFICATION_KEYWORD: 'notification';
67 ORDERED_BY_KEYWORD : 'ordered-by';
68 ORGANIZATION_KEYWORD: 'organization';
69 OUTPUT_KEYWORD : 'output';
70 PATH_KEYWORD : 'path';
71 PATTERN_KEYWORD : 'pattern';
72 POSITION_KEYWORD : 'position';
73 PREFIX_KEYWORD : 'prefix';
74 PRESENCE_KEYWORD : 'presence';
75 RANGE_KEYWORD : 'range';
76 REFERENCE_KEYWORD : 'reference';
77 REFINE_KEYWORD : 'refine';
78 REQUIRE_INSTANCE_KEYWORD : 'require-instance';
79 REVISION_KEYWORD : 'revision';
80 REVISION_DATE_KEYWORD : 'revision-date';
81 RPC_KEYWORD : 'rpc';
82 STATUS_KEYWORD : 'status';
83 SUBMODULE_KEYWORD : 'submodule';
84 TYPE_KEYWORD : 'type';
85 TYPEDEF_KEYWORD : 'typedef';
86 UNIQUE_KEYWORD : 'unique';
87 UNITS_KEYWORD : 'units';
88 USES_KEYWORD : 'uses';
89 VALUE_KEYWORD : 'value';
90 WHEN_KEYWORD : 'when';
91 YANG_VERSION_KEYWORD: 'yang-version';
92 YIN_ELEMENT_KEYWORD : 'yin-element';
93 ADD_KEYWORD : 'add';
94 CURRENT_KEYWORD : 'current';
95 DELETE_KEYWORD : 'delete';
96 DEPRECATED_KEYWORD : 'deprecated';
97 FALSE_KEYWORD : 'false';
98 MAX_KEYWORD : 'max';
99 MIN_KEYWORD : 'min';
100 NOT_SUPPORTED_KEYWORD : 'not-supported';
101 OBSOLETE_KEYWORD : 'obsolete';
102 REPLACE_KEYWORD : 'replace';
103 SYSTEM_KEYWORD : 'system';
104 TRUE_KEYWORD : 'true';
105 UNBOUNDED_KEYWORD : 'unbounded';
106 USER_KEYWORD : 'user';
Vidyashree Rama84e4ba72016-06-30 14:31:18 +0530107 COMPILER_ANNOTATION_KEYWORD : 'compiler-annotation';
Vidyashree Rama918f1622016-07-28 17:33:15 +0530108 COMPILER_ANNOTATION : IDENTIFIER COLON COMPILER_ANNOTATION_KEYWORD;
109 APP_DATA_STRUCTURE_KEYWORD : 'app-data-structure';
110 APP_DATA_STRUCTURE : IDENTIFIER COLON APP_DATA_STRUCTURE_KEYWORD;
111 DATA_STRUCTURE_KEYWORD : 'data-structure';
112 DATA_STRUCTURE : IDENTIFIER COLON DATA_STRUCTURE_KEYWORD;
113 DATA_STRUCTURE_KEY : IDENTIFIER COLON KEY_KEYWORD;
114 APP_EXTENDED_KEYWORD : 'app-extended-name';
115 APP_EXTENDED : IDENTIFIER COLON APP_EXTENDED_KEYWORD;
Sean Condon6b3a6452016-12-07 17:47:00 +0000116 //From ietf-netconf-acm.yang RFC 6536
117 DEFAULT_DENY_WRITE_KEYWORD : 'default-deny-write';
118 DEFAULT_DENY_WRITE : IDENTIFIER COLON DEFAULT_DENY_WRITE_KEYWORD;
119 DEFAULT_DENY_ALL_KEYWORD : 'default-deny-all';
120 DEFAULT_DENY_ALL : IDENTIFIER COLON DEFAULT_DENY_ALL_KEYWORD;
Vidyashree Rama66bc5252016-02-05 22:32:34 +0530121
122 // Lexer tokens to be skipped
123 COMMENT
124 : '/*' .*? '*/' -> channel(HIDDEN)
125 ;
126 WS : [ \r\t\u000C\n]+ -> channel(HIDDEN)
127 ;
128 LINE_COMMENT
Naoki Miyata9b0187d2017-06-22 12:26:15 +0900129 : '//' ~[\r\n]* -> channel(HIDDEN)
Vidyashree Rama66bc5252016-02-05 22:32:34 +0530130 ;
131
132 // Additional rules
133 INTEGER : DIGIT+;
134 DATE_ARG : DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT;
135 LEFT_CURLY_BRACE : '{';
136 RIGHT_CURLY_BRACE : '}';
137 IDENTIFIER : (ALPHA | '_')
138 (ALPHA | DIGIT | '_' | '-' | '.')*;
139 STMTEND : ';';
140 DQUOTE : '"';
141 COLON : ':';
Vidyashree Rama66bc5252016-02-05 22:32:34 +0530142 PLUS : '+';
143 MINUS: '-';
144
Vidyashree Rama3c586732017-05-12 19:48:07 +0530145 UNKNOWN_STATEMENT : IDENTIFIER COLON IDENTIFIER;
146
Naoki Miyata9b0187d2017-06-22 12:26:15 +0900147 STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '}' | '"' | '+' | '\'')~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '+')* ) | SUB_STRING );
Vidyashree Rama66bc5252016-02-05 22:32:34 +0530148
149 //Fragment rules
150 fragment SUB_STRING : ('"' (ESC | ~["])*'"') | ('\'' (ESC | ~['])*'\'') ;
151 fragment ESC : '\\' (["\\/bfnrt] | UNICODE) ;
152 fragment UNICODE : 'u' HEX HEX HEX HEX ;
153 fragment HEX : [0-9a-fA-F] ;
154 fragment ALPHA : [A-Za-z];
155 fragment DIGIT : [0-9];
156 fragment URN : [u][r][n];
Sean Condon6b3a6452016-12-07 17:47:00 +0000157 fragment HTTP : [h][t][t][p];