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
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;
}
}