From d9f18bd107bacf12d5fc96200eb7b095e6116968 Mon Sep 17 00:00:00 2001 From: dibyendumajumdar Date: Wed, 1 Nov 2023 09:28:40 +0000 Subject: Revert "Report unclosed block in parsing (#28)" This reverts commit e3c412bbbdd6f6eefe2ac889f6d59aeaef71beb1. --- chapter05/src/main/java/com/seaofnodes/simple/Parser.java | 4 +--- .../src/test/java/com/seaofnodes/simple/Chapter05Test.java | 10 ---------- 2 files changed, 1 insertion(+), 13 deletions(-) (limited to 'chapter05') diff --git a/chapter05/src/main/java/com/seaofnodes/simple/Parser.java b/chapter05/src/main/java/com/seaofnodes/simple/Parser.java index a287f997..79b50672 100644 --- a/chapter05/src/main/java/com/seaofnodes/simple/Parser.java +++ b/chapter05/src/main/java/com/seaofnodes/simple/Parser.java @@ -115,9 +115,7 @@ public class Parser { // Enter a new scope _scope.push(); Node n = null; - while (!match("}")) { - if (_lexer.isEOF()) throw errorSyntax("}"); - + while (!match("}") && !_lexer.isEOF()) { Node n0 = parseStatement(); if (n0 != null) n = n0; // Allow null returns from eg showGraph } diff --git a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java index 254f4530..ab956e9f 100644 --- a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java +++ b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java @@ -429,14 +429,4 @@ return c; // this test used to fail in chapter 1 assertEquals("return -100;", new Parser("return -100;").parse().print()); } - - @Test - public void testBad6() { - try { - new Parser("int a=1; int b=2; int c=0; { int b=3; c=a+b;").parse(); - fail(); - } catch( RuntimeException e ) { - assertEquals("Syntax error, expected }: ",e.getMessage()); - } - } } -- cgit v1.2.3