Bug 2366: Introducing support for statement ANTLR4 parser as defined in RFC6020,... 25/14925/9
authorMartin Ciglan <mciglan@cisco.com>
Thu, 5 Feb 2015 15:24:54 +0000 (16:24 +0100)
committerRobert Varga <nite@hq.sk>
Sat, 21 Mar 2015 17:23:26 +0000 (17:23 +0000)
Change-Id: Ia0a789a68819c48f8d5f0bd5f1dbf5405e45e0bc
Signed-off-by: Martin Ciglan <mciglan@cisco.com>
yang/yang-parser-impl/src/main/antlr/YangStatementLexer.g4 [new file with mode: 0644]
yang/yang-parser-impl/src/main/antlr/YangStatementParser.g4 [new file with mode: 0644]

diff --git a/yang/yang-parser-impl/src/main/antlr/YangStatementLexer.g4 b/yang/yang-parser-impl/src/main/antlr/YangStatementLexer.g4
new file mode 100644 (file)
index 0000000..c69853d
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+//
+// This program and the accompanying materials are made available under the
+// terms of the Eclipse Public License v1.0 which accompanies this distribution,
+// and is available at http://www.eclipse.org/legal/epl-v10.html
+//
+lexer grammar YangStatementLexer;
+
+@header {
+package org.opendaylight.yangtools.antlrv4.code.gen;
+}
+
+tokens{
+    SEMICOLON,
+    LEFT_BRACE,
+    RIGHT_BRACE,
+    SEP,
+    IDENTIFIER,
+    COLON,
+    PLUS
+}
+
+SEMICOLON : ';' -> type(SEMICOLON);
+LEFT_BRACE : '{' -> type(LEFT_BRACE);
+RIGHT_BRACE : '}' -> type(RIGHT_BRACE);
+COLON : ':' -> type(COLON);
+PLUS : '+' -> type(PLUS);
+
+LINE_COMMENT :  [ \n\r\t]* ('//' (~[\r\n]*)) [ \n\r\t]* -> skip;
+
+START_BLOCK_COMMENT : '/*' ->pushMode(BLOCK_COMMENT_MODE), skip;
+
+SEP: [ \n\r\t]+ -> type(SEP);
+IDENTIFIER : [a-zA-Z_/][a-zA-Z0-9_\-.:/]* -> type(IDENTIFIER);
+
+fragment SUB_STRING : ('"' (ESC | ~["])*'"') | ('\'' (ESC | ~['])*'\'');
+fragment ESC : '\\' (["\\/bfnrt] | UNICODE);
+fragment UNICODE : 'u' HEX HEX HEX HEX;
+fragment HEX : [0-9a-fA-F] ;
+
+STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '\'' | ':' | '/' | '=' | '[' | ']' )~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | ':' | '/' | '=' | '[' | ']')* ) | SUB_STRING );
+
+mode BLOCK_COMMENT_MODE;
+END_BLOCK_COMMENT : '*/' -> popMode, skip;
+BLOCK_COMMENT :  . -> more, skip;
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/main/antlr/YangStatementParser.g4 b/yang/yang-parser-impl/src/main/antlr/YangStatementParser.g4
new file mode 100644 (file)
index 0000000..3ac195d
--- /dev/null
@@ -0,0 +1,21 @@
+//
+// Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+//
+// This program and the accompanying materials are made available under the
+// terms of the Eclipse Public License v1.0 which accompanies this distribution,
+// and is available at http://www.eclipse.org/legal/epl-v10.html
+//
+parser grammar YangStatementParser;
+
+@header {
+package org.opendaylight.yangtools.antlrv4.code.gen;
+}
+
+options{
+    tokenVocab = YangStatementLexer;
+}
+
+statement : SEP? keyword SEP? (argument)? SEP? (SEMICOLON | LEFT_BRACE SEP? (statement)* SEP? RIGHT_BRACE SEP?) SEP?;
+keyword : (IDENTIFIER COLON)? IDENTIFIER;
+
+argument : STRING | IDENTIFIER | STRING (SEP? PLUS SEP? STRING)*;
\ No newline at end of file