edits
[cdsspec-compiler.git] / grammer / util.jj
index 7e8b0c3dc788f2420527ceb4840fa121bc727e52..5b5446bb9c102c3882efd813cab07652ea4687be 100644 (file)
@@ -49,6 +49,12 @@ public class UtilParser {
                return parser.FuncDecl();
        }
 
+       public static VariableDeclaration parseDeclaration(String line)
+       throws ParseException {
+               InputStream input = new ByteArrayInputStream(line.getBytes());
+               UtilParser parser = new UtilParser(input);
+               return parser.Declaration();
+       }
 
        public static String stringArray2String(ArrayList<String> content) {
                StringBuilder sb = new StringBuilder();
@@ -274,7 +280,10 @@ String Type() :
        (<CONST>
        { type = "const"; }
        )?
-       (((str = <STRUCT>.image | str = <CLASS>.image | str = <UNSIGNED>.image) { type = type + " " + str; })? 
+       (
+               ((str = <STRUCT>.image | str = <CLASS>.image | str = <UNSIGNED>.image) {
+               type = type.equals("") ? type + str : type + " " + str;
+               })? 
        (
        name = ParseQualifiedName() {
                if (!type.equals(""))
@@ -426,6 +435,17 @@ ArrayList<VariableDeclaration > FormalParamList() :
        }
 }
 
+VariableDeclaration Declaration() :
+{
+       String type, param;
+}
+{
+       (type = Type()) (param = <IDENTIFIER>.image)  <SEMI_COLON>
+       {
+               return new VariableDeclaration(type, param);
+       }
+}
+
 VariableDeclaration TypeParam() :
 {
        String type, param;