Skip to content

Commit 5523fc1

Browse files
author
dlsmith
committed
DynamicJava: Another parser fix, this time handling Errors thrown by JavaCharStream (due to malformed Unicode escapes).
git-svn-id: file:///tmp/test-svn/trunk@4657 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 0a882b8 commit 5523fc1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

dynamicjava/src/koala/dynamicjava/parser/wrapper/JavaCCParser.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ public List<Node> parseStream() {
101101
catch (TokenMgrError e) {
102102
throw new ParseError(e);
103103
}
104+
catch (Error e) {
105+
// JavaCharStream does not use a useful exception type for escape character errors
106+
String msg = e.getMessage();
107+
if (msg != null && msg.startsWith("Invalid escape character")) {
108+
throw new ParseError(e);
109+
}
110+
else { throw e; }
111+
}
104112
}
105113

106114
/**
@@ -117,5 +125,13 @@ public List<Node> parseCompilationUnit() {
117125
catch (TokenMgrError e) {
118126
throw new ParseError(e);
119127
}
128+
catch (Error e) {
129+
// JavaCharStream does not use a useful exception type for escape character errors
130+
String msg = e.getMessage();
131+
if (msg != null && msg.startsWith("Invalid escape character")) {
132+
throw new ParseError(e);
133+
}
134+
else { throw e; }
135+
}
120136
}
121137
}

dynamicjava/src/koala/dynamicjava/parser/wrapper/ParseError.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ public ParseError(ParseException e) {
9393
pe = e;
9494
}
9595

96-
public ParseError(TokenMgrError e) {
97-
this(e.getMessage(), "", -1, -1);
96+
public ParseError(Throwable t) {
97+
this(t.getMessage(), "", -1, -1);
9898
}
9999

100100
/**

0 commit comments

Comments
 (0)