From 3c9dd93c8ba7360f2e91c8e87709cbe8273d7fa3 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Fri, 24 Jan 2020 14:35:15 +0100 Subject: [PATCH] Fixed again priority of "->" vs "*" in type expressions. Fixed negative tests. --- src/bin/expect_tests/lexer_tests.ml | 72 ++++++++++++++-------- src/bin/expect_tests/syntax_error_tests.ml | 4 +- src/passes/1-parser/cameligo/Parser.mly | 2 +- src/passes/1-parser/pascaligo/Parser.mly | 4 +- src/test/contracts/high-order.ligo | 63 +++++++++---------- 5 files changed, 80 insertions(+), 65 deletions(-) diff --git a/src/bin/expect_tests/lexer_tests.ml b/src/bin/expect_tests/lexer_tests.ml index 99c75f077..0b60086ce 100644 --- a/src/bin/expect_tests/lexer_tests.ml +++ b/src/bin/expect_tests/lexer_tests.ml @@ -3,9 +3,10 @@ open Cli_expect let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/lexer/broken_string.ligo" ; "main" ] ; [%expect {| -ligo: lexer error: The string starting here is interrupted by a line break. +ligo: : Lexical error in file "broken_string.ligo", line 1, characters 18-19: + The string starting here is interrupted by a line break. Hint: Remove the break, close the string before or insert a backslash. - {"parser_loc":"in file \"broken_string.ligo\", line 1, characters 18-19"} + {"parser_loc":"in file \"broken_string.ligo\", line 1, characters 18-19"} If you're not sure how to fix this error, you can @@ -19,9 +20,10 @@ ligo: lexer error: The string starting here is interrupted by a line break. run_ligo_bad [ "compile-contract" ; "../../test/lexer/broken_string.mligo" ; "main" ] ; [%expect {| -ligo: lexer error: The string starting here is interrupted by a line break. +ligo: : Lexical error at line 1, characters 8-9: + The string starting here is interrupted by a line break. Hint: Remove the break, close the string before or insert a backslash. - {"parser_loc":"in file \"broken_string.mligo\", line 1, characters 8-9"} + {"parser_loc":"in file \"broken_string.mligo\", line 1, characters 8-9"} If you're not sure how to fix this error, you can @@ -35,7 +37,8 @@ ligo: lexer error: The string starting here is interrupted by a line break. run_ligo_bad [ "compile-contract" ; "../../test/lexer/broken_string.religo" ; "main" ] ; [%expect {| -ligo: lexer error: The string starting here is interrupted by a line break. +ligo: : Lexical error at line 1, characters 8-9: + The string starting here is interrupted by a line break. Hint: Remove the break, close the string before or insert a backslash. {"parser_loc":"in file \"broken_string.religo\", line 1, characters 8-9"} @@ -51,7 +54,8 @@ ligo: lexer error: The string starting here is interrupted by a line break. run_ligo_bad [ "compile-contract" ; "../../test/lexer/negative_byte_sequence.ligo" ; "main" ] ; [%expect {| -ligo: lexer error: Negative byte sequence. +ligo: : Lexical error in file "negative_byte_sequence.ligo", line 1, characters 18-23: + Negative byte sequence. Hint: Remove the leading minus sign. {"parser_loc":"in file \"negative_byte_sequence.ligo\", line 1, characters 18-23"} @@ -67,7 +71,8 @@ ligo: lexer error: Negative byte sequence. run_ligo_bad [ "compile-contract" ; "../../test/lexer/negative_byte_sequence.mligo" ; "main" ] ; [%expect {| -ligo: lexer error: Negative byte sequence. +ligo: : Lexical error at line 1, characters 8-13: + Negative byte sequence. Hint: Remove the leading minus sign. {"parser_loc":"in file \"negative_byte_sequence.mligo\", line 1, characters 8-13"} @@ -83,9 +88,10 @@ ligo: lexer error: Negative byte sequence. run_ligo_bad [ "compile-contract" ; "../../test/lexer/negative_byte_sequence.religo" ; "main" ] ; [%expect {| -ligo: lexer error: Negative byte sequence. +ligo: : Lexical error at line 1, characters 8-13: + Negative byte sequence. Hint: Remove the leading minus sign. - {"parser_loc":"in file \"negative_byte_sequence.religo\", line 1, characters 8-13"} + {"parser_loc":"in file \"negative_byte_sequence.religo\", line 1, characters 8-13"} If you're not sure how to fix this error, you can @@ -99,7 +105,8 @@ ligo: lexer error: Negative byte sequence. run_ligo_bad [ "compile-contract" ; "../../test/lexer/reserved_name.ligo" ; "main" ] ; [%expect {| -ligo: lexer error: Reserved name: arguments. +ligo: : Lexical error in file "reserved_name.ligo", line 1, characters 4-13: + Reserved name: arguments. Hint: Change the name. {"parser_loc":"in file \"reserved_name.ligo\", line 1, characters 4-13"} @@ -115,7 +122,8 @@ ligo: lexer error: Reserved name: arguments. run_ligo_bad [ "compile-contract" ; "../../test/lexer/reserved_name.religo" ; "main" ] ; [%expect {| -ligo: lexer error: Reserved name: end. +ligo: : Lexical error at line 1, characters 4-7: + Reserved name: end. Hint: Change the name. {"parser_loc":"in file \"reserved_name.religo\", line 1, characters 4-7"} @@ -131,7 +139,8 @@ ligo: lexer error: Reserved name: end. run_ligo_bad [ "compile-contract" ; "../../test/lexer/reserved_name.mligo" ; "main" ] ; [%expect {| -ligo: lexer error: Reserved name: object. +ligo: : Lexical error at line 1, characters 4-10: + Reserved name: object. Hint: Change the name. {"parser_loc":"in file \"reserved_name.mligo\", line 1, characters 4-10"} @@ -147,7 +156,8 @@ ligo: lexer error: Reserved name: object. run_ligo_bad [ "compile-contract" ; "../../test/lexer/unexpected_character.ligo" ; "main" ] ; [%expect {| -ligo: lexer error: Unexpected character '\239'. +ligo: : Lexical error in file "unexpected_character.ligo", line 1, characters 18-19: + Unexpected character '\239'. {"parser_loc":"in file \"unexpected_character.ligo\", line 1, characters 18-19"} @@ -162,7 +172,8 @@ ligo: lexer error: Unexpected character '\239'. run_ligo_bad [ "compile-contract" ; "../../test/lexer/unexpected_character.mligo" ; "main" ] ; [%expect {| -ligo: lexer error: Unexpected character '\239'. +ligo: : Lexical error at line 1, characters 8-9: + Unexpected character '\239'. {"parser_loc":"in file \"unexpected_character.mligo\", line 1, characters 8-9"} @@ -177,7 +188,8 @@ ligo: lexer error: Unexpected character '\239'. run_ligo_bad [ "compile-contract" ; "../../test/lexer/unexpected_character.religo" ; "main" ] ; [%expect {| -ligo: lexer error: Unexpected character '\239'. +ligo: : Lexical error at line 1, characters 8-9: + Unexpected character '\239'. {"parser_loc":"in file \"unexpected_character.religo\", line 1, characters 8-9"} @@ -192,7 +204,8 @@ ligo: lexer error: Unexpected character '\239'. run_ligo_bad [ "compile-contract" ; "../../test/lexer/unterminated_comment.mligo" ; "main" ] ; [%expect {| -ligo: lexer error: Unterminated comment. +ligo: : Lexical error at line 1, characters 0-2: + Unterminated comment. Hint: Close with "*)". {"parser_loc":"in file \"unterminated_comment.mligo\", line 1, characters 0-2"} @@ -208,7 +221,8 @@ ligo: lexer error: Unterminated comment. run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_symbol.ligo" ; "main" ] ; [%expect {| -ligo: lexer error: Invalid symbol. +ligo: : Lexical error in file "invalid_symbol.ligo", line 1, characters 17-20: + Invalid symbol. Hint: Check the LIGO syntax you use. {"parser_loc":"in file \"invalid_symbol.ligo\", line 1, characters 17-20"} @@ -224,7 +238,8 @@ ligo: lexer error: Invalid symbol. run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_symbol.mligo" ; "main" ] ; [%expect {| -ligo: lexer error: Invalid symbol. +ligo: : Lexical error at line 1, characters 10-13: + Invalid symbol. Hint: Check the LIGO syntax you use. {"parser_loc":"in file \"invalid_symbol.mligo\", line 1, characters 10-13"} @@ -240,7 +255,8 @@ ligo: lexer error: Invalid symbol. run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_symbol.religo" ; "main" ] ; [%expect {| -ligo: lexer error: Invalid symbol. +ligo: : Lexical error at line 1, characters 10-11: + Invalid symbol. Hint: Check the LIGO syntax you use. {"parser_loc":"in file \"invalid_symbol.religo\", line 1, characters 10-11"} @@ -256,7 +272,8 @@ ligo: lexer error: Invalid symbol. run_ligo_bad [ "compile-contract" ; "../../test/lexer/missing_break.ligo" ; "main" ] ; [%expect {| -ligo: lexer error: Missing break. +ligo: : Lexical error in file "missing_break.ligo", line 1, characters 18-18: + Missing break. Hint: Insert some space. {"parser_loc":"in file \"missing_break.ligo\", line 1, characters 18-18"} @@ -272,7 +289,8 @@ ligo: lexer error: Missing break. run_ligo_bad [ "compile-contract" ; "../../test/lexer/missing_break.mligo" ; "main" ] ; [%expect {| -ligo: lexer error: Missing break. +ligo: : Lexical error at line 1, characters 11-11: + Missing break. Hint: Insert some space. {"parser_loc":"in file \"missing_break.mligo\", line 1, characters 11-11"} @@ -288,7 +306,8 @@ ligo: lexer error: Missing break. run_ligo_bad [ "compile-contract" ; "../../test/lexer/missing_break.religo" ; "main" ] ; [%expect {| -ligo: lexer error: Missing break. +ligo: : Lexical error at line 1, characters 11-11: + Missing break. Hint: Insert some space. {"parser_loc":"in file \"missing_break.religo\", line 1, characters 11-11"} @@ -304,7 +323,8 @@ ligo: lexer error: Missing break. run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_character_in_string.ligo" ; "main" ] ; [%expect {| -ligo: lexer error: Invalid character in string. +ligo: : Lexical error in file "invalid_character_in_string.ligo", line 1, characters 19-20: + Invalid character in string. Hint: Remove or replace the character. {"parser_loc":"in file \"invalid_character_in_string.ligo\", line 1, characters 19-20"} @@ -320,7 +340,8 @@ ligo: lexer error: Invalid character in string. run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_character_in_string.mligo" ; "main" ] ; [%expect {| -ligo: lexer error: Invalid character in string. +ligo: : Lexical error at line 1, characters 9-10: + Invalid character in string. Hint: Remove or replace the character. {"parser_loc":"in file \"invalid_character_in_string.mligo\", line 1, characters 9-10"} @@ -336,7 +357,8 @@ ligo: lexer error: Invalid character in string. run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_character_in_string.religo" ; "main" ] ; [%expect {| -ligo: lexer error: Invalid character in string. +ligo: : Lexical error at line 1, characters 9-10: + Invalid character in string. Hint: Remove or replace the character. {"parser_loc":"in file \"invalid_character_in_string.religo\", line 1, characters 9-10"} diff --git a/src/bin/expect_tests/syntax_error_tests.ml b/src/bin/expect_tests/syntax_error_tests.ml index 7082dbcf9..0d75b8c47 100644 --- a/src/bin/expect_tests/syntax_error_tests.ml +++ b/src/bin/expect_tests/syntax_error_tests.ml @@ -3,8 +3,8 @@ open Cli_expect let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_syntax.ligo" ; "main" ] ; [%expect {| - ligo: parser error: Parse error at "-" from (1, 16) to (1, 17). In file "|../../test/contracts/negative/error_syntax.ligo" - {"parser_loc":"in file \"\", line 1, characters 16-17"} + ligo: : Parse error in file "error_syntax.ligo", line 1, characters 16-17, after "bar" and before "-". + {"parser_loc":"in file \"error_syntax.ligo\", line 1, characters 16-17"} If you're not sure how to fix this error, you can diff --git a/src/passes/1-parser/cameligo/Parser.mly b/src/passes/1-parser/cameligo/Parser.mly index e6cc6f903..08c267a13 100644 --- a/src/passes/1-parser/cameligo/Parser.mly +++ b/src/passes/1-parser/cameligo/Parser.mly @@ -182,7 +182,7 @@ sum_type: variant: "" { {$1 with value={constr=$1; arg=None}} } -| "" "of" cartesian { +| "" "of" fun_type { let region = cover $1.region (type_expr_to_region $3) and value = {constr=$1; arg = Some ($2,$3)} in {region; value} } diff --git a/src/passes/1-parser/pascaligo/Parser.mly b/src/passes/1-parser/pascaligo/Parser.mly index 70a03bdb6..a36adceee 100644 --- a/src/passes/1-parser/pascaligo/Parser.mly +++ b/src/passes/1-parser/pascaligo/Parser.mly @@ -201,7 +201,7 @@ sum_type: variant: "" { {$1 with value = {constr=$1; arg=None}} } -| "" "of" cartesian { +| "" "of" fun_type { let region = cover $1.region (type_expr_to_region $3) and value = {constr=$1; arg = Some ($2,$3)} in {region; value} } @@ -315,7 +315,7 @@ param_decl: in ParamConst {region; value} } param_type: - cartesian { $1 } + fun_type { $1 } block: "begin" sep_or_term_list(statement,";") "end" { diff --git a/src/test/contracts/high-order.ligo b/src/test/contracts/high-order.ligo index 5540d6f99..20162400d 100644 --- a/src/test/contracts/high-order.ligo +++ b/src/test/contracts/high-order.ligo @@ -1,52 +1,45 @@ // Test a PascaLIGO function which takes another PascaLIGO function as an argument function foobar (const i : int) : int is - block { - function foo (const i : int) : int is - i ; - function bar (const f : int -> int) : int is - f ( i ) ; - } with bar (foo) ; + begin + function foo (const i : int) : int is i; + function bar (const f : int -> int) : int is f (i); + end with bar (foo); // higher order function with more than one argument -function higher2(const i: int; const f: int -> int): int is - block { - const ii: int = f(i) - } with ii +function higher2(const i : int; const f : int -> int): int is + begin + const ii: int = f (i) + end with ii function foobar2 (const i : int) : int is - block { - function foo2 (const i : int) : int is - i; - } with higher2(i,foo2) + begin + function foo2 (const i : int) : int is i + end with higher2 (i,foo2) const a : int = 0; + function foobar3 (const i : int) : int is - block { - function foo2 (const i : int) : int is - (a+i); - } with higher2(i,foo2) + begin + function foo2 (const i : int) : int is a+i + end with higher2 (i,foo2) -function f (const i : int) : int is - i +function f (const i : int) : int is i -function g (const i : int) : int is - f(i) +function g (const i : int) : int is f (i) -function foobar4 (const i : int) : int is - g(g(i)) +function foobar4 (const i : int) : int is g (g (i)) -function higher3(const i: int; const f: int -> int; const g: int -> int): int is - block { - const ii: int = f(g(i)); - } with ii +function higher3(const i : int; const f : int -> int; const g : int -> int) +: int is + begin + const ii : int = f(g(i)) + end with ii function foobar5 (const i : int) : int is - block { + begin const a : int = 0; - function foo (const i : int) : int is - (a+i); - function goo (const i : int) : int is - foo(i); - } with higher3(i,foo,goo) + function foo (const i : int) : int is a+i; + function goo (const i : int) : int is foo (i) + end with higher3(i,foo,goo) -function foobar6 (const i : int) : (int->int) is f \ No newline at end of file +function foobar6 (const i : int) : int -> int is f