diff --git a/Compiler/src/compiler/parser/Parser.java b/Compiler/src/compiler/parser/Parser.java index 3a35b80f..22c4bab1 100644 --- a/Compiler/src/compiler/parser/Parser.java +++ b/Compiler/src/compiler/parser/Parser.java @@ -167,8 +167,7 @@ private void parseClassMember() throws ParserException, IOException { throw new ParserException(token, TokenType.LP); } token = tokenSupplier.getNextToken(); - if (token.getType() != TokenType.IDENTIFIER - || token.getSymbol().getValue().equals("String") == false) { + if (token.getType() != TokenType.IDENTIFIER || !token.getSymbol().getValue().equals("String")) { throw new ParserException(token, TokenType.IDENTIFIER); } token = tokenSupplier.getNextToken(); diff --git a/Compiler/testdata/parser5/methods/MissingBody.java b/Compiler/testdata/parser5/methods/MissingBody.java new file mode 100644 index 00000000..52d71895 --- /dev/null +++ b/Compiler/testdata/parser5/methods/MissingBody.java @@ -0,0 +1,14 @@ +/** + * comma after last parameter + */ + +class Error { + + public method(int a, int b) + + public method2(int a, int b) { + + } + + +} \ No newline at end of file diff --git a/Compiler/testdata/parser5/MissingCommaInParameterList.parser b/Compiler/testdata/parser5/methods/MissingBody.parser similarity index 100% rename from Compiler/testdata/parser5/MissingCommaInParameterList.parser rename to Compiler/testdata/parser5/methods/MissingBody.parser diff --git a/Compiler/testdata/parser5/methods/MissingReturnType.java b/Compiler/testdata/parser5/methods/MissingReturnType.java new file mode 100644 index 00000000..db44ccff --- /dev/null +++ b/Compiler/testdata/parser5/methods/MissingReturnType.java @@ -0,0 +1,11 @@ +/** + * comma after last parameter + */ + +class Error { + + public missingReturnType(int a, int b) + { + } + +} \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/MissingReturnType.parser b/Compiler/testdata/parser5/methods/MissingReturnType.parser new file mode 100644 index 00000000..c2270834 --- /dev/null +++ b/Compiler/testdata/parser5/methods/MissingReturnType.parser @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/MissingRightParanthesisInParameterList.java b/Compiler/testdata/parser5/methods/MissingRightParanthesisInParameterList.java new file mode 100644 index 00000000..f2f76118 --- /dev/null +++ b/Compiler/testdata/parser5/methods/MissingRightParanthesisInParameterList.java @@ -0,0 +1,10 @@ +/** + * comma after last parameter + */ + +class Error { + + public void missingRightParanthesis(int a, int b + { + } +} \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/MissingRightParanthesisInParameterList.parser b/Compiler/testdata/parser5/methods/MissingRightParanthesisInParameterList.parser new file mode 100644 index 00000000..c2270834 --- /dev/null +++ b/Compiler/testdata/parser5/methods/MissingRightParanthesisInParameterList.parser @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Compiler/testdata/parser5/MissingCommaInParameterList.java b/Compiler/testdata/parser5/methods/ObsoleteCommaInParameterList.java similarity index 100% rename from Compiler/testdata/parser5/MissingCommaInParameterList.java rename to Compiler/testdata/parser5/methods/ObsoleteCommaInParameterList.java diff --git a/Compiler/testdata/parser5/methods/ObsoleteCommaInParameterList.parser b/Compiler/testdata/parser5/methods/ObsoleteCommaInParameterList.parser new file mode 100644 index 00000000..c2270834 --- /dev/null +++ b/Compiler/testdata/parser5/methods/ObsoleteCommaInParameterList.parser @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/main/MissingMainName.java b/Compiler/testdata/parser5/methods/main/MissingMainName.java new file mode 100644 index 00000000..c5162723 --- /dev/null +++ b/Compiler/testdata/parser5/methods/main/MissingMainName.java @@ -0,0 +1,11 @@ +/** + * comma after last parameter + */ + +class Error { + + + public static void (String[] args{ + + } +} \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/main/MissingMainName.parser b/Compiler/testdata/parser5/methods/main/MissingMainName.parser new file mode 100644 index 00000000..c2270834 --- /dev/null +++ b/Compiler/testdata/parser5/methods/main/MissingMainName.parser @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/main/MissingParameterMain.java b/Compiler/testdata/parser5/methods/main/MissingParameterMain.java new file mode 100644 index 00000000..c8249372 --- /dev/null +++ b/Compiler/testdata/parser5/methods/main/MissingParameterMain.java @@ -0,0 +1,11 @@ +/** + * comma after last parameter + */ + +class Error { + + + public static void main(){ + + } +} \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/main/MissingParameterMain.parser b/Compiler/testdata/parser5/methods/main/MissingParameterMain.parser new file mode 100644 index 00000000..c2270834 --- /dev/null +++ b/Compiler/testdata/parser5/methods/main/MissingParameterMain.parser @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/main/MissingReturnTypeMain.java b/Compiler/testdata/parser5/methods/main/MissingReturnTypeMain.java new file mode 100644 index 00000000..05ff9d37 --- /dev/null +++ b/Compiler/testdata/parser5/methods/main/MissingReturnTypeMain.java @@ -0,0 +1,11 @@ +/** + * comma after last parameter + */ + +class Error { + + public static main(String[] args) { + + } + +} \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/main/MissingReturnTypeMain.parser b/Compiler/testdata/parser5/methods/main/MissingReturnTypeMain.parser new file mode 100644 index 00000000..c2270834 --- /dev/null +++ b/Compiler/testdata/parser5/methods/main/MissingReturnTypeMain.parser @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/main/NoArrayParameter.java b/Compiler/testdata/parser5/methods/main/NoArrayParameter.java new file mode 100644 index 00000000..59d89621 --- /dev/null +++ b/Compiler/testdata/parser5/methods/main/NoArrayParameter.java @@ -0,0 +1,11 @@ +/** + * comma after last parameter + */ + +class Error { + + + public static void main(String args{ + + } +} \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/main/NoArrayParameter.parser b/Compiler/testdata/parser5/methods/main/NoArrayParameter.parser new file mode 100644 index 00000000..c2270834 --- /dev/null +++ b/Compiler/testdata/parser5/methods/main/NoArrayParameter.parser @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/main/WrongParameterType.java b/Compiler/testdata/parser5/methods/main/WrongParameterType.java new file mode 100644 index 00000000..a9f510a5 --- /dev/null +++ b/Compiler/testdata/parser5/methods/main/WrongParameterType.java @@ -0,0 +1,11 @@ +/** + * comma after last parameter + */ + +class Error { + + + public static void main(Hans[] args{ + + } +} \ No newline at end of file diff --git a/Compiler/testdata/parser5/methods/main/WrongParameterType.parser b/Compiler/testdata/parser5/methods/main/WrongParameterType.parser new file mode 100644 index 00000000..c2270834 --- /dev/null +++ b/Compiler/testdata/parser5/methods/main/WrongParameterType.parser @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/Compiler/tests/compiler/parser/ParserOutputTest.java b/Compiler/tests/compiler/parser/ParserOutputTest.java index 812bb2d3..bd508a00 100644 --- a/Compiler/tests/compiler/parser/ParserOutputTest.java +++ b/Compiler/tests/compiler/parser/ParserOutputTest.java @@ -80,6 +80,7 @@ public void testParserFiles() throws Exception { } private static void testSourceFile(Path sourceFile, Path parserFile) throws Exception { + System.out.println("Testing parsing of " + sourceFile); // read expected output List expectedOutput = Files.readAllLines(parserFile, StandardCharsets.US_ASCII); Parser parser = TestUtils.initParser(sourceFile); diff --git a/Compiler/tests/compiler/parser/ParserTest.java b/Compiler/tests/compiler/parser/ParserTest.java index 95308230..69fbe8e8 100644 --- a/Compiler/tests/compiler/parser/ParserTest.java +++ b/Compiler/tests/compiler/parser/ParserTest.java @@ -29,11 +29,18 @@ public void testParseEmptyFile() throws IOException, ParserException { } @Test - public void testParseWrongClassDeclarationStart() throws IOException, ParserException { + public void testParseOnlyIntToken() throws IOException, ParserException { int errors = parseWithEof(TokenType.INT); assertEquals(1, errors); } + @Test + public void testParseCurlyBracketClassName() throws IOException, ParserException { + int errors = parseWithEof(TokenType.CLASS, TokenType.RCURLYBRACKET, TokenType.LCURLYBRACKET, + TokenType.RCURLYBRACKET); + assertEquals(2, errors); + } + @Test public void testParseEmptyClass() throws IOException, ParserException { parseWithEof( // class Class { }