summaryrefslogtreecommitdiff
path: root/src/PicoRec.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/PicoRec.java')
-rw-r--r--src/PicoRec.java27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/PicoRec.java b/src/PicoRec.java
index f601ce3..191d2f8 100644
--- a/src/PicoRec.java
+++ b/src/PicoRec.java
@@ -48,18 +48,11 @@ public class PicoRec {
/**
* Try to parse the input.
*
- * @return true if the language is recognized, false otherwise.
+ * @throws ParseError if the language is not recognized.
*/
- public boolean parse(String text) {
+ public void parse(String text) {
input = text;
offset = 0;
- try {
- // TODO implement this
- return true;
- } catch (ParseError ex) {
- System.err.println("Parsing failed due to: " + ex);
- return false;
- }
}
/** Skip layout characters. */
@@ -111,9 +104,9 @@ public class PicoRec {
}
/** Exception that is raised for parser errors. */
- private static class ParseError extends RuntimeException {
+ public static class ParseError extends RuntimeException {
private static final long serialVersionUID = 1L;
- ParseError(String message) {
+ private ParseError(String message) {
super(message);
}
}
@@ -122,10 +115,16 @@ public class PicoRec {
/* Convenience functions for testing. */
private void check(String input, boolean expectOk) {
- boolean accepted = parse(input);
System.out.println("Testing input: " + input);
- if (expectOk && !accepted || !expectOk && accepted) {
- throw new RuntimeException("Unexpected result for " + input);
+ try {
+ parse(input);
+ if (!expectOk) {
+ throw new RuntimeException("Unexpected pass for " + input);
+ }
+ } catch (ParseError ex) {
+ if (expectOk) {
+ throw new RuntimeException(ex);
+ }
}
}