more work on preproc with chars (issue #752)

This commit is contained in:
benfry
2011-06-27 16:54:47 +00:00
parent f9906b1f75
commit 0e2e2a493e

View File

@@ -132,7 +132,8 @@ import antlr.collections.AST;
* @author Jonathan Feinberg <jdf@pobox.com>
*/
public class PdePreprocessor {
protected static final String UNICODE_ESCAPES = "0123456789abcdefABCDEF";
// used for calling the ASTFactory to get the root node
private static final int ROOT_ID = 0;
@@ -254,15 +255,26 @@ public class PdePreprocessor {
throw new SketchException("Unterminated character constant (after initial quote)", 0,
countNewlines(program.substring(0, i)));
}
boolean escaped = false;
if (program.charAt(i) == '\\') {
i++; // step over the backslash
escaped = true;
}
if (i >= length) {
throw new SketchException("Unterminated character constant (after backslash)", 0,
countNewlines(program.substring(0, i)));
}
if (program.charAt(i) == 'u') {
i += 5; // step over the u, and the four digit unicode constant
if (escaped && program.charAt(i) == 'u') { // unicode escape sequence?
i++; // step over the u
//i += 4; // and the four digit unicode constant
for (int j = 0; j < 4; j++) {
if (UNICODE_ESCAPES.indexOf(program.charAt(i)) == -1) {
throw new SketchException("Bad or unfinished \\uXXXX sequence " +
"(malformed Unicode character constant)", 0,
countNewlines(program.substring(0, i)));
}
i++;
}
} else {
i++; // step over a single character
}
@@ -276,7 +288,6 @@ public class PdePreprocessor {
countNewlines(program.substring(0, i)));
}
}
}
}