geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r571083 - in /geronimo/sandbox/gshell/trunk/gshell-parser/src: main/antlr/CommandLine.g main/antlr/CommandLineWalker.g test/java/org/apache/geronimo/gshell/parser/CommandLineParserTest.java
Date Thu, 30 Aug 2007 09:15:05 GMT
Author: jdillon
Date: Thu Aug 30 02:15:04 2007
New Revision: 571083

URL: http://svn.apache.org/viewvc?rev=571083&view=rev
Log:
Add a walker grammar... antlr is still making my head spin :-(

Added:
    geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLineWalker.g
      - copied, changed from r571074, geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLine.g
Modified:
    geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLine.g
    geronimo/sandbox/gshell/trunk/gshell-parser/src/test/java/org/apache/geronimo/gshell/parser/CommandLineParserTest.java

Modified: geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLine.g
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLine.g?rev=571083&r1=571082&r2=571083&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLine.g (original)
+++ geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLine.g Thu Aug 30 02:15:04
2007
@@ -24,7 +24,7 @@
 grammar CommandLine;
 
 options {
-        language=Java;
+	language=Java;
 	output=AST;
 	// k=2;
 	// backtrack=true;
@@ -43,11 +43,11 @@
 //
 
 compilationUnit
-	:	( expression^ ( ';' | NewLine | EOF ) )*
+	:	( expression ( ';' | NewLine | EOF ) )*
 	;
 
 expression
-	:	( WhiteSpace )* ( argument^ ( WhiteSpace )* )+
+	:	( WhiteSpace )* ( argument ( WhiteSpace )* )+
 	;
 
 argument

Copied: geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLineWalker.g (from
r571074, geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLine.g)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLineWalker.g?p2=geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLineWalker.g&p1=geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLine.g&r1=571074&r2=571083&rev=571083&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLine.g (original)
+++ geronimo/sandbox/gshell/trunk/gshell-parser/src/main/antlr/CommandLineWalker.g Thu Aug
30 02:15:04 2007
@@ -21,78 +21,29 @@
 // $Rev$ $Id$
 //
 
-grammar CommandLine;
+tree grammar CommandLineWalker;
 
 options {
-        language=Java;
-	output=AST;
-	// k=2;
-	// backtrack=true;
-	// memoize=true;
+	language=Java;
+	tokenVocab=CommandLine;
+    	ASTLabelType=CommonTree;
 }
 
 @header {
 	package org.apache.geronimo.gshell.parser;
 }
-@lexer::header {
-  	package org.apache.geronimo.gshell.parser;
-}
-
-//
-// FIXME: Still need to work out whitespace muck, this isn't always happy... :-(
-//
 
-compilationUnit
-	:	( expression^ ( ';' | NewLine | EOF ) )*
+commandLine
+	:	expression*
 	;
 
 expression
-	:	( WhiteSpace )* ( argument^ ( WhiteSpace )* )+
+	:	argument*
 	;
 
 argument
-	:	literal
-	;
-
-literal
 	:	OpaqueStringLiteral
 	| 	StringLiteral
 	| 	PlainStringLiteral
-	;	
-
-//
-// Lexer
-//
-
-//
-// FIXME: Need to figure out how to handle \r\n too
-//
-
-NewLine
-	:	( '\n' )
-	;
-
-WhiteSpace
-	:	( ' ' | '\t' | '\r' ) // { $channel=HIDDEN; }
-	;
-
-PlainStringLiteral
-	: 	( ~( ';' | '\'' | '"' | WhiteSpace ) )+
-	;
-
-OpaqueStringLiteral
-	:  	'\'' ( EscapeSequence | ~( '\\' | '\'' ) )* '\''
-    ;
-
-//
-// TODO: Figure out how to parse out ${foo.bar} and "$foo bar", for variable expansion
-//
-
-StringLiteral
-    :  	'"' ( EscapeSequence | ~( '\\' | '"' ) )* '"'
-    ;
-
-fragment
-EscapeSequence
-    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
 	;
+    

Modified: geronimo/sandbox/gshell/trunk/gshell-parser/src/test/java/org/apache/geronimo/gshell/parser/CommandLineParserTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-parser/src/test/java/org/apache/geronimo/gshell/parser/CommandLineParserTest.java?rev=571083&r1=571082&r2=571083&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-parser/src/test/java/org/apache/geronimo/gshell/parser/CommandLineParserTest.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-parser/src/test/java/org/apache/geronimo/gshell/parser/CommandLineParserTest.java
Thu Aug 30 02:15:04 2007
@@ -23,6 +23,7 @@
 import org.antlr.runtime.ANTLRStringStream;
 import org.antlr.runtime.CharStream;
 import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.tree.CommonTreeNodeStream;
 import org.antlr.runtime.tree.Tree;
 
 /**
@@ -38,7 +39,7 @@
         CharStream stream = new ANTLRStringStream(input);
 
         CommandLineLexer lex = new CommandLineLexer(stream);
-        CommonTokenStream tokens = new CommonTokenStream(lex);
+        CommonTokenStream ts = new CommonTokenStream(lex);
 
         /*
         CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree);
@@ -47,8 +48,14 @@
 		walker.program();
         */
         
-        CommandLineParser parser = new CommandLineParser(tokens);
+        CommandLineParser parser = new CommandLineParser(ts);
         CommandLineParser.compilationUnit_return r = parser.compilationUnit();
         System.out.println("tree="+((Tree)r.tree).toStringTree());
+
+
+        CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree);
+		nodes.setTokenStream(ts);
+		CommandLineWalker walker = new CommandLineWalker(nodes);
+		walker.commandLine();
     }
 }



Mime
View raw message