edits
[cdsspec-compiler.git] / src / edu / uci / eecs / specExtraction / VariableDeclaration.java
index 541a43397ea27fa627fa75a75d45afc34e44d242..259be57bb48bda3b9d3d88baab62040b89df5513 100644 (file)
@@ -4,6 +4,9 @@ import java.io.File;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import edu.uci.eecs.utilParser.ParseException;
+import edu.uci.eecs.utilParser.UtilParser;
+
 /**
  * <p>
  * This class represents a variable declaration in C/C++, in which there exist a
@@ -24,17 +27,15 @@ public class VariableDeclaration {
 
        public VariableDeclaration(File file, int lineNum, String line)
                        throws WrongAnnotationException {
-               // "([<>\*\w\s]+)\s?(\w+)\s;"
-               Pattern regexp = Pattern.compile("([<>&\\*\\w\\s]+)\\s?(\\w+)\\s?;");
-               Matcher matcher = regexp.matcher(line);
-               if (matcher.find()) {
-                       type = matcher.group(1);
-                       name = matcher.group(2);
-               } else {
-                       type = null;
-                       name = null;
+               VariableDeclaration decl = null;
+               try {
+                       decl = UtilParser.parseDeclaration(line);
+               } catch (ParseException e) {
                        WrongAnnotationException.err(file, lineNum, "The declaration: \""
-                                       + line + "\" has wrong syntax.");
+                               + line + "\" has wrong syntax.");
+               } finally {
+                       type = decl == null ? null : decl.type;
+                       name = decl == null ? null : decl.name;
                }
        }