Merge branch 'dev' of gitlab.com:ligolang/ligo into rinderknecht-dev
This commit is contained in:
commit
8bdc103ec8
28
CHANGELOG.md
Normal file
28
CHANGELOG.md
Normal file
@ -0,0 +1,28 @@
|
||||
# Changelog
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1899dfe8d7285580b3aa30fab933ed589f8f1bc5] - 2020-01-08
|
||||
### Added
|
||||
- Partial application and OCaml-like currying behavior to CameLIGO & ReasonLIGO
|
||||
|
||||
### Changed
|
||||
- Contract entrypoints now need to use tuple parameters in CameLIGO
|
||||
|
||||
### Docs
|
||||
- Explain currying
|
||||
- Now use tuple parameters in function examples
|
||||
- Now have map examples which are runnable as a combined block for doc tests
|
||||
|
||||
### Tests
|
||||
- More tests take advantage of tuple parameter destructuring (i.e.
|
||||
`let thing (p,s: param * storage) : int = ...`)
|
||||
- Entrypoints now use tuple parameters
|
||||
- Added Currying behavior test
|
||||
|
||||
|
||||
## [Changelog Patch](https://gitlab.com/ligolang/ligo/merge_requests/300) - 2020-01-08
|
||||
### Added
|
||||
- CHANGELOG.md that keeps track of notable changes to LIGO, etc
|
||||
- 'changelog' command to LIGO command line that dumps CHANGELOG.md to stdout
|
||||
- Help tips message with options for getting assistance that's printed on error
|
@ -15,6 +15,7 @@ depends: [
|
||||
"ppx_let"
|
||||
"ppx_deriving"
|
||||
"ppx_expect"
|
||||
"ppx_blob"
|
||||
"tezos-utils"
|
||||
"proto-alpha-utils"
|
||||
"yojson"
|
||||
|
@ -337,6 +337,14 @@ let compile_expression =
|
||||
let doc = "Subcommand: compile to a michelson value." in
|
||||
(Term.ret term , Term.info ~doc cmdname)
|
||||
|
||||
let dump_changelog =
|
||||
let f display_format = toplevel ~display_format @@ (ok @@ [%blob "../../CHANGELOG.md"]) in
|
||||
let term =
|
||||
Term.(const f $ display_format) in
|
||||
let cmdname = "changelog" in
|
||||
let doc = "Dump the LIGO changelog to stdout." in
|
||||
(Term.ret term , Term.info ~doc cmdname)
|
||||
|
||||
let run ?argv () =
|
||||
Term.eval_choice ?argv main [
|
||||
compile_file ;
|
||||
@ -348,4 +356,5 @@ let run ?argv () =
|
||||
dry_run ;
|
||||
run_function ;
|
||||
evaluate_value ;
|
||||
dump_changelog ;
|
||||
]
|
||||
|
@ -2,9 +2,22 @@ open Cmdliner
|
||||
open Trace
|
||||
open Main.Display
|
||||
|
||||
let error_suggest: string = "\n If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'"
|
||||
|
||||
let toplevel ~(display_format : display_format) (x : string result) : unit Term.ret =
|
||||
match x with
|
||||
| Ok _ -> Format.printf "%a%!" (formatted_string_result_pp display_format) x;
|
||||
`Ok ()
|
||||
| Error _ ->
|
||||
`Error (false, Format.asprintf "%a%!" (formatted_string_result_pp display_format) x)
|
||||
begin
|
||||
match display_format with
|
||||
| `Human_readable -> print_string error_suggest ;
|
||||
| _ -> ()
|
||||
end ;
|
||||
`Error (false, Format.asprintf "%a%!" (formatted_string_result_pp display_format) x)
|
||||
|
@ -7,8 +7,9 @@
|
||||
)
|
||||
(modules cli cli_helpers version)
|
||||
(preprocess
|
||||
(pps ppx_let bisect_ppx --conditional)
|
||||
(pps ppx_let ppx_blob bisect_ppx --conditional)
|
||||
)
|
||||
(preprocessor_deps (file ../../CHANGELOG.md))
|
||||
(flags (:standard -open Simple_utils))
|
||||
)
|
||||
|
||||
@ -31,7 +32,7 @@
|
||||
(modules runligo)
|
||||
(package ligo)
|
||||
(preprocess
|
||||
(pps ppx_let bisect_ppx --conditional)
|
||||
(pps ppx_let ppx_blob bisect_ppx --conditional)
|
||||
)
|
||||
(flags (:standard -open Simple_utils))
|
||||
)
|
||||
|
@ -23,10 +23,30 @@ let%expect_test _ =
|
||||
[%expect {| (Pair (Pair {} {}) 3) |}] ;
|
||||
|
||||
run_ligo_bad [ "compile-storage" ; contract "coase.ligo" ; "main" ; "Buy_single (record card_to_buy = 1n end)" ] ;
|
||||
[%expect {| ligo: different kinds: {"a":"record[next_id -> nat , cards -> (TO_Map (nat,record[card_pattern -> nat , card_owner -> address])) , card_patterns -> (TO_Map (nat,record[quantity -> nat , coefficient -> mutez]))]","b":"sum[Transfer_single -> record[destination -> address , card_to_transfer -> nat] , Sell_single -> record[card_to_sell -> nat] , Buy_single -> record[card_to_buy -> nat]]"} |}] ;
|
||||
[%expect {|
|
||||
ligo: different kinds: {"a":"record[next_id -> nat , cards -> (TO_Map (nat,record[card_pattern -> nat , card_owner -> address])) , card_patterns -> (TO_Map (nat,record[quantity -> nat , coefficient -> mutez]))]","b":"sum[Transfer_single -> record[destination -> address , card_to_transfer -> nat] , Sell_single -> record[card_to_sell -> nat] , Buy_single -> record[card_to_buy -> nat]]"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |}] ;
|
||||
|
||||
run_ligo_bad [ "compile-parameter" ; contract "coase.ligo" ; "main" ; "record cards = (map end : cards) ; card_patterns = (map end : card_patterns) ; next_id = 3n ; end" ] ;
|
||||
[%expect {| ligo: different kinds: {"a":"sum[Transfer_single -> record[destination -> address , card_to_transfer -> nat] , Sell_single -> record[card_to_sell -> nat] , Buy_single -> record[card_to_buy -> nat]]","b":"record[next_id -> nat , cards -> (TO_Map (nat,record[card_pattern -> nat , card_owner -> address])) , card_patterns -> (TO_Map (nat,record[quantity -> nat , coefficient -> mutez]))]"} |}] ;
|
||||
[%expect {|
|
||||
ligo: different kinds: {"a":"sum[Transfer_single -> record[destination -> address , card_to_transfer -> nat] , Sell_single -> record[card_to_sell -> nat] , Buy_single -> record[card_to_buy -> nat]]","b":"record[next_id -> nat , cards -> (TO_Map (nat,record[card_pattern -> nat , card_owner -> address])) , card_patterns -> (TO_Map (nat,record[quantity -> nat , coefficient -> mutez]))]"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |}] ;
|
||||
|
||||
()
|
||||
|
||||
@ -931,19 +951,58 @@ let%expect_test _ =
|
||||
|
||||
let%expect_test _ =
|
||||
run_ligo_bad [ "compile-contract" ; contract "bad_type_operator.ligo" ; "main" ] ;
|
||||
[%expect {| ligo: bad type operator (TO_Map (unit,unit)): |}]
|
||||
[%expect {|
|
||||
ligo: bad type operator (TO_Map (unit,unit)):
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |}]
|
||||
|
||||
let%expect_test _ =
|
||||
run_ligo_bad [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ] ;
|
||||
[%expect {| ligo: Execution failed: {"value":"some_string","type":"string"} |}]
|
||||
[%expect {|
|
||||
ligo: Execution failed: {"value":"some_string","type":"string"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |}]
|
||||
|
||||
let%expect_test _ =
|
||||
run_ligo_bad [ "compile-contract" ; contract "bad_address_format.religo" ; "main" ] ;
|
||||
[%expect {| ligo: in file "bad_address_format.religo", line 2, characters 25-47. Badly formatted literal: address "KT1badaddr" {"location":"in file \"bad_address_format.religo\", line 2, characters 25-47"} |}]
|
||||
[%expect {|
|
||||
ligo: in file "bad_address_format.religo", line 2, characters 25-47. Badly formatted literal: address "KT1badaddr" {"location":"in file \"bad_address_format.religo\", line 2, characters 25-47"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |}]
|
||||
|
||||
let%expect_test _ =
|
||||
run_ligo_bad [ "compile-contract" ; contract "bad_timestamp.ligo" ; "main" ] ;
|
||||
[%expect {| ligo: in file "bad_timestamp.ligo", line 5, characters 29-43. Badly formatted timestamp "badtimestamp": {"location":"in file \"bad_timestamp.ligo\", line 5, characters 29-43"} |}]
|
||||
[%expect {|
|
||||
ligo: in file "bad_timestamp.ligo", line 5, characters 29-43. Badly formatted timestamp "badtimestamp": {"location":"in file \"bad_timestamp.ligo\", line 5, characters 29-43"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |}]
|
||||
|
||||
let%expect_test _ =
|
||||
run_ligo_good [ "dry-run" ; contract "redeclaration.ligo" ; "main" ; "unit" ; "0" ] ;
|
||||
@ -951,4 +1010,4 @@ let%expect_test _ =
|
||||
|
||||
let%expect_test _ =
|
||||
run_ligo_good [ "dry-run" ; contract "double_main.ligo" ; "main" ; "unit" ; "0" ] ;
|
||||
[%expect {|( [] , 2 ) |}]
|
||||
[%expect {|( [] , 2 ) |}]
|
||||
|
@ -1,6 +1,6 @@
|
||||
(library
|
||||
(name cli_expect_tests)
|
||||
(libraries simple-utils cli)
|
||||
(inline_tests (deps (source_tree ../../test/contracts)))
|
||||
(inline_tests (deps (source_tree ../../test/contracts) (source_tree ../../test/lexer)))
|
||||
(preprocess (pps ppx_let ppx_expect))
|
||||
(flags (:standard -open Simple_utils)))
|
||||
|
@ -14,6 +14,9 @@ let%expect_test _ =
|
||||
Use `ligo COMMAND --help' for help on a single command.
|
||||
|
||||
COMMANDS
|
||||
changelog
|
||||
Dump the LIGO changelog to stdout.
|
||||
|
||||
compile-contract
|
||||
Subcommand: compile a contract.
|
||||
|
||||
@ -68,6 +71,9 @@ let%expect_test _ =
|
||||
Use `ligo COMMAND --help' for help on a single command.
|
||||
|
||||
COMMANDS
|
||||
changelog
|
||||
Dump the LIGO changelog to stdout.
|
||||
|
||||
compile-contract
|
||||
Subcommand: compile a contract.
|
||||
|
||||
|
351
src/bin/expect_tests/lexer_tests.ml
Normal file
351
src/bin/expect_tests/lexer_tests.ml
Normal file
@ -0,0 +1,351 @@
|
||||
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.
|
||||
Hint: Remove the break, close the string before or insert a backslash.
|
||||
{"parser_loc":"in file \"broken_string.ligo\", line 1, characters 18-19"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
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.
|
||||
Hint: Remove the break, close the string before or insert a backslash.
|
||||
{"parser_loc":"in file \"broken_string.mligo\", line 1, characters 8-9"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
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.
|
||||
Hint: Remove the break, close the string before or insert a backslash.
|
||||
{"parser_loc":"in file \"broken_string.religo\", line 1, characters 8-9"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/negative_byte_sequence.ligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Negative byte sequence.
|
||||
Hint: Remove the leading minus sign.
|
||||
{"parser_loc":"in file \"negative_byte_sequence.ligo\", line 1, characters 18-23"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/negative_byte_sequence.mligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Negative byte sequence.
|
||||
Hint: Remove the leading minus sign.
|
||||
{"parser_loc":"in file \"negative_byte_sequence.mligo\", line 1, characters 8-13"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/negative_byte_sequence.religo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Negative byte sequence.
|
||||
Hint: Remove the leading minus sign.
|
||||
{"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
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/reserved_name.ligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Reserved name: args.
|
||||
Hint: Change the name.
|
||||
{"parser_loc":"in file \"reserved_name.ligo\", line 1, characters 4-8"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/reserved_name.religo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Reserved name: end.
|
||||
Hint: Change the name.
|
||||
{"parser_loc":"in file \"reserved_name.religo\", line 1, characters 4-7"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/reserved_name.mligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Reserved name: object.
|
||||
Hint: Change the name.
|
||||
{"parser_loc":"in file \"reserved_name.mligo\", line 1, characters 4-10"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/unexpected_character.ligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Unexpected character '\239'.
|
||||
{"parser_loc":"in file \"unexpected_character.ligo\", line 1, characters 18-19"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/unexpected_character.mligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Unexpected character '\239'.
|
||||
{"parser_loc":"in file \"unexpected_character.mligo\", line 1, characters 8-9"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/unexpected_character.religo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Unexpected character '\239'.
|
||||
{"parser_loc":"in file \"unexpected_character.religo\", line 1, characters 8-9"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/unterminated_comment.mligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Unterminated comment.
|
||||
Hint: Close with "*)".
|
||||
{"parser_loc":"in file \"unterminated_comment.mligo\", line 1, characters 0-2"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_symbol.ligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Invalid symbol.
|
||||
Hint: Check the LIGO syntax you use.
|
||||
{"parser_loc":"in file \"invalid_symbol.ligo\", line 1, characters 17-20"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_symbol.mligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Invalid symbol.
|
||||
Hint: Check the LIGO syntax you use.
|
||||
{"parser_loc":"in file \"invalid_symbol.mligo\", line 1, characters 10-13"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_symbol.religo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Invalid symbol.
|
||||
Hint: Check the LIGO syntax you use.
|
||||
{"parser_loc":"in file \"invalid_symbol.religo\", line 1, characters 10-11"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/missing_break.ligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Missing break.
|
||||
Hint: Insert some space.
|
||||
{"parser_loc":"in file \"missing_break.ligo\", line 1, characters 18-18"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/missing_break.mligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Missing break.
|
||||
Hint: Insert some space.
|
||||
{"parser_loc":"in file \"missing_break.mligo\", line 1, characters 11-11"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/missing_break.religo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Missing break.
|
||||
Hint: Insert some space.
|
||||
{"parser_loc":"in file \"missing_break.religo\", line 1, characters 11-11"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_character_in_string.ligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Invalid character in string.
|
||||
Hint: Remove or replace the character.
|
||||
{"parser_loc":"in file \"invalid_character_in_string.ligo\", line 1, characters 19-20"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_character_in_string.mligo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Invalid character in string.
|
||||
Hint: Remove or replace the character.
|
||||
{"parser_loc":"in file \"invalid_character_in_string.mligo\", line 1, characters 9-10"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ];
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_character_in_string.religo" ; "main" ] ;
|
||||
[%expect {|
|
||||
ligo: lexer error: Invalid character in string.
|
||||
Hint: Remove or replace the character.
|
||||
{"parser_loc":"in file \"invalid_character_in_string.religo\", line 1, characters 9-10"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog'
|
||||
|} ]
|
@ -2,24 +2,94 @@ open Cli_expect
|
||||
|
||||
let%expect_test _ =
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_1.mligo" ; "main" ] ;
|
||||
[%expect {| ligo: in file "error_typer_1.mligo", line 3, characters 19-27. different type constructors: Expected these two constant type constructors to be the same, but they're different {"a":"string","b":"int"} |} ] ;
|
||||
[%expect {|
|
||||
ligo: in file "error_typer_1.mligo", line 3, characters 19-27. different type constructors: Expected these two constant type constructors to be the same, but they're different {"a":"string","b":"int"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |} ] ;
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_2.mligo" ; "main" ] ;
|
||||
[%expect {| ligo: in file "error_typer_2.mligo", line 3, characters 24-39. different type constructors: Expected these two n-ary type constructors to be the same, but they're different {"a":"(TO_list(string))","b":"(TO_option(int))"} |} ] ;
|
||||
[%expect {|
|
||||
ligo: in file "error_typer_2.mligo", line 3, characters 24-39. different type constructors: Expected these two n-ary type constructors to be the same, but they're different {"a":"(TO_list(string))","b":"(TO_option(int))"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |} ] ;
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_3.mligo" ; "main" ] ;
|
||||
[%expect {| ligo: in file "error_typer_3.mligo", line 3, characters 34-53. tuples have different sizes: Expected these two types to be the same, but they're different (both are tuples, but with a different number of arguments) {"a":"tuple[int , string , bool]","b":"tuple[int , string]"} |} ] ;
|
||||
[%expect {|
|
||||
ligo: in file "error_typer_3.mligo", line 3, characters 34-53. tuples have different sizes: Expected these two types to be the same, but they're different (both are tuples, but with a different number of arguments) {"a":"tuple[int , string , bool]","b":"tuple[int , string]"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |} ] ;
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_4.mligo" ; "main" ] ;
|
||||
[%expect {| ligo: in file "error_typer_4.mligo", line 4, characters 17-56. different keys in record: {"key_a":"d","key_b":"c"} |} ] ;
|
||||
[%expect {|
|
||||
ligo: in file "error_typer_4.mligo", line 4, characters 17-56. different keys in record: {"key_a":"d","key_b":"c"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |} ] ;
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_5.mligo" ; "main" ] ;
|
||||
[%expect {| ligo: unbound type variable: {"variable":"boolean","in":"- E[]\tT[] ]","did_you_mean":"bool"} |} ] ;
|
||||
[%expect {|
|
||||
ligo: unbound type variable: {"variable":"boolean","in":"- E[]\tT[] ]","did_you_mean":"bool"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |} ] ;
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_6.mligo" ; "main" ] ;
|
||||
[%expect {| ligo: in file "error_typer_6.mligo", line 1, characters 30-64. different type constructors: Expected these two constant type constructors to be the same, but they're different {"a":"string","b":"bool"} |} ] ;
|
||||
[%expect {|
|
||||
ligo: in file "error_typer_6.mligo", line 1, characters 30-64. different type constructors: Expected these two constant type constructors to be the same, but they're different {"a":"string","b":"bool"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |} ] ;
|
||||
|
||||
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_7.mligo" ; "main" ] ;
|
||||
[%expect {| ligo: in file "error_typer_7.mligo", line 4, characters 18-48. records have different sizes: Expected these two types to be the same, but they're different (both are records, but with a different number of arguments) {"a":"record[b -> string , a -> int]","b":"record[c -> bool , b -> string , a -> int]"} |} ] ;
|
||||
[%expect {|
|
||||
ligo: in file "error_typer_7.mligo", line 4, characters 18-48. records have different sizes: Expected these two types to be the same, but they're different (both are records, but with a different number of arguments) {"a":"record[b -> string , a -> int]","b":"record[c -> bool , b -> string , a -> int]"}
|
||||
|
||||
|
||||
If you're not sure how to fix this error, you can
|
||||
do one of the following:
|
||||
|
||||
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
|
||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||
* Check the changelog by running 'ligo changelog' |} ] ;
|
||||
|
||||
|
||||
|
@ -18,9 +18,21 @@ module Errors = struct
|
||||
] in
|
||||
error ~data title message
|
||||
|
||||
let parser_error start end_ =
|
||||
let parser_error source (start: Lexing.position) (end_: Lexing.position) lexbuf =
|
||||
let title () = "parser error" in
|
||||
let message () = "" in
|
||||
let file = if source = "" then
|
||||
""
|
||||
else
|
||||
Format.sprintf "In file \"%s|%s\"" start.pos_fname source
|
||||
in
|
||||
let str = Format.sprintf
|
||||
"Parse error at \"%s\" from (%d, %d) to (%d, %d). %s\n"
|
||||
(Lexing.lexeme lexbuf)
|
||||
start.pos_lnum (start.pos_cnum - start.pos_bol)
|
||||
end_.pos_lnum (end_.pos_cnum - end_.pos_bol)
|
||||
file
|
||||
in
|
||||
let message () = str in
|
||||
let loc = Region.make
|
||||
~start:(Pos.from_byte start)
|
||||
~stop:(Pos.from_byte end_)
|
||||
@ -32,9 +44,21 @@ module Errors = struct
|
||||
] in
|
||||
error ~data title message
|
||||
|
||||
let unrecognized_error start end_ =
|
||||
let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf =
|
||||
let title () = "unrecognized error" in
|
||||
let message () = "" in
|
||||
let file = if source = "" then
|
||||
""
|
||||
else
|
||||
Format.sprintf "In file \"%s|%s\"" start.pos_fname source
|
||||
in
|
||||
let str = Format.sprintf
|
||||
"Parse error at \"%s\" from (%d, %d) to (%d, %d). %s\n"
|
||||
(Lexing.lexeme lexbuf)
|
||||
start.pos_lnum (start.pos_cnum - start.pos_bol)
|
||||
end_.pos_lnum (end_.pos_cnum - end_.pos_bol)
|
||||
file
|
||||
in
|
||||
let message () = str in
|
||||
let loc = Region.make
|
||||
~start:(Pos.from_byte start)
|
||||
~stop:(Pos.from_byte end_)
|
||||
@ -52,7 +76,7 @@ open Errors
|
||||
|
||||
type 'a parser = (Lexing.lexbuf -> LexToken.token) -> Lexing.lexbuf -> 'a
|
||||
|
||||
let parse (parser: 'a parser) lexbuf =
|
||||
let parse (parser: 'a parser) source lexbuf =
|
||||
let Lexer.{read ; close ; _} = Lexer.open_token_stream None in
|
||||
let result =
|
||||
try
|
||||
@ -61,14 +85,14 @@ let parse (parser: 'a parser) lexbuf =
|
||||
| Parser.Error ->
|
||||
let start = Lexing.lexeme_start_p lexbuf in
|
||||
let end_ = Lexing.lexeme_end_p lexbuf in
|
||||
fail @@ (parser_error start end_)
|
||||
fail @@ (parser_error source start end_ lexbuf)
|
||||
| Lexer.Error e ->
|
||||
fail @@ (lexer_error e)
|
||||
| _ ->
|
||||
let _ = Printexc.print_backtrace Pervasives.stdout in
|
||||
let start = Lexing.lexeme_start_p lexbuf in
|
||||
let end_ = Lexing.lexeme_end_p lexbuf in
|
||||
fail @@ (unrecognized_error start end_)
|
||||
fail @@ (unrecognized_error source start end_ lexbuf)
|
||||
in
|
||||
close ();
|
||||
result
|
||||
@ -87,12 +111,12 @@ let parse_file (source: string) : AST.t result =
|
||||
generic_try (simple_error "error opening file") @@
|
||||
(fun () -> open_in pp_input) in
|
||||
let lexbuf = Lexing.from_channel channel in
|
||||
parse (Parser.contract) lexbuf
|
||||
parse (Parser.contract) source lexbuf
|
||||
|
||||
let parse_string (s:string) : AST.t result =
|
||||
let lexbuf = Lexing.from_string s in
|
||||
parse (Parser.contract) lexbuf
|
||||
parse (Parser.contract) "" lexbuf
|
||||
|
||||
let parse_expression (s:string) : AST.expr result =
|
||||
let lexbuf = Lexing.from_string s in
|
||||
parse (Parser.interactive_expr) lexbuf
|
||||
parse (Parser.interactive_expr) "" lexbuf
|
@ -47,9 +47,21 @@ module Errors = struct
|
||||
] in
|
||||
error ~data title message
|
||||
|
||||
let parser_error start end_ =
|
||||
let parser_error source (start: Lexing.position) (end_: Lexing.position) lexbuf =
|
||||
let title () = "parser error" in
|
||||
let message () = "" in
|
||||
let file = if source = "" then
|
||||
""
|
||||
else
|
||||
Format.sprintf "In file \"%s|%s\"" start.pos_fname source
|
||||
in
|
||||
let str = Format.sprintf
|
||||
"Parse error at \"%s\" from (%d, %d) to (%d, %d). %s\n"
|
||||
(Lexing.lexeme lexbuf)
|
||||
start.pos_lnum (start.pos_cnum - start.pos_bol)
|
||||
end_.pos_lnum (end_.pos_cnum - end_.pos_bol)
|
||||
file
|
||||
in
|
||||
let message () = str in
|
||||
let loc = Region.make
|
||||
~start:(Pos.from_byte start)
|
||||
~stop:(Pos.from_byte end_)
|
||||
@ -61,9 +73,21 @@ module Errors = struct
|
||||
] in
|
||||
error ~data title message
|
||||
|
||||
let unrecognized_error start end_ =
|
||||
let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf =
|
||||
let title () = "unrecognized error" in
|
||||
let message () = "" in
|
||||
let file = if source = "" then
|
||||
""
|
||||
else
|
||||
Format.sprintf "In file \"%s|%s\"" start.pos_fname source
|
||||
in
|
||||
let str = Format.sprintf
|
||||
"Parse error at \"%s\" from (%d, %d) to (%d, %d). %s\n"
|
||||
(Lexing.lexeme lexbuf)
|
||||
start.pos_lnum (start.pos_cnum - start.pos_bol)
|
||||
end_.pos_lnum (end_.pos_cnum - end_.pos_bol)
|
||||
file
|
||||
in
|
||||
let message () = str in
|
||||
let loc = Region.make
|
||||
~start:(Pos.from_byte start)
|
||||
~stop:(Pos.from_byte end_)
|
||||
@ -81,7 +105,7 @@ open Errors
|
||||
|
||||
type 'a parser = (Lexing.lexbuf -> LexToken.token) -> Lexing.lexbuf -> 'a
|
||||
|
||||
let parse (parser: 'a parser) lexbuf =
|
||||
let parse (parser: 'a parser) source lexbuf =
|
||||
let Lexer.{read ; close ; _} = Lexer.open_token_stream None in
|
||||
let result =
|
||||
try
|
||||
@ -95,15 +119,15 @@ let parse (parser: 'a parser) lexbuf =
|
||||
fail @@ (reserved_name name)
|
||||
| Parser.Error ->
|
||||
let start = Lexing.lexeme_start_p lexbuf in
|
||||
let end_ = Lexing.lexeme_end_p lexbuf
|
||||
in fail @@ (parser_error start end_)
|
||||
let end_ = Lexing.lexeme_end_p lexbuf in
|
||||
fail @@ (parser_error source start end_ lexbuf)
|
||||
| Lexer.Error e ->
|
||||
fail @@ (lexer_error e)
|
||||
| _ ->
|
||||
let _ = Printexc.print_backtrace Pervasives.stdout in
|
||||
let start = Lexing.lexeme_start_p lexbuf in
|
||||
let end_ = Lexing.lexeme_end_p lexbuf in
|
||||
fail @@ (unrecognized_error start end_)
|
||||
fail @@ (unrecognized_error source start end_ lexbuf)
|
||||
in
|
||||
close ();
|
||||
result
|
||||
@ -122,12 +146,12 @@ let parse_file (source: string) : AST.t result =
|
||||
generic_try (simple_error "error opening file") @@
|
||||
(fun () -> open_in pp_input) in
|
||||
let lexbuf = Lexing.from_channel channel in
|
||||
parse (Parser.contract) lexbuf
|
||||
parse (Parser.contract) source lexbuf
|
||||
|
||||
let parse_string (s:string) : AST.t result =
|
||||
let lexbuf = Lexing.from_string s in
|
||||
parse (Parser.contract) lexbuf
|
||||
parse (Parser.contract) "" lexbuf
|
||||
|
||||
let parse_expression (s:string) : AST.expr result =
|
||||
let lexbuf = Lexing.from_string s in
|
||||
parse (Parser.interactive_expr) lexbuf
|
||||
parse (Parser.interactive_expr) "" lexbuf
|
||||
|
@ -29,9 +29,21 @@ module Errors = struct
|
||||
] in
|
||||
error ~data title message
|
||||
|
||||
let parser_error start end_ =
|
||||
let parser_error source (start: Lexing.position) (end_: Lexing.position) lexbuf =
|
||||
let title () = "parser error" in
|
||||
let message () = "" in
|
||||
let file = if source = "" then
|
||||
""
|
||||
else
|
||||
Format.sprintf "In file \"%s|%s\"" start.pos_fname source
|
||||
in
|
||||
let str = Format.sprintf
|
||||
"Parse error at \"%s\" from (%d, %d) to (%d, %d). %s\n"
|
||||
(Lexing.lexeme lexbuf)
|
||||
start.pos_lnum (start.pos_cnum - start.pos_bol)
|
||||
end_.pos_lnum (end_.pos_cnum - end_.pos_bol)
|
||||
file
|
||||
in
|
||||
let message () = str in
|
||||
let loc = Region.make
|
||||
~start:(Pos.from_byte start)
|
||||
~stop:(Pos.from_byte end_)
|
||||
@ -43,9 +55,21 @@ module Errors = struct
|
||||
] in
|
||||
error ~data title message
|
||||
|
||||
let unrecognized_error start end_ =
|
||||
let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf =
|
||||
let title () = "unrecognized error" in
|
||||
let message () = "" in
|
||||
let file = if source = "" then
|
||||
""
|
||||
else
|
||||
Format.sprintf "In file \"%s|%s\"" start.pos_fname source
|
||||
in
|
||||
let str = Format.sprintf
|
||||
"Parse error at \"%s\" from (%d, %d) to (%d, %d). %s\n"
|
||||
(Lexing.lexeme lexbuf)
|
||||
start.pos_lnum (start.pos_cnum - start.pos_bol)
|
||||
end_.pos_lnum (end_.pos_cnum - end_.pos_bol)
|
||||
file
|
||||
in
|
||||
let message () = str in
|
||||
let loc = Region.make
|
||||
~start:(Pos.from_byte start)
|
||||
~stop:(Pos.from_byte end_)
|
||||
@ -63,7 +87,7 @@ open Errors
|
||||
|
||||
type 'a parser = (Lexing.lexbuf -> LexToken.token) -> Lexing.lexbuf -> 'a
|
||||
|
||||
let parse (parser: 'a parser) lexbuf =
|
||||
let parse (parser: 'a parser) source lexbuf =
|
||||
let Lexer.{read ; close ; _} = Lexer.open_token_stream None in
|
||||
let result =
|
||||
try
|
||||
@ -74,14 +98,14 @@ let parse (parser: 'a parser) lexbuf =
|
||||
| Parser.Error ->
|
||||
let start = Lexing.lexeme_start_p lexbuf in
|
||||
let end_ = Lexing.lexeme_end_p lexbuf in
|
||||
fail @@ (parser_error start end_)
|
||||
fail @@ (parser_error source start end_ lexbuf)
|
||||
| Lexer.Error e ->
|
||||
fail @@ (lexer_error e)
|
||||
| _ ->
|
||||
let _ = Printexc.print_backtrace Pervasives.stdout in
|
||||
let start = Lexing.lexeme_start_p lexbuf in
|
||||
let end_ = Lexing.lexeme_end_p lexbuf in
|
||||
fail @@ (unrecognized_error start end_)
|
||||
fail @@ (unrecognized_error source start end_ lexbuf)
|
||||
in
|
||||
close ();
|
||||
result
|
||||
@ -100,12 +124,12 @@ let parse_file (source: string) : AST.t result =
|
||||
generic_try (simple_error "error opening file") @@
|
||||
(fun () -> open_in pp_input) in
|
||||
let lexbuf = Lexing.from_channel channel in
|
||||
parse (Parser.contract) lexbuf
|
||||
parse (Parser.contract) source lexbuf
|
||||
|
||||
let parse_string (s:string) : AST.t result =
|
||||
let lexbuf = Lexing.from_string s in
|
||||
parse (Parser.contract) lexbuf
|
||||
parse (Parser.contract) "" lexbuf
|
||||
|
||||
let parse_expression (s:string) : AST.expr result =
|
||||
let lexbuf = Lexing.from_string s in
|
||||
parse (Parser.interactive_expr) lexbuf
|
||||
parse (Parser.interactive_expr) "" lexbuf
|
||||
|
@ -12,6 +12,42 @@ module Errors = struct
|
||||
] in
|
||||
error ~data title message ()
|
||||
|
||||
let bad_empty_arity cst loc () =
|
||||
let cst_name = thunk @@ Format.asprintf "%a" Stage_common.PP.constant cst in
|
||||
let title = thunk @@ "Wrong "^(cst_name ())^" literal arity" in
|
||||
let message = thunk @@ (cst_name ())^" literal expects no parameter" in
|
||||
let data = [
|
||||
("location" , fun () -> Format.asprintf "%a" Location.pp loc) ;
|
||||
] in
|
||||
error ~data title message ()
|
||||
|
||||
let bad_single_arity cst loc () =
|
||||
let cst_name = thunk @@ Format.asprintf "%a" Stage_common.PP.constant cst in
|
||||
let title = thunk @@ "Wrong "^(cst_name ())^" literal arity" in
|
||||
let message = thunk @@ (cst_name ())^" literal expects a single parameter" in
|
||||
let data = [
|
||||
("location" , fun () -> Format.asprintf "%a" Location.pp loc) ;
|
||||
] in
|
||||
error ~data title message ()
|
||||
|
||||
let bad_map_param_type cst loc () =
|
||||
let cst_name = thunk @@ Format.asprintf "%a" Stage_common.PP.constant cst in
|
||||
let title = thunk @@ "Wrong "^(cst_name ())^" literal parameter type" in
|
||||
let message = thunk @@ (cst_name ())^" literal expects a list of pairs as parameter" in
|
||||
let data = [
|
||||
("location" , fun () -> Format.asprintf "%a" Location.pp loc) ;
|
||||
] in
|
||||
error ~data title message ()
|
||||
|
||||
let bad_set_param_type cst loc () =
|
||||
let cst_name = thunk @@ Format.asprintf "%a" Stage_common.PP.constant cst in
|
||||
let title = thunk @@ "Wrong "^(cst_name ())^" literal parameter type" in
|
||||
let message = thunk @@ (cst_name ())^" literal expects a list as parameter" in
|
||||
let data = [
|
||||
("location" , fun () -> Format.asprintf "%a" Location.pp loc) ;
|
||||
] in
|
||||
error ~data title message ()
|
||||
|
||||
end
|
||||
open Errors
|
||||
|
||||
@ -32,18 +68,18 @@ let peephole_expression : expression -> expression result = fun e ->
|
||||
Protocol.Alpha_context.Contract.of_b58check s in
|
||||
return l
|
||||
)
|
||||
| E_constant (C_BIG_MAP_LITERAL , lst) -> (
|
||||
| E_constant (C_BIG_MAP_LITERAL as cst, lst) -> (
|
||||
let%bind elt =
|
||||
trace_option (simple_error "big_map literal expects a single parameter") @@
|
||||
trace_option (bad_single_arity cst e.location) @@
|
||||
List.to_singleton lst
|
||||
in
|
||||
let%bind lst =
|
||||
trace (simple_error "big_map literal expects a list as parameter") @@
|
||||
trace_strong (bad_map_param_type cst e.location) @@
|
||||
get_e_list elt.expression
|
||||
in
|
||||
let aux = fun (e : expression) ->
|
||||
trace (simple_error "big_map literal expects a list of pairs as parameter") @@
|
||||
let%bind tpl = get_e_tuple e.expression in
|
||||
let aux = fun (e' : expression) ->
|
||||
trace_strong (bad_map_param_type cst e.location) @@
|
||||
let%bind tpl = get_e_tuple e'.expression in
|
||||
let%bind (a , b) =
|
||||
trace_option (simple_error "of pairs") @@
|
||||
List.to_pair tpl
|
||||
@ -53,18 +89,18 @@ let peephole_expression : expression -> expression result = fun e ->
|
||||
let%bind pairs = bind_map_list aux lst in
|
||||
return @@ E_big_map pairs
|
||||
)
|
||||
| E_constant (C_MAP_LITERAL, lst) -> (
|
||||
| E_constant (C_MAP_LITERAL as cst, lst) -> (
|
||||
let%bind elt =
|
||||
trace_option (simple_error "map literal expects a single parameter") @@
|
||||
trace_option (bad_single_arity cst e.location) @@
|
||||
List.to_singleton lst
|
||||
in
|
||||
let%bind lst =
|
||||
trace (simple_error "map literal expects a list as parameter") @@
|
||||
trace_strong (bad_map_param_type cst e.location) @@
|
||||
get_e_list elt.expression
|
||||
in
|
||||
let aux = fun (e : expression) ->
|
||||
trace (simple_error "map literal expects a list of pairs as parameter") @@
|
||||
let%bind tpl = get_e_tuple e.expression in
|
||||
let aux = fun (e' : expression) ->
|
||||
trace_strong (bad_map_param_type cst e.location) @@
|
||||
let%bind tpl = get_e_tuple e'.expression in
|
||||
let%bind (a , b) =
|
||||
trace_option (simple_error "of pairs") @@
|
||||
List.to_pair tpl
|
||||
@ -74,34 +110,34 @@ let peephole_expression : expression -> expression result = fun e ->
|
||||
let%bind pairs = bind_map_list aux lst in
|
||||
return @@ E_map pairs
|
||||
)
|
||||
| E_constant (C_BIG_MAP_EMPTY, lst) -> (
|
||||
| E_constant (C_BIG_MAP_EMPTY as cst, lst) -> (
|
||||
let%bind () =
|
||||
trace_strong (simple_error "BIG_MAP_EMPTY expects no parameter") @@
|
||||
trace_strong (bad_empty_arity cst e.location) @@
|
||||
Assert.assert_list_empty lst
|
||||
in
|
||||
return @@ E_big_map []
|
||||
)
|
||||
| E_constant (C_MAP_EMPTY, lst) -> (
|
||||
| E_constant (C_MAP_EMPTY as cst, lst) -> (
|
||||
let%bind () =
|
||||
trace_strong (simple_error "MAP_EMPTY expects no parameter") @@
|
||||
trace_strong (bad_empty_arity cst e.location) @@
|
||||
Assert.assert_list_empty lst
|
||||
in
|
||||
return @@ E_map []
|
||||
)
|
||||
| E_constant (C_SET_LITERAL, lst) -> (
|
||||
| E_constant (C_SET_LITERAL as cst, lst) -> (
|
||||
let%bind elt =
|
||||
trace_option (simple_error "map literal expects a single parameter") @@
|
||||
trace_option (bad_single_arity cst e.location) @@
|
||||
List.to_singleton lst
|
||||
in
|
||||
let%bind lst =
|
||||
trace (simple_error "map literal expects a list as parameter") @@
|
||||
trace_strong (bad_set_param_type cst e.location) @@
|
||||
get_e_list elt.expression
|
||||
in
|
||||
return @@ E_set lst
|
||||
)
|
||||
| E_constant (C_SET_EMPTY, lst) -> (
|
||||
| E_constant (C_SET_EMPTY as cst, lst) -> (
|
||||
let%bind () =
|
||||
trace_strong (simple_error "SET_EMPTY expects no parameter") @@
|
||||
trace_strong (bad_empty_arity cst e.location) @@
|
||||
Assert.assert_list_empty lst
|
||||
in
|
||||
return @@ E_set []
|
||||
|
4
src/test/lexer/broken_string.ligo
Normal file
4
src/test/lexer/broken_string.ligo
Normal file
@ -0,0 +1,4 @@
|
||||
const a: string = "broken
|
||||
over
|
||||
multiple
|
||||
lines";
|
4
src/test/lexer/broken_string.mligo
Normal file
4
src/test/lexer/broken_string.mligo
Normal file
@ -0,0 +1,4 @@
|
||||
let a = "broken
|
||||
over
|
||||
multiple
|
||||
lines";
|
4
src/test/lexer/broken_string.religo
Normal file
4
src/test/lexer/broken_string.religo
Normal file
@ -0,0 +1,4 @@
|
||||
let a = "broken
|
||||
over
|
||||
multiple
|
||||
lines";
|
1
src/test/lexer/invalid_character_in_string.ligo
Normal file
1
src/test/lexer/invalid_character_in_string.ligo
Normal file
@ -0,0 +1 @@
|
||||
const z: string = " ";
|
1
src/test/lexer/invalid_character_in_string.mligo
Normal file
1
src/test/lexer/invalid_character_in_string.mligo
Normal file
@ -0,0 +1 @@
|
||||
let z = " ";
|
1
src/test/lexer/invalid_character_in_string.religo
Normal file
1
src/test/lexer/invalid_character_in_string.religo
Normal file
@ -0,0 +1 @@
|
||||
let z = " ";
|
1
src/test/lexer/invalid_symbol.ligo
Normal file
1
src/test/lexer/invalid_symbol.ligo
Normal file
@ -0,0 +1 @@
|
||||
const b: int = 1 ... 10;
|
1
src/test/lexer/invalid_symbol.mligo
Normal file
1
src/test/lexer/invalid_symbol.mligo
Normal file
@ -0,0 +1 @@
|
||||
let b = 1 ... 10;
|
1
src/test/lexer/invalid_symbol.religo
Normal file
1
src/test/lexer/invalid_symbol.religo
Normal file
@ -0,0 +1 @@
|
||||
let b = 1 # 10;
|
1
src/test/lexer/missing_break.ligo
Normal file
1
src/test/lexer/missing_break.ligo
Normal file
@ -0,0 +1 @@
|
||||
const a: int = 300zennies;
|
1
src/test/lexer/missing_break.mligo
Normal file
1
src/test/lexer/missing_break.mligo
Normal file
@ -0,0 +1 @@
|
||||
let a = 300zennies;
|
1
src/test/lexer/missing_break.religo
Normal file
1
src/test/lexer/missing_break.religo
Normal file
@ -0,0 +1 @@
|
||||
let a = 300zennies;
|
1
src/test/lexer/negative_byte_sequence.ligo
Normal file
1
src/test/lexer/negative_byte_sequence.ligo
Normal file
@ -0,0 +1 @@
|
||||
const a: string = -0x222;
|
1
src/test/lexer/negative_byte_sequence.mligo
Normal file
1
src/test/lexer/negative_byte_sequence.mligo
Normal file
@ -0,0 +1 @@
|
||||
let a = -0x222;
|
1
src/test/lexer/negative_byte_sequence.religo
Normal file
1
src/test/lexer/negative_byte_sequence.religo
Normal file
@ -0,0 +1 @@
|
||||
let a = -0x222;
|
1
src/test/lexer/reserved_name.ligo
Normal file
1
src/test/lexer/reserved_name.ligo
Normal file
@ -0,0 +1 @@
|
||||
let args = 1;
|
1
src/test/lexer/reserved_name.mligo
Normal file
1
src/test/lexer/reserved_name.mligo
Normal file
@ -0,0 +1 @@
|
||||
let object = 1;
|
1
src/test/lexer/reserved_name.religo
Normal file
1
src/test/lexer/reserved_name.religo
Normal file
@ -0,0 +1 @@
|
||||
let end = 1;
|
1
src/test/lexer/unexpected_character.ligo
Normal file
1
src/test/lexer/unexpected_character.ligo
Normal file
@ -0,0 +1 @@
|
||||
const x: string = <20><><EFBFBD>;
|
1
src/test/lexer/unexpected_character.mligo
Normal file
1
src/test/lexer/unexpected_character.mligo
Normal file
@ -0,0 +1 @@
|
||||
let x = <20><><EFBFBD>;
|
1
src/test/lexer/unexpected_character.religo
Normal file
1
src/test/lexer/unexpected_character.religo
Normal file
@ -0,0 +1 @@
|
||||
let x = <20><><EFBFBD>;
|
1
src/test/lexer/unterminated_comment.mligo
Normal file
1
src/test/lexer/unterminated_comment.mligo
Normal file
@ -0,0 +1 @@
|
||||
(* not closed
|
25
vendors/ligo-utils/simple-utils/cover.sh
vendored
25
vendors/ligo-utils/simple-utils/cover.sh
vendored
@ -87,6 +87,15 @@ while : ; do
|
||||
no_eq=$1
|
||||
break
|
||||
;;
|
||||
--messages=*)
|
||||
if test -n "$messages"; then
|
||||
fatal_error "Repeated option --messages."; fi
|
||||
messages=$(expr "$1" : "[^=]*=\(.*\)")
|
||||
;;
|
||||
--messages)
|
||||
no_eq=$1
|
||||
break
|
||||
;;
|
||||
-h | --help | -help)
|
||||
help=yes
|
||||
;;
|
||||
@ -113,6 +122,7 @@ usage () {
|
||||
Usage: $(basename $0) [-h|--help]
|
||||
--par-tokens=<par_tokens>.mly
|
||||
--lex-tokens=<lex_tokens>.mli
|
||||
--messages=<parser>.msg
|
||||
--unlexer=<binary>
|
||||
--ext=<extension>
|
||||
--dir=<path>
|
||||
@ -135,6 +145,7 @@ Display control:
|
||||
Mandatory options:
|
||||
--lex-tokens=<name>.mli the lexical tokens
|
||||
--par-tokens=<name>.mly the syntactical tokens
|
||||
--messages=<parser>.msg the complete errors messages
|
||||
--ext=EXT Unix file extension for the
|
||||
generated LIGO files
|
||||
(no starting period)
|
||||
@ -160,6 +171,9 @@ fi
|
||||
|
||||
# Checking options
|
||||
|
||||
if test -z "$messages"; then
|
||||
fatal_error "Messages not found (use --messages)."; fi
|
||||
|
||||
if test -z "$unlexer"; then
|
||||
fatal_error "Unlexer binary not found (use --unlexer)."; fi
|
||||
|
||||
@ -172,6 +186,9 @@ if test -z "$par_tokens"; then
|
||||
if test -z "$lex_tokens"; then
|
||||
fatal_error "No lexical tokens specification (use --lex-tokens)."; fi
|
||||
|
||||
if test ! -e "$messages"; then
|
||||
fatal_error "Error messages \"$messages\" not found (use messages.sh)."; fi
|
||||
|
||||
if test ! -e "$parser"; then
|
||||
fatal_error "Parser specification \"$parser\" not found."; fi
|
||||
|
||||
@ -218,12 +235,6 @@ if test "$ext_start" != "0"
|
||||
then fatal_error "LIGO extensions must not start with a period."
|
||||
fi
|
||||
|
||||
# Checking the presence of the messages
|
||||
|
||||
msg=$parser_base.msg
|
||||
if test ! -e $msg; then
|
||||
fatal_error "File $msg not found."; fi
|
||||
|
||||
# ====================================================================
|
||||
# Menhir's flags
|
||||
|
||||
@ -233,7 +244,7 @@ flags="--table --strict --external-tokens $lex_tokens_base \
|
||||
# ====================================================================
|
||||
# Producing erroneous sentences from Menhir's error messages
|
||||
|
||||
msg=$parser_base.msg
|
||||
msg=$messages
|
||||
raw=$parser_base.msg.raw
|
||||
printf "Making $raw from $msg... "
|
||||
menhir --echo-errors $parser_base.msg $flags $mly > $raw 2>/dev/null
|
||||
|
Loading…
Reference in New Issue
Block a user