activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r690397 - in /activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main: java/org/apache/activemq/protobuf/compiler/ javacc/
Date Fri, 29 Aug 2008 21:34:09 GMT
Author: chirino
Date: Fri Aug 29 14:34:08 2008
New Revision: 690397

URL: http://svn.apache.org/viewvc?rev=690397&view=rev
Log:
Updated parser so it can successfully parse all the unit test proto files.  Generator is still
in progress.

Added:
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/GroupDescriptor.java
Modified:
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/javacc/proto-parser.jj

Added: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/GroupDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/GroupDescriptor.java?rev=690397&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/GroupDescriptor.java
(added)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/GroupDescriptor.java
Fri Aug 29 14:34:08 2008
@@ -0,0 +1,20 @@
+package org.apache.activemq.protobuf.compiler;
+
+import java.util.Map;
+
+public class GroupDescriptor extends FieldDescriptor {
+    private Map<String,FieldDescriptor> fields;
+
+    public GroupDescriptor(ProtoDescriptor protoDescriptor) {
+        super(protoDescriptor);
+    }
+
+    public Map<String, FieldDescriptor> getFields() {
+        return fields;
+    }
+
+    public void setFields(Map<String, FieldDescriptor> fields) {
+        this.fields = fields;
+    }
+
+}

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java?rev=690397&r1=690396&r2=690397&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java
(original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java
Fri Aug 29 14:34:08 2008
@@ -29,6 +29,7 @@
     private Map<String,EnumDescriptor> enums;
     private final ProtoDescriptor protoDescriptor;
     private List<ExtendDescriptor> extendsList;
+    private Map<String, OptionDescriptor> options;
 
     public MessageDescriptor(ProtoDescriptor protoDescriptor) {
         this.protoDescriptor = protoDescriptor;
@@ -90,4 +91,12 @@
         
     }
 
+    public Map<String, OptionDescriptor> getOptions() {
+        return options;
+    }
+
+    public void setOptions(Map<String, OptionDescriptor> options) {
+        this.options = options;
+    }
+
 }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java?rev=690397&r1=690396&r2=690397&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java
