diff --git a/mlir/examples/toy/Ch1/include/toy/Parser.h b/mlir/examples/toy/Ch1/include/toy/Parser.h --- a/mlir/examples/toy/Ch1/include/toy/Parser.h +++ b/mlir/examples/toy/Ch1/include/toy/Parser.h @@ -396,7 +396,11 @@ /// decl_list ::= identifier | identifier, decl_list std::unique_ptr parsePrototype() { auto loc = lexer.getLastLocation(); + + if (lexer.getCurToken() != tok_def) + return parseError("def", "in prototype"); lexer.consume(tok_def); + if (lexer.getCurToken() != tok_identifier) return parseError("function name", "in prototype"); diff --git a/mlir/examples/toy/Ch2/include/toy/Parser.h b/mlir/examples/toy/Ch2/include/toy/Parser.h --- a/mlir/examples/toy/Ch2/include/toy/Parser.h +++ b/mlir/examples/toy/Ch2/include/toy/Parser.h @@ -396,7 +396,11 @@ /// decl_list ::= identifier | identifier, decl_list std::unique_ptr parsePrototype() { auto loc = lexer.getLastLocation(); + + if (lexer.getCurToken() != tok_def) + return parseError("def", "in prototype"); lexer.consume(tok_def); + if (lexer.getCurToken() != tok_identifier) return parseError("function name", "in prototype"); diff --git a/mlir/examples/toy/Ch3/include/toy/Parser.h b/mlir/examples/toy/Ch3/include/toy/Parser.h --- a/mlir/examples/toy/Ch3/include/toy/Parser.h +++ b/mlir/examples/toy/Ch3/include/toy/Parser.h @@ -396,7 +396,11 @@ /// decl_list ::= identifier | identifier, decl_list std::unique_ptr parsePrototype() { auto loc = lexer.getLastLocation(); + + if (lexer.getCurToken() != tok_def) + return parseError("def", "in prototype"); lexer.consume(tok_def); + if (lexer.getCurToken() != tok_identifier) return parseError("function name", "in prototype"); diff --git a/mlir/examples/toy/Ch4/include/toy/Parser.h b/mlir/examples/toy/Ch4/include/toy/Parser.h --- a/mlir/examples/toy/Ch4/include/toy/Parser.h +++ b/mlir/examples/toy/Ch4/include/toy/Parser.h @@ -396,7 +396,11 @@ /// decl_list ::= identifier | identifier, decl_list std::unique_ptr parsePrototype() { auto loc = lexer.getLastLocation(); + + if (lexer.getCurToken() != tok_def) + return parseError("def", "in prototype"); lexer.consume(tok_def); + if (lexer.getCurToken() != tok_identifier) return parseError("function name", "in prototype"); diff --git a/mlir/examples/toy/Ch5/include/toy/Parser.h b/mlir/examples/toy/Ch5/include/toy/Parser.h --- a/mlir/examples/toy/Ch5/include/toy/Parser.h +++ b/mlir/examples/toy/Ch5/include/toy/Parser.h @@ -396,7 +396,11 @@ /// decl_list ::= identifier | identifier, decl_list std::unique_ptr parsePrototype() { auto loc = lexer.getLastLocation(); + + if (lexer.getCurToken() != tok_def) + return parseError("def", "in prototype"); lexer.consume(tok_def); + if (lexer.getCurToken() != tok_identifier) return parseError("function name", "in prototype"); diff --git a/mlir/examples/toy/Ch6/include/toy/Parser.h b/mlir/examples/toy/Ch6/include/toy/Parser.h --- a/mlir/examples/toy/Ch6/include/toy/Parser.h +++ b/mlir/examples/toy/Ch6/include/toy/Parser.h @@ -396,7 +396,11 @@ /// decl_list ::= identifier | identifier, decl_list std::unique_ptr parsePrototype() { auto loc = lexer.getLastLocation(); + + if (lexer.getCurToken() != tok_def) + return parseError("def", "in prototype"); lexer.consume(tok_def); + if (lexer.getCurToken() != tok_identifier) return parseError("function name", "in prototype"); diff --git a/mlir/examples/toy/Ch7/include/toy/Parser.h b/mlir/examples/toy/Ch7/include/toy/Parser.h --- a/mlir/examples/toy/Ch7/include/toy/Parser.h +++ b/mlir/examples/toy/Ch7/include/toy/Parser.h @@ -534,7 +534,11 @@ /// decl_list ::= identifier | identifier, decl_list std::unique_ptr parsePrototype() { auto loc = lexer.getLastLocation(); + + if (lexer.getCurToken() != tok_def) + return parseError("def", "in prototype"); lexer.consume(tok_def); + if (lexer.getCurToken() != tok_identifier) return parseError("function name", "in prototype"); diff --git a/mlir/test/Examples/Toy/Ch1/empty.toy b/mlir/test/Examples/Toy/Ch1/empty.toy new file mode 100644 --- /dev/null +++ b/mlir/test/Examples/Toy/Ch1/empty.toy @@ -0,0 +1,3 @@ +# RUN: toyc-ch1 %s -emit=ast 2>&1 | FileCheck %s +# CHECK-NOT: Assert +# CHECK: Parse error diff --git a/mlir/test/Examples/Toy/Ch2/empty.toy b/mlir/test/Examples/Toy/Ch2/empty.toy new file mode 100644 --- /dev/null +++ b/mlir/test/Examples/Toy/Ch2/empty.toy @@ -0,0 +1,3 @@ +# RUN: toyc-ch2 %s -emit=ast 2>&1 | FileCheck %s +# CHECK-NOT: Assert +# CHECK: Parse error diff --git a/mlir/test/Examples/Toy/Ch3/empty.toy b/mlir/test/Examples/Toy/Ch3/empty.toy new file mode 100644 --- /dev/null +++ b/mlir/test/Examples/Toy/Ch3/empty.toy @@ -0,0 +1,3 @@ +# RUN: toyc-ch3 %s -emit=ast 2>&1 | FileCheck %s +# CHECK-NOT: Assert +# CHECK: Parse error diff --git a/mlir/test/Examples/Toy/Ch4/empty.toy b/mlir/test/Examples/Toy/Ch4/empty.toy new file mode 100644 --- /dev/null +++ b/mlir/test/Examples/Toy/Ch4/empty.toy @@ -0,0 +1,3 @@ +# RUN: toyc-ch4 %s -emit=ast 2>&1 | FileCheck %s +# CHECK-NOT: Assert +# CHECK: Parse error diff --git a/mlir/test/Examples/Toy/Ch5/empty.toy b/mlir/test/Examples/Toy/Ch5/empty.toy new file mode 100644 --- /dev/null +++ b/mlir/test/Examples/Toy/Ch5/empty.toy @@ -0,0 +1,3 @@ +# RUN: toyc-ch5 %s -emit=ast 2>&1 | FileCheck %s +# CHECK-NOT: Assert +# CHECK: Parse error diff --git a/mlir/test/Examples/Toy/Ch6/empty.toy b/mlir/test/Examples/Toy/Ch6/empty.toy new file mode 100644 --- /dev/null +++ b/mlir/test/Examples/Toy/Ch6/empty.toy @@ -0,0 +1,3 @@ +# RUN: toyc-ch6 %s -emit=ast 2>&1 | FileCheck %s +# CHECK-NOT: Assert +# CHECK: Parse error diff --git a/mlir/test/Examples/Toy/Ch7/empty.toy b/mlir/test/Examples/Toy/Ch7/empty.toy new file mode 100644 --- /dev/null +++ b/mlir/test/Examples/Toy/Ch7/empty.toy @@ -0,0 +1,4 @@ +# RUN: toyc-ch7 %s -emit=ast 2>&1 | FileCheck %s +# CHECK-NOT: Assert +# CHECK-NOT: Parse error +# CHECK: Module