Vidyashree Rama | da62150 | 2016-02-05 22:32:34 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vidyashree Rama | da62150 | 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 | |
| 23 | // Statements keywords |
| 24 | ANYXML_KEYWORD : 'anyxml'; |
| 25 | ARGUMENT_KEYWORD : 'argument'; |
| 26 | AUGMENT_KEYWORD : 'augment'; |
| 27 | BASE_KEYWORD : 'base'; |
| 28 | BELONGS_TO_KEYWORD : 'belongs-to'; |
| 29 | BIT_KEYWORD : 'bit'; |
| 30 | CASE_KEYWORD : 'case'; |
| 31 | CHOICE_KEYWORD : 'choice'; |
| 32 | CONFIG_KEYWORD : 'config'; |
| 33 | CONTACT_KEYWORD : 'contact'; |
| 34 | CONTAINER_KEYWORD : 'container'; |
| 35 | DEFAULT_KEYWORD : 'default'; |
| 36 | DESCRIPTION_KEYWORD : 'description'; |
| 37 | ENUM_KEYWORD : 'enum'; |
| 38 | ERROR_APP_TAG_KEYWORD : 'error-app-tag'; |
| 39 | ERROR_MESSAGE_KEYWORD : 'error-message'; |
| 40 | EXTENSION_KEYWORD : 'extension'; |
| 41 | DEVIATION_KEYWORD : 'deviation'; |
| 42 | DEVIATE_KEYWORD : 'deviate'; |
| 43 | FEATURE_KEYWORD : 'feature'; |
| 44 | FRACTION_DIGITS_KEYWORD : 'fraction-digits'; |
| 45 | GROUPING_KEYWORD : 'grouping'; |
| 46 | IDENTITY_KEYWORD : 'identity'; |
| 47 | IF_FEATURE_KEYWORD : 'if-feature'; |
| 48 | IMPORT_KEYWORD : 'import'; |
| 49 | INCLUDE_KEYWORD : 'include'; |
| 50 | INPUT_KEYWORD : 'input'; |
| 51 | KEY_KEYWORD : 'key'; |
| 52 | LEAF_KEYWORD : 'leaf'; |
| 53 | LEAF_LIST_KEYWORD : 'leaf-list'; |
| 54 | LENGTH_KEYWORD : 'length'; |
| 55 | LIST_KEYWORD : 'list'; |
| 56 | MANDATORY_KEYWORD : 'mandatory'; |
| 57 | MAX_ELEMENTS_KEYWORD : 'max-elements'; |
| 58 | MIN_ELEMENTS_KEYWORD : 'min-elements'; |
| 59 | MODULE_KEYWORD : 'module'; |
| 60 | MUST_KEYWORD : 'must'; |
| 61 | NAMESPACE_KEYWORD : 'namespace'; |
| 62 | NOTIFICATION_KEYWORD: 'notification'; |
| 63 | ORDERED_BY_KEYWORD : 'ordered-by'; |
| 64 | ORGANIZATION_KEYWORD: 'organization'; |
| 65 | OUTPUT_KEYWORD : 'output'; |
| 66 | PATH_KEYWORD : 'path'; |
| 67 | PATTERN_KEYWORD : 'pattern'; |
| 68 | POSITION_KEYWORD : 'position'; |
| 69 | PREFIX_KEYWORD : 'prefix'; |
| 70 | PRESENCE_KEYWORD : 'presence'; |
| 71 | RANGE_KEYWORD : 'range'; |
| 72 | REFERENCE_KEYWORD : 'reference'; |
| 73 | REFINE_KEYWORD : 'refine'; |
| 74 | REQUIRE_INSTANCE_KEYWORD : 'require-instance'; |
| 75 | REVISION_KEYWORD : 'revision'; |
| 76 | REVISION_DATE_KEYWORD : 'revision-date'; |
| 77 | RPC_KEYWORD : 'rpc'; |
| 78 | STATUS_KEYWORD : 'status'; |
| 79 | SUBMODULE_KEYWORD : 'submodule'; |
| 80 | TYPE_KEYWORD : 'type'; |
| 81 | TYPEDEF_KEYWORD : 'typedef'; |
| 82 | UNIQUE_KEYWORD : 'unique'; |
| 83 | UNITS_KEYWORD : 'units'; |
| 84 | USES_KEYWORD : 'uses'; |
| 85 | VALUE_KEYWORD : 'value'; |
| 86 | WHEN_KEYWORD : 'when'; |
| 87 | YANG_VERSION_KEYWORD: 'yang-version'; |
| 88 | YIN_ELEMENT_KEYWORD : 'yin-element'; |
| 89 | ADD_KEYWORD : 'add'; |
| 90 | CURRENT_KEYWORD : 'current'; |
| 91 | DELETE_KEYWORD : 'delete'; |
| 92 | DEPRECATED_KEYWORD : 'deprecated'; |
| 93 | FALSE_KEYWORD : 'false'; |
| 94 | MAX_KEYWORD : 'max'; |
| 95 | MIN_KEYWORD : 'min'; |
| 96 | NOT_SUPPORTED_KEYWORD : 'not-supported'; |
| 97 | OBSOLETE_KEYWORD : 'obsolete'; |
| 98 | REPLACE_KEYWORD : 'replace'; |
| 99 | SYSTEM_KEYWORD : 'system'; |
| 100 | TRUE_KEYWORD : 'true'; |
| 101 | UNBOUNDED_KEYWORD : 'unbounded'; |
| 102 | USER_KEYWORD : 'user'; |
| 103 | |
| 104 | // Lexer tokens to be skipped |
| 105 | COMMENT |
| 106 | : '/*' .*? '*/' -> channel(HIDDEN) |
| 107 | ; |
| 108 | WS : [ \r\t\u000C\n]+ -> channel(HIDDEN) |
| 109 | ; |
| 110 | LINE_COMMENT |
| 111 | : '//' ~[\r\n]* '\r'? '\n' -> channel(HIDDEN) |
| 112 | ; |
| 113 | |
| 114 | // Additional rules |
| 115 | INTEGER : DIGIT+; |
| 116 | DATE_ARG : DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT; |
| 117 | LEFT_CURLY_BRACE : '{'; |
| 118 | RIGHT_CURLY_BRACE : '}'; |
| 119 | IDENTIFIER : (ALPHA | '_') |
| 120 | (ALPHA | DIGIT | '_' | '-' | '.')*; |
| 121 | STMTEND : ';'; |
| 122 | DQUOTE : '"'; |
| 123 | COLON : ':'; |
| 124 | PLUS : '+'; |
| 125 | MINUS: '-'; |
| 126 | |
| 127 | STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '\'')~( '\r' | '\n' | '\t' | ' ' | ';' | '{' )* ) | SUB_STRING ); |
| 128 | |
| 129 | //Fragment rules |
| 130 | fragment SUB_STRING : ('"' (ESC | ~["])*'"') | ('\'' (ESC | ~['])*'\'') ; |
| 131 | fragment ESC : '\\' (["\\/bfnrt] | UNICODE) ; |
| 132 | fragment UNICODE : 'u' HEX HEX HEX HEX ; |
| 133 | fragment HEX : [0-9a-fA-F] ; |
| 134 | fragment ALPHA : [A-Za-z]; |
| 135 | fragment DIGIT : [0-9]; |
| 136 | fragment URN : [u][r][n]; |
| 137 | fragment HTTP : [h][t][t][p]; |