(original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java
Fri Aug 29 14:34:08 2008
@@ -77,11 +77,12 @@
         List<File> recFiles = Arrays.asList(files);
         for (File file : recFiles) {
             try {
+                getLog().info("Compiling: "+file.getPath());
                 JavaGenerator generator = new JavaGenerator();
                 generator.setOutputDirectory(outputDirectory);
                 generator.compile(file);
             } catch (ParseException e) {
-                throw new MojoExecutionException("Parse failed: " + e.getMessage(), e);
+                throw new MojoExecutionException("Parse failed: "+file.getPath()+"\n"+ e.getMessage(),
e);
             } catch (CompilerException e) {
                 throw new MojoExecutionException("Compile failed", e);
             } catch (IOException e) {

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/javacc/proto-parser.jj
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/javacc/proto-parser.jj?rev=690397&r1=690396&r2=690397&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/javacc/proto-parser.jj (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/javacc/proto-parser.jj Fri
Aug 29 14:34:08 2008
@@ -95,6 +95,7 @@
   | <REPEATED:"repeated">
   | <RETURNS:"returns">
   | <TO:"to">
+  | <MAX:"max">
 
   | <LBRACE: "{">
   | <RBRACE: "}">
@@ -107,8 +108,33 @@
   | <PERIOD: ".">
   | <COMMA: ",">
   
-  | <NUMBER: (["0"-"9"])+>
-  | <STRING: "\"" ( ~["\""] )+ "\"">
+  | < INTEGER: ("-")? (
+        <DECIMAL_LITERAL> (["l","L"])?
+      | <HEX_LITERAL> (["l","L"])?
+      | <OCTAL_LITERAL> (["l","L"])? 
+    ) >
+  | < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
+  | < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
+  | < #OCTAL_LITERAL: "0" (["0"-"7"])* >
+  | < FLOAT: ("-")? (
+        (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
+      | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
+      | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
+      | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
+    )>
+  | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+  | <STRING:
+      "\""
+      (   (~["\"","\\","\n","\r"])
+        | ("\\"
+            ( ["a","v","n","t","b","r","f","\\","'","\""]
+            | ["x","X"]["0"-"9","A"-"F","a"-"f"]["0"-"9","A"-"F","a"-"f"]
+            | ["0"-"7"] ( ["0"-"7"] )?
+            | ["0"-"3"] ["0"-"7"] ["0"-"7"]
+            )
+          )
+      )*
+      "\"">
   | <ID: ["A"-"Z","a"-"z"] (["a"-"z","A"-"Z","0"-"9","_"])*>
 }
 
@@ -131,10 +157,9 @@
     String o;
 }
 {
-	(
-		<PACKAGE> packageName=PackageID() <SEMICOLON>
-	)?
     (
+		<PACKAGE> packageName=PackageID() <SEMICOLON>
+	|	
         <OPTION> optionD = OptionDescriptor(proto) <SEMICOLON>
         { opts.put(optionD.getName(),optionD); }
     |   
@@ -168,6 +193,138 @@
     }
 }
 
+
+MessageDescriptor MessageDescriptor(ProtoDescriptor proto) :
+{
+    String name;
+    LinkedHashMap<String,FieldDescriptor> fields = new LinkedHashMap<String,FieldDescriptor>();
+    LinkedHashMap<String,MessageDescriptor> messages = new LinkedHashMap<String,MessageDescriptor>();
+    LinkedHashMap<String,EnumDescriptor> enums = new LinkedHashMap<String,EnumDescriptor>();
+    ArrayList<ExtendDescriptor> extendsList = new ArrayList<ExtendDescriptor>();
+    LinkedHashMap<String,OptionDescriptor> opts = new LinkedHashMap<String,OptionDescriptor>();
+
+    OptionDescriptor optionD;
+    ExtensionsDescriptor extensionsD=null;
+	FieldDescriptor fieldD;
+	MessageDescriptor messageD;
+	EnumDescriptor enumD;
+	ExtendDescriptor extendD;
+}
+{
+    <MESSAGE> name = ID() <LBRACE>
+    (
+        <OPTION> optionD = OptionDescriptor(proto) <SEMICOLON>
+        { opts.put(optionD.getName(),optionD); }
+	|	
+    	fieldD = FieldDescriptor(proto)
+    	{ fields.put(fieldD.getName(), fieldD); }
+    |   
+        messageD = MessageDescriptor(proto) (<SEMICOLON>)?
+        { messages.put(messageD.getName(),messageD); }
+    |   
+        enumD = EnumDescriptor(proto) (<SEMICOLON>)?
+        { enums.put(enumD.getName(), enumD); }
+    |   
+        extensionsD = ExtensionsDescriptor(proto) <SEMICOLON>
+    |   
+        extendD = ExtendDescriptor(proto) (<SEMICOLON>)?
+        { extendsList.add(extendD); }
+    )*
+    <RBRACE>
+    {
+    	MessageDescriptor rc = new MessageDescriptor(proto);
+    	rc.setName(name);
+    	rc.setFields(fields);
+    	rc.setMessages(messages);
+    	rc.setEnums(enums);
+    	rc.setExtensions(extensionsD);
+    	rc.setOptions(opts);
+    	return rc;
+    }
+}
+
+/**
+ * Parses something like:
+ * optional string foo = 1;
+ */
+FieldDescriptor FieldDescriptor(ProtoDescriptor proto) :
+{
+    String rule;
+    String type;
+    String name;
+    int tag;
+    LinkedHashMap<String,OptionDescriptor> opts = new LinkedHashMap<String,OptionDescriptor>();
+    LinkedHashMap<String,FieldDescriptor> fields = new LinkedHashMap<String,FieldDescriptor>();
+    OptionDescriptor optionD;
+	FieldDescriptor fieldD;
+	FieldDescriptor rc;
+}
+{
+
+    rule = Rule()
+    (
+        // We have to go through the look ahead trouble because based on if 'type' is 'group'

+        // we need to look ahead to see if it looks like a group declaration instead it being

+        // message type called group.
+        
+	    LOOKAHEAD(5)
+		type = PackageID()
+	    name = ID()
+	    <EQUALS>
+	    tag = Integer()
+	    (
+	    	<LBRACKET>
+	    	optionD = OptionDescriptor(proto)
+	    	{
+	    		opts.put(optionD.getName(), optionD);
+	    	}
+	    	(
+	    		<COMMA>
+		    	optionD = OptionDescriptor(proto)
+		    	{
+	    			opts.put(optionD.getName(), optionD);
+	    		}
+	    	)*
+	    	<RBRACKET>
+	    )?
+	    <SEMICOLON>    
+	    {
+	    	FieldDescriptor t = new FieldDescriptor(proto);
+	    	t.setName(name);
+	    	t.setType(type);
+	    	t.setRule(rule);
+	    	t.setTag(tag);
+	    	t.setOptions(opts);
+	    	rc=t;
+	    }
+    	|
+		<GROUP>
+	    name = ID()
+	    <EQUALS>
+	    tag = Integer()
+	    <LBRACE>
+	    (
+	       	fieldD = FieldDescriptor(proto)
+	    	{ fields.put(fieldD.getName(), fieldD); }
+	    )*
+	    <RBRACE> 
+	    ( <SEMICOLON> )?  
+	    {
+	    	GroupDescriptor t = new GroupDescriptor(proto);
+	    	t.setName(name);
+	    	t.setType("group");
+	    	t.setRule(rule);
+	    	t.setTag(tag);
+	    	t.setOptions(opts);
+	    	t.setFields(fields);
+	    	rc=t;
+	    }
+    )
+    {
+		return rc;
+    }
+}
+
 ServiceDescriptor ServiceDescriptor(ProtoDescriptor proto) :
 {
     String name;
@@ -246,49 +403,6 @@
     }
 }
 
-MessageDescriptor MessageDescriptor(ProtoDescriptor proto) :
-{
-    String name;
-    LinkedHashMap<String,FieldDescriptor> fields = new LinkedHashMap<String,FieldDescriptor>();
-    LinkedHashMap<String,MessageDescriptor> messages = new LinkedHashMap<String,MessageDescriptor>();
-    LinkedHashMap<String,EnumDescriptor> enums = new LinkedHashMap<String,EnumDescriptor>();
-    ArrayList<ExtendDescriptor> extendsList = new ArrayList<ExtendDescriptor>();
-
-    ExtensionsDescriptor extensionsD=null;
-	FieldDescriptor fieldD;
-	MessageDescriptor messageD;
-	EnumDescriptor enumD;
-	ExtendDescriptor extendD;
-}
-{
-    <MESSAGE> name = ID() <LBRACE>
-    (
-    	fieldD = FieldDescriptor(proto) <SEMICOLON>
-    	{ fields.put(fieldD.getName(), fieldD); }
-    |   
-        messageD = MessageDescriptor(proto) (<SEMICOLON>)?
-        { messages.put(messageD.getName(),messageD); }
-    |   
-        enumD = EnumDescriptor(proto) (<SEMICOLON>)?
-        { enums.put(enumD.getName(), enumD); }
-    |   
-        extensionsD = ExtensionsDescriptor(proto) <SEMICOLON>
-    |   
-        extendD = ExtendDescriptor(proto) (<SEMICOLON>)?
-        { extendsList.add(extendD); }
-    )*
-    <RBRACE>
-    {
-    	MessageDescriptor rc = new MessageDescriptor(proto);
-    	rc.setName(name);
-    	rc.setFields(fields);
-    	rc.setMessages(messages);
-    	rc.setEnums(enums);
-    	rc.setExtensions(extensionsD);
-    	return rc;
-    }
-}
-
 ExtensionsDescriptor ExtensionsDescriptor(ProtoDescriptor proto) :
 {
 	int first;
@@ -298,7 +412,14 @@
     <EXTENSIONS> 
     first = Integer() 
     <TO> 
-    last = Integer() 
+    (
+    	last = Integer()
+    	|
+    	<MAX>
+    	{
+    		last=536870911;
+    	}
+    )
     {
     	ExtensionsDescriptor rc = new ExtensionsDescriptor(proto);
     	rc.setFirst(first);
@@ -352,58 +473,12 @@
     }
 }
 
-/**
- * Parses something like:
- * optional string foo = 1;
- */
-FieldDescriptor FieldDescriptor(ProtoDescriptor proto) :
-{
-    String rule;
-    String type;
-    String name;
-    int tag;
-    LinkedHashMap<String,OptionDescriptor> opts = new LinkedHashMap<String,OptionDescriptor>();
-    OptionDescriptor optionD;
-}
-{
-
-    rule = Rule()
-    type = PackageID()
-    name = ID()
-    <EQUALS>
-    tag = Integer()
-    (
-    	<LBRACKET>
-    	optionD = OptionDescriptor(proto)
-    	{
-    		opts.put(optionD.getName(), optionD);
-    	}
-    	(
-    		<COMMA>
-	    	optionD = OptionDescriptor(proto)
-	    	{
-    			opts.put(optionD.getName(), optionD);
-    		}
-    	)*
-    	<RBRACKET>
-    )?    
-    {
-    	FieldDescriptor rc = new FieldDescriptor(proto);
-    	rc.setName(name);
-    	rc.setType(type);
-    	rc.setRule(rule);
-    	rc.setTag(tag);
-    	rc.setOptions(opts);
-    	return rc;
-    }
-}
-
 int Integer() :
 {
     Token t;
 }
 {
-  	t = <NUMBER>
+  	t = <INTEGER>
     {
     	return Integer.parseInt(t.image);
     }
@@ -429,6 +504,7 @@
 
 String Value() :
 {
+    Token t;
     String value=null;
 }
 {
@@ -436,6 +512,16 @@
     	value = StringLitteral()
     	|
   		value = ID()
+  		|
+  		t = <INTEGER>
+  		{
+  			value = t.image;
+  		}
+  		|
+  		t = <FLOAT>
+  		{
+  			value = t.image;
+  		}
     )
     {
     	return value;
@@ -449,6 +535,7 @@
 {
     (
           t = <ID>
+        | t = <GROUP>
         | t = <IMPORT>
         | t = <PACKAGE>
         | t = <SERVICE>
@@ -458,12 +545,12 @@
         | t = <EXTENSIONS>
         | t = <EXTEND>
         | t = <ENUM>
-        | t = <GROUP>
         | t = <REQURIED>
         | t = <OPTIONAL>
         | t = <REPEATED>
         | t = <RETURNS>
         | t = <TO>
+        | t = <MAX>
     )
     {
     	return t.image;
@@ -476,21 +563,23 @@
     StringBuffer sb = new StringBuffer();
 }
 {
-    t = ID()
-    {
-    	sb.append(t);
-    }
-    (
-    	<PERIOD>
-    	t=ID()
-    	{
-    		sb.append(".");
-    		sb.append(t);
-    	}
-    )* 
-    {
-	    return sb.toString();
-    }    
+	(
+	    t = ID()
+	    {
+	    	sb.append(t);
+	    }
+	    (
+	    	<PERIOD>
+	    	t=ID()
+	    	{
+	    		sb.append(".");
+	    		sb.append(t);
+	    	}
+	    )*
+	)
+	{
+		return sb.toString();
+	}
 }
 
 



Mime
View raw message