Vidyashree Rama | 66bc525 | 2016-02-05 22:32:34 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 72b2df2 | 2017-08-03 18:48:28 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Vidyashree Rama | 66bc525 | 2016-02-05 22:32:34 +0530 | [diff] [blame] | 3 | * |
| 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 | |
| 21 | lexer grammar YangLexer; |
| 22 | |
Gaurav Agrawal | c34a322 | 2017-03-01 13:18:38 +0530 | [diff] [blame] | 23 | @header { |
| 24 | package org.onosproject.yang.compiler.parser.antlrgencode; |
| 25 | } |
| 26 | |
Vidyashree Rama | 66bc525 | 2016-02-05 22:32:34 +0530 | [diff] [blame] | 27 | // 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 Rama | 84e4ba7 | 2016-06-30 14:31:18 +0530 | [diff] [blame] | 107 | COMPILER_ANNOTATION_KEYWORD : 'compiler-annotation'; |
Vidyashree Rama | 918f162 | 2016-07-28 17:33:15 +0530 | [diff] [blame] | 108 | 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 Condon | 6b3a645 | 2016-12-07 17:47:00 +0000 | [diff] [blame] | 116 | //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 Rama | 66bc525 | 2016-02-05 22:32:34 +0530 | [diff] [blame] | 121 | |
| 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 Miyata | 9b0187d | 2017-06-22 12:26:15 +0900 | [diff] [blame] | 129 | : '//' ~[\r\n]* -> channel(HIDDEN) |
Vidyashree Rama | 66bc525 | 2016-02-05 22:32:34 +0530 | [diff] [blame] | 130 | ; |
| 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 Rama | 66bc525 | 2016-02-05 22:32:34 +0530 | [diff] [blame] | 142 | PLUS : '+'; |
| 143 | MINUS: '-'; |
| 144 | |
Vidyashree Rama | 3c58673 | 2017-05-12 19:48:07 +0530 | [diff] [blame] | 145 | UNKNOWN_STATEMENT : IDENTIFIER COLON IDENTIFIER; |
| 146 | |
Naoki Miyata | 9b0187d | 2017-06-22 12:26:15 +0900 | [diff] [blame] | 147 | STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '}' | '"' | '+' | '\'')~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '+')* ) | SUB_STRING ); |
Vidyashree Rama | 66bc525 | 2016-02-05 22:32:34 +0530 | [diff] [blame] | 148 | |
| 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 Condon | 6b3a645 | 2016-12-07 17:47:00 +0000 | [diff] [blame] | 157 | fragment HTTP : [h][t][t][p]; |