summaryrefslogtreecommitdiff
path: root/chapter05
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2023-10-29 09:52:59 -0700
committerDibyendu Majumdar <dibyendumajumdar@users.noreply.github.com>2023-11-01 18:56:50 +0000
commit4a425c35b81b144006907361fe55f2b3390e5d7c (patch)
treed754c545633e78d72948e76dffcf286247bee7ae /chapter05
parentccd83187b172f8ba3cd7c49b59a080fb027a184b (diff)
downloadSimple-4a425c35b81b144006907361fe55f2b3390e5d7c.tar.gz
Simple-4a425c35b81b144006907361fe55f2b3390e5d7c.zip
Fix broken error report
Diffstat (limited to 'chapter05')
-rw-r--r--chapter05/src/main/java/com/seaofnodes/simple/Parser.java2
-rw-r--r--chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java11
2 files changed, 11 insertions, 2 deletions
diff --git a/chapter05/src/main/java/com/seaofnodes/simple/Parser.java b/chapter05/src/main/java/com/seaofnodes/simple/Parser.java
index 7ea74306..a66ee278 100644
--- a/chapter05/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter05/src/main/java/com/seaofnodes/simple/Parser.java
@@ -479,7 +479,7 @@ public class Parser {
private String parsePunctuation() {
int start = _position;
- return new String(_input, start, start+1);
+ return new String(_input, start, 1);
}
}
diff --git a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java
index 32ac5aac..2ad7e59a 100644
--- a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java
+++ b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java
@@ -115,7 +115,16 @@ return c;
assertEquals("Expected an identifier, found 'else'",e.getMessage());
}
}
-
+
+ @Test
+ public void testChapter5Keyword3() {
+ try {
+ new Parser("int a=1; ififif(arg)inta=2;return a;").parse();
+ fail();
+ } catch( RuntimeException e ) {
+ assertEquals("Syntax error, expected =: (",e.getMessage());
+ }
+ }
@Test
public void testChapter4Peephole() {
Parser parser = new Parser("return 1+arg+2; #showGraph;");