From 6de51d550680d1b463cd7309435b8c62f514e3a1 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Tue, 30 Jul 2024 12:29:03 -0400 Subject: [PATCH 01/28] Basic round-trip parse unit test Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/dune | 5 +++++ test/parser/test_parser.ml | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 test/parser/dune create mode 100644 test/parser/test_parser.ml diff --git a/test/parser/dune b/test/parser/dune new file mode 100644 index 00000000..4f9b31f2 --- /dev/null +++ b/test/parser/dune @@ -0,0 +1,5 @@ +(test + (name test_parser) + (modes exe) + (libraries tlapm_lib) +) diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml new file mode 100644 index 00000000..f2c9c1a9 --- /dev/null +++ b/test/parser/test_parser.ml @@ -0,0 +1,4 @@ +let () = + match Tlapm_lib.module_of_string "---- MODULE Test ---- x == 5 ====" with + | None -> print_endline "Parse failed" + | Some mule -> print_endline mule.core.name.core \ No newline at end of file From 52c8a4ad9d3b6a30a5360ed1f7240de2389f1ed7 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Wed, 16 Oct 2024 16:05:28 -0400 Subject: [PATCH 02/28] Syntax corpus files copied by dune build Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/dune | 1 + test/parser/syntax_corpus/README.md | 11 + test/parser/syntax_corpus/assume-prove.txt | 174 +++ test/parser/syntax_corpus/case.txt | 217 +++ test/parser/syntax_corpus/conjlist.txt | 603 +++++++++ test/parser/syntax_corpus/disjlist.txt | 603 +++++++++ test/parser/syntax_corpus/except.txt | 173 +++ test/parser/syntax_corpus/expressions.txt | 73 + test/parser/syntax_corpus/fairness.txt | 92 ++ test/parser/syntax_corpus/functions.txt | 219 +++ test/parser/syntax_corpus/if_then_else.txt | 131 ++ test/parser/syntax_corpus/infix_op.txt | 1194 +++++++++++++++++ test/parser/syntax_corpus/jlist.txt | 172 +++ test/parser/syntax_corpus/labels.txt | 40 + test/parser/syntax_corpus/let_in.txt | 253 ++++ test/parser/syntax_corpus/modules.txt | 64 + test/parser/syntax_corpus/number.txt | 79 ++ test/parser/syntax_corpus/operators.txt | 79 ++ test/parser/syntax_corpus/postfix_op.txt | 126 ++ test/parser/syntax_corpus/prefix_op.txt | 203 +++ test/parser/syntax_corpus/proofs.txt | 521 +++++++ test/parser/syntax_corpus/quantification.txt | 157 +++ test/parser/syntax_corpus/records.txt | 150 +++ test/parser/syntax_corpus/recursive.txt | 66 + test/parser/syntax_corpus/regression.txt | 79 ++ .../rejected_syntax/blank_file.txt | 6 + test/parser/syntax_corpus/sets.txt | 234 ++++ .../parser/syntax_corpus/step_expressions.txt | 77 ++ test/parser/syntax_corpus/string.txt | 89 ++ test/parser/syntax_corpus/subexpressions.txt | 93 ++ test/parser/syntax_corpus/unit.txt | 113 ++ test/parser/syntax_corpus/use_or_hide.txt | 40 + test/parser/test_parser.ml | 17 +- 33 files changed, 6148 insertions(+), 1 deletion(-) create mode 100644 test/parser/syntax_corpus/README.md create mode 100644 test/parser/syntax_corpus/assume-prove.txt create mode 100644 test/parser/syntax_corpus/case.txt create mode 100644 test/parser/syntax_corpus/conjlist.txt create mode 100644 test/parser/syntax_corpus/disjlist.txt create mode 100644 test/parser/syntax_corpus/except.txt create mode 100644 test/parser/syntax_corpus/expressions.txt create mode 100644 test/parser/syntax_corpus/fairness.txt create mode 100644 test/parser/syntax_corpus/functions.txt create mode 100644 test/parser/syntax_corpus/if_then_else.txt create mode 100644 test/parser/syntax_corpus/infix_op.txt create mode 100644 test/parser/syntax_corpus/jlist.txt create mode 100644 test/parser/syntax_corpus/labels.txt create mode 100644 test/parser/syntax_corpus/let_in.txt create mode 100644 test/parser/syntax_corpus/modules.txt create mode 100644 test/parser/syntax_corpus/number.txt create mode 100644 test/parser/syntax_corpus/operators.txt create mode 100644 test/parser/syntax_corpus/postfix_op.txt create mode 100644 test/parser/syntax_corpus/prefix_op.txt create mode 100644 test/parser/syntax_corpus/proofs.txt create mode 100644 test/parser/syntax_corpus/quantification.txt create mode 100644 test/parser/syntax_corpus/records.txt create mode 100644 test/parser/syntax_corpus/recursive.txt create mode 100644 test/parser/syntax_corpus/regression.txt create mode 100644 test/parser/syntax_corpus/rejected_syntax/blank_file.txt create mode 100644 test/parser/syntax_corpus/sets.txt create mode 100644 test/parser/syntax_corpus/step_expressions.txt create mode 100644 test/parser/syntax_corpus/string.txt create mode 100644 test/parser/syntax_corpus/subexpressions.txt create mode 100644 test/parser/syntax_corpus/unit.txt create mode 100644 test/parser/syntax_corpus/use_or_hide.txt diff --git a/test/parser/dune b/test/parser/dune index 4f9b31f2..c9ef83fe 100644 --- a/test/parser/dune +++ b/test/parser/dune @@ -2,4 +2,5 @@ (name test_parser) (modes exe) (libraries tlapm_lib) + (deps (glob_files_rec syntax_corpus/*)) ) diff --git a/test/parser/syntax_corpus/README.md b/test/parser/syntax_corpus/README.md new file mode 100644 index 00000000..b9c02e56 --- /dev/null +++ b/test/parser/syntax_corpus/README.md @@ -0,0 +1,11 @@ +This is a corpus of TLA⁺ syntax inputs along with their expected parse tree outputs. +The tests are only intended to exercise syntax parsing and are often invalid at the semantic level (referencing nonexistent variable names, for example). +The tests use the format developed by tree-sitter, which you can see [here](https://tree-sitter.github.io/tree-sitter/creating-parsers#command-test). +Syntax inputs which are intended to cause a parse failure are tagged with `:error` in the test case header. +Every TLA⁺ tool that parses the language should adapt this corpus to ensure parser conformance. +Currently, there are three existing tools that implement a TLA⁺ parser: +1. [SANY](https://github.com/tlaplus/tlaplus/tree/master/tlatools/org.lamport.tlatools/src/tla2sany), which has adapted these tests +2. [TLAPM](https://github.com/tlaplus/tlapm), which has not yet adapted these tests +3. [tree-sitter-tlaplus](https://github.com/tlaplus-community/tree-sitter-tlaplus), which has adapted these tests + +Translating a given tool's internal parse tree format to match the standardized format used by these tests is a lot of work, but ensures very thorough testing of the parser and exposes the ability to rapidly add regression tests to all parsers if a tricky parsing bug is uncovered in one of the tools. diff --git a/test/parser/syntax_corpus/assume-prove.txt b/test/parser/syntax_corpus/assume-prove.txt new file mode 100644 index 00000000..198bdf15 --- /dev/null +++ b/test/parser/syntax_corpus/assume-prove.txt @@ -0,0 +1,174 @@ +===============================||| +Basic Assume/Prove +===============================||| + +---- MODULE Test ---- +THEOREM thm == + ASSUME P, Q + PROVE C +OBVIOUS +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (theorem + name: (identifier) (def_eq) + statement: (assume_prove + assumption: (identifier_ref) + assumption: (identifier_ref) + conclusion: (identifier_ref) + ) + proof: (terminal_proof) + ) +(double_line))) + +===============================||| +Nested Assume/Prove With Label +===============================||| + +---- MODULE Test ---- +THEOREM thm == + ASSUME asm :: + ASSUME P + PROVE Q + PROVE C +OMITTED +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (theorem + name: (identifier) (def_eq) + statement: (assume_prove + assumption: (inner_assume_prove + (identifier) (label_as) + (assume_prove + assumption: (identifier_ref) + conclusion: (identifier_ref) + ) + ) + conclusion: (identifier_ref) + ) + proof: (terminal_proof) + ) +(double_line))) + +===============================||| +Assume/Prove With New Constant +===============================||| + +---- MODULE Test ---- +THEOREM thm == + ASSUME NEW CONSTANT x \in S + PROVE C +OBVIOUS +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (theorem + name: (identifier) (def_eq) + statement: (assume_prove + assumption: (new (statement_level) (identifier) (set_in) (identifier_ref)) + conclusion: (identifier_ref) + ) + proof: (terminal_proof) + ) +(double_line))) + +===============================||| +Assume/Prove With New Operator +===============================||| + +---- MODULE Test ---- +THEOREM thm == + ASSUME NEW TEMPORAL f(_, _) + PROVE C +OMITTED +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (theorem + name: (identifier) (def_eq) + statement: (assume_prove + assumption: (new (statement_level) (operator_declaration + name: (identifier) parameter: (placeholder) parameter: (placeholder) + )) + conclusion: (identifier_ref) + ) + proof: (terminal_proof) + ) +(double_line))) + +===============================||| +Assume/Prove in Suffices Step +===============================||| + +---- MODULE Test ---- +THEOREM TRUE +<1>a. SUFFICES + ASSUME CONSTANT x \in S + PROVE TRUE +<1>b. QED +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (theorem statement: (boolean) + proof: (non_terminal_proof + (proof_step (proof_step_id (level) (name)) + (suffices_proof_step (assume_prove + assumption: (new (statement_level) (identifier) (set_in) (identifier_ref)) + conclusion: (boolean) + )) + ) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + +===============================||| +Assume/Prove with Mixed Assumptions +===============================||| + +---- MODULE Test ---- +THEOREM thm == + ASSUME + NEW f, + 1 + 2, + /\ 1 + /\ 2, + lbl :: ASSUME P PROVE Q + PROVE C +OMITTED +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (theorem + name: (identifier) (def_eq) + statement: (assume_prove + assumption: (new (identifier)) + assumption: (bound_infix_op lhs: (nat_number) symbol: (plus) rhs: (nat_number)) + assumption: (conj_list (conj_item (bullet_conj) (nat_number)) (conj_item (bullet_conj) (nat_number))) + assumption: (inner_assume_prove + (identifier) + (label_as) + (assume_prove + assumption: (identifier_ref) + conclusion: (identifier_ref) + ) + ) + conclusion: (identifier_ref) + ) + proof: (terminal_proof) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/case.txt b/test/parser/syntax_corpus/case.txt new file mode 100644 index 00000000..516b7557 --- /dev/null +++ b/test/parser/syntax_corpus/case.txt @@ -0,0 +1,217 @@ +=============||| +Basic CASE +=============||| + +---- MODULE Test ---- +op == + CASE 1 -> 2 + [] 3 -> 4 + [] OTHER -> 5 +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (case + (case_arm (nat_number) (case_arrow) (nat_number)) + (case_box) (case_arm (nat_number) (case_arrow) (nat_number)) + (case_box) (other_arm (case_arrow) (nat_number)) + ) + ) +(double_line))) + +=============||| +Solitary CASE +=============||| + +---- MODULE Test ---- +op == CASE 1 -> 2 +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (case (case_arm (nat_number) (case_arrow) (nat_number))) + ) +(double_line))) + +=============||| +CASE with dangling else +=============||| + +---- MODULE Test ---- +op == + CASE 1 -> + CASE 2 -> 3 + [] OTHER -> 4 +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (case (case_arm (nat_number) (case_arrow) + (case + (case_arm (nat_number) (case_arrow) (nat_number)) + (case_box) (other_arm (case_arrow) (nat_number)) + ) + )) + ) +(double_line))) + +=============||| +Conjlist with CASE +=============||| + +---- MODULE Test ---- +op == + /\ CASE 1 -> 2 + [] 3 -> 2 + [] OTHER -> 5 + /\ 6 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (case + (case_arm (nat_number) (case_arrow) (nat_number)) + (case_box) (case_arm (nat_number) (case_arrow) (nat_number)) + (case_box) (other_arm (case_arrow) (nat_number)) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Conjlist inside CASE +=============||| + +---- MODULE Test ---- +op == + CASE + /\ 1 + /\ 2 + -> + /\ 3 + /\ 4 + [] + /\ 5 + /\ 6 + -> + /\ 7 + /\ 8 + [] OTHER -> + /\ 7 + /\ 8 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (case + (case_arm + (conj_list (conj_item (bullet_conj) (nat_number)) (conj_item (bullet_conj) (nat_number))) + (case_arrow) + (conj_list (conj_item (bullet_conj) (nat_number)) (conj_item (bullet_conj) (nat_number))) + ) + (case_box) + (case_arm + (conj_list (conj_item (bullet_conj) (nat_number)) (conj_item (bullet_conj) (nat_number))) + (case_arrow) + (conj_list (conj_item (bullet_conj) (nat_number)) (conj_item (bullet_conj) (nat_number))) + ) + (case_box) + (other_arm (case_arrow) + (conj_list (conj_item (bullet_conj) (nat_number)) (conj_item (bullet_conj) (nat_number))) + ) + ) + ) +(double_line))) + +=============||| +Disjlist with CASE +=============||| + +---- MODULE Test ---- +op == + \/ CASE 1 -> 2 + [] 3 -> 2 + [] OTHER -> 5 + \/ 6 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item + (bullet_disj) + (case + (case_arm (nat_number) (case_arrow) (nat_number)) + (case_box) (case_arm (nat_number) (case_arrow) (nat_number)) + (case_box) (other_arm (case_arrow) (nat_number)) + ) + ) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Disjlist inside CASE +=============||| + +---- MODULE Test ---- +op == + CASE + \/ 1 + \/ 2 + -> + \/ 3 + \/ 4 + [] + \/ 5 + \/ 6 + -> + \/ 7 + \/ 8 + [] OTHER -> + \/ 7 + \/ 8 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (case + (case_arm + (disj_list (disj_item (bullet_disj) (nat_number)) (disj_item (bullet_disj) (nat_number))) + (case_arrow) + (disj_list (disj_item (bullet_disj) (nat_number)) (disj_item (bullet_disj) (nat_number))) + ) + (case_box) + (case_arm + (disj_list (disj_item (bullet_disj) (nat_number)) (disj_item (bullet_disj) (nat_number))) + (case_arrow) + (disj_list (disj_item (bullet_disj) (nat_number)) (disj_item (bullet_disj) (nat_number))) + ) + (case_box) + (other_arm (case_arrow) + (disj_list (disj_item (bullet_disj) (nat_number)) (disj_item (bullet_disj) (nat_number))) + ) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/conjlist.txt b/test/parser/syntax_corpus/conjlist.txt new file mode 100644 index 00000000..967a6974 --- /dev/null +++ b/test/parser/syntax_corpus/conjlist.txt @@ -0,0 +1,603 @@ +=============||| +Basic Conjlist +=============||| + +---- MODULE Test ---- +op == + /\ 1 + /\ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Inline Conjlist +=============||| + +---- MODULE Test ---- +op == /\ 1 + /\ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Start-of-Line Conjlist +=============||| + +---- MODULE Test ---- +op == +/\ 1 +/\ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Left-Shifted Conjlist +=============||| + +---- MODULE Test ---- +op == + /\ 1 +/\ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (conj_list (conj_item (bullet_conj) (nat_number))) + (land) + (nat_number) + ) + ) +(double_line))) + +=============||| +Right-Shifted Conjlist +=============||| + +---- MODULE Test ---- +op == +/\ 1 + /\ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (bound_infix_op + (nat_number) + (land) + (nat_number) + ) + ) + ) + ) +(double_line))) + +=============||| +Separated Conjlist +=============||| + +---- MODULE Test ---- +op == + /\ 1 + + /\ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Multiline Conjlist +=============||| + +---- MODULE Test ---- +op == + /\ + 1 + /\ + 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Nested Conjlist +=============||| + +---- MODULE Test ---- +op == + /\ /\ 1 + /\ 2 + /\ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Start-of-Line Nested Conjlist +=============||| + +---- MODULE Test ---- +op == +/\ /\ 1 + /\ 2 +/\ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Infix Op Conjlist +=============||| + +---- MODULE Test ---- +op == + /\ 1 + + 2 + /\ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (bound_infix_op + (nat_number) + (plus) + (nat_number) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Division Infix Op Conjlist +=============||| + +---- MODULE Test ---- +op == + /\ 1 + / 2 + /\ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (bound_infix_op + (nat_number) + (slash) + (nat_number) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Infix Op Terminated Conjlist +=============||| + +---- MODULE Test ---- +op == + /\ 1 + + 2 + /\ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (bound_infix_op + (conj_list (conj_item (bullet_conj) (nat_number))) + (plus) + (nat_number) + ) + (land) + (nat_number) + ) + ) +(double_line))) + +=============||| +Division Infix Op Terminated Conjlist +=============||| + +---- MODULE Test ---- +op == + /\ 1 + / 2 + /\ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (bound_infix_op + (conj_list (conj_item (bullet_conj) (nat_number))) + (slash) + (nat_number) + ) + (land) + (nat_number) + ) + ) +(double_line))) + +=============||| +Not a Conjlist +=============||| + +---- MODULE Test ---- +op == 1 /\ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (nat_number) + (land) + (nat_number) + ) + ) +(double_line))) + +=============||| +Conjlist with Parentheses +=============||| + +---- MODULE Test ---- +op == + /\ (1) + /\ (2) +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (parentheses (nat_number))) + (conj_item (bullet_conj) (parentheses (nat_number))) + ) + ) +(double_line))) + +=============||| +Conjlist Terminated by Parentheses +=============||| + +---- MODULE Test ---- +op == ( + /\ 1 + ) + /\ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (parentheses + (conj_list (conj_item (bullet_conj) (nat_number))) + ) + (land) + (nat_number) + ) + ) +(double_line))) + +=============||| +Nested Conjlist Terminated by Parentheses +=============||| + +---- MODULE Test ---- +op == ( + /\ 1 + /\ /\ 2 + /\ 3 + ) + /\ 4 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (parentheses + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item + (bullet_conj) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + ) + ) + (land) + (nat_number) + ) + ) +(double_line))) + +=============||| +Double-Nested Conjlist Terminated by Parentheses +=============||| + +---- MODULE Test ---- +op == + /\ 1 + /\ /\ 2 + ( + /\ 3 + /\ 4 + ) + /\ 5 + /\ 6 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item + (bullet_conj) + (conj_list + (conj_item + (bullet_conj) + (bound_infix_op + (nat_number) + (plus) + (parentheses + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Module-End-Terminated Conjlist +=============||| + +---- MODULE Test ---- +op == + /\ 1 + /\ 2 ==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Keyword-Unit-Terminated Conjlist +=============||| + +---- MODULE Test ---- +op1 == + /\ 1 + /\ 2 + ASSUME x + +op2 == + /\ 3 + /\ 4 + LOCAL INSTANCE ModuleName + +op3 == + /\ 5 + /\ 6 + ----------------- + +op4 == + /\ 7 + /\ 8 + ---- MODULE Nested ---- + ==== + +op5 == + /\ 9 + /\ 10 + VARIABLES x, y +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + (assumption (identifier_ref)) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + (local_definition (instance (identifier_ref))) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + (single_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + (module (header_line) (identifier) (header_line) (double_line)) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + (variable_declaration (identifier) (identifier)) +(double_line))) + +=============||| +Conjlist with Empty Tuple +=============||| + +---- MODULE Test ---- +op == + /\ 1 + /\ <<>> +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (tuple_literal (langle_bracket) (rangle_bracket))) + ) + ) +(double_line))) + +=============||| +Conjlist with Empty Set +=============||| + +---- MODULE Test ---- +op == + /\ 1 + /\ {} +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (finite_set_literal)) + ) + ) +(double_line))) diff --git a/test/parser/syntax_corpus/disjlist.txt b/test/parser/syntax_corpus/disjlist.txt new file mode 100644 index 00000000..aad910e0 --- /dev/null +++ b/test/parser/syntax_corpus/disjlist.txt @@ -0,0 +1,603 @@ +=============||| +Basic Disjlist +=============||| + +---- MODULE Test ---- +op == + \/ 1 + \/ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Inline Disjlist +=============||| + +---- MODULE Test ---- +op == \/ 1 + \/ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Start-of-Line Disjlist +=============||| + +---- MODULE Test ---- +op == +\/ 1 +\/ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Left-Shifted Disjlist +=============||| + +---- MODULE Test ---- +op == + \/ 1 +\/ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (disj_list (disj_item (bullet_disj) (nat_number))) + (lor) + (nat_number) + ) + ) +(double_line))) + +=============||| +Right-Shifted Disjlist +=============||| + +---- MODULE Test ---- +op == +\/ 1 + \/ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item + (bullet_disj) + (bound_infix_op + (nat_number) + (lor) + (nat_number) + ) + ) + ) + ) +(double_line))) + +=============||| +Separated Disjlist +=============||| + +---- MODULE Test ---- +op == + \/ 1 + + \/ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Multiline Disjlist +=============||| + +---- MODULE Test ---- +op == + \/ + 1 + \/ + 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Nested Disjlist +=============||| + +---- MODULE Test ---- +op == + \/ \/ 1 + \/ 2 + \/ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item + (bullet_disj) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Start-of-Line Nested Disjlist +=============||| + +---- MODULE Test ---- +op == +\/ \/ 1 + \/ 2 +\/ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Infix Op Disjlist +=============||| + +---- MODULE Test ---- +op == + \/ 1 + + 2 + \/ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item + (bullet_disj) + (bound_infix_op + (nat_number) + (plus) + (nat_number) + ) + ) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Division Infix Op Disjlist +=============||| + +---- MODULE Test ---- +op == + \/ 1 + / 2 + \/ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item + (bullet_disj) + (bound_infix_op + (nat_number) + (slash) + (nat_number) + ) + ) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Infix Op Terminated Disjlist +=============||| + +---- MODULE Test ---- +op == + \/ 1 + + 2 + \/ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (bound_infix_op + (disj_list (disj_item (bullet_disj) (nat_number))) + (plus) + (nat_number) + ) + (lor) + (nat_number) + ) + ) +(double_line))) + +=============||| +Division Infix Op Terminated Disjlist +=============||| + +---- MODULE Test ---- +op == + \/ 1 + / 2 + \/ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (bound_infix_op + (disj_list (disj_item (bullet_disj) (nat_number))) + (slash) + (nat_number) + ) + (lor) + (nat_number) + ) + ) +(double_line))) + +=============||| +Not a Disjlist +=============||| + +---- MODULE Test ---- +op == 1 \/ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (nat_number) + (lor) + (nat_number) + ) + ) +(double_line))) + +=============||| +Disjlist with Parentheses +=============||| + +---- MODULE Test ---- +op == + \/ (1) + \/ (2) +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (parentheses (nat_number))) + (disj_item (bullet_disj) (parentheses (nat_number))) + ) + ) +(double_line))) + +=============||| +Disjlist Terminated by Parentheses +=============||| + +---- MODULE Test ---- +op == ( + \/ 1 + ) + \/ 2 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (parentheses + (disj_list (disj_item (bullet_disj) (nat_number))) + ) + (lor) + (nat_number) + ) + ) +(double_line))) + +=============||| +Nested Disjlist Terminated by Parentheses +=============||| + +---- MODULE Test ---- +op == ( + \/ 1 + \/ \/ 2 + \/ 3 + ) + \/ 4 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (parentheses + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item + (bullet_disj) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + ) + ) + (lor) + (nat_number) + ) + ) +(double_line))) + +=============||| +Double-Nested Disjlist Terminated by Parentheses +=============||| + +---- MODULE Test ---- +op == + \/ 1 + \/ \/ 2 + ( + \/ 3 + \/ 4 + ) + \/ 5 + \/ 6 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item + (bullet_disj) + (disj_list + (disj_item + (bullet_disj) + (bound_infix_op + (nat_number) + (plus) + (parentheses + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + ) + ) + (disj_item (bullet_disj) (nat_number)) + ) + ) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Module-End-Terminated Disjlist +=============||| + +---- MODULE Test ---- +op == + \/ 1 + \/ 2 ==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Keyword-Unit-Terminated Disjlist +=============||| + +---- MODULE Test ---- +op1 == + \/ 1 + \/ 2 + ASSUME x + +op2 == + \/ 3 + \/ 4 + LOCAL INSTANCE ModuleName + +op3 == + \/ 5 + \/ 6 + ----------------- + +op4 == + \/ 7 + \/ 8 + ---- MODULE Nested ---- + ==== + +op5 == + \/ 9 + \/ 10 + VARIABLES x, y +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + (assumption (identifier_ref)) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + (local_definition (instance (identifier_ref))) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + (single_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + (module (header_line) (identifier) (header_line) (double_line)) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + (variable_declaration (identifier) (identifier)) +(double_line))) + +=============||| +Disjlist with Empty Tuple +=============||| + +---- MODULE Test ---- +op == + \/ 1 + \/ <<>> +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (tuple_literal (langle_bracket) (rangle_bracket))) + ) + ) +(double_line))) + +=============||| +Disjlist with Empty Set +=============||| + +---- MODULE Test ---- +op == + \/ 1 + \/ {} +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (finite_set_literal)) + ) + ) +(double_line))) diff --git a/test/parser/syntax_corpus/except.txt b/test/parser/syntax_corpus/except.txt new file mode 100644 index 00000000..3d8d8e2c --- /dev/null +++ b/test/parser/syntax_corpus/except.txt @@ -0,0 +1,173 @@ +=============||| +Basic record update +=============||| + +---- MODULE Test ---- +r == [a EXCEPT ![2] = "a"] +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: + (except + expr_to_update: (identifier_ref) + (except_update + update_specifier: + (except_update_specifier + (except_update_fn_appl (nat_number))) + new_val: (string)) + )) +(double_line))) + +=============||| +Single nested record update +=============||| + +---- MODULE Test ---- +r == [a EXCEPT ![2]["a"][3] = @ + 1] +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (except + expr_to_update: (identifier_ref) + (except_update + update_specifier: (except_update_specifier + (except_update_fn_appl (nat_number)) + (except_update_fn_appl (string)) + (except_update_fn_appl (nat_number)) + ) + new_val: (bound_infix_op lhs: (prev_func_val) symbol: (plus) rhs: (nat_number)) + ) + ) + ) +(double_line))) + +=============||| +Single nested record update with dot syntax +=============||| + +---- MODULE Test ---- +r == [a EXCEPT !.x.y.z = "b"] +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: + (except + expr_to_update: (identifier_ref) + (except_update + update_specifier: + (except_update_specifier + (except_update_record_field (identifier_ref)) + (except_update_record_field (identifier_ref)) + (except_update_record_field (identifier_ref))) + new_val: (string)) + )) +(double_line))) + +=============||| +Multiple nested record updates +=============||| + +---- MODULE Test ---- +r == [a EXCEPT ![2]["a"][3] = @, !["b"][x] = 5, ![y][z] = "c"] +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: + (except + expr_to_update: (identifier_ref) + (except_update + update_specifier: + (except_update_specifier + (except_update_fn_appl (nat_number)) + (except_update_fn_appl (string)) + (except_update_fn_appl (nat_number))) + new_val: (prev_func_val)) + (except_update + update_specifier: + (except_update_specifier + (except_update_fn_appl (string)) + (except_update_fn_appl (identifier_ref))) + new_val: (nat_number)) + (except_update + update_specifier: + (except_update_specifier + (except_update_fn_appl (identifier_ref)) + (except_update_fn_appl (identifier_ref))) + new_val: (string)) + )) +(double_line))) + +=============||| +Multiple nested record updates with dot syntax +=============||| + +---- MODULE Test ---- +r == [a EXCEPT !.a.b.c = @, !.b.x = 5] +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: + (except + expr_to_update: (identifier_ref) + (except_update + update_specifier: + (except_update_specifier + (except_update_record_field (identifier_ref)) + (except_update_record_field (identifier_ref)) + (except_update_record_field (identifier_ref))) + new_val: (prev_func_val)) + (except_update + update_specifier: + (except_update_specifier + (except_update_record_field (identifier_ref)) + (except_update_record_field (identifier_ref))) + new_val: (nat_number)) + )) +(double_line))) + +=============||| +Multiple nested record updates with mixed dot/function syntax +=============||| + +---- MODULE Test ---- +r == [a EXCEPT !.a.b["c"] = "b", ![2].x = @] +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: + (except + expr_to_update: (identifier_ref) + (except_update + update_specifier: + (except_update_specifier + (except_update_record_field (identifier_ref)) + (except_update_record_field (identifier_ref)) + (except_update_fn_appl (string))) + new_val: (string)) + (except_update + update_specifier: + (except_update_specifier + (except_update_fn_appl (nat_number)) + (except_update_record_field (identifier_ref))) + new_val: (prev_func_val)) + )) +(double_line))) + diff --git a/test/parser/syntax_corpus/expressions.txt b/test/parser/syntax_corpus/expressions.txt new file mode 100644 index 00000000..fb5d4a07 --- /dev/null +++ b/test/parser/syntax_corpus/expressions.txt @@ -0,0 +1,73 @@ +==============================||| +Nested Parentheses +==============================||| + +---- MODULE Test ---- +op == ((((x)))) +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (parentheses (parentheses (parentheses (parentheses (identifier_ref))))) + ) +(double_line))) + +==============================||| +Tuple Literal +==============================||| + +---- MODULE Test ---- +op == <>>> +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (tuple_literal + (langle_bracket) + (identifier_ref) + (tuple_literal + (langle_bracket) + (identifier_ref) + (identifier_ref) + (rangle_bracket) + ) + (rangle_bracket) + ) + ) +(double_line))) + +======================||| +Tuple Literal with Jlist +======================||| + +---- MODULE Test ---- +op == << + /\ 1 + /\ 2 + >> + /\ 3 +==== + +----------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (bound_infix_op + lhs: (tuple_literal + (langle_bracket) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + (rangle_bracket) + ) + symbol: (land) + rhs: (nat_number) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/fairness.txt b/test/parser/syntax_corpus/fairness.txt new file mode 100644 index 00000000..50d18fdd --- /dev/null +++ b/test/parser/syntax_corpus/fairness.txt @@ -0,0 +1,92 @@ +=====================||| +Basic Weak Fairness +=====================||| + +---- MODULE Test ---- +op == WF_(vars)(x) +==== + +---------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (fairness (parentheses (identifier_ref)) (identifier_ref)) + ) +(double_line))) + +=====================||| +Basic Strong Fairness +=====================||| + +---- MODULE Test ---- +op == SF_(vars)(x) +==== + +---------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (fairness (parentheses (identifier_ref)) (identifier_ref)) + ) +(double_line))) + +=====================||| +Weak Fairness Ambiguity +=====================||| + +---- MODULE Test ---- +op == WF_vars(x) +==== + +---------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (fairness (identifier_ref) (identifier_ref)) + ) +(double_line))) + +=====================||| +Strong Fairness Ambiguity +=====================||| + +---- MODULE Test ---- +op == SF_vars(x) +==== + +---------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (fairness (identifier_ref) (identifier_ref)) + ) +(double_line))) + +==============================||| +Fairness with Tuple Literal +==============================||| + +---- MODULE Test ---- +op == WF_<>(f) +op == SF_x(f) +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (fairness + (tuple_literal + (langle_bracket) + (identifier_ref) + (identifier_ref) + (rangle_bracket) + ) + (identifier_ref) + ) + ) + (operator_definition name: (identifier) (def_eq) + definition: (fairness (identifier_ref) (identifier_ref)) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/functions.txt b/test/parser/syntax_corpus/functions.txt new file mode 100644 index 00000000..7981e4bf --- /dev/null +++ b/test/parser/syntax_corpus/functions.txt @@ -0,0 +1,219 @@ +===============================||| +Function Definition +===============================||| + +---- MODULE Test ---- +f[x \in Nat] == x +f[x, y \in Nat] == x +f[x, y \in Nat, z \in Real] == x +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (function_definition + name: (identifier) + (quantifier_bound + intro: (identifier) + (set_in) + set: (nat_number_set) + ) + (def_eq) + definition: (identifier_ref) + ) + (function_definition + name: (identifier) + (quantifier_bound + intro: (identifier) + intro: (identifier) + (set_in) + set: (nat_number_set) + ) + (def_eq) + definition: (identifier_ref) + ) + (function_definition + name: (identifier) + (quantifier_bound + intro: (identifier) + intro: (identifier) + (set_in) + set: (nat_number_set) + ) + (quantifier_bound + intro: (identifier) + (set_in) + set: (real_number_set) + ) + (def_eq) + definition: (identifier_ref) + ) +(double_line))) + +===============================||| +Function Evaluation +===============================||| + +---- MODULE Test ---- +op == f[1,2,3] +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (function_evaluation (identifier_ref) (nat_number) (nat_number) (nat_number)) + ) +(double_line))) + +===============================||| +Jlist Inside Function Evaluation +===============================||| + +---- MODULE Test ---- +op == + /\ 1 + /\ f[ + \/ 2 + \/ 3, + /\ 4 + ] +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) + (function_evaluation (identifier_ref) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + (conj_list (conj_item (bullet_conj) (nat_number))) + ) + ) + ) + ) +(double_line))) + +===============================||| +Function Literal +===============================||| + +---- MODULE Test ---- +op == [n \in Nat |-> 2*n] +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (function_literal + (quantifier_bound intro: (identifier) (set_in) set: (nat_number_set)) + (all_map_to) + (bound_infix_op lhs: (nat_number) symbol: (mul) rhs: (identifier_ref)) + ) + ) +(double_line))) + +===============================||| +Function Literal with Multiple Parameters and Jlist +===============================||| + +---- MODULE Test ---- +op == [ + x, y \in Nat, <> \in + /\ A + /\ B + |-> + /\ A + /\ B + ] +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (function_literal + (quantifier_bound intro: (identifier) intro: (identifier) (set_in) set: (nat_number_set)) + (quantifier_bound + intro: (tuple_of_identifiers (langle_bracket) (identifier) (identifier) (rangle_bracket)) + (set_in) + set: (conj_list + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + ) + ) + (all_map_to) + (conj_list + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + ) + ) + ) +(double_line))) + +===============================||| +Function Set +===============================||| + +---- MODULE Test ---- +op == [Nat -> [Nat -> Real]] +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (set_of_functions + (nat_number_set) + (maps_to) + (set_of_functions + (nat_number_set) + (maps_to) + (real_number_set) + ) + ) + ) +(double_line))) + +===============================||| +Jlist Inside Function Set +===============================||| + +---- MODULE Test ---- +op == [ + /\ A + /\ B + /\ C + -> + /\ D + /\ E + /\ F + ] +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (set_of_functions + (conj_list + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + ) + (maps_to) + (conj_list + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + ) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/if_then_else.txt b/test/parser/syntax_corpus/if_then_else.txt new file mode 100644 index 00000000..69607f29 --- /dev/null +++ b/test/parser/syntax_corpus/if_then_else.txt @@ -0,0 +1,131 @@ +==================||| +ITE with Strings +==================||| + +---- MODULE Test ---- +op == IF "A" THEN "B" ELSE "C" +==== + +------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (if_then_else (string) (string) (string)) + ) +(double_line))) + +=============||| +Conjlist with ITE +=============||| + +---- MODULE Test ---- +op == + /\ IF 1 + THEN 2 + ELSE 3 + /\ 4 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (if_then_else + (nat_number) + (nat_number) + (nat_number) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Conjlist inside ITE +=============||| + +---- MODULE Test ---- +op == + IF + /\ 1 + /\ 2 + THEN 3 + ELSE 4 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (if_then_else + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + (nat_number) + (nat_number) + ) + ) +(double_line))) + +=============||| +Disjlist with ITE +=============||| + +---- MODULE Test ---- +op == + \/ IF 1 + THEN 2 + ELSE 3 + \/ 4 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item + (bullet_disj) + (if_then_else + (nat_number) + (nat_number) + (nat_number) + ) + ) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Disjlist inside ITE +=============||| + +---- MODULE Test ---- +op == + IF + \/ 1 + \/ 2 + THEN 3 + ELSE 4 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (if_then_else + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + (nat_number) + (nat_number) + ) + ) +(double_line))) diff --git a/test/parser/syntax_corpus/infix_op.txt b/test/parser/syntax_corpus/infix_op.txt new file mode 100644 index 00000000..053bcdc6 --- /dev/null +++ b/test/parser/syntax_corpus/infix_op.txt @@ -0,0 +1,1194 @@ +=============||| +Infix Operator Definition +=============||| + +---- MODULE Test ---- + +x & y == 0 +x && y == 1 +x \approx y == 2 +x := y == 3 +x \asymp y == 4 +x \bigcirc y == 5 +x ::= y == 6 +x \bullet y == 7 +x \intersect y == 8 +x \cap y == 9 +x \cdot y == 10 +x \o y == 11 +x \circ y == 12 +x @@ y == 13 +x \cong y == 14 +x \union y == 15 +x \cup y == 16 +x \div y == 17 +x $ y == 18 +x $$ y == 19 +x \doteq y == 20 +x .. y == 21 +x ... y == 22 +x = y == 23 +x \equiv y == 24 +x !! y == 25 +x >= y == 26 +x \geq y == 27 +x \gg y == 28 +x > y == 29 +x ## y == 30 +x <=> y == 31 +x => y == 32 +x \in y == 33 +x /\ y == 34 +x \land y == 35 +x =| y == 36 +x ~> y == 37 +x <= y == 38 +x =< y == 39 +x \leq y == 40 +x \ll y == 41 +x \/ y == 42 +x \lor y == 43 +x -| y == 44 +x < y == 45 +x <: y == 46 +x :> y == 47 +x - y == 48 +x -- y == 49 +x % y == 50 +x %% y == 51 +x * y == 52 +x ** y == 53 +x /= y == 54 +x # y == 55 +x \notin y == 56 +x (.) y == 57 +x \odot y == 58 +x (-) y == 59 +x \ominus y == 60 +x (+) y == 61 +x \oplus y == 62 +x (/) y == 63 +x \oslash y == 64 +x (\X) y == 65 +x \otimes y == 66 +x + y == 67 +x -+-> y == 68 +x ++ y == 69 +x ^ y == 70 +x ^^ y == 71 +x \prec y == 72 +x \preceq y == 73 +x \propto y == 74 +x ?? y == 75 +x |= y == 76 +x |- y == 77 +x \ y == 78 +x \sim y == 79 +x \simeq y == 80 +x / y == 81 +x // y == 82 +x \sqcap y == 83 +x \sqcup y == 84 +x \sqsubset y == 85 +x \sqsubseteq y == 86 +x \sqsupset y == 87 +x \sqsupseteq y == 88 +x \star y == 89 +x \subset y == 90 +x \subseteq y == 91 +x \succ y == 92 +x \succeq y == 93 +x \supset y == 94 +x \supseteq y == 95 +x \X y == 96 +x \times y == 97 +x \uplus y == 98 +x | y == 99 +x || y == 100 +x \wr y == 101 + +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition parameter: (identifier) name: (infix_op_symbol (amp)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (ampamp)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (approx)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (assign)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (asymp)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (bigcirc)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (bnf_rule)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (bullet)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (cap)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (cap)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (cdot)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (circ)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (circ)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (compose)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (cong)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (cup)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (cup)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (div)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (dol)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (doldol)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (doteq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (dots_2)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (dots_3)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (eq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (equiv)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (excl)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (geq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (geq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (gg)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (gt)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (hashhash)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (iff)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (implies)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (in)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (land)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (land)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (ld_ttile)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (leads_to)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (leq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (leq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (leq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (ll)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (lor)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (lor)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (ls_ttile)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (lt)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (map_from)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (map_to)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (minus)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (minusminus)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (mod)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (modmod)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (mul)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (mulmul)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (neq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (neq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (notin)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (odot)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (odot)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (ominus)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (ominus)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (oplus)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (oplus)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (oslash)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (oslash)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (otimes)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (otimes)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (plus)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (plus_arrow)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (plusplus)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (pow)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (powpow)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (prec)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (preceq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (propto)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (qq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (rd_ttile)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (rs_ttile)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (setminus)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (sim)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (simeq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (slash)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (slashslash)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (sqcap)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (sqcup)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (sqsubset)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (sqsubseteq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (sqsupset)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (sqsupseteq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (star)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (subset)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (subseteq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (succ)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (succeq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (supset)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (supseteq)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (times)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (times)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (uplus)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (vert)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (vertvert)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (wr)) parameter: (identifier) (def_eq) definition: (nat_number)) +(double_line))) + + +=============||| +Infix Operator Declaration as Parameter +=============||| + +---- MODULE Test ---- + +op( + _ & _, + _ && _, + _ \approx _, + _ := _, + _ \asymp _, + _ \bigcirc _, + _ ::= _, + _ \bullet _, + _ \intersect _, + _ \cap _, + _ \cdot _, + _ \o _, + _ \circ _, + _ @@ _, + _ \cong _, + _ \union _, + _ \cup _, + _ \div _, + _ $ _, + _ $$ _, + _ \doteq _, + _ .. _, + _ ... _, + _ = _, + _ \equiv _, + _ !! _, + _ >= _, + _ \geq _, + _ \gg _, + _ > _, + _ ## _, + _ <=> _, + _ => _, + _ \in _, + _ /\ _, + _ \land _, + _ =| _, + _ ~> _, + _ <= _, + _ =< _, + _ \leq _, + _ \ll _, + _ \/ _, + _ \lor _, + _ -| _, + _ < _, + _ <: _, + _ :> _, + _ - _, + _ -- _, + _ % _, + _ %% _, + _ * _, + _ ** _, + _ /= _, + _ # _, + _ \notin _, + _ (.) _, + _ \odot _, + _ (-) _, + _ \ominus _, + _ (+) _, + _ \oplus _, + _ (/) _, + _ \oslash _, + _ (\X) _, + _ \otimes _, + _ + _, + _ -+-> _, + _ ++ _, + _ ^ _, + _ ^^ _, + _ \prec _, + _ \preceq _, + _ \propto _, + _ ?? _, + _ |= _, + _ |- _, + _ \ _, + _ \sim _, + _ \simeq _, + _ / _, + _ // _, + _ \sqcap _, + _ \sqcup _, + _ \sqsubset _, + _ \sqsubseteq _, + _ \sqsupset _, + _ \sqsupseteq _, + _ \star _, + _ \subset _, + _ \subseteq _, + _ \succ _, + _ \succeq _, + _ \supset _, + _ \supseteq _, + _ \X _, + _ \times _, + _ \uplus _, + _ | _, + _ || _, + _ \wr _ +) == 1 + +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (amp)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (ampamp)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (approx)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (assign)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (asymp)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (bigcirc)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (bnf_rule)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (bullet)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (cap)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (cap)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (cdot)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (circ)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (circ)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (compose)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (cong)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (cup)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (cup)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (div)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (dol)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (doldol)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (doteq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (dots_2)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (dots_3)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (eq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (equiv)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (excl)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (geq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (geq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (gg)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (gt)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (hashhash)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (iff)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (implies)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (in)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (land)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (land)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (ld_ttile)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (leads_to)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (leq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (leq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (leq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (ll)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (lor)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (lor)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (ls_ttile)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (lt)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (map_from)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (map_to)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (minus)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (minusminus)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (mod)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (modmod)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (mul)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (mulmul)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (neq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (neq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (notin)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (odot)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (odot)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (ominus)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (ominus)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (oplus)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (oplus)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (oslash)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (oslash)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (otimes)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (otimes)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (plus)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (plus_arrow)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (plusplus)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (pow)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (powpow)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (prec)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (preceq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (propto)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (qq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (rd_ttile)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (rs_ttile)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (setminus)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (sim)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (simeq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (slash)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (slashslash)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (sqcap)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (sqcup)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (sqsubset)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (sqsubseteq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (sqsupset)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (sqsupseteq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (star)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (subset)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (subseteq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (succ)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (succeq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (supset)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (supseteq)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (times)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (times)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (uplus)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (vert)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (vertvert)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (wr)) (placeholder)) + (def_eq) + definition: (nat_number) + ) +(double_line))) + +=============||| +Infix Operator Application +=============||| + +---- MODULE Test ---- + +op == { + x & y, + x && y, + x \approx y, + x := y, + x \asymp y, + x \bigcirc y, + x ::= y, + x \bullet y, + x \intersect y, + x \cap y, + x \cdot y, + x \o y, + x \circ y, + x @@ y, + x \cong y, + x \union y, + x \cup y, + x \div y, + x $ y, + x $$ y, + x \doteq y, + x .. y, + x ... y, + x = y, + x \equiv y, + x !! y, + x >= y, + x \geq y, + x \gg y, + x > y, + x ## y, + x <=> y, + x => y, + x \in y, + x /\ y, + x \land y, + x =| y, + x ~> y, + x <= y, + x =< y, + x \leq y, + x \ll y, + x \/ y, + x \lor y, + x -| y, + x < y, + x <: y, + x :> y, + x - y, + x -- y, + x % y, + x %% y, + x * y, + x ** y, + x /= y, + x # y, + x \notin y, + x (.) y, + x \odot y, + x (-) y, + x \ominus y, + x (+) y, + x \oplus y, + x (/) y, + x \oslash y, + x (\X) y, + x \otimes y, + x + y, + x -+-> y, + x ++ y, + x ^ y, + x ^^ y, + x \prec y, + x \preceq y, + x \propto y, + x ?? y, + x |= y, + x |- y, + x \ y, + x \sim y, + x \simeq y, + x / y, + x // y, + x \sqcap y, + x \sqcup y, + x \sqsubset y, + x \sqsubseteq y, + x \sqsupset y, + x \sqsupseteq y, + x \star y, + x \subset y, + x \subseteq y, + x \succ y, + x \succeq y, + x \supset y, + x \supseteq y, + x \X y, + x \times y, + x \uplus y, + x | y, + x || y, + x \wr y +} + +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (finite_set_literal + (bound_infix_op lhs: (identifier_ref) symbol: (amp) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (ampamp) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (approx) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (assign) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (asymp) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (bigcirc) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (bnf_rule) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (bullet) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (cap) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (cap) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (cdot) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (circ) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (circ) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (compose) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (cong) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (cup) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (cup) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (div) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (dol) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (doldol) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (doteq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (dots_2) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (dots_3) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (eq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (equiv) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (excl) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (geq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (geq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (gg) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (gt) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (hashhash) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (iff) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (implies) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (in) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (land) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (land) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (ld_ttile) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (leads_to) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (leq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (leq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (leq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (ll) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (lor) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (lor) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (ls_ttile) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (lt) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (map_from) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (map_to) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (minus) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (minusminus) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (mod) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (modmod) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (mul) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (mulmul) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (neq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (neq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (notin) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (odot) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (odot) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (ominus) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (ominus) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (oplus) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (oplus) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (oslash) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (oslash) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (otimes) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (otimes) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (plus) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (plus_arrow) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (plusplus) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (pow) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (powpow) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (prec) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (preceq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (propto) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (qq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (rd_ttile) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (rs_ttile) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (setminus) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (sim) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (simeq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (slash) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (slashslash) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (sqcap) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (sqcup) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (sqsubset) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (sqsubseteq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (sqsupset) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (sqsupseteq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (star) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (subset) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (subseteq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (succ) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (succeq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (supset) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (supseteq) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (times) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (times) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (uplus) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (vert) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (vertvert) rhs: (identifier_ref)) + (bound_infix_op lhs: (identifier_ref) symbol: (wr) rhs: (identifier_ref)) + )) +(double_line))) + +=============||| +Infix Operators as Parameters +=============||| + +---- MODULE Test ---- +op == f( + &, + &&, + \approx, + :=, + \asymp, + \bigcirc, + ::=, + \bullet, + \intersect, + \cap, + \cdot, + \o, + \circ, + @@, + \cong, + \union, + \cup, + \div, + $, + $$, + \doteq, + .., + ..., + =, + \equiv, + !!, + >=, + \geq, + \gg, + >, + ##, + <=>, + =>, + \in, + /\, + \land, + =|, + ~>, + <=, + =<, + \leq, + \ll, + \/, + \lor, + -|, + <, + <:, + :>, + -, + --, + %, + %%, + *, + **, + /=, + #, + \notin, + (.), + \odot, + (-), + \ominus, + (+), + \oplus, + (/), + \oslash, + (\X), + \otimes, + +, + -+->, + ++, + ^, + ^^, + \prec, + \preceq, + \propto, + ??, + |=, + |-, + \, + \sim, + \simeq, + /, + //, + \sqcap, + \sqcup, + \sqsubset, + \sqsubseteq, + \sqsupset, + \sqsupseteq, + \star, + \subset, + \subseteq, + \succ, + \succeq, + \supset, + \supseteq, + \uplus, + |, + ||, + \wr +) +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (bound_op name: (identifier_ref) + parameter: (infix_op_symbol (amp)) + parameter: (infix_op_symbol (ampamp)) + parameter: (infix_op_symbol (approx)) + parameter: (infix_op_symbol (assign)) + parameter: (infix_op_symbol (asymp)) + parameter: (infix_op_symbol (bigcirc)) + parameter: (infix_op_symbol (bnf_rule)) + parameter: (infix_op_symbol (bullet)) + parameter: (infix_op_symbol (cap)) + parameter: (infix_op_symbol (cap)) + parameter: (infix_op_symbol (cdot)) + parameter: (infix_op_symbol (circ)) + parameter: (infix_op_symbol (circ)) + parameter: (infix_op_symbol (compose)) + parameter: (infix_op_symbol (cong)) + parameter: (infix_op_symbol (cup)) + parameter: (infix_op_symbol (cup)) + parameter: (infix_op_symbol (div)) + parameter: (infix_op_symbol (dol)) + parameter: (infix_op_symbol (doldol)) + parameter: (infix_op_symbol (doteq)) + parameter: (infix_op_symbol (dots_2)) + parameter: (infix_op_symbol (dots_3)) + parameter: (infix_op_symbol (eq)) + parameter: (infix_op_symbol (equiv)) + parameter: (infix_op_symbol (excl)) + parameter: (infix_op_symbol (geq)) + parameter: (infix_op_symbol (geq)) + parameter: (infix_op_symbol (gg)) + parameter: (infix_op_symbol (gt)) + parameter: (infix_op_symbol (hashhash)) + parameter: (infix_op_symbol (iff)) + parameter: (infix_op_symbol (implies)) + parameter: (infix_op_symbol (in)) + parameter: (infix_op_symbol (land)) + parameter: (infix_op_symbol (land)) + parameter: (infix_op_symbol (ld_ttile)) + parameter: (infix_op_symbol (leads_to)) + parameter: (infix_op_symbol (leq)) + parameter: (infix_op_symbol (leq)) + parameter: (infix_op_symbol (leq)) + parameter: (infix_op_symbol (ll)) + parameter: (infix_op_symbol (lor)) + parameter: (infix_op_symbol (lor)) + parameter: (infix_op_symbol (ls_ttile)) + parameter: (infix_op_symbol (lt)) + parameter: (infix_op_symbol (map_from)) + parameter: (infix_op_symbol (map_to)) + parameter: (infix_op_symbol (minus)) + parameter: (infix_op_symbol (minusminus)) + parameter: (infix_op_symbol (mod)) + parameter: (infix_op_symbol (modmod)) + parameter: (infix_op_symbol (mul)) + parameter: (infix_op_symbol (mulmul)) + parameter: (infix_op_symbol (neq)) + parameter: (infix_op_symbol (neq)) + parameter: (infix_op_symbol (notin)) + parameter: (infix_op_symbol (odot)) + parameter: (infix_op_symbol (odot)) + parameter: (infix_op_symbol (ominus)) + parameter: (infix_op_symbol (ominus)) + parameter: (infix_op_symbol (oplus)) + parameter: (infix_op_symbol (oplus)) + parameter: (infix_op_symbol (oslash)) + parameter: (infix_op_symbol (oslash)) + parameter: (infix_op_symbol (otimes)) + parameter: (infix_op_symbol (otimes)) + parameter: (infix_op_symbol (plus)) + parameter: (infix_op_symbol (plus_arrow)) + parameter: (infix_op_symbol (plusplus)) + parameter: (infix_op_symbol (pow)) + parameter: (infix_op_symbol (powpow)) + parameter: (infix_op_symbol (prec)) + parameter: (infix_op_symbol (preceq)) + parameter: (infix_op_symbol (propto)) + parameter: (infix_op_symbol (qq)) + parameter: (infix_op_symbol (rd_ttile)) + parameter: (infix_op_symbol (rs_ttile)) + parameter: (infix_op_symbol (setminus)) + parameter: (infix_op_symbol (sim)) + parameter: (infix_op_symbol (simeq)) + parameter: (infix_op_symbol (slash)) + parameter: (infix_op_symbol (slashslash)) + parameter: (infix_op_symbol (sqcap)) + parameter: (infix_op_symbol (sqcup)) + parameter: (infix_op_symbol (sqsubset)) + parameter: (infix_op_symbol (sqsubseteq)) + parameter: (infix_op_symbol (sqsupset)) + parameter: (infix_op_symbol (sqsupseteq)) + parameter: (infix_op_symbol (star)) + parameter: (infix_op_symbol (subset)) + parameter: (infix_op_symbol (subseteq)) + parameter: (infix_op_symbol (succ)) + parameter: (infix_op_symbol (succeq)) + parameter: (infix_op_symbol (supset)) + parameter: (infix_op_symbol (supseteq)) + parameter: (infix_op_symbol (uplus)) + parameter: (infix_op_symbol (vert)) + parameter: (infix_op_symbol (vertvert)) + parameter: (infix_op_symbol (wr)) + )) +(double_line))) + +=============||| +Nonfix Infix Operators +=============||| + +---- MODULE Test ---- +op == { + A!B!&(x, y), + A!B!&&(x, y), + A!B!\approx(x, y), + A!B!:=(x, y), + A!B!\asymp(x, y), + A!B!\bigcirc(x, y), + A!B!::=(x, y), + A!B!\bullet(x, y), + A!B!\intersect(x, y), + A!B!\cap(x, y), + A!B!\cdot(x, y), + A!B!\o(x, y), + A!B!\circ(x, y), + A!B!@@(x, y), + A!B!\cong(x, y), + A!B!\union(x, y), + A!B!\cup(x, y), + A!B!\div(x, y), + A!B!$(x, y), + A!B!$$(x, y), + A!B!\doteq(x, y), + A!B!..(x, y), + A!B!...(x, y), + A!B!=(x, y), + A!B!\equiv(x, y), + A!B!>=(x, y), + A!B!\geq(x, y), + A!B!\gg(x, y), + A!B!>(x, y), + A!B!##(x, y), + A!B!<=>(x, y), + A!B!=>(x, y), + A!B!\in(x, y), + A!B!\land(x, y), + A!B!=|(x, y), + A!B!~>(x, y), + A!B!<=(x, y), + A!B!=<(x, y), + A!B!\leq(x, y), + A!B!\ll(x, y), + A!B!\lor(x, y), + A!B!-|(x, y), + A!B!<(x, y), + A!B!<:(x, y), + A!B!:>(x, y), + A!B!-(x, y), + A!B!--(x, y), + A!B!%(x, y), + A!B!%%(x, y), + A!B!*(x, y), + A!B!**(x, y), + A!B!/=(x, y), + A!B!#(x, y), + A!B!\notin(x, y), + A!B!(.)(x, y), + A!B!\odot(x, y), + A!B!(-)(x, y), + A!B!\ominus(x, y), + A!B!(+)(x, y), + A!B!\oplus(x, y), + A!B!(/)(x, y), + A!B!\oslash(x, y), + A!B!(\X)(x, y), + A!B!\otimes(x, y), + A!B!+(x, y), + A!B!-+->(x, y), + A!B!++(x, y), + A!B!^(x, y), + A!B!^^(x, y), + A!B!\prec(x, y), + A!B!\preceq(x, y), + A!B!\propto(x, y), + A!B!??(x, y), + A!B!|=(x, y), + A!B!|-(x, y), + A!B!\(x, y), + A!B!\sim(x, y), + A!B!\simeq(x, y), + A!B!/(x, y), + A!B!//(x, y), + A!B!\sqcap(x, y), + A!B!\sqcup(x, y), + A!B!\sqsubset(x, y), + A!B!\sqsubseteq(x, y), + A!B!\sqsupset(x, y), + A!B!\sqsupseteq(x, y), + A!B!\star(x, y), + A!B!\subset(x, y), + A!B!\subseteq(x, y), + A!B!\succ(x, y), + A!B!\succeq(x, y), + A!B!\supset(x, y), + A!B!\supseteq(x, y), + A!B!\X(x, y), + A!B!\times(x, y), + A!B!\uplus(x, y), + A!B!|(x, y), + A!B!||(x, y), + A!B!\wr(x, y) +} +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (finite_set_literal + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (amp)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (ampamp)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (approx)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (assign)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (asymp)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (bigcirc)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (bnf_rule)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (bullet)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (cap)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (cap)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (cdot)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (circ)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (circ)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (compose)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (cong)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (cup)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (cup)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (div)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (dol)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (doldol)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (doteq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (dots_2)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (dots_3)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (eq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (equiv)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (geq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (geq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (gg)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (gt)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (hashhash)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (iff)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (implies)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (in)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (land)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (ld_ttile)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (leads_to)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (leq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (leq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (leq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (ll)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (lor)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (ls_ttile)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (lt)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (map_from)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (map_to)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (minus)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (minusminus)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (mod)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (modmod)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (mul)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (mulmul)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (neq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (neq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (notin)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (odot)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (odot)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (ominus)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (ominus)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (oplus)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (oplus)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (oslash)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (oslash)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (otimes)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (otimes)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (plus)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (plus_arrow)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (plusplus)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (pow)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (powpow)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (prec)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (preceq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (propto)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (qq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (rd_ttile)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (rs_ttile)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (setminus)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (sim)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (simeq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (slash)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (slashslash)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (sqcap)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (sqcup)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (sqsubset)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (sqsubseteq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (sqsupset)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (sqsupseteq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (star)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (subset)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (subseteq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (succ)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (succeq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (supset)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (supseteq)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (times)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (times)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (uplus)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (vert)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (vertvert)) (identifier_ref) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (wr)) (identifier_ref) (identifier_ref))) + )) +(double_line))) + diff --git a/test/parser/syntax_corpus/jlist.txt b/test/parser/syntax_corpus/jlist.txt new file mode 100644 index 00000000..e86502c7 --- /dev/null +++ b/test/parser/syntax_corpus/jlist.txt @@ -0,0 +1,172 @@ +=============||| +Conjlist Followed by Disjunct +=============||| + +---- MODULE Test ---- +op == + /\ 1 + /\ 2 + \/ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + (lor) + (nat_number) + ) + ) +(double_line))) + +=============||| +Disjlist Followed by Conjunct +=============||| + +---- MODULE Test ---- +op == + \/ 1 + \/ 2 + /\ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + (land) + (nat_number) + ) + ) +(double_line))) + +=============||| +Two Mismatched Jlists +=============||| + +---- MODULE Test ---- +opA == + /\ 1 + /\ 2 + \/ 3 + +opB == + \/ 1 + \/ 2 + /\ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + (lor) + (nat_number) + ) + ) + (operator_definition (identifier) (def_eq) + (bound_infix_op + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + (land) + (nat_number) + ) + ) +(double_line))) + +=============||| +Nested Alternating Jlists +=============||| + +---- MODULE Test ---- +op == + /\ \/ 1 + \/ 2 + /\ \/ 3 + \/ /\ 4 + /\ 5 + /\ 6 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + (conj_item + (bullet_conj) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item + (bullet_disj) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Jlists Containing Colon-Prefixed Infix Operators (GH87) +=============||| + +---- MODULE Test ---- +conj == + /\ lbl :: A + /\ B := C + /\ D ::= E + +disj == + \/ lbl :: A + \/ B := C + \/ D ::= E +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (label (identifier) (label_as) (identifier_ref))) + (conj_item (bullet_conj) (bound_infix_op (identifier_ref) (assign) (identifier_ref))) + (conj_item (bullet_conj) (bound_infix_op (identifier_ref) (bnf_rule) (identifier_ref))) + ) + ) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (label (identifier) (label_as) (identifier_ref))) + (disj_item (bullet_disj) (bound_infix_op (identifier_ref) (assign) (identifier_ref))) + (disj_item (bullet_disj) (bound_infix_op (identifier_ref) (bnf_rule) (identifier_ref))) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/labels.txt b/test/parser/syntax_corpus/labels.txt new file mode 100644 index 00000000..4826f717 --- /dev/null +++ b/test/parser/syntax_corpus/labels.txt @@ -0,0 +1,40 @@ +=============||| +Basic Label +=============||| + +---- MODULE Test ---- +op(x) == lbl :: x +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) parameter: (identifier) (def_eq) + definition: (label name: (identifier) (label_as) expression: (identifier_ref)) + ) +(double_line))) + +=============||| +Label With Parameters +=============||| + +---- MODULE Test ---- +op == \A a, b \in Nat : lbl(a, b) :: P(a, b) +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (bounded_quantification + quantifier: (forall) + bound: (quantifier_bound intro: (identifier) intro: (identifier) (set_in) set: (nat_number_set)) + expression: (label + name: (identifier) parameter: (identifier_ref) parameter: (identifier_ref) + (label_as) + expression: (bound_op name: (identifier_ref) parameter: (identifier_ref) parameter: (identifier_ref)) + ) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/let_in.txt b/test/parser/syntax_corpus/let_in.txt new file mode 100644 index 00000000..4c76b0e7 --- /dev/null +++ b/test/parser/syntax_corpus/let_in.txt @@ -0,0 +1,253 @@ +=============||| +RECURSIVE inside LET/IN +=============||| + +---- MODULE Test ---- +op == + LET + RECURSIVE f(_) + f(n) == IF n =< 0 THEN 1 ELSE n * f(n-1) + IN f(5) +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (let_in + (recursive_declaration (operator_declaration (identifier) (placeholder))) + (operator_definition (identifier) (identifier) (def_eq) + (if_then_else + (bound_infix_op (identifier_ref) (leq) (nat_number)) + (nat_number) + (bound_infix_op (identifier_ref) (mul) + (bound_op (identifier_ref) + (bound_infix_op (identifier_ref) (minus) (nat_number)) + ) + ) + ) + ) + (bound_op (identifier_ref) (nat_number)) + ) + ) +(double_line))) + +=============||| +Conjlist with LET/IN +=============||| + +---- MODULE Test ---- +op == + /\ LET x == 1 IN 2 + /\ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (let_in + (operator_definition (identifier) (def_eq) (nat_number)) + (nat_number) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Conjlist with RECURSIVE in LET/IN +=============||| + +---- MODULE Test ---- +op == + /\ LET RECURSIVE f IN P + /\ Q +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (let_in + (recursive_declaration (identifier)) + (identifier_ref) + ) + ) + (conj_item (bullet_conj) (identifier_ref)) + ) + ) +(double_line))) + +=============||| +Conjlist with INSTANCE in LET/IN +=============||| + +---- MODULE Test ---- +op == + /\ LET M1 == INSTANCE M2 IN P + /\ Q +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (let_in + (module_definition (identifier) (def_eq) (instance (identifier_ref))) + (identifier_ref) + ) + ) + (conj_item (bullet_conj) (identifier_ref)) + ) + ) +(double_line))) + +=============||| +Conjlist inside LET/IN +=============||| + +---- MODULE Test ---- +op == + LET + x == + /\ 1 + /\ 2 + IN 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (let_in + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + (nat_number) + ) + ) +(double_line))) + +=============||| +Disjlist with LET/IN +=============||| + +---- MODULE Test ---- +op == + \/ LET x == 1 IN 2 + \/ 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item + (bullet_disj) + (let_in + (operator_definition (identifier) (def_eq) (nat_number)) + (nat_number) + ) + ) + (disj_item (bullet_disj) (nat_number)) + ) + ) +(double_line))) + +=============||| +Disjlist with RECURSIVE in LET/IN +=============||| + +---- MODULE Test ---- +op == + \/ LET RECURSIVE f IN P + \/ Q +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item + (bullet_disj) + (let_in + (recursive_declaration (identifier)) + (identifier_ref) + ) + ) + (disj_item (bullet_disj) (identifier_ref)) + ) + ) +(double_line))) + +=============||| +Disjlist with INSTANCE in LET/IN +=============||| + +---- MODULE Test ---- +op == + \/ LET M1 == INSTANCE M2 IN P + \/ Q +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item + (bullet_disj) + (let_in + (module_definition (identifier) (def_eq) (instance (identifier_ref))) + (identifier_ref) + ) + ) + (disj_item (bullet_disj) (identifier_ref)) + ) + ) +(double_line))) + +=============||| +Disjlist inside LET/IN +=============||| + +---- MODULE Test ---- +op == + LET + x == + \/ 1 + \/ 2 + IN 3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (let_in + (operator_definition (identifier) (def_eq) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + (nat_number) + ) + ) +(double_line))) diff --git a/test/parser/syntax_corpus/modules.txt b/test/parser/syntax_corpus/modules.txt new file mode 100644 index 00000000..74008724 --- /dev/null +++ b/test/parser/syntax_corpus/modules.txt @@ -0,0 +1,64 @@ +=============||| +Single module +=============||| + +---- MODULE Test ---- +==== + +-------------||| + +(source_file + (module (header_line) (identifier) (header_line) (double_line)) +) + +=============||| +Module with EXTENDS +=============||| + +---- MODULE Test ---- +EXTENDS M1, M2, M3 +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (extends (identifier_ref) (identifier_ref) (identifier_ref)) +(double_line))) + +=============||| +Nested modules +=============||| + +---- MODULE Test ---- +---- MODULE Inner ---- +==== +==== + +-------------||| + +(source_file + (module (header_line) (identifier) (header_line) + (module (header_line) (identifier) (header_line) (double_line)) + (double_line)) +) + +=============||| +Multiple Nested modules +=============||| + +---- MODULE Test ---- +---- MODULE Inner ---- +==== +---- MODULE Inner2 ---- +==== +==== + +-------------||| + +(source_file + (module (header_line) (identifier) (header_line) + (module (header_line) (identifier) (header_line) (double_line)) + (module (header_line) (identifier) (header_line) (double_line)) + (double_line)) +) + diff --git a/test/parser/syntax_corpus/number.txt b/test/parser/syntax_corpus/number.txt new file mode 100644 index 00000000..f91c5e2c --- /dev/null +++ b/test/parser/syntax_corpus/number.txt @@ -0,0 +1,79 @@ +======================||| +All Number Formats +======================||| + +---- MODULE Test ---- +op == 12345 +op == 12345.12345 +op == \b01010101 +op == \B10101010 +op == \o01234567 +op == \O76543210 +op == \h0123456789abcdef +op == \H9876543210FEDCBA +==== + +----------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) (nat_number)) + (operator_definition (identifier) (def_eq) (real_number)) + (operator_definition (identifier) (def_eq) (binary_number (format) (value))) + (operator_definition (identifier) (def_eq) (binary_number (format) (value))) + (operator_definition (identifier) (def_eq) (octal_number (format) (value))) + (operator_definition (identifier) (def_eq) (octal_number (format) (value))) + (operator_definition (identifier) (def_eq) (hex_number (format) (value))) + (operator_definition (identifier) (def_eq) (hex_number (format) (value))) +(double_line))) + +======================||| +All Number Sets +======================||| + +---- MODULE Test ---- +op == Nat +op == Int +op == Real +==== + +----------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (nat_number_set)) + (operator_definition name: (identifier) (def_eq) definition: (int_number_set)) + (operator_definition name: (identifier) (def_eq) definition: (real_number_set)) +(double_line))) + +=============||| +Number Set Definitions +=============||| + +---- MODULE Test ---- +Nat == {} +op == A!Nat +Int == {} +op == A!Int +Real == {} +op == A!Real +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (nat_number_set) (def_eq) definition: (finite_set_literal)) + (operator_definition name: (identifier) (def_eq) definition: (prefixed_op + prefix: (subexpr_prefix (subexpr_component (identifier_ref))) + op: (nat_number_set) + )) + (operator_definition name: (int_number_set) (def_eq) definition: (finite_set_literal)) + (operator_definition name: (identifier) (def_eq) definition: (prefixed_op + prefix: (subexpr_prefix (subexpr_component (identifier_ref))) + op: (int_number_set) + )) + (operator_definition name: (real_number_set) (def_eq) definition: (finite_set_literal)) + (operator_definition name: (identifier) (def_eq) definition: (prefixed_op + prefix: (subexpr_prefix (subexpr_component (identifier_ref))) + op: (real_number_set) + )) +(double_line))) + diff --git a/test/parser/syntax_corpus/operators.txt b/test/parser/syntax_corpus/operators.txt new file mode 100644 index 00000000..a8102537 --- /dev/null +++ b/test/parser/syntax_corpus/operators.txt @@ -0,0 +1,79 @@ +=============||| +Lexically-Conflicting Nonfix Operators +=============||| + +---- MODULE Test ---- +conflicts_with_octal == \o (1,2) +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_nonfix_op (infix_op_symbol (circ)) (nat_number) (nat_number)) + ) +(double_line))) + +=============||| +Minus and Negative +=============||| + +---- MODULE Test ---- +op == -. (1) +op == - (1) +op == - 1 - 2 +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_nonfix_op (prefix_op_symbol (negative)) (nat_number)) + ) + (operator_definition (identifier) (def_eq) + (bound_prefix_op (negative) (parentheses (nat_number))) + ) + (operator_definition (identifier) (def_eq) + (bound_infix_op (bound_prefix_op (negative) (nat_number)) (minus) (nat_number)) + ) +(double_line))) + +=============||| +Higher-Order Operator Parameter Declarations +=============||| + +---- MODULE Test ---- +f(x, g(_, _), _+_, -._, _^+) == x +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) + (identifier) + (operator_declaration (identifier) (placeholder) (placeholder)) + (operator_declaration (placeholder) (infix_op_symbol (plus)) (placeholder)) + (operator_declaration (prefix_op_symbol (negative)) (placeholder)) + (operator_declaration (placeholder) (postfix_op_symbol (sup_plus))) + (def_eq) (identifier_ref)) +(double_line))) + +=============||| +LAMBDA Parameter +=============||| + +---- MODULE Test ---- +op == f(LAMBDA x, y : x + y, LAMBDA x : 0) +==== + +--------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (bound_op name: (identifier_ref) + parameter: (lambda (identifier) (identifier) (bound_infix_op lhs: (identifier_ref) symbol: (plus) rhs: (identifier_ref))) + parameter: (lambda (identifier) (nat_number)) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/postfix_op.txt b/test/parser/syntax_corpus/postfix_op.txt new file mode 100644 index 00000000..8899520e --- /dev/null +++ b/test/parser/syntax_corpus/postfix_op.txt @@ -0,0 +1,126 @@ +=============||| +Postfix Operator Definition +=============||| + +---- MODULE Test ---- + +x^+ == 1 +x^* == 2 +x^# == 3 +x' == 4 + +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition parameter: (identifier) name: (postfix_op_symbol (sup_plus)) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (postfix_op_symbol (asterisk)) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (postfix_op_symbol (sup_hash)) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (postfix_op_symbol (prime)) (def_eq) definition: (nat_number)) +(double_line))) + +=============||| +Postfix Operator Declaration as Parameter +=============||| + +---- MODULE Test ---- + +op( + _ ^+, + _ ^*, + _ ^#, + _ ' +) == 4 + +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) + parameter: (operator_declaration (placeholder) name: (postfix_op_symbol (sup_plus))) + parameter: (operator_declaration (placeholder) name: (postfix_op_symbol (asterisk))) + parameter: (operator_declaration (placeholder) name: (postfix_op_symbol (sup_hash))) + parameter: (operator_declaration (placeholder) name: (postfix_op_symbol (prime))) + (def_eq) + definition: (nat_number) + ) +(double_line))) + +=============||| +Postfix Operator Application +=============||| + +---- MODULE Test ---- +op == { + x^+, + x^*, + x^#, + x' +} +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (finite_set_literal + (bound_postfix_op lhs: (identifier_ref) symbol: (sup_plus)) + (bound_postfix_op lhs: (identifier_ref) symbol: (asterisk)) + (bound_postfix_op lhs: (identifier_ref) symbol: (sup_hash)) + (bound_postfix_op lhs: (identifier_ref) symbol: (prime)) + )) +(double_line))) + +=============||| +Postfix Operators as Parameters +=============||| + +---- MODULE Test ---- +op == f( + ^+, + ^*, + ^#, + ' +) +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (bound_op name: (identifier_ref) + parameter: (postfix_op_symbol (sup_plus)) + parameter: (postfix_op_symbol (asterisk)) + parameter: (postfix_op_symbol (sup_hash)) + parameter: (postfix_op_symbol (prime)) + )) +(double_line))) + +=============||| +Nonfix Postfix Operators +=============||| + +---- MODULE Test ---- +op == { + A!B!^+(x), + A!B!^*(x), + A!B!^#(x), + A!B!'(x) +} +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (finite_set_literal + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (postfix_op_symbol (sup_plus)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (postfix_op_symbol (asterisk)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (postfix_op_symbol (sup_hash)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (postfix_op_symbol (prime)) (identifier_ref))) + )) +(double_line))) + diff --git a/test/parser/syntax_corpus/prefix_op.txt b/test/parser/syntax_corpus/prefix_op.txt new file mode 100644 index 00000000..031efcd4 --- /dev/null +++ b/test/parser/syntax_corpus/prefix_op.txt @@ -0,0 +1,203 @@ +=============||| +Prefix Operator Definition +=============||| + +---- MODULE Test ---- + +~x == 1 +\lnot x == 2 +\neg x == 3 +UNION x == 4 +SUBSET x == 5 +DOMAIN x == 6 +-. x == 7 +ENABLED x == 8 +UNCHANGED x == 9 +[] x == 10 +<> x == 11 + +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (prefix_op_symbol (lnot)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition name: (prefix_op_symbol (lnot)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition name: (prefix_op_symbol (lnot)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition name: (prefix_op_symbol (union)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition name: (prefix_op_symbol (powerset)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition name: (prefix_op_symbol (domain)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition name: (prefix_op_symbol (negative)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition name: (prefix_op_symbol (enabled)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition name: (prefix_op_symbol (unchanged)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition name: (prefix_op_symbol (always)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition name: (prefix_op_symbol (eventually)) parameter: (identifier) (def_eq) definition: (nat_number)) +(double_line))) + +=============||| +Prefix Operator Declaration as Parameter +=============||| + +---- MODULE Test ---- + +op( + ~ _, + \lnot _, + \neg _, + UNION _, + SUBSET _, + DOMAIN _, + -. _, + ENABLED _, + UNCHANGED _, + [] _, + <> _ +) == 11 + +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) + parameter: (operator_declaration name: (prefix_op_symbol (lnot)) (placeholder)) + parameter: (operator_declaration name: (prefix_op_symbol (lnot)) (placeholder)) + parameter: (operator_declaration name: (prefix_op_symbol (lnot)) (placeholder)) + parameter: (operator_declaration name: (prefix_op_symbol (union)) (placeholder)) + parameter: (operator_declaration name: (prefix_op_symbol (powerset)) (placeholder)) + parameter: (operator_declaration name: (prefix_op_symbol (domain)) (placeholder)) + parameter: (operator_declaration name: (prefix_op_symbol (negative)) (placeholder)) + parameter: (operator_declaration name: (prefix_op_symbol (enabled)) (placeholder)) + parameter: (operator_declaration name: (prefix_op_symbol (unchanged)) (placeholder)) + parameter: (operator_declaration name: (prefix_op_symbol (always)) (placeholder)) + parameter: (operator_declaration name: (prefix_op_symbol (eventually)) (placeholder)) + (def_eq) + definition: (nat_number) + ) +(double_line))) + +=============||| +Prefix Operator Application +=============||| + +---- MODULE Test ---- +op == { + ~x, + \lnot x, + \neg x, + UNION x, + SUBSET x, + DOMAIN x, + -x, + ENABLED x, + UNCHANGED x, + []x, + <>x +} +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (finite_set_literal + (bound_prefix_op symbol: (lnot) rhs: (identifier_ref)) + (bound_prefix_op symbol: (lnot) rhs: (identifier_ref)) + (bound_prefix_op symbol: (lnot) rhs: (identifier_ref)) + (bound_prefix_op symbol: (union) rhs: (identifier_ref)) + (bound_prefix_op symbol: (powerset) rhs: (identifier_ref)) + (bound_prefix_op symbol: (domain) rhs: (identifier_ref)) + (bound_prefix_op symbol: (negative) rhs: (identifier_ref)) + (bound_prefix_op symbol: (enabled) rhs: (identifier_ref)) + (bound_prefix_op symbol: (unchanged) rhs: (identifier_ref)) + (bound_prefix_op symbol: (always) rhs: (identifier_ref)) + (bound_prefix_op symbol: (eventually) rhs: (identifier_ref)) + )) +(double_line))) + +=============||| +Prefix Operator References +=============||| + +---- MODULE Test ---- +op == f( + ~, + \lnot, + \neg, + UNION, + SUBSET, + DOMAIN, + -., + ENABLED, + UNCHANGED, + [], + <> +) +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (bound_op name: (identifier_ref) + parameter: (prefix_op_symbol (lnot)) + parameter: (prefix_op_symbol (lnot)) + parameter: (prefix_op_symbol (lnot)) + parameter: (prefix_op_symbol (union)) + parameter: (prefix_op_symbol (powerset)) + parameter: (prefix_op_symbol (domain)) + parameter: (prefix_op_symbol (negative)) + parameter: (prefix_op_symbol (enabled)) + parameter: (prefix_op_symbol (unchanged)) + parameter: (prefix_op_symbol (always)) + parameter: (prefix_op_symbol (eventually)) + )) +(double_line))) + +=============||| +Nonfix Prefix Operators +=============||| + +---- MODULE Test ---- +op == { + A!B!~(x), + A!B!\lnot(x), + A!B!\neg(x), + A!B!UNION(x), + A!B!SUBSET(x), + A!B!DOMAIN(x), + A!B!-.(x), + A!B!ENABLED(x), + A!B!UNCHANGED(x), + A!B![](x), + A!B!<>(x) +} +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (finite_set_literal + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (lnot)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (lnot)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (lnot)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (union)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (powerset)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (domain)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (negative)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (enabled)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (unchanged)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (always)) (identifier_ref))) + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (prefix_op_symbol (eventually)) (identifier_ref))) + )) +(double_line))) + diff --git a/test/parser/syntax_corpus/proofs.txt b/test/parser/syntax_corpus/proofs.txt new file mode 100644 index 00000000..2163b1d9 --- /dev/null +++ b/test/parser/syntax_corpus/proofs.txt @@ -0,0 +1,521 @@ +===============================||| +Theorem Without Proof +===============================||| + +---- MODULE Test ---- +THEOREM TRUE +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean)) +(double_line))) + +===============================||| +Named Theorem Without Proof +===============================||| + +---- MODULE Test ---- +PROPOSITION x == TRUE +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (identifier) (def_eq) (boolean)) +(double_line))) + +===============================||| +Obvious Proof +===============================||| + +---- MODULE Test ---- +LEMMA TRUE +OBVIOUS +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) (terminal_proof)) +(double_line))) + +===============================||| +Named Obvious Proof +===============================||| + +---- MODULE Test ---- +COROLLARY def == TRUE +PROOF OBVIOUS +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (identifier) (def_eq) (boolean) (terminal_proof)) +(double_line))) + +===============================||| +Omitted Proof +===============================||| + +---- MODULE Test ---- +THEOREM x == TRUE +PROOF OMITTED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (identifier) (def_eq) (boolean) (terminal_proof)) +(double_line))) + +===============================||| +Proof by Definition +===============================||| + +---- MODULE Test ---- +PROPOSITION TRUE +PROOF BY DEF > +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (terminal_proof (use_body + (use_body_def (infix_op_symbol (gt))) + )) + ) +(double_line))) + +===============================||| +Proof by Multiple Definitions +===============================||| + +---- MODULE Test ---- +LEMMA TRUE +PROOF BY ONLY + P, + MODULE Naturals, + Q, + MODULE Integers + DEFS + >, + R, + MODULE Reals, + = +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (terminal_proof (use_body + (use_body_expr + (identifier_ref) + (module_ref (identifier_ref)) + (identifier_ref) + (module_ref (identifier_ref)) + ) + (use_body_def + (infix_op_symbol (gt)) + (identifier_ref) + (module_ref (identifier_ref)) + (infix_op_symbol (eq)) + ) + )) + ) +(double_line))) + +===============================||| +Proof by QED +===============================||| + +---- MODULE Test ---- +COROLLARY TRUE +PROOF <1>a QED BY <1>a, <*>a +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (qed_step (proof_step_id (level) (name)) + (terminal_proof (use_body (use_body_expr + (proof_step_ref (level) (name)) + (proof_step_ref (level) (name)) + ))) + ) + ) + ) +(double_line))) + +===============================||| +Proof with Variety of Step Types +===============================||| + +---- MODULE Test ---- +THEOREM TRUE +<1>a..... op == 1 +<1>b..... DEFINE op2 == 2 +<1>c..... HAVE 3 +<1>d..... WITNESS 2, 3 +<1>e..... TAKE a, b, c +<1>f..... <1>a +<1>g..... SUFFICES 5 +<1>h..... CASE 6 +<1>i..... PICK a, b, c : 7 +<1>j..... HIDE 8 +<1>k..... USE 9 +<1>l..... INSTANCE M +<1>m..... QED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (definition_proof_step (operator_definition (identifier) (def_eq) (nat_number)))) + (proof_step (proof_step_id (level) (name)) (definition_proof_step (operator_definition (identifier) (def_eq) (nat_number)))) + (proof_step (proof_step_id (level) (name)) (have_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (witness_proof_step (nat_number) (nat_number))) + (proof_step (proof_step_id (level) (name)) (take_proof_step (identifier) (identifier) (identifier))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (proof_step_ref (level) (name)))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (case_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (pick_proof_step (identifier) (identifier) (identifier) (nat_number))) + (proof_step (proof_step_id (level) (name)) (use_or_hide (use_body (use_body_expr (nat_number))))) + (proof_step (proof_step_id (level) (name)) (use_or_hide (use_body (use_body_expr (nat_number))))) + (proof_step (proof_step_id (level) (name)) (instance (identifier_ref))) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + +===============================||| +Stepped Proof by Definition +===============================||| + +---- MODULE Test ---- +PROPOSITION P => Q +PROOF + <1> P + <1> Q + PROOF BY P + <1> QED +===================== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (bound_infix_op (identifier_ref) (implies) (identifier_ref)) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (identifier_ref))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (identifier_ref) + (terminal_proof (use_body (use_body_expr (identifier_ref)))) + )) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + +===============================||| +Proof with Star Steps +===============================||| + +---- MODULE Test ---- +LEMMA TRUE +<*> 1 +<0> 2 +<*> 3 +<0> 4 +<*> 5 +<0> QED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + +===============================||| +Proof with Plus Step +===============================||| + +---- MODULE Test ---- +COROLLARY TRUE +<+> 1 +<0> 2 +<*> 3 +<0> 4 +<*> 5 +<0> QED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + +===============================||| +Nested Proof +===============================||| + +---- MODULE Test ---- +THEOREM TRUE +PROOF +<*> 1 +<0> 2 + <+> 3 + <1> 4 + <*> QED +<0> 5 +<*> 6 +<0> QED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + +===============================||| +Nested Proof Off QED +===============================||| + +---- MODULE Test ---- +PROPOSITION TRUE +PROOF +<*> 1 + PROOF + <+> 2 + <1> QED + PROOF + <*> 3 + <1000> 4 + <*> QED + <2> QED +<0> QED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name)) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ))) + (qed_step (proof_step_id (level) (name))) + )) + ))) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + + +===============================||| +Proof with Nested Terminal Proof +===============================||| + +---- MODULE Test ---- +LEMMA TRUE +PROOF +<*> 1 + <+> 2 + <1> QED + PROOF BY P +<*> 3 + <+> 4 + <1> QED + OBVIOUS +<*> 5 + <+> 6 + <1> QED + PROOF OMITTED +<*> 7 +<0> QED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name)) (terminal_proof (use_body (use_body_expr (identifier_ref))))) + ))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name)) (terminal_proof)) + ))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name)) (terminal_proof)) + ))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + +===============================||| +Implicit Nested Proof Levels +===============================||| + +---- MODULE Test ---- +COROLLARY TRUE +<*> 1 + <+> 2 + <+> 3 + <+> 4 + <*> QED + <*> QED + <*> 5 + <+> 6 + <*> QED + <*> QED +<*> 7 +<*> QED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ))) + (qed_step (proof_step_id (level) (name))) + ))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ))) + (qed_step (proof_step_id (level) (name))) + ))) + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + +==============================||| +Proof Containing Jlist +==============================||| + +---- MODULE Test ---- +THEOREM TRUE +<*>a1a... + /\ 1 + /\ \/ 2 + <+>b2b... WITNESS + \/ 3 + \/ /\ 4, + /\ \/ 5 + /\ 6 + <*>c3c... QED BY + /\ 7 + /\ \/ 8, + \/ /\ 9 + \/ 10 +<*>d4d... QED BY + \/ 11 + \/ /\ 12, + /\ \/ 13 + /\ 14 +==== + +------------------------------||| + + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (disj_list (disj_item (bullet_disj) (nat_number)))) + ) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (witness_proof_step + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (conj_list (conj_item (bullet_conj) (nat_number)))) + ) + (conj_list + (conj_item (bullet_conj) (disj_list (disj_item (bullet_disj) (nat_number)))) + (conj_item (bullet_conj) (nat_number)) + ) + )) + (qed_step (proof_step_id (level) (name)) (terminal_proof (use_body (use_body_expr + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (disj_list (disj_item (bullet_disj) (nat_number)))) + ) + (disj_list + (disj_item (bullet_disj) (conj_list (conj_item (bullet_conj) (nat_number)))) + (disj_item (bullet_disj) (nat_number)) + ) + )))) + ) + )) + (qed_step (proof_step_id (level) (name)) (terminal_proof (use_body (use_body_expr + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (conj_list (conj_item (bullet_conj) (nat_number)))) + ) + (conj_list + (conj_item (bullet_conj) (disj_list (disj_item (bullet_disj) (nat_number)))) + (conj_item (bullet_conj) (nat_number)) + ) + )))) + )) +(double_line))) + diff --git a/test/parser/syntax_corpus/quantification.txt b/test/parser/syntax_corpus/quantification.txt new file mode 100644 index 00000000..468f200f --- /dev/null +++ b/test/parser/syntax_corpus/quantification.txt @@ -0,0 +1,157 @@ +==============================||| +Bounded Quantification +==============================||| + +---- MODULE Test ---- +op == \A x, y \in Nat, z \in Int, <> \in Real : FALSE +op == \E <> \in Nat, a, b \in Int : TRUE +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (bounded_quantification + quantifier: (forall) + bound: (quantifier_bound + intro: (identifier) intro: (identifier) + (set_in) + set: (nat_number_set) + ) + bound: (quantifier_bound + intro: (identifier) + (set_in) + set: (int_number_set) + ) + bound: (quantifier_bound + intro: (tuple_of_identifiers (langle_bracket) (identifier) (identifier) (identifier) (rangle_bracket)) + (set_in) + set: (real_number_set) + ) + expression: (boolean) + ) + ) + (operator_definition name: (identifier) (def_eq) + definition: (bounded_quantification + quantifier: (exists) + bound: (quantifier_bound + intro: (tuple_of_identifiers (langle_bracket) (identifier) (identifier) (rangle_bracket)) + (set_in) + set: (nat_number_set) + ) + bound: (quantifier_bound + intro: (identifier) intro: (identifier) + (set_in) + set: (int_number_set) + ) + expression: (boolean) + ) + ) +(double_line))) + +==============================||| +Unbounded Quantification +==============================||| + +---- MODULE Test ---- +op == \A x : TRUE +op == \E x, y : FALSE +op == \AA x, y, z : TRUE +op == \EE x, y, z, w : FALSE +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (unbounded_quantification + quantifier: (forall) + intro: (identifier) + expression: (boolean) + ) + ) + (operator_definition name: (identifier) (def_eq) + definition: (unbounded_quantification + quantifier: (exists) + intro: (identifier) + intro: (identifier) + expression: (boolean) + ) + ) + (operator_definition name: (identifier) (def_eq) + definition: (unbounded_quantification + quantifier: (temporal_forall) + intro: (identifier) + intro: (identifier) + intro: (identifier) + expression: (boolean) + ) + ) + (operator_definition name: (identifier) (def_eq) + definition: (unbounded_quantification + quantifier: (temporal_exists) + intro: (identifier) + intro: (identifier) + intro: (identifier) + intro: (identifier) + expression: (boolean) + ) + ) +(double_line))) + +==============================||| +Bounded CHOOSE +==============================||| + +---- MODULE Test ---- +op == CHOOSE x \in Nat : TRUE +op == CHOOSE <> \in S : FALSE +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (choose + intro: (identifier) + (set_in) + set: (nat_number_set) + expression: (boolean) + ) + ) + (operator_definition name: (identifier) (def_eq) + definition: (choose + intro: (tuple_of_identifiers (langle_bracket) (identifier) (identifier) (identifier) (rangle_bracket)) + (set_in) + set: (identifier_ref) + expression: (boolean) + ) + ) +(double_line))) + +==============================||| +Unbounded CHOOSE +==============================||| + +---- MODULE Test ---- +op == CHOOSE x : TRUE +op == CHOOSE <> : FALSE +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (choose + intro: (identifier) + expression: (boolean) + ) + ) + (operator_definition name: (identifier) (def_eq) + definition: (choose + intro: (tuple_of_identifiers (langle_bracket) (identifier) (identifier) (identifier) (rangle_bracket)) + expression: (boolean) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/records.txt b/test/parser/syntax_corpus/records.txt new file mode 100644 index 00000000..f36d35ce --- /dev/null +++ b/test/parser/syntax_corpus/records.txt @@ -0,0 +1,150 @@ +==============================||| +Record Literal +==============================||| + +---- MODULE Test ---- +op == [ + foo |-> 1, + bar |-> 2, + baz |-> 3 +] +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (record_literal + (identifier) (all_map_to) (nat_number) + (identifier) (all_map_to) (nat_number) + (identifier) (all_map_to) (nat_number) + ) + ) +(double_line))) + +==============================||| +Record Literal with JList +==============================||| + +---- MODULE Test ---- +op == [ + foo |-> + /\ 1 + /\ 2, + bar |-> + \/ 3 + \/ 4 +] +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (record_literal + (identifier) (all_map_to) (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + (identifier) (all_map_to) (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + ) +(double_line))) + +==============================||| +Set of Records +==============================||| + +---- MODULE Test ---- +op == [ + foo : Nat, + bar : Int, + baz : Real +] +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (set_of_records + (identifier) (nat_number_set) + (identifier) (int_number_set) + (identifier) (real_number_set) + ) + ) +(double_line))) + +==============================||| +Set of Records with JList +==============================||| + +---- MODULE Test ---- +op == [ + foo : + /\ 1 + /\ 2, + bar : + \/ 3 + \/ 4 +] +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (set_of_records + (identifier) (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + (identifier) (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + ) + ) +(double_line))) + +==============================||| +Record Value +==============================||| + +---- MODULE Test ---- +op == foo.bar +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (record_value (identifier_ref) (identifier_ref)) + ) +(double_line))) + +==============================||| +Record Value Inside Jlist +==============================||| + +---- MODULE Test ---- +op == + /\ 1 + /\ foo.bar + +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (record_value (identifier_ref) (identifier_ref))) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/recursive.txt b/test/parser/syntax_corpus/recursive.txt new file mode 100644 index 00000000..2f4f264d --- /dev/null +++ b/test/parser/syntax_corpus/recursive.txt @@ -0,0 +1,66 @@ +=============||| +Basic Recursive Declaration +=============||| + +---- MODULE Test ---- +RECURSIVE f(_) +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (recursive_declaration (operator_declaration (identifier) (placeholder))) +(double_line))) + +=============||| +Recursive Declaration Without Parameters +=============||| + +---- MODULE Test ---- +RECURSIVE f +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (recursive_declaration (identifier)) +(double_line))) + +=============||| +Multiple Recursive Declarations +=============||| + +---- MODULE Test ---- +RECURSIVE f(_), g(_) +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (recursive_declaration + (operator_declaration (identifier) (placeholder)) + (operator_declaration (identifier) (placeholder)) + ) +(double_line))) + +=============||| +Mixed Recursive Declarations +=============||| + +---- MODULE Test ---- +RECURSIVE f(_), g, h(_, _, _), _+_, -. _, _ ^+ +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (recursive_declaration + (operator_declaration (identifier) (placeholder)) + (identifier) + (operator_declaration (identifier) (placeholder) (placeholder) (placeholder)) + (operator_declaration (placeholder) (infix_op_symbol (plus)) (placeholder)) + (operator_declaration (prefix_op_symbol (negative)) (placeholder)) + (operator_declaration (placeholder) (postfix_op_symbol (sup_plus))) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/regression.txt b/test/parser/syntax_corpus/regression.txt new file mode 100644 index 00000000..789ae928 --- /dev/null +++ b/test/parser/syntax_corpus/regression.txt @@ -0,0 +1,79 @@ +=============||| +Operators with Colon Prefixes & Jlists (GH87) +=============||| + +---- MODULE Test ---- +op == + /\ A :> B + /\ A := B + /\ A ::= B + /\ A :: B + /\ A +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) + (bound_infix_op (identifier_ref) (map_to) (identifier_ref)) + ) + (conj_item (bullet_conj) + (bound_infix_op (identifier_ref) (assign) (identifier_ref)) + ) + (conj_item (bullet_conj) + (bound_infix_op (identifier_ref) (bnf_rule) (identifier_ref)) + ) + (conj_item (bullet_conj) + (label (identifier) (label_as) (identifier_ref)) + ) + (conj_item (bullet_conj) (identifier_ref)) + ) + ) +(double_line))) + +=============||| +Junct Tokens as Higher-Level Parameters (TSTLA#GH96) +=============||| + +---- MODULE Test ---- +op == op(/\, x, /\) +op == op(∧, x, ∧) +op == op(\/, x, \/) +op == op(∨, x, ∨) +==== + +--------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (bound_op name: (identifier_ref) + parameter: (infix_op_symbol (land)) + parameter: (identifier_ref) + parameter: (infix_op_symbol (land)) + ) + ) + (operator_definition name: (identifier) (def_eq) definition: + (bound_op name: (identifier_ref) + parameter: (infix_op_symbol (land)) + parameter: (identifier_ref) + parameter: (infix_op_symbol (land)) + ) + ) + (operator_definition name: (identifier) (def_eq) definition: + (bound_op name: (identifier_ref) + parameter: (infix_op_symbol (lor)) + parameter: (identifier_ref) + parameter: (infix_op_symbol (lor)) + ) + ) + (operator_definition name: (identifier) (def_eq) definition: + (bound_op name: (identifier_ref) + parameter: (infix_op_symbol (lor)) + parameter: (identifier_ref) + parameter: (infix_op_symbol (lor)) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/rejected_syntax/blank_file.txt b/test/parser/syntax_corpus/rejected_syntax/blank_file.txt new file mode 100644 index 00000000..246493c0 --- /dev/null +++ b/test/parser/syntax_corpus/rejected_syntax/blank_file.txt @@ -0,0 +1,6 @@ +=============||| +Blank File Parse Error +:error +=============||| +-------------||| + diff --git a/test/parser/syntax_corpus/sets.txt b/test/parser/syntax_corpus/sets.txt new file mode 100644 index 00000000..2297b57f --- /dev/null +++ b/test/parser/syntax_corpus/sets.txt @@ -0,0 +1,234 @@ +======================||| +Empty Set +======================||| + +---- MODULE Test ---- +op == { } +==== + +----------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (finite_set_literal) + ) +(double_line))) + +======================||| +Set Literal +======================||| + +---- MODULE Test ---- +op == { + x \in BOOLEAN, + y \in STRING, + TRUE, + FALSE, + ((1 + 2) * 3), + {1,2,3} +} +==== + +----------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (finite_set_literal + (bound_infix_op lhs: (identifier_ref) symbol: (in) rhs: (boolean_set)) + (bound_infix_op lhs: (identifier_ref) symbol: (in) rhs: (string_set)) + (boolean) + (boolean) + (parentheses + (bound_infix_op + lhs: (parentheses + (bound_infix_op lhs: (nat_number) symbol: (plus) rhs: (nat_number)) + ) symbol: (mul) + rhs: (nat_number) + ) + ) + (finite_set_literal (nat_number) (nat_number) (nat_number)) + ) + ) +(double_line))) + +======================||| +Set Literal with Jlist +======================||| + +---- MODULE Test ---- +op == { + /\ 1 + /\ 2 + } + /\ 3 +==== + +----------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (bound_infix_op + lhs: (finite_set_literal + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + symbol: (land) + rhs: (nat_number) + ) + ) +(double_line))) + +======================||| +Set Map +======================||| + +---- MODULE Test ---- +op == {f(x) : x \in Nat} +==== + +----------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (set_map + map: (bound_op name: (identifier_ref) parameter: (identifier_ref)) + generator: (quantifier_bound intro: (identifier) (set_in) set: (nat_number_set)) + ) + ) +(double_line))) + +======================||| +Set Map with Multiple Generators +======================||| + +---- MODULE Test ---- +op == {f(x, y, z) : x \in Int, y, z \in Real} +==== + +----------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (set_map + map: (bound_op name: (identifier_ref) parameter: (identifier_ref) parameter: (identifier_ref) parameter: (identifier_ref)) + generator: (quantifier_bound intro: (identifier) (set_in) set: (int_number_set)) + generator: (quantifier_bound intro: (identifier) intro: (identifier) (set_in) set: (real_number_set)) + ) + ) +(double_line))) + + +======================||| +Set Filter +======================||| + +---- MODULE Test ---- +op == {x \in Nat : P(x)} +==== + +----------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (set_filter + generator: (quantifier_bound intro: (identifier) (set_in) set: (nat_number_set)) + filter: (bound_op name: (identifier_ref) parameter: (identifier_ref)) + ) + ) +(double_line))) + +======================||| +Set Filter with Tuple +======================||| + +---- MODULE Test ---- +op == {<> \in Nat \X Int \X Real : P(x, y, z)} +==== + +----------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (set_filter + generator: (quantifier_bound + intro: (tuple_of_identifiers (langle_bracket) (identifier) (identifier) (identifier) (rangle_bracket)) + (set_in) + set: (bound_infix_op + lhs: (bound_infix_op + lhs: (nat_number_set) + symbol: (times) + rhs: (int_number_set) + ) + symbol: (times) + rhs: (real_number_set) + ) + ) + filter: (bound_op name: (identifier_ref) parameter: (identifier_ref) parameter: (identifier_ref) parameter: (identifier_ref)) + ) + ) +(double_line))) + +=====================||| +Set Filter Precedence +=====================||| + +---- MODULE Test ---- +op == {x \in S : x \in T} +==== + +---------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (set_filter + generator: (quantifier_bound + intro: (identifier) (set_in) set: (identifier_ref) + ) + filter: (bound_infix_op + lhs: (identifier_ref) symbol: (in) rhs: (identifier_ref) + ) + ) + ) +(double_line))) + +======================||| +Set Filter with Jlist +======================||| + +---- MODULE Test ---- +op == { + x \in + /\ A + /\ B + /\ C + : + /\ D + /\ E + /\ F +} +==== + +----------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (set_filter + (quantifier_bound + (identifier) (set_in) + (conj_list + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + ) + ) + (conj_list + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + ) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/step_expressions.txt b/test/parser/syntax_corpus/step_expressions.txt new file mode 100644 index 00000000..146cf333 --- /dev/null +++ b/test/parser/syntax_corpus/step_expressions.txt @@ -0,0 +1,77 @@ +=============||| +Step Expression Or Stuttering +=============||| + +---- MODULE Test ---- +op == [A]_<> +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (step_expr_or_stutter + (identifier_ref) + (tuple_literal (langle_bracket) (identifier_ref) (identifier_ref) (identifier_ref) (rangle_bracket)) + ) + ) +(double_line))) + +=============||| +Step Expression No Stuttering +=============||| + +---- MODULE Test ---- +op == <>_<> +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (step_expr_no_stutter + (langle_bracket) + (identifier_ref) + (rangle_bracket_sub) + (tuple_literal (langle_bracket) (identifier_ref) (identifier_ref) (identifier_ref) (rangle_bracket)) + ) + ) +(double_line))) + +=============||| +Step Expressions with Jlist +=============||| + +---- MODULE Test ---- + +op == [ + /\ 1 + /\ 2 + ]_x + +op == << + /\ 1 + /\ 2 + >>_x + +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (step_expr_or_stutter + (conj_list (conj_item (bullet_conj) (nat_number)) (conj_item (bullet_conj) (nat_number))) + (identifier_ref) + ) + ) + (operator_definition (identifier) (def_eq) + (step_expr_no_stutter + (langle_bracket) + (conj_list (conj_item (bullet_conj) (nat_number)) (conj_item (bullet_conj) (nat_number))) + (rangle_bracket_sub) + (identifier_ref) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/string.txt b/test/parser/syntax_corpus/string.txt new file mode 100644 index 00000000..1e60bec0 --- /dev/null +++ b/test/parser/syntax_corpus/string.txt @@ -0,0 +1,89 @@ +==================||| +Basic String +==================||| + +---- MODULE Test ---- +op == "Hello, world!" +==== + +------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) (string)) +(double_line))) + +==================||| +Escape Quote String +==================||| + +---- MODULE Test ---- +op == "The cow goes \"moo\", the chicken goes \"cluck cluck\"" +==== + +------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (string + (escape_char) + (escape_char) + (escape_char) + (escape_char) + ) + ) +(double_line))) + +==================||| +Escape Escape String +==================||| + +---- MODULE Test ---- +op == <<"/\\", "\\/">> +==== + +------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (tuple_literal (langle_bracket) + (string (escape_char)) + (string (escape_char)) + (rangle_bracket)) + ) +(double_line))) + +==================||| +String with block comment start +==================||| + +---- MODULE Test ---- +op == "(*" +==== + +------------------||| + +(source_file + (module + (header_line) + (identifier) + (header_line) + (operator_definition + (identifier) + (def_eq) + (string)) + (double_line))) + +==================||| +String Set +==================||| + +---- MODULE Test ---- +op == STRING +==== + +------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (string_set)) +(double_line))) + diff --git a/test/parser/syntax_corpus/subexpressions.txt b/test/parser/syntax_corpus/subexpressions.txt new file mode 100644 index 00000000..a7de2733 --- /dev/null +++ b/test/parser/syntax_corpus/subexpressions.txt @@ -0,0 +1,93 @@ +==============================||| +Basic Submodule Reference +==============================||| + +---- MODULE Test ---- +op == M!X!Y!Z +==== + +------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (prefixed_op + (subexpr_prefix + (subexpr_component (identifier_ref)) + (subexpr_component (identifier_ref)) + (subexpr_component (identifier_ref)) + ) + (identifier_ref) + ) + ) +(double_line))) + +==============================||| +Subexpression Tree Navigation +==============================||| + +---- MODULE Test ---- +tree_nav == op(a, b)!<>!3!(x, y)!:!@ +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (subexpression + (subexpr_prefix + (subexpr_component (bound_op name: (identifier_ref) parameter: (identifier_ref) parameter: (identifier_ref))) + (subexpr_tree_nav (langle_bracket)) + (subexpr_tree_nav (rangle_bracket)) + (subexpr_tree_nav (child_id)) + (subexpr_tree_nav (operator_args (identifier_ref) (identifier_ref))) + (subexpr_tree_nav (colon)) + ) + (subexpr_tree_nav (address)) + ) + ) +(double_line))) + +===============================||| +Proof Step ID Subexpression Tree Navigation +===============================||| + +---- MODULE Test ---- +COROLLARY TRUE +PROOF <1>a QED BY <1>a!<>!3!(x, y)!:!@, <*>a!<>!3!(x, y)!:!@ +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (theorem statement: (boolean) + proof: (non_terminal_proof + (qed_step (proof_step_id (level) (name)) + (terminal_proof (use_body (use_body_expr + (subexpression + (subexpr_prefix + (proof_step_ref (level) (name)) + (subexpr_tree_nav (langle_bracket)) + (subexpr_tree_nav (rangle_bracket)) + (subexpr_tree_nav (child_id)) + (subexpr_tree_nav (operator_args (identifier_ref) (identifier_ref))) + (subexpr_tree_nav (colon)) + ) + (subexpr_tree_nav (address)) + ) + (subexpression + (subexpr_prefix + (proof_step_ref (level) (name)) + (subexpr_tree_nav (langle_bracket)) + (subexpr_tree_nav (rangle_bracket)) + (subexpr_tree_nav (child_id)) + (subexpr_tree_nav (operator_args (identifier_ref) (identifier_ref))) + (subexpr_tree_nav (colon)) + ) + (subexpr_tree_nav (address)) + ) + ))) + ) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/unit.txt b/test/parser/syntax_corpus/unit.txt new file mode 100644 index 00000000..8029dfe0 --- /dev/null +++ b/test/parser/syntax_corpus/unit.txt @@ -0,0 +1,113 @@ +=============||| +VARIABLE Declaration +=============||| + +---- MODULE Test ---- +VARIABLE a, b, c +VARIABLES x, y, z +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (variable_declaration (identifier) (identifier) (identifier)) + (variable_declaration (identifier) (identifier) (identifier)) +(double_line))) + +=============||| +CONSTANT Declaration +=============||| + +---- MODULE Test ---- +CONSTANT x, y, z +CONSTANTS f(_, _), _+_, -._, _^+ +==== + +-------------||| + +(source_file (module (header_line) (identifier) (header_line) + (constant_declaration (identifier) (identifier) (identifier)) + (constant_declaration + (operator_declaration (identifier) (placeholder) (placeholder)) + (operator_declaration (placeholder) (infix_op_symbol (plus)) (placeholder)) + (operator_declaration (prefix_op_symbol (negative)) (placeholder)) + (operator_declaration (placeholder) (postfix_op_symbol (sup_plus))) + ) +(double_line))) + +=============||| +Basic Operator Definition +=============||| + +---- MODULE Test ---- +op == f(10) +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (bound_op name: (identifier_ref) parameter: (nat_number)) + ) +(double_line))) + +===============================||| +INSTANCE With Jlist Substitutions +===============================||| + +---- MODULE Test ---- +INSTANCE M WITH + A <- /\ 1, + B <- /\ 2, + C <- /\ \/ 3 + \/ 4, + D <- \/ 5 +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (instance (identifier_ref) + (substitution (identifier_ref) (gets) + (conj_list (conj_item (bullet_conj) (nat_number))) + ) + (substitution (identifier_ref) (gets) + (conj_list (conj_item (bullet_conj) (nat_number))) + ) + (substitution (identifier_ref) (gets) + (conj_list (conj_item (bullet_conj) + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + )) + ) + (substitution (identifier_ref) (gets) + (disj_list (disj_item (bullet_disj) (nat_number))) + ) + ) +(double_line))) + +===============================||| +INSTANCE With Operator Substitutions +===============================||| + +---- MODULE Test ---- +INSTANCE M WITH + A <- a, + SUBSET <- b, + * <- c, + ' <- d +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (instance (identifier_ref) + (substitution (identifier_ref) (gets) (identifier_ref)) + (substitution (prefix_op_symbol (powerset)) (gets) (identifier_ref)) + (substitution (infix_op_symbol (mul)) (gets) (identifier_ref)) + (substitution (postfix_op_symbol (prime)) (gets) (identifier_ref)) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/use_or_hide.txt b/test/parser/syntax_corpus/use_or_hide.txt new file mode 100644 index 00000000..1736a64f --- /dev/null +++ b/test/parser/syntax_corpus/use_or_hide.txt @@ -0,0 +1,40 @@ +=============||| +Use & Hide Declarations +=============||| + +---- MODULE Test ---- +USE x, MODULE M, 1 + 3 +HIDE DEFS MODULE M, -., *, ^+ +USE x, MODULE M DEF MODULE M, x +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (use_or_hide (use_body + (use_body_expr + (identifier_ref) + (module_ref (identifier_ref)) + (bound_infix_op lhs: (nat_number) symbol: (plus) rhs: (nat_number)) + ) + )) + (use_or_hide (use_body + (use_body_def + (module_ref (identifier_ref)) + (prefix_op_symbol (negative)) + (infix_op_symbol (mul)) + (postfix_op_symbol (sup_plus)) + ) + )) + (use_or_hide (use_body + (use_body_expr + (identifier_ref) + (module_ref (identifier_ref)) + ) + (use_body_def + (module_ref (identifier_ref)) + (identifier_ref) + ) + )) +(double_line))) + diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index f2c9c1a9..4c6c6356 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -1,4 +1,19 @@ +open In_channel;; +open List;; +open Str;; + let () = match Tlapm_lib.module_of_string "---- MODULE Test ---- x == 5 ====" with | None -> print_endline "Parse failed" - | Some mule -> print_endline mule.core.name.core \ No newline at end of file + | Some mule -> print_endline mule.core.name.core + +let () = + let test_file = open_in "syntax_corpus/modules.txt" in + try + let lines = input_lines test_file in + iter print_endline lines; + flush stdout; + close_in test_file + with e -> + close_in_noerr test_file; + raise e \ No newline at end of file From 76b0b248305e0a2497641a8774e8f213aa37f820 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Thu, 17 Oct 2024 18:18:11 -0400 Subject: [PATCH 03/28] Basic parsing of test file format Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/test_parser.ml | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index 4c6c6356..e462d8a8 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -1,19 +1,43 @@ open In_channel;; open List;; open Str;; +open String;; let () = match Tlapm_lib.module_of_string "---- MODULE Test ---- x == 5 ====" with | None -> print_endline "Parse failed" | Some mule -> print_endline mule.core.name.core + +let header_regex = regexp {|^===+||||} -let () = - let test_file = open_in "syntax_corpus/modules.txt" in +let separator_regex = regexp {|^---+||||} + +let parse_test_body input = + match split separator_regex input with + | input :: output :: [] -> (trim input, trim output) + | _ -> raise (Invalid_argument "Malformed test body") + +let rec parse_split_test_file input = + match input with + | [] -> [] + | test_name :: test_body :: ls -> + let (test_input, test_output) = parse_test_body test_body in + (trim test_name, test_input, test_output) :: (parse_split_test_file ls) + | _ -> raise (Invalid_argument "Malformed test file") + +let parse_test_file path = + let test_file = open_in path in try - let lines = input_lines test_file in - iter print_endline lines; - flush stdout; - close_in test_file + let text = input_all test_file in + close_in test_file; + parse_split_test_file (split header_regex text) with e -> close_in_noerr test_file; - raise e \ No newline at end of file + raise e + + +let () = + let tests = parse_test_file "syntax_corpus/modules.txt" in + let test_names = List.map (fun (a, _, _) -> a) tests in + List.iter print_endline test_names; + flush stdout; \ No newline at end of file From 88ff8ed684b002d2347aadbfda1a21d251f3c176 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Fri, 18 Oct 2024 20:02:55 -0400 Subject: [PATCH 04/28] More structured parsing of all test files Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/syntax_corpus/README.md | 11 ----- test/parser/test_parser.ml | 75 ++++++++++++++++++----------- 2 files changed, 47 insertions(+), 39 deletions(-) delete mode 100644 test/parser/syntax_corpus/README.md diff --git a/test/parser/syntax_corpus/README.md b/test/parser/syntax_corpus/README.md deleted file mode 100644 index b9c02e56..00000000 --- a/test/parser/syntax_corpus/README.md +++ /dev/null @@ -1,11 +0,0 @@ -This is a corpus of TLA⁺ syntax inputs along with their expected parse tree outputs. -The tests are only intended to exercise syntax parsing and are often invalid at the semantic level (referencing nonexistent variable names, for example). -The tests use the format developed by tree-sitter, which you can see [here](https://tree-sitter.github.io/tree-sitter/creating-parsers#command-test). -Syntax inputs which are intended to cause a parse failure are tagged with `:error` in the test case header. -Every TLA⁺ tool that parses the language should adapt this corpus to ensure parser conformance. -Currently, there are three existing tools that implement a TLA⁺ parser: -1. [SANY](https://github.com/tlaplus/tlaplus/tree/master/tlatools/org.lamport.tlatools/src/tla2sany), which has adapted these tests -2. [TLAPM](https://github.com/tlaplus/tlapm), which has not yet adapted these tests -3. [tree-sitter-tlaplus](https://github.com/tlaplus-community/tree-sitter-tlaplus), which has adapted these tests - -Translating a given tool's internal parse tree format to match the standardized format used by these tests is a lot of work, but ensures very thorough testing of the parser and exposes the ability to rapidly add regression tests to all parsers if a tricky parsing bug is uncovered in one of the tools. diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index e462d8a8..08688229 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -4,40 +4,59 @@ open Str;; open String;; let () = - match Tlapm_lib.module_of_string "---- MODULE Test ---- x == 5 ====" with - | None -> print_endline "Parse failed" - | Some mule -> print_endline mule.core.name.core - + match Tlapm_lib.module_of_string "---- MODULE Test ---- x == 5 ====" with + | None -> print_endline "Parse failed" + | Some mule -> print_endline mule.core.name.core + let header_regex = regexp {|^===+||||} let separator_regex = regexp {|^---+||||} -let parse_test_body input = - match split separator_regex input with - | input :: output :: [] -> (trim input, trim output) - | _ -> raise (Invalid_argument "Malformed test body") - -let rec parse_split_test_file input = - match input with - | [] -> [] - | test_name :: test_body :: ls -> - let (test_input, test_output) = parse_test_body test_body in - (trim test_name, test_input, test_output) :: (parse_split_test_file ls) - | _ -> raise (Invalid_argument "Malformed test file") +type syntax_test = { + file : string; + name : string; + input : string; + output : string; +} let parse_test_file path = - let test_file = open_in path in - try - let text = input_all test_file in - close_in test_file; - parse_split_test_file (split header_regex text) - with e -> - close_in_noerr test_file; - raise e + let test_file = open_in path in + try + let text = input_all test_file in + close_in test_file; + let rec parse_split_test_file input = + let parse_test_body input = + match split separator_regex input with + | input :: output :: [] -> (trim input, trim output) + | _ -> Invalid_argument "Test body lacks separator" |> raise + in match input with + | [] -> [] + | test_name :: test_body :: ls -> + let (test_input, test_output) = parse_test_body test_body in { + file = path; + name = trim test_name; + input = test_input; + output = test_output; + } :: (parse_split_test_file ls) + | _ -> Invalid_argument (Printf.sprintf "Test file %s contains extra header separators" path) |> raise + in split header_regex text |> parse_split_test_file + with e -> + close_in_noerr test_file; + raise e +let rec get_all_files_under path = + if Sys.is_directory path then + Sys.readdir path + |> Array.to_list + |> List.map (Filename.concat path) + |> List.map get_all_files_under + |> List.flatten + else [path] let () = - let tests = parse_test_file "syntax_corpus/modules.txt" in - let test_names = List.map (fun (a, _, _) -> a) tests in - List.iter print_endline test_names; - flush stdout; \ No newline at end of file + let corpus_files = get_all_files_under "syntax_corpus" in + let test_corpus = List.map parse_test_file corpus_files in + test_corpus + |> List.flatten + |> List.iter (fun r -> Printf.printf "%s\n%s\n%s\n%s\n" r.file r.name r.input r.output); + flush stdout; \ No newline at end of file From 5fc1074c2b28b6feb593b9d1c11470b282df9fa4 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Mon, 21 Oct 2024 13:10:26 -0400 Subject: [PATCH 05/28] Show syntax_test datastructure using ppx_deriving Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- Makefile | 2 +- test/parser/dune | 1 + test/parser/test_parser.ml | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c23f1454..3c028153 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ opam-deps-opt: opam install --yes eio_main lsp opam-deps-dev: - opam install --yes ocamlformat ocaml-lsp-server earlybird + opam install --yes ocamlformat ocaml-lsp-server earlybird ppx_deriving build: dune build diff --git a/test/parser/dune b/test/parser/dune index c9ef83fe..5b755e0b 100644 --- a/test/parser/dune +++ b/test/parser/dune @@ -3,4 +3,5 @@ (modes exe) (libraries tlapm_lib) (deps (glob_files_rec syntax_corpus/*)) + (preprocess (pps ppx_deriving.show)) ) diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index 08688229..32b53db8 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -17,7 +17,7 @@ type syntax_test = { name : string; input : string; output : string; -} +} [@@deriving show] let parse_test_file path = let test_file = open_in path in @@ -58,5 +58,6 @@ let () = let test_corpus = List.map parse_test_file corpus_files in test_corpus |> List.flatten - |> List.iter (fun r -> Printf.printf "%s\n%s\n%s\n%s\n" r.file r.name r.input r.output); + |> List.map show_syntax_test + |> List.iter print_endline; flush stdout; \ No newline at end of file From 878932599c58818b2c76297641c93ed80739fe09 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Mon, 21 Oct 2024 14:41:29 -0400 Subject: [PATCH 06/28] Parse test attributes Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/test_parser.ml | 67 +++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index 32b53db8..fadd6333 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -12,39 +12,68 @@ let header_regex = regexp {|^===+||||} let separator_regex = regexp {|^---+||||} +type test_attribute = + | Skip + | Error +[@@deriving show] + +let str_to_test_attribute (attr : string) : test_attribute = + match attr with + | ":skip" -> Skip + | ":error" -> Error + | _ -> Invalid_argument (Printf.sprintf "Invalid attribute %s" attr) |> raise + type syntax_test = { file : string; name : string; + attrs : test_attribute list; input : string; - output : string; + expect : string; } [@@deriving show] -let parse_test_file path = +let parse_test_header (header : string list) : string * (test_attribute list) = + let is_attr (line : string) : bool = length line > 0 && ':' == get line 0 in + let test_name = List.find (fun line -> line |> is_attr |> not) header in + let test_attrs = header |> List.filter is_attr |> List.map str_to_test_attribute in + (test_name, test_attrs) + +(** Given the body of a test as a string, split it into input and expected + output; raise an error if this is not possible. + @param path The path to the test file, for error reporting purposes. + @param test_name The test name, for error reporting purposes. + @param input The unparsed test body, as a string. + @return A two-tuple with first element input and second element output. + @raise Invalid_argument If body text lacks a separator. *) +let parse_test_body (path : string) (test_name : string) (input : string) : string * string = + match split separator_regex input with + | input :: output :: [] -> (trim input, trim output) + | _ -> Invalid_argument (Printf.sprintf "Test body for %s in file %s lacks separator" test_name path) |> raise + +let rec parse_split_test_file (path : string) (input : string list) : syntax_test list = + match input with + | [] -> [] + | test_header :: test_body :: ls -> + let (test_name, test_attrs) = test_header |> trim |> split_on_char '\n' |> parse_test_header in + let (test_input, test_output) = parse_test_body path test_name test_body in { + file = path; + name = test_name; + attrs = test_attrs; + input = test_input; + expect = test_output; + } :: (parse_split_test_file path ls) + | _ -> Invalid_argument (Printf.sprintf "Test file %s contains extra header separators" path) |> raise + +let parse_test_file (path : string) : syntax_test list = let test_file = open_in path in try let text = input_all test_file in close_in test_file; - let rec parse_split_test_file input = - let parse_test_body input = - match split separator_regex input with - | input :: output :: [] -> (trim input, trim output) - | _ -> Invalid_argument "Test body lacks separator" |> raise - in match input with - | [] -> [] - | test_name :: test_body :: ls -> - let (test_input, test_output) = parse_test_body test_body in { - file = path; - name = trim test_name; - input = test_input; - output = test_output; - } :: (parse_split_test_file ls) - | _ -> Invalid_argument (Printf.sprintf "Test file %s contains extra header separators" path) |> raise - in split header_regex text |> parse_split_test_file + split header_regex text |> parse_split_test_file path with e -> close_in_noerr test_file; raise e -let rec get_all_files_under path = +let rec get_all_files_under (path : string) : string list = if Sys.is_directory path then Sys.readdir path |> Array.to_list From e44b1c2aa2b05c1fac82d17a01a2e396766c1a9f Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Mon, 21 Oct 2024 14:48:10 -0400 Subject: [PATCH 07/28] Split corpus file parsing logic into separate file Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/syntax_corpus_file_parser.ml | 81 ++++++++++++++++++++++ test/parser/test_parser.ml | 85 +----------------------- 2 files changed, 84 insertions(+), 82 deletions(-) create mode 100644 test/parser/syntax_corpus_file_parser.ml diff --git a/test/parser/syntax_corpus_file_parser.ml b/test/parser/syntax_corpus_file_parser.ml new file mode 100644 index 00000000..3e7c1abb --- /dev/null +++ b/test/parser/syntax_corpus_file_parser.ml @@ -0,0 +1,81 @@ +open In_channel;; +open List;; +open Str;; +open String;; + +let header_regex = regexp {|^===+||||} + +let separator_regex = regexp {|^---+||||} + +type test_attribute = + | Skip + | Error +[@@deriving show] + +let str_to_test_attribute (attr : string) : test_attribute = + match attr with + | ":skip" -> Skip + | ":error" -> Error + | _ -> Invalid_argument (Printf.sprintf "Invalid attribute %s" attr) |> raise + +type syntax_test = { + file : string; + name : string; + attrs : test_attribute list; + input : string; + expect : string; +} [@@deriving show] + +let parse_test_header (header : string list) : string * (test_attribute list) = + let is_attr (line : string) : bool = length line > 0 && ':' == get line 0 in + let test_name = List.find (fun line -> line |> is_attr |> not) header in + let test_attrs = header |> List.filter is_attr |> List.map str_to_test_attribute in + (test_name, test_attrs) + +(** Given the body of a test as a string, split it into input and expected + output; raise an error if this is not possible. + @param path The path to the test file, for error reporting purposes. + @param test_name The test name, for error reporting purposes. + @param input The unparsed test body, as a string. + @return A two-tuple with first element input and second element output. + @raise Invalid_argument If body text lacks a separator. *) +let parse_test_body (path : string) (test_name : string) (input : string) : string * string = + match split separator_regex input with + | input :: output :: [] -> (trim input, trim output) + | _ -> Invalid_argument (Printf.sprintf "Test body for %s in file %s lacks separator" test_name path) |> raise + +let rec parse_split_test_file (path : string) (input : string list) : syntax_test list = + match input with + | [] -> [] + | test_header :: test_body :: ls -> + let (test_name, test_attrs) = test_header |> trim |> split_on_char '\n' |> parse_test_header in + let (test_input, test_output) = parse_test_body path test_name test_body in { + file = path; + name = test_name; + attrs = test_attrs; + input = test_input; + expect = test_output; + } :: (parse_split_test_file path ls) + | _ -> Invalid_argument (Printf.sprintf "Test file %s contains extra header separators" path) |> raise + +let parse_test_file (path : string) : syntax_test list = + let test_file = open_in path in + try + let text = input_all test_file in + close_in test_file; + split header_regex text |> parse_split_test_file path + with e -> + close_in_noerr test_file; + raise e + +let rec get_all_files_under (path : string) : string list = + if Sys.is_directory path then + Sys.readdir path + |> Array.to_list + |> List.map (Filename.concat path) + |> List.map get_all_files_under + |> List.flatten + else [path] + +let get_all_tests_under (path : string) : syntax_test list = + path |> get_all_files_under |> List.map parse_test_file |> List.flatten \ No newline at end of file diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index fadd6333..6bfa6158 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -1,92 +1,13 @@ -open In_channel;; -open List;; -open Str;; -open String;; +open Syntax_corpus_file_parser;; let () = match Tlapm_lib.module_of_string "---- MODULE Test ---- x == 5 ====" with | None -> print_endline "Parse failed" | Some mule -> print_endline mule.core.name.core - -let header_regex = regexp {|^===+||||} - -let separator_regex = regexp {|^---+||||} - -type test_attribute = - | Skip - | Error -[@@deriving show] - -let str_to_test_attribute (attr : string) : test_attribute = - match attr with - | ":skip" -> Skip - | ":error" -> Error - | _ -> Invalid_argument (Printf.sprintf "Invalid attribute %s" attr) |> raise - -type syntax_test = { - file : string; - name : string; - attrs : test_attribute list; - input : string; - expect : string; -} [@@deriving show] - -let parse_test_header (header : string list) : string * (test_attribute list) = - let is_attr (line : string) : bool = length line > 0 && ':' == get line 0 in - let test_name = List.find (fun line -> line |> is_attr |> not) header in - let test_attrs = header |> List.filter is_attr |> List.map str_to_test_attribute in - (test_name, test_attrs) - -(** Given the body of a test as a string, split it into input and expected - output; raise an error if this is not possible. - @param path The path to the test file, for error reporting purposes. - @param test_name The test name, for error reporting purposes. - @param input The unparsed test body, as a string. - @return A two-tuple with first element input and second element output. - @raise Invalid_argument If body text lacks a separator. *) -let parse_test_body (path : string) (test_name : string) (input : string) : string * string = - match split separator_regex input with - | input :: output :: [] -> (trim input, trim output) - | _ -> Invalid_argument (Printf.sprintf "Test body for %s in file %s lacks separator" test_name path) |> raise - -let rec parse_split_test_file (path : string) (input : string list) : syntax_test list = - match input with - | [] -> [] - | test_header :: test_body :: ls -> - let (test_name, test_attrs) = test_header |> trim |> split_on_char '\n' |> parse_test_header in - let (test_input, test_output) = parse_test_body path test_name test_body in { - file = path; - name = test_name; - attrs = test_attrs; - input = test_input; - expect = test_output; - } :: (parse_split_test_file path ls) - | _ -> Invalid_argument (Printf.sprintf "Test file %s contains extra header separators" path) |> raise - -let parse_test_file (path : string) : syntax_test list = - let test_file = open_in path in - try - let text = input_all test_file in - close_in test_file; - split header_regex text |> parse_split_test_file path - with e -> - close_in_noerr test_file; - raise e - -let rec get_all_files_under (path : string) : string list = - if Sys.is_directory path then - Sys.readdir path - |> Array.to_list - |> List.map (Filename.concat path) - |> List.map get_all_files_under - |> List.flatten - else [path] let () = - let corpus_files = get_all_files_under "syntax_corpus" in - let test_corpus = List.map parse_test_file corpus_files in - test_corpus - |> List.flatten + "syntax_corpus" + |> get_all_tests_under |> List.map show_syntax_test |> List.iter print_endline; flush stdout; \ No newline at end of file From cb43c6a08c32c3461723c7d5c892328c652911d3 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Mon, 21 Oct 2024 15:20:25 -0400 Subject: [PATCH 08/28] Added documentation to syntax corpus file parser Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/syntax_corpus_file_parser.ml | 45 +++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/test/parser/syntax_corpus_file_parser.ml b/test/parser/syntax_corpus_file_parser.ml index 3e7c1abb..8baef39f 100644 --- a/test/parser/syntax_corpus_file_parser.ml +++ b/test/parser/syntax_corpus_file_parser.ml @@ -1,23 +1,38 @@ +(** This file contains functionality for parsing syntax test corpus files + into a form for consumption by unit tests. The file format was created + by tree-sitter; see: + https://tree-sitter.github.io/tree-sitter/creating-parsers#command-test +*) + open In_channel;; open List;; open Str;; open String;; +(** A regex for finding test header delimiters. *) let header_regex = regexp {|^===+||||} +(** A regex for finding test body separators. *) let separator_regex = regexp {|^---+||||} +(** Test attributes for controlling test execution. *) type test_attribute = | Skip | Error [@@deriving show] +(** Given a string attribute tag, resolve it to an enumerated type. + @param attr The unparsed attribute tag. + @return A {!type:test_attribute} instance corresponding to the tag. + @raise Invalid_argument If tag does not correspond to valid attribute. +*) let str_to_test_attribute (attr : string) : test_attribute = match attr with | ":skip" -> Skip | ":error" -> Error | _ -> Invalid_argument (Printf.sprintf "Invalid attribute %s" attr) |> raise +(** All information necessary to run a single syntax test. *) type syntax_test = { file : string; name : string; @@ -26,6 +41,11 @@ type syntax_test = { expect : string; } [@@deriving show] +(** Given a test header as a list of lines, decompose & parse it into the + test name and a list of test attributes. + @param header A test header split into a list of lines. + @return A tuple of (test_name, test_attributes). +*) let parse_test_header (header : string list) : string * (test_attribute list) = let is_attr (line : string) : bool = length line > 0 && ':' == get line 0 in let test_name = List.find (fun line -> line |> is_attr |> not) header in @@ -38,12 +58,21 @@ let parse_test_header (header : string list) : string * (test_attribute list) = @param test_name The test name, for error reporting purposes. @param input The unparsed test body, as a string. @return A two-tuple with first element input and second element output. - @raise Invalid_argument If body text lacks a separator. *) + @raise Invalid_argument If body text lacks a separator. +*) let parse_test_body (path : string) (test_name : string) (input : string) : string * string = match split separator_regex input with | input :: output :: [] -> (trim input, trim output) | _ -> Invalid_argument (Printf.sprintf "Test body for %s in file %s lacks separator" test_name path) |> raise +(** Given a test file which has been split using the {!val:header_regex}, + parse the various sections to construct a list of information about the + tests that it contains. + @param path The test file path, for error reporting purposes. + @param input The test file contents, split on header tokens. + @return A list of syntax tests. + @raise Invalid_argument If there are too many or too few sections. +*) let rec parse_split_test_file (path : string) (input : string list) : syntax_test list = match input with | [] -> [] @@ -58,6 +87,10 @@ let rec parse_split_test_file (path : string) (input : string list) : syntax_tes } :: (parse_split_test_file path ls) | _ -> Invalid_argument (Printf.sprintf "Test file %s contains extra header separators" path) |> raise +(** Given a path to a syntax test corpus file, parse all tests in that file. + @param path The path to the syntax test corpus file. + @return A list of tests contained in the file. +*) let parse_test_file (path : string) : syntax_test list = let test_file = open_in path in try @@ -68,6 +101,11 @@ let parse_test_file (path : string) : syntax_test list = close_in_noerr test_file; raise e +(** Given the path to a directory, recursively find all files located within + that directory. + @param path The path to a directory to search under. + @return A list of paths to files under the directory. +*) let rec get_all_files_under (path : string) : string list = if Sys.is_directory path then Sys.readdir path @@ -77,5 +115,10 @@ let rec get_all_files_under (path : string) : string list = |> List.flatten else [path] +(** Given the path to a directory, return a list of all syntax tests in all + files under that directory. + @param path The path to a directory to search under. + @return A list of syntax tests from the files under the directory. +*) let get_all_tests_under (path : string) : syntax_test list = path |> get_all_files_under |> List.map parse_test_file |> List.flatten \ No newline at end of file From d6a7a84ba9fc02968168a3a7f1916480914a3e21 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Mon, 21 Oct 2024 17:20:29 -0400 Subject: [PATCH 09/28] Parse expected test output using sexplib Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/dune | 2 +- test/parser/syntax_corpus_file_parser.ml | 47 ++++++++++++++++++------ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/test/parser/dune b/test/parser/dune index 5b755e0b..5a1c994e 100644 --- a/test/parser/dune +++ b/test/parser/dune @@ -1,7 +1,7 @@ (test (name test_parser) (modes exe) - (libraries tlapm_lib) + (libraries tlapm_lib sexplib) (deps (glob_files_rec syntax_corpus/*)) (preprocess (pps ppx_deriving.show)) ) diff --git a/test/parser/syntax_corpus_file_parser.ml b/test/parser/syntax_corpus_file_parser.ml index 8baef39f..b6da0fb2 100644 --- a/test/parser/syntax_corpus_file_parser.ml +++ b/test/parser/syntax_corpus_file_parser.ml @@ -8,6 +8,7 @@ open In_channel;; open List;; open Str;; open String;; +open Sexplib;; (** A regex for finding test header delimiters. *) let header_regex = regexp {|^===+||||} @@ -32,15 +33,32 @@ let str_to_test_attribute (attr : string) : test_attribute = | ":error" -> Error | _ -> Invalid_argument (Printf.sprintf "Invalid attribute %s" attr) |> raise -(** All information necessary to run a single syntax test. *) -type syntax_test = { +(** Metadata about a syntax test. *) +type syntax_test_info = { file : string; name : string; - attrs : test_attribute list; + skip : bool; +} [@@deriving show] + +(** A syntax test expected to produce an error. *) +type error_syntax_test = { + info : syntax_test_info; + input : string; +} [@@deriving show] + +(** A syntax test expected to produce a specific parse tree. *) +type expected_syntax_test = { + info : syntax_test_info; input : string; - expect : string; + expect : Sexp.t; } [@@deriving show] +(** All information necessary to run a single syntax test. *) +type syntax_test = + | Expected_test of expected_syntax_test + | Error_test of error_syntax_test +[@@deriving show] + (** Given a test header as a list of lines, decompose & parse it into the test name and a list of test attributes. @param header A test header split into a list of lines. @@ -78,13 +96,20 @@ let rec parse_split_test_file (path : string) (input : string list) : syntax_tes | [] -> [] | test_header :: test_body :: ls -> let (test_name, test_attrs) = test_header |> trim |> split_on_char '\n' |> parse_test_header in - let (test_input, test_output) = parse_test_body path test_name test_body in { - file = path; - name = test_name; - attrs = test_attrs; - input = test_input; - expect = test_output; - } :: (parse_split_test_file path ls) + let (test_input, test_output) = parse_test_body path test_name test_body in + let test_info = { file = path; name = test_name; skip = List.mem Skip test_attrs; } in + let test = + if List.mem Error test_attrs + then Error_test { + info = test_info; + input = test_input; + } + else Expected_test { + info = test_info; + input = test_input; + expect = Sexp.of_string test_output + } + in test :: (parse_split_test_file path ls) | _ -> Invalid_argument (Printf.sprintf "Test file %s contains extra header separators" path) |> raise (** Given a path to a syntax test corpus file, parse all tests in that file. From e0ea1c470899b7ea21dd2b17cb7c9459d8140ad8 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Mon, 21 Oct 2024 17:56:23 -0400 Subject: [PATCH 10/28] Send corpus tests into parser Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/syntax_corpus_file_parser.ml | 25 ++++++++++++++---------- test/parser/test_parser.ml | 16 ++++++++++++--- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/test/parser/syntax_corpus_file_parser.ml b/test/parser/syntax_corpus_file_parser.ml index b6da0fb2..cc0c7bc1 100644 --- a/test/parser/syntax_corpus_file_parser.ml +++ b/test/parser/syntax_corpus_file_parser.ml @@ -37,28 +37,32 @@ let str_to_test_attribute (attr : string) : test_attribute = type syntax_test_info = { file : string; name : string; - skip : bool; } [@@deriving show] (** A syntax test expected to produce an error. *) type error_syntax_test = { - info : syntax_test_info; input : string; } [@@deriving show] (** A syntax test expected to produce a specific parse tree. *) type expected_syntax_test = { - info : syntax_test_info; input : string; expect : Sexp.t; } [@@deriving show] -(** All information necessary to run a single syntax test. *) -type syntax_test = +(** Enumeration of syntax test variants. *) +type syntax_test_variant = | Expected_test of expected_syntax_test | Error_test of error_syntax_test [@@deriving show] +(** All information necessary to run a single syntax test. *) +type syntax_test = { + info : syntax_test_info; + skip : bool; + test : syntax_test_variant; +} [@@deriving show] + (** Given a test header as a list of lines, decompose & parse it into the test name and a list of test attributes. @param header A test header split into a list of lines. @@ -97,19 +101,20 @@ let rec parse_split_test_file (path : string) (input : string list) : syntax_tes | test_header :: test_body :: ls -> let (test_name, test_attrs) = test_header |> trim |> split_on_char '\n' |> parse_test_header in let (test_input, test_output) = parse_test_body path test_name test_body in - let test_info = { file = path; name = test_name; skip = List.mem Skip test_attrs; } in - let test = + let test_variant = if List.mem Error test_attrs then Error_test { - info = test_info; input = test_input; } else Expected_test { - info = test_info; input = test_input; expect = Sexp.of_string test_output } - in test :: (parse_split_test_file path ls) + in { + info = { file = path; name = test_name; }; + skip = List.mem Skip test_attrs; + test = test_variant; + } :: (parse_split_test_file path ls) | _ -> Invalid_argument (Printf.sprintf "Test file %s contains extra header separators" path) |> raise (** Given a path to a syntax test corpus file, parse all tests in that file. diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index 6bfa6158..a6e09487 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -8,6 +8,16 @@ let () = let () = "syntax_corpus" |> get_all_tests_under - |> List.map show_syntax_test - |> List.iter print_endline; - flush stdout; \ No newline at end of file + |> List.iter ( + fun test -> + if test.skip then print_endline (show_syntax_test_info test.info) else + match test.test with + | Error_test test -> ( + match Tlapm_lib.module_of_string test.input with + | None -> print_endline "Successful failure" + | Some _ -> print_endline "Failing success") + | Expected_test test -> ( + match Tlapm_lib.module_of_string test.input with + | None -> print_endline "Successful success" + | Some _ -> print_endline "Failing failure") + ) \ No newline at end of file From 5be306b20e2f8bb0d078cd8c75efcaeb697bbaf7 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Mon, 21 Oct 2024 20:12:32 -0400 Subject: [PATCH 11/28] Update test corpus, print failures Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/syntax_corpus/assume.txt | 36 +++++++++++++ test/parser/syntax_corpus/functions.txt | 13 +++++ test/parser/syntax_corpus/jlist.txt | 15 ++++++ test/parser/syntax_corpus/labels.txt | 30 +++++++++++ test/parser/syntax_corpus/modules.txt | 21 ++++++++ test/parser/syntax_corpus/proofs.txt | 16 ++++++ test/parser/syntax_corpus/records.txt | 65 ++++++++++++++++++++++++ test/parser/syntax_corpus/string.txt | 23 +++++++++ test/parser/syntax_corpus_file_parser.ml | 7 +-- test/parser/test_parser.ml | 21 +++++--- 10 files changed, 236 insertions(+), 11 deletions(-) create mode 100644 test/parser/syntax_corpus/assume.txt diff --git a/test/parser/syntax_corpus/assume.txt b/test/parser/syntax_corpus/assume.txt new file mode 100644 index 00000000..ced0775b --- /dev/null +++ b/test/parser/syntax_corpus/assume.txt @@ -0,0 +1,36 @@ +===============================||| +Basic Module Assumptions +===============================||| + +---- MODULE Test ---- +ASSUME TRUE +ASSUMPTION TRUE +AXIOM TRUE +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (assumption (boolean)) + (assumption (boolean)) + (assumption (boolean)) +(double_line))) + +===============================||| +Named Module Assumptions +===============================||| + +---- MODULE Test ---- +ASSUME a1 == TRUE +ASSUMPTION a2 == TRUE +AXIOM a3 == TRUE +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (assumption name: (identifier) (def_eq) (boolean)) + (assumption name: (identifier) (def_eq) (boolean)) + (assumption name: (identifier) (def_eq) (boolean)) +(double_line))) + diff --git a/test/parser/syntax_corpus/functions.txt b/test/parser/syntax_corpus/functions.txt index 7981e4bf..785189ce 100644 --- a/test/parser/syntax_corpus/functions.txt +++ b/test/parser/syntax_corpus/functions.txt @@ -6,6 +6,7 @@ Function Definition f[x \in Nat] == x f[x, y \in Nat] == x f[x, y \in Nat, z \in Real] == x +f[x \in [Nat -> (Nat)]] == x ==== -------------------------------||| @@ -48,6 +49,18 @@ f[x, y \in Nat, z \in Real] == x (def_eq) definition: (identifier_ref) ) + (function_definition + name: (identifier) + (quantifier_bound + intro: (identifier) + (set_in) + set: (set_of_functions + (nat_number_set) (maps_to) (parentheses (nat_number_set)) + ) + ) + (def_eq) + definition: (identifier_ref) + ) (double_line))) ===============================||| diff --git a/test/parser/syntax_corpus/jlist.txt b/test/parser/syntax_corpus/jlist.txt index e86502c7..18dfa258 100644 --- a/test/parser/syntax_corpus/jlist.txt +++ b/test/parser/syntax_corpus/jlist.txt @@ -170,3 +170,18 @@ disj == ) (double_line))) +=============||| +Invalid parentheses use in jlist +:error +=============||| + +---- MODULE Test ---- +op == + /\ 1 + /\ (2 +) + /\ 3 +==== + +-------------||| + diff --git a/test/parser/syntax_corpus/labels.txt b/test/parser/syntax_corpus/labels.txt index 4826f717..43df6cc6 100644 --- a/test/parser/syntax_corpus/labels.txt +++ b/test/parser/syntax_corpus/labels.txt @@ -38,3 +38,33 @@ op == \A a, b \in Nat : lbl(a, b) :: P(a, b) ) (double_line))) +=============||| +Label not interfering with precedence +=============||| + +---- MODULE Test ---- +op == a + lab :: b * c +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (bound_infix_op lhs: (identifier_ref) symbol: (plus) rhs: + (label name: (identifier) (label_as) expression: + (bound_infix_op lhs: (identifier_ref) symbol: (mul) rhs: (identifier_ref)) + ) + ) + ) +(double_line))) + +=============||| +Label interfering with precedence +:error +=============||| + +---- MODULE Test ---- +op == a * lab :: b + c +==== + +-------------||| diff --git a/test/parser/syntax_corpus/modules.txt b/test/parser/syntax_corpus/modules.txt index 74008724..0f41a306 100644 --- a/test/parser/syntax_corpus/modules.txt +++ b/test/parser/syntax_corpus/modules.txt @@ -62,3 +62,24 @@ Multiple Nested modules (double_line)) ) +=============||| +Blank File Parse Error +:error +=============||| +-------------||| + +=============||| +Missing Module Terminator +:error +=============||| +---- MODULE Test ---- +-------------||| + +=============||| +Terminating Open Parentheses +:error +=============||| +---- MODULE Test ---- +f[x \in Nat] == ( +-------------||| + diff --git a/test/parser/syntax_corpus/proofs.txt b/test/parser/syntax_corpus/proofs.txt index 2163b1d9..f10bf4c2 100644 --- a/test/parser/syntax_corpus/proofs.txt +++ b/test/parser/syntax_corpus/proofs.txt @@ -153,6 +153,22 @@ PROOF <1>a QED BY <1>a, <*>a ) (double_line))) +===============================||| +Extra QED +:error +===============================||| + +---- MODULE Test ---- +THEOREM x == TRUE +<*> P + <+> Q + <*> QED + <*> QED +<*> QED +==== + +-------------------------------||| + ===============================||| Proof with Variety of Step Types ===============================||| diff --git a/test/parser/syntax_corpus/records.txt b/test/parser/syntax_corpus/records.txt index f36d35ce..f61a4cd9 100644 --- a/test/parser/syntax_corpus/records.txt +++ b/test/parser/syntax_corpus/records.txt @@ -22,6 +22,38 @@ op == [ ) (double_line))) +==============================||| +Nested Record Literal +==============================||| + +---- MODULE Test ---- +op == [ + foo |-> [ + foo |-> 1, + bar |-> 2, + baz |-> 3 + ], + bar |-> 2, + baz |-> 3 +] +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (record_literal + (identifier) (all_map_to) (record_literal + (identifier) (all_map_to) (nat_number) + (identifier) (all_map_to) (nat_number) + (identifier) (all_map_to) (nat_number) + ) + (identifier) (all_map_to) (nat_number) + (identifier) (all_map_to) (nat_number) + ) + ) +(double_line))) + ==============================||| Record Literal with JList ==============================||| @@ -78,6 +110,39 @@ op == [ ) (double_line))) +==============================||| +Nested Set of Records +==============================||| + +---- MODULE Test ---- +op == [ + foo : [ + foo : Nat, + bar : Int, + baz : Real + ], + bar : Int, + baz : Real +] +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (set_of_records + (identifier) (set_of_records + (identifier) (nat_number_set) + (identifier) (int_number_set) + (identifier) (real_number_set) + ) + (identifier) (int_number_set) + (identifier) (real_number_set) + ) + ) +(double_line))) + + ==============================||| Set of Records with JList ==============================||| diff --git a/test/parser/syntax_corpus/string.txt b/test/parser/syntax_corpus/string.txt index 1e60bec0..2adf8670 100644 --- a/test/parser/syntax_corpus/string.txt +++ b/test/parser/syntax_corpus/string.txt @@ -87,3 +87,26 @@ op == STRING (operator_definition name: (identifier) (def_eq) definition: (string_set)) (double_line))) +==================||| +String with supported escape chars +==================||| + +---- MODULE Test ---- +op == "\\ \n \r \f \t \"" +==== + +------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (string + (escape_char) + (escape_char) + (escape_char) + (escape_char) + (escape_char) + (escape_char) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus_file_parser.ml b/test/parser/syntax_corpus_file_parser.ml index cc0c7bc1..5c52008c 100644 --- a/test/parser/syntax_corpus_file_parser.ml +++ b/test/parser/syntax_corpus_file_parser.ml @@ -6,6 +6,7 @@ open In_channel;; open List;; +open Printf;; open Str;; open String;; open Sexplib;; @@ -31,7 +32,7 @@ let str_to_test_attribute (attr : string) : test_attribute = match attr with | ":skip" -> Skip | ":error" -> Error - | _ -> Invalid_argument (Printf.sprintf "Invalid attribute %s" attr) |> raise + | _ -> Invalid_argument (sprintf "Invalid attribute %s" attr) |> raise (** Metadata about a syntax test. *) type syntax_test_info = { @@ -85,7 +86,7 @@ let parse_test_header (header : string list) : string * (test_attribute list) = let parse_test_body (path : string) (test_name : string) (input : string) : string * string = match split separator_regex input with | input :: output :: [] -> (trim input, trim output) - | _ -> Invalid_argument (Printf.sprintf "Test body for %s in file %s lacks separator" test_name path) |> raise + | _ -> Invalid_argument (sprintf "Test body for %s in file %s lacks separator" test_name path) |> raise (** Given a test file which has been split using the {!val:header_regex}, parse the various sections to construct a list of information about the @@ -115,7 +116,7 @@ let rec parse_split_test_file (path : string) (input : string list) : syntax_tes skip = List.mem Skip test_attrs; test = test_variant; } :: (parse_split_test_file path ls) - | _ -> Invalid_argument (Printf.sprintf "Test file %s contains extra header separators" path) |> raise + | _ -> Invalid_argument (sprintf "Test file %s contains extra header separators" path) |> raise (** Given a path to a syntax test corpus file, parse all tests in that file. @param path The path to the syntax test corpus file. diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index a6e09487..3546b9bf 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -1,10 +1,15 @@ open Syntax_corpus_file_parser;; +open Printf;; let () = match Tlapm_lib.module_of_string "---- MODULE Test ---- x == 5 ====" with | None -> print_endline "Parse failed" | Some mule -> print_endline mule.core.name.core +let parse (input : string) : Tlapm_lib__M_t.mule option = + try Tlapm_lib.module_of_string input + with _ -> None + let () = "syntax_corpus" |> get_all_tests_under @@ -12,12 +17,12 @@ let () = fun test -> if test.skip then print_endline (show_syntax_test_info test.info) else match test.test with - | Error_test test -> ( - match Tlapm_lib.module_of_string test.input with - | None -> print_endline "Successful failure" - | Some _ -> print_endline "Failing success") - | Expected_test test -> ( - match Tlapm_lib.module_of_string test.input with - | None -> print_endline "Successful success" - | Some _ -> print_endline "Failing failure") + | Error_test error_test -> ( + match parse error_test.input with + | None -> (*print_endline (sprintf "SUCCESS [ error] %s: %s" test.info.file test.info.name)*) () + | Some _ -> print_endline (sprintf "FAILURE [no error] %s: %s" test.info.file test.info.name); flush stdout) + | Expected_test expected_test -> ( + match parse expected_test.input with + | None -> print_endline (sprintf "FAILURE [ error] %s: %s" test.info.file test.info.name); flush stdout + | Some _ -> (*print_endline (sprintf "SUCCESS [no error] %s: %s" test.info.file test.info.name))*) ()) ) \ No newline at end of file From 3b47b05acf6e60c0f05a14d17cfca10391a8399b Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Tue, 22 Oct 2024 10:03:53 -0400 Subject: [PATCH 12/28] Accumulate test run summary Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/syntax_corpus_file_parser.ml | 36 ++++-------- test/parser/test_parser.ml | 73 +++++++++++++++++++----- 2 files changed, 69 insertions(+), 40 deletions(-) diff --git a/test/parser/syntax_corpus_file_parser.ml b/test/parser/syntax_corpus_file_parser.ml index 5c52008c..4a3c7742 100644 --- a/test/parser/syntax_corpus_file_parser.ml +++ b/test/parser/syntax_corpus_file_parser.ml @@ -36,25 +36,14 @@ let str_to_test_attribute (attr : string) : test_attribute = (** Metadata about a syntax test. *) type syntax_test_info = { - file : string; + path : string; name : string; } [@@deriving show] -(** A syntax test expected to produce an error. *) -type error_syntax_test = { - input : string; -} [@@deriving show] - -(** A syntax test expected to produce a specific parse tree. *) -type expected_syntax_test = { - input : string; - expect : Sexp.t; -} [@@deriving show] - (** Enumeration of syntax test variants. *) type syntax_test_variant = - | Expected_test of expected_syntax_test - | Error_test of error_syntax_test + | Error_test of string + | Expected_test of (string * Sexp.t) [@@deriving show] (** All information necessary to run a single syntax test. *) @@ -100,21 +89,16 @@ let rec parse_split_test_file (path : string) (input : string list) : syntax_tes match input with | [] -> [] | test_header :: test_body :: ls -> - let (test_name, test_attrs) = test_header |> trim |> split_on_char '\n' |> parse_test_header in - let (test_input, test_output) = parse_test_body path test_name test_body in - let test_variant = + let (name, test_attrs) = test_header |> trim |> split_on_char '\n' |> parse_test_header in + let (test_input, test_output) = parse_test_body path name test_body in + let test = if List.mem Error test_attrs - then Error_test { - input = test_input; - } - else Expected_test { - input = test_input; - expect = Sexp.of_string test_output - } + then Error_test test_input + else Expected_test (test_input, Sexp.of_string test_output) in { - info = { file = path; name = test_name; }; + info = { path; name; }; skip = List.mem Skip test_attrs; - test = test_variant; + test; } :: (parse_split_test_file path ls) | _ -> Invalid_argument (sprintf "Test file %s contains extra header separators" path) |> raise diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index 3546b9bf..442e914b 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -1,5 +1,4 @@ open Syntax_corpus_file_parser;; -open Printf;; let () = match Tlapm_lib.module_of_string "---- MODULE Test ---- x == 5 ====" with @@ -10,19 +9,65 @@ let parse (input : string) : Tlapm_lib__M_t.mule option = try Tlapm_lib.module_of_string input with _ -> None +type test_run_summary = { + total : int; + succeeded : int; + failed : int; + skipped : int; + failures : syntax_test_info list; +} [@@deriving show] + +let test_summary_init = { + total = 0; + succeeded = 0; + failed = 0; + skipped = 0; + failures = []; +} + +let test_summary_succeeded = { + test_summary_init with + total = 1; + succeeded = 1; +} + +let test_summary_failed info = { + test_summary_init with + total = 1; + failed = 1; + failures = [info]; +} + +let test_summary_skipped = { + test_summary_init with + total = 1; + skipped = 1; +} + +let acc_test_summary acc e = { + total = acc.total + e.total; + succeeded = acc.succeeded + e.succeeded; + failed = acc.failed + e.failed; + skipped = acc.skipped + e.skipped; + failures = List.append acc.failures e.failures; +} + +let run_test (test : syntax_test) : test_run_summary = + if test.skip then test_summary_skipped else + match test.test with + | Error_test input -> ( + match parse input with + | None -> test_summary_succeeded + | Some _ -> test_summary_failed test.info) + | Expected_test (input, _) -> ( + match parse input with + | None -> test_summary_failed test.info + | Some _ -> test_summary_succeeded) + let () = "syntax_corpus" |> get_all_tests_under - |> List.iter ( - fun test -> - if test.skip then print_endline (show_syntax_test_info test.info) else - match test.test with - | Error_test error_test -> ( - match parse error_test.input with - | None -> (*print_endline (sprintf "SUCCESS [ error] %s: %s" test.info.file test.info.name)*) () - | Some _ -> print_endline (sprintf "FAILURE [no error] %s: %s" test.info.file test.info.name); flush stdout) - | Expected_test expected_test -> ( - match parse expected_test.input with - | None -> print_endline (sprintf "FAILURE [ error] %s: %s" test.info.file test.info.name); flush stdout - | Some _ -> (*print_endline (sprintf "SUCCESS [no error] %s: %s" test.info.file test.info.name))*) ()) - ) \ No newline at end of file + |> List.map run_test + |> List.fold_left acc_test_summary test_summary_init + |> show_test_run_summary + |> print_endline \ No newline at end of file From 5a9a76dfb520213c4c0ac8584961a2d6a6ce6940 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Tue, 22 Oct 2024 16:34:06 -0400 Subject: [PATCH 13/28] Isolate failing syntax test cases Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/syntax_corpus/infix_op.txt | 75 ++++++-- test/parser/syntax_corpus/number.txt | 18 +- test/parser/syntax_corpus/proofs.txt | 86 ++++++++- test/parser/syntax_corpus/quantification.txt | 173 ++++++++++++++++++- test/parser/syntax_corpus/regression.txt | 16 -- test/parser/syntax_corpus/sets.txt | 31 +++- test/parser/test_parser.ml | 10 +- 7 files changed, 356 insertions(+), 53 deletions(-) diff --git a/test/parser/syntax_corpus/infix_op.txt b/test/parser/syntax_corpus/infix_op.txt index 053bcdc6..d1660f06 100644 --- a/test/parser/syntax_corpus/infix_op.txt +++ b/test/parser/syntax_corpus/infix_op.txt @@ -1,3 +1,19 @@ +=============||| +Cartesian Product Infix Op Definition +=============||| + +---- MODULE Test ---- +x \X y == 0 +x \times y == 0 +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition parameter: (identifier) name: (infix_op_symbol (times)) parameter: (identifier) (def_eq) definition: (nat_number)) + (operator_definition parameter: (identifier) name: (infix_op_symbol (times)) parameter: (identifier) (def_eq) definition: (nat_number)) +(double_line))) + =============||| Infix Operator Definition =============||| @@ -100,8 +116,6 @@ x \succ y == 92 x \succeq y == 93 x \supset y == 94 x \supseteq y == 95 -x \X y == 96 -x \times y == 97 x \uplus y == 98 x | y == 99 x || y == 100 @@ -208,14 +222,28 @@ x \wr y == 101 (operator_definition parameter: (identifier) name: (infix_op_symbol (succeq)) parameter: (identifier) (def_eq) definition: (nat_number)) (operator_definition parameter: (identifier) name: (infix_op_symbol (supset)) parameter: (identifier) (def_eq) definition: (nat_number)) (operator_definition parameter: (identifier) name: (infix_op_symbol (supseteq)) parameter: (identifier) (def_eq) definition: (nat_number)) - (operator_definition parameter: (identifier) name: (infix_op_symbol (times)) parameter: (identifier) (def_eq) definition: (nat_number)) - (operator_definition parameter: (identifier) name: (infix_op_symbol (times)) parameter: (identifier) (def_eq) definition: (nat_number)) (operator_definition parameter: (identifier) name: (infix_op_symbol (uplus)) parameter: (identifier) (def_eq) definition: (nat_number)) (operator_definition parameter: (identifier) name: (infix_op_symbol (vert)) parameter: (identifier) (def_eq) definition: (nat_number)) (operator_definition parameter: (identifier) name: (infix_op_symbol (vertvert)) parameter: (identifier) (def_eq) definition: (nat_number)) (operator_definition parameter: (identifier) name: (infix_op_symbol (wr)) parameter: (identifier) (def_eq) definition: (nat_number)) (double_line))) +=============||| +Cartesian Product Declaration as Parameter +=============||| + +---- MODULE Test ---- +op(_ \X _, _ \times _) == TRUE +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (times)) (placeholder)) + parameter: (operator_declaration (placeholder) name: (infix_op_symbol (times)) (placeholder)) + (def_eq) definition: (boolean)) +(double_line))) =============||| Infix Operator Declaration as Parameter @@ -320,8 +348,6 @@ op( _ \succeq _, _ \supset _, _ \supseteq _, - _ \X _, - _ \times _, _ \uplus _, _ | _, _ || _, @@ -430,8 +456,6 @@ op( parameter: (operator_declaration (placeholder) name: (infix_op_symbol (succeq)) (placeholder)) parameter: (operator_declaration (placeholder) name: (infix_op_symbol (supset)) (placeholder)) parameter: (operator_declaration (placeholder) name: (infix_op_symbol (supseteq)) (placeholder)) - parameter: (operator_declaration (placeholder) name: (infix_op_symbol (times)) (placeholder)) - parameter: (operator_declaration (placeholder) name: (infix_op_symbol (times)) (placeholder)) parameter: (operator_declaration (placeholder) name: (infix_op_symbol (uplus)) (placeholder)) parameter: (operator_declaration (placeholder) name: (infix_op_symbol (vert)) (placeholder)) parameter: (operator_declaration (placeholder) name: (infix_op_symbol (vertvert)) (placeholder)) @@ -663,6 +687,39 @@ op == { )) (double_line))) +=============||| +Cartesian Product as Parameter +=============||| + +---- MODULE Test ---- +op == f(\X, \times) +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (bound_op name: (identifier_ref) + parameter: (infix_op_symbol (times)) + parameter: (infix_op_symbol (times)) + )) +(double_line))) + +=============||| +Infix Minus as Parameter +=============||| + +---- MODULE Test ---- +op == f ( - ) +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: (bound_op name: (identifier_ref) + parameter: (infix_op_symbol (minus)) + )) +(double_line))) + =============||| Infix Operators as Parameters =============||| @@ -717,7 +774,6 @@ op == f( <, <:, :>, - -, --, %, %%, @@ -824,7 +880,6 @@ op == f( parameter: (infix_op_symbol (lt)) parameter: (infix_op_symbol (map_from)) parameter: (infix_op_symbol (map_to)) - parameter: (infix_op_symbol (minus)) parameter: (infix_op_symbol (minusminus)) parameter: (infix_op_symbol (mod)) parameter: (infix_op_symbol (modmod)) diff --git a/test/parser/syntax_corpus/number.txt b/test/parser/syntax_corpus/number.txt index f91c5e2c..a2016a81 100644 --- a/test/parser/syntax_corpus/number.txt +++ b/test/parser/syntax_corpus/number.txt @@ -1,10 +1,24 @@ ======================||| -All Number Formats +Common Number Formats ======================||| ---- MODULE Test ---- op == 12345 op == 12345.12345 +==== + +----------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) (nat_number)) + (operator_definition (identifier) (def_eq) (real_number)) +(double_line))) + +======================||| +Bitfield Number Formats +======================||| + +---- MODULE Test ---- op == \b01010101 op == \B10101010 op == \o01234567 @@ -16,8 +30,6 @@ op == \H9876543210FEDCBA ----------------------||| (source_file (module (header_line) (identifier) (header_line) - (operator_definition (identifier) (def_eq) (nat_number)) - (operator_definition (identifier) (def_eq) (real_number)) (operator_definition (identifier) (def_eq) (binary_number (format) (value))) (operator_definition (identifier) (def_eq) (binary_number (format) (value))) (operator_definition (identifier) (def_eq) (octal_number (format) (value))) diff --git a/test/parser/syntax_corpus/proofs.txt b/test/parser/syntax_corpus/proofs.txt index f10bf4c2..10f069cc 100644 --- a/test/parser/syntax_corpus/proofs.txt +++ b/test/parser/syntax_corpus/proofs.txt @@ -98,13 +98,10 @@ Proof by Multiple Definitions LEMMA TRUE PROOF BY ONLY P, - MODULE Naturals, - Q, - MODULE Integers + Q DEFS >, R, - MODULE Reals, = ==== @@ -115,27 +112,79 @@ PROOF BY ONLY (terminal_proof (use_body (use_body_expr (identifier_ref) - (module_ref (identifier_ref)) (identifier_ref) - (module_ref (identifier_ref)) ) (use_body_def (infix_op_symbol (gt)) (identifier_ref) - (module_ref (identifier_ref)) (infix_op_symbol (eq)) ) )) ) (double_line))) +===============================||| +Proof by Module References +===============================||| + +---- MODULE Test ---- +LEMMA TRUE +PROOF BY ONLY + MODULE Naturals, + MODULE Integers + DEFS + MODULE Reals, + MODULE Sequences +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (terminal_proof (use_body + (use_body_expr + (module_ref (identifier_ref)) + (module_ref (identifier_ref)) + ) + (use_body_def + (module_ref (identifier_ref)) + (module_ref (identifier_ref)) + ) + )) + ) +(double_line))) + ===============================||| Proof by QED ===============================||| ---- MODULE Test ---- COROLLARY TRUE -PROOF <1>a QED BY <1>a, <*>a +PROOF <1>a QED BY <1>a, <1>b +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (qed_step (proof_step_id (level) (name)) + (terminal_proof (use_body (use_body_expr + (proof_step_ref (level) (name)) + (proof_step_ref (level) (name)) + ))) + ) + ) + ) +(double_line))) + +===============================||| +Proof by QED with implicit step level +===============================||| + +---- MODULE Test ---- +COROLLARY TRUE +PROOF <1>a QED BY <1>a, <*>b ==== -------------------------------||| @@ -186,7 +235,6 @@ THEOREM TRUE <1>i..... PICK a, b, c : 7 <1>j..... HIDE 8 <1>k..... USE 9 -<1>l..... INSTANCE M <1>m..... QED ==== @@ -206,6 +254,26 @@ THEOREM TRUE (proof_step (proof_step_id (level) (name)) (pick_proof_step (identifier) (identifier) (identifier) (nat_number))) (proof_step (proof_step_id (level) (name)) (use_or_hide (use_body (use_body_expr (nat_number))))) (proof_step (proof_step_id (level) (name)) (use_or_hide (use_body (use_body_expr (nat_number))))) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + +===============================||| +Proof with INSTANCE step type +===============================||| + +---- MODULE Test ---- +THEOREM TRUE +<1>a..... INSTANCE M +<1>b..... QED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof (proof_step (proof_step_id (level) (name)) (instance (identifier_ref))) (qed_step (proof_step_id (level) (name))) ) diff --git a/test/parser/syntax_corpus/quantification.txt b/test/parser/syntax_corpus/quantification.txt index 468f200f..a85cea40 100644 --- a/test/parser/syntax_corpus/quantification.txt +++ b/test/parser/syntax_corpus/quantification.txt @@ -3,8 +3,64 @@ Bounded Quantification ==============================||| ---- MODULE Test ---- -op == \A x, y \in Nat, z \in Int, <> \in Real : FALSE -op == \E <> \in Nat, a, b \in Int : TRUE +op == \A x, y \in Nat, z \in Int, a, b, c \in Real : FALSE +op == \E x, y \in Nat, a, b \in Int : TRUE +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (bounded_quantification + quantifier: (forall) + bound: (quantifier_bound + intro: (identifier) + intro: (identifier) + (set_in) + set: (nat_number_set) + ) + bound: (quantifier_bound + intro: (identifier) + (set_in) + set: (int_number_set) + ) + bound: (quantifier_bound + intro: (identifier) + intro: (identifier) + intro: (identifier) + (set_in) + set: (real_number_set) + ) + expression: (boolean) + ) + ) + (operator_definition name: (identifier) (def_eq) + definition: (bounded_quantification + quantifier: (exists) + bound: (quantifier_bound + intro: (identifier) + intro: (identifier) + (set_in) + set: (nat_number_set) + ) + bound: (quantifier_bound + intro: (identifier) + intro: (identifier) + (set_in) + set: (int_number_set) + ) + expression: (boolean) + ) + ) +(double_line))) + +==============================||| +Bounded Quantification With Tuples +==============================||| + +---- MODULE Test ---- +op == \A <> \in Nat, <> \in Int, <> \in Real : FALSE +op == \E <> \in Nat, <> \in Int : TRUE ==== ------------------------------||| @@ -14,17 +70,88 @@ op == \E <> \in Nat, a, b \in Int : TRUE definition: (bounded_quantification quantifier: (forall) bound: (quantifier_bound - intro: (identifier) intro: (identifier) + intro: (tuple_of_identifiers (langle_bracket) + (identifier) + (identifier) + (rangle_bracket)) + (set_in) + set: (nat_number_set) + ) + bound: (quantifier_bound + intro: (tuple_of_identifiers (langle_bracket) + (identifier) + (rangle_bracket)) + (set_in) + set: (int_number_set) + ) + bound: (quantifier_bound + intro: (tuple_of_identifiers (langle_bracket) + (identifier) + (identifier) + (identifier) + (rangle_bracket)) + (set_in) + set: (real_number_set) + ) + expression: (boolean) + ) + ) + (operator_definition name: (identifier) (def_eq) + definition: (bounded_quantification + quantifier: (exists) + bound: (quantifier_bound + intro: (tuple_of_identifiers (langle_bracket) + (identifier) + (identifier) + (rangle_bracket)) (set_in) set: (nat_number_set) ) bound: (quantifier_bound + intro: (tuple_of_identifiers (langle_bracket) + (identifier) + (identifier) + (rangle_bracket)) + (set_in) + set: (int_number_set) + ) + expression: (boolean) + ) + ) +(double_line))) + +==============================||| +Mixed Bounded Quantification With Tuples +==============================||| + +---- MODULE Test ---- +op == \A x, y \in Nat, <> \in Int, a, b, c \in Real : FALSE +op == \E <> \in Nat, a, b \in Int : TRUE +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (bounded_quantification + quantifier: (forall) + bound: (quantifier_bound + intro: (identifier) intro: (identifier) (set_in) + set: (nat_number_set) + ) + bound: (quantifier_bound + intro: (tuple_of_identifiers (langle_bracket) + (identifier) + (rangle_bracket)) + (set_in) set: (int_number_set) ) bound: (quantifier_bound - intro: (tuple_of_identifiers (langle_bracket) (identifier) (identifier) (identifier) (rangle_bracket)) + intro: (identifier) + intro: (identifier) + intro: (identifier) (set_in) set: (real_number_set) ) @@ -35,12 +162,16 @@ op == \E <> \in Nat, a, b \in Int : TRUE definition: (bounded_quantification quantifier: (exists) bound: (quantifier_bound - intro: (tuple_of_identifiers (langle_bracket) (identifier) (identifier) (rangle_bracket)) + intro: (tuple_of_identifiers (langle_bracket) + (identifier) + (identifier) + (rangle_bracket)) (set_in) set: (nat_number_set) ) bound: (quantifier_bound - intro: (identifier) intro: (identifier) + intro: (identifier) + intro: (identifier) (set_in) set: (int_number_set) ) @@ -105,7 +236,6 @@ Bounded CHOOSE ---- MODULE Test ---- op == CHOOSE x \in Nat : TRUE -op == CHOOSE <> \in S : FALSE ==== ------------------------------||| @@ -119,6 +249,19 @@ op == CHOOSE <> \in S : FALSE expression: (boolean) ) ) +(double_line))) + +==============================||| +Bounded CHOOSE With Tuple +==============================||| + +---- MODULE Test ---- +op == CHOOSE <> \in S : FALSE +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) (operator_definition name: (identifier) (def_eq) definition: (choose intro: (tuple_of_identifiers (langle_bracket) (identifier) (identifier) (identifier) (rangle_bracket)) @@ -135,7 +278,6 @@ Unbounded CHOOSE ---- MODULE Test ---- op == CHOOSE x : TRUE -op == CHOOSE <> : FALSE ==== ------------------------------||| @@ -147,6 +289,20 @@ op == CHOOSE <> : FALSE expression: (boolean) ) ) +(double_line))) + + +==============================||| +Unbounded CHOOSE With Tuple +==============================||| + +---- MODULE Test ---- +op == CHOOSE <> : FALSE +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) (operator_definition name: (identifier) (def_eq) definition: (choose intro: (tuple_of_identifiers (langle_bracket) (identifier) (identifier) (identifier) (rangle_bracket)) @@ -154,4 +310,3 @@ op == CHOOSE <> : FALSE ) ) (double_line))) - diff --git a/test/parser/syntax_corpus/regression.txt b/test/parser/syntax_corpus/regression.txt index 789ae928..1077f76c 100644 --- a/test/parser/syntax_corpus/regression.txt +++ b/test/parser/syntax_corpus/regression.txt @@ -39,9 +39,7 @@ Junct Tokens as Higher-Level Parameters (TSTLA#GH96) ---- MODULE Test ---- op == op(/\, x, /\) -op == op(∧, x, ∧) op == op(\/, x, \/) -op == op(∨, x, ∨) ==== --------------||| @@ -54,20 +52,6 @@ op == op(∨, x, ∨) parameter: (infix_op_symbol (land)) ) ) - (operator_definition name: (identifier) (def_eq) definition: - (bound_op name: (identifier_ref) - parameter: (infix_op_symbol (land)) - parameter: (identifier_ref) - parameter: (infix_op_symbol (land)) - ) - ) - (operator_definition name: (identifier) (def_eq) definition: - (bound_op name: (identifier_ref) - parameter: (infix_op_symbol (lor)) - parameter: (identifier_ref) - parameter: (infix_op_symbol (lor)) - ) - ) (operator_definition name: (identifier) (def_eq) definition: (bound_op name: (identifier_ref) parameter: (infix_op_symbol (lor)) diff --git a/test/parser/syntax_corpus/sets.txt b/test/parser/syntax_corpus/sets.txt index 2297b57f..1013fb86 100644 --- a/test/parser/syntax_corpus/sets.txt +++ b/test/parser/syntax_corpus/sets.txt @@ -14,14 +14,39 @@ op == { } ) (double_line))) +======================||| +Mistaken Set Filter Test +======================||| + +---- MODULE Test ---- + +op == {x \in Nat} +op == {x \in BOOLEAN, y \in STRING} + +==== + +----------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (finite_set_literal + (bound_infix_op lhs: (identifier_ref) symbol: (in) rhs: (nat_number_set)) + ) + ) + (operator_definition name: (identifier) (def_eq) definition: + (finite_set_literal + (bound_infix_op lhs: (identifier_ref) symbol: (in) rhs: (boolean_set)) + (bound_infix_op lhs: (identifier_ref) symbol: (in) rhs: (string_set)) + ) + ) +(double_line))) + ======================||| Set Literal ======================||| ---- MODULE Test ---- op == { - x \in BOOLEAN, - y \in STRING, TRUE, FALSE, ((1 + 2) * 3), @@ -34,8 +59,6 @@ op == { (source_file (module (header_line) name: (identifier) (header_line) (operator_definition name: (identifier) (def_eq) definition: (finite_set_literal - (bound_infix_op lhs: (identifier_ref) symbol: (in) rhs: (boolean_set)) - (bound_infix_op lhs: (identifier_ref) symbol: (in) rhs: (string_set)) (boolean) (boolean) (parentheses diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index 442e914b..1701e4dc 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -64,10 +64,16 @@ let run_test (test : syntax_test) : test_run_summary = | None -> test_summary_failed test.info | Some _ -> test_summary_succeeded) -let () = - "syntax_corpus" +let run_test_corpus (path : string) (pred : syntax_test -> bool) : test_run_summary = + path |> get_all_tests_under + |> List.filter pred |> List.map run_test |> List.fold_left acc_test_summary test_summary_init + +let () = + (*fun test -> String.equal test.info.name "Proof Containing Jlist"*) + (fun _ -> true) + |> run_test_corpus "syntax_corpus" |> show_test_run_summary |> print_endline \ No newline at end of file From a80c1e452fa3841b4e62e3d71baf2550fa82a9e3 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Tue, 22 Oct 2024 19:44:23 -0400 Subject: [PATCH 14/28] Encode failing tests; assert on test failure Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/test_parser.ml | 60 ++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index 1701e4dc..576dd3f6 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -1,10 +1,5 @@ open Syntax_corpus_file_parser;; -let () = - match Tlapm_lib.module_of_string "---- MODULE Test ---- x == 5 ====" with - | None -> print_endline "Parse failed" - | Some mule -> print_endline mule.core.name.core - let parse (input : string) : Tlapm_lib__M_t.mule option = try Tlapm_lib.module_of_string input with _ -> None @@ -52,28 +47,57 @@ let acc_test_summary acc e = { failures = List.append acc.failures e.failures; } -let run_test (test : syntax_test) : test_run_summary = +let run_test (should_fail : syntax_test -> bool) (test : syntax_test) : test_run_summary = if test.skip then test_summary_skipped else match test.test with | Error_test input -> ( match parse input with - | None -> test_summary_succeeded - | Some _ -> test_summary_failed test.info) + | None -> if should_fail test then test_summary_failed test.info else test_summary_succeeded + | Some _ -> if should_fail test then test_summary_succeeded else test_summary_failed test.info) | Expected_test (input, _) -> ( match parse input with - | None -> test_summary_failed test.info - | Some _ -> test_summary_succeeded) + | None -> if should_fail test then test_summary_succeeded else test_summary_failed test.info + | Some _ -> if should_fail test then test_summary_failed test.info else test_summary_succeeded) -let run_test_corpus (path : string) (pred : syntax_test -> bool) : test_run_summary = +let run_test_corpus (path : string) (should_fail : syntax_test -> bool) (filter_pred : syntax_test -> bool) : test_run_summary = path |> get_all_tests_under - |> List.filter pred - |> List.map run_test + |> List.filter filter_pred + |> List.map (run_test should_fail) |> List.fold_left acc_test_summary test_summary_init +let error_test_names = [ + "Invalid parentheses use in jlist"; + "Bounded Quantification With Tuples"; + "Mixed Bounded Quantification With Tuples"; + "Bounded CHOOSE With Tuple"; + "Unbounded CHOOSE With Tuple"; + "Cartesian Product Infix Op Definition"; + "Cartesian Product Declaration as Parameter"; + "Infix Minus as Parameter"; + "RECURSIVE inside LET/IN"; + "Conjlist with RECURSIVE in LET/IN"; + "Disjlist with RECURSIVE in LET/IN"; + "Use & Hide Declarations"; + "Label interfering with precedence"; + "Bitfield Number Formats"; + "Proof by Module References"; + "Proof by QED with implicit step level"; + "Proof with INSTANCE step type"; + "Proof Containing Jlist"; + "Prefix Operator References"; + "Mistaken Set Filter Test"; + "Set Filter with Tuple"; + "Proof Step ID Subexpression Tree Navigation"; +] + let () = - (*fun test -> String.equal test.info.name "Proof Containing Jlist"*) - (fun _ -> true) - |> run_test_corpus "syntax_corpus" - |> show_test_run_summary - |> print_endline \ No newline at end of file + (* Keeping this around because it's useful when wanting to run a single test. *) + (*let filter_pred = fun test -> String.equal test.info.name "Proof Containing Jlist" in*) + let filter_pred = fun _ -> true in + let test_results = run_test_corpus + "syntax_corpus" + (fun test -> List.mem test.info.name error_test_names) + filter_pred + in print_endline (show_test_run_summary test_results); + ignore (assert (0 == test_results.failed)); \ No newline at end of file From 4476a3223b3b9acfc631c07cd06ee226ef0c73b6 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Tue, 22 Oct 2024 19:57:28 -0400 Subject: [PATCH 15/28] Added documentation to syntax corpus test file Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/test_parser.ml | 50 ++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index 576dd3f6..b9ffedfc 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -1,9 +1,22 @@ +(** This test runs a battery of TLA+ syntax fragments against TLAPM's syntax + parser. In the future it will check the actual parse tree emitted by + TLAPM, but for now it just checks whether TLAPM parses without error all + the syntax it is expected to parse. Tests sourced from: + https://github.com/tlaplus/tlaplus-standard/tree/main/tests/tlaplus_syntax +*) + open Syntax_corpus_file_parser;; +(** Calls TLAPM's parser with the given input. Catches all exceptions and + treats them as parse failures. + @param input The TLA+ fragment to parse. + @return None if parse failure, syntax tree root if successful. +*) let parse (input : string) : Tlapm_lib__M_t.mule option = try Tlapm_lib.module_of_string input with _ -> None +(** Datatype summarizing a run of all the syntax tests. *) type test_run_summary = { total : int; succeeded : int; @@ -12,6 +25,7 @@ type test_run_summary = { failures : syntax_test_info list; } [@@deriving show] +(** A blank test summary. *) let test_summary_init = { total = 0; succeeded = 0; @@ -20,12 +34,14 @@ let test_summary_init = { failures = []; } +(** Summary for a successful test. *) let test_summary_succeeded = { test_summary_init with total = 1; succeeded = 1; } +(** Summary for a failed test. *) let test_summary_failed info = { test_summary_init with total = 1; @@ -33,12 +49,14 @@ let test_summary_failed info = { failures = [info]; } +(** Summary for a skipped test. *) let test_summary_skipped = { test_summary_init with total = 1; skipped = 1; } +(** Merge and accumulate two test summaries into one. *) let acc_test_summary acc e = { total = acc.total + e.total; succeeded = acc.succeeded + e.succeeded; @@ -47,6 +65,14 @@ let acc_test_summary acc e = { failures = List.append acc.failures e.failures; } +(** Runs a given syntax test. Checks whether test should be skipped, what + kind of test it is, and whether the test is expected to fail due to a + known bug in the TLAPM parser; then sends the test's TLA+ fragment into + the parser to see what happens. + @param should_fail Whether this test should fail due to a TLAPM bug. + @param test Information about the test itself. + @return A summary of the test's execution. +*) let run_test (should_fail : syntax_test -> bool) (test : syntax_test) : test_run_summary = if test.skip then test_summary_skipped else match test.test with @@ -59,6 +85,14 @@ let run_test (should_fail : syntax_test -> bool) (test : syntax_test) : test_run | None -> if should_fail test then test_summary_succeeded else test_summary_failed test.info | Some _ -> if should_fail test then test_summary_failed test.info else test_summary_succeeded) +(** Given a path to a directory containing a corpus of syntax tests, get all + the tests encoded in those files, filter them as appropriate, then run + them all and collect the results. + @param path Path to the directory containing the corpus of syntax tests. + @param should_fail Whether a test should fail due to a TLAPM bug. + @param filter_predicate Whether to actually execute a test. + @return Accumulated summary of all test executions. +*) let run_test_corpus (path : string) (should_fail : syntax_test -> bool) (filter_pred : syntax_test -> bool) : test_run_summary = path |> get_all_tests_under @@ -66,7 +100,8 @@ let run_test_corpus (path : string) (should_fail : syntax_test -> bool) (filter_ |> List.map (run_test should_fail) |> List.fold_left acc_test_summary test_summary_init -let error_test_names = [ +(** Names of tests that are known to fail due to TLAPM parser bugs. *) +let failing_test_names = [ "Invalid parentheses use in jlist"; "Bounded Quantification With Tuples"; "Mixed Bounded Quantification With Tuples"; @@ -91,13 +126,14 @@ let error_test_names = [ "Proof Step ID Subexpression Tree Navigation"; ] +(** The top-level test; runs all syntax tests, prints summary, then fails + with an assertion if any tests failed. +*) let () = (* Keeping this around because it's useful when wanting to run a single test. *) (*let filter_pred = fun test -> String.equal test.info.name "Proof Containing Jlist" in*) let filter_pred = fun _ -> true in - let test_results = run_test_corpus - "syntax_corpus" - (fun test -> List.mem test.info.name error_test_names) - filter_pred - in print_endline (show_test_run_summary test_results); - ignore (assert (0 == test_results.failed)); \ No newline at end of file + let should_fail = fun (test : syntax_test) -> List.mem test.info.name failing_test_names in + let test_results = run_test_corpus "syntax_corpus" should_fail filter_pred in + print_endline (show_test_run_summary test_results); + ignore (assert (0 == test_results.failed)); From 7af9882a40652b4c08dd24c12176246281a50972 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Wed, 23 Oct 2024 07:48:24 -0400 Subject: [PATCH 16/28] Simplified test control logic Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/test_parser.ml | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index b9ffedfc..e3e8c16b 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -65,25 +65,35 @@ let acc_test_summary acc e = { failures = List.append acc.failures e.failures; } -(** Runs a given syntax test. Checks whether test should be skipped, what - kind of test it is, and whether the test is expected to fail due to a - known bug in the TLAPM parser; then sends the test's TLA+ fragment into - the parser to see what happens. +(** Runs a given syntax test by determining its type then sending the input + into the TLAPM parser. @param should_fail Whether this test should fail due to a TLAPM bug. @param test Information about the test itself. - @return A summary of the test's execution. + @return Whether the test succeeded. *) -let run_test (should_fail : syntax_test -> bool) (test : syntax_test) : test_run_summary = - if test.skip then test_summary_skipped else +let run_test (test : syntax_test) : bool = match test.test with | Error_test input -> ( match parse input with - | None -> if should_fail test then test_summary_failed test.info else test_summary_succeeded - | Some _ -> if should_fail test then test_summary_succeeded else test_summary_failed test.info) + | None -> true + | Some _ -> false) | Expected_test (input, _) -> ( match parse input with - | None -> if should_fail test then test_summary_succeeded else test_summary_failed test.info - | Some _ -> if should_fail test then test_summary_failed test.info else test_summary_succeeded) + | None -> false + | Some _ -> true) + +(** Controls run of a given syntax test. Checks whether test should be + skipped and whether it is expected to fail, then runs test and returns + summary. + @param should_fail Whether this test should fail due to a TLAPM bug. + @param test Information about the test itself. + @return Test run summary. +*) +let control_test_run (should_fail : syntax_test -> bool) (test : syntax_test) : test_run_summary = + if test.skip then test_summary_skipped else + if run_test test = should_fail test + then test_summary_failed test.info + else test_summary_succeeded (** Given a path to a directory containing a corpus of syntax tests, get all the tests encoded in those files, filter them as appropriate, then run @@ -97,7 +107,7 @@ let run_test_corpus (path : string) (should_fail : syntax_test -> bool) (filter_ path |> get_all_tests_under |> List.filter filter_pred - |> List.map (run_test should_fail) + |> List.map (control_test_run should_fail) |> List.fold_left acc_test_summary test_summary_init (** Names of tests that are known to fail due to TLAPM parser bugs. *) From 0bde78db69e2064fcd94a426c4ef2b08cf2b5171 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Wed, 23 Oct 2024 08:31:54 -0400 Subject: [PATCH 17/28] Accumulate test summaries in place Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- Makefile | 2 +- test/parser/dune | 2 +- test/parser/test_parser.ml | 67 ++++++++++++-------------------------- 3 files changed, 22 insertions(+), 49 deletions(-) diff --git a/Makefile b/Makefile index 3c028153..95065820 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ opam-deps-opt: opam install --yes eio_main lsp opam-deps-dev: - opam install --yes ocamlformat ocaml-lsp-server earlybird ppx_deriving + opam install --yes ocamlformat ocaml-lsp-server earlybird ppx_deriving ounit2 build: dune build diff --git a/test/parser/dune b/test/parser/dune index 5a1c994e..80280744 100644 --- a/test/parser/dune +++ b/test/parser/dune @@ -1,7 +1,7 @@ (test (name test_parser) (modes exe) - (libraries tlapm_lib sexplib) + (libraries tlapm_lib ounit2 sexplib) (deps (glob_files_rec syntax_corpus/*)) (preprocess (pps ppx_deriving.show)) ) diff --git a/test/parser/test_parser.ml b/test/parser/test_parser.ml index e3e8c16b..0987aa58 100644 --- a/test/parser/test_parser.ml +++ b/test/parser/test_parser.ml @@ -6,6 +6,7 @@ *) open Syntax_corpus_file_parser;; +open OUnit2;; (** Calls TLAPM's parser with the given input. Catches all exceptions and treats them as parse failures. @@ -34,37 +35,6 @@ let test_summary_init = { failures = []; } -(** Summary for a successful test. *) -let test_summary_succeeded = { - test_summary_init with - total = 1; - succeeded = 1; -} - -(** Summary for a failed test. *) -let test_summary_failed info = { - test_summary_init with - total = 1; - failed = 1; - failures = [info]; -} - -(** Summary for a skipped test. *) -let test_summary_skipped = { - test_summary_init with - total = 1; - skipped = 1; -} - -(** Merge and accumulate two test summaries into one. *) -let acc_test_summary acc e = { - total = acc.total + e.total; - succeeded = acc.succeeded + e.succeeded; - failed = acc.failed + e.failed; - skipped = acc.skipped + e.skipped; - failures = List.append acc.failures e.failures; -} - (** Runs a given syntax test by determining its type then sending the input into the TLAPM parser. @param should_fail Whether this test should fail due to a TLAPM bug. @@ -73,27 +43,27 @@ let acc_test_summary acc e = { *) let run_test (test : syntax_test) : bool = match test.test with - | Error_test input -> ( - match parse input with - | None -> true - | Some _ -> false) - | Expected_test (input, _) -> ( - match parse input with - | None -> false - | Some _ -> true) + | Error_test input -> parse input |> Option.is_none + | Expected_test (input, _) -> parse input |> Option.is_some (** Controls run of a given syntax test. Checks whether test should be skipped and whether it is expected to fail, then runs test and returns summary. @param should_fail Whether this test should fail due to a TLAPM bug. + @param acc Accumulation variable for test summarization. @param test Information about the test itself. @return Test run summary. *) -let control_test_run (should_fail : syntax_test -> bool) (test : syntax_test) : test_run_summary = - if test.skip then test_summary_skipped else +let control_test_run + (should_fail : syntax_test -> bool) + (acc : test_run_summary) + (test : syntax_test) + : test_run_summary = + let acc = {acc with total = acc.total + 1} in + if test.skip then {acc with skipped = acc.skipped + 1} else if run_test test = should_fail test - then test_summary_failed test.info - else test_summary_succeeded + then {acc with failed = acc.failed + 1; failures = test.info :: acc.failures} + else {acc with succeeded = acc.succeeded + 1} (** Given a path to a directory containing a corpus of syntax tests, get all the tests encoded in those files, filter them as appropriate, then run @@ -103,12 +73,15 @@ let control_test_run (should_fail : syntax_test -> bool) (test : syntax_test) : @param filter_predicate Whether to actually execute a test. @return Accumulated summary of all test executions. *) -let run_test_corpus (path : string) (should_fail : syntax_test -> bool) (filter_pred : syntax_test -> bool) : test_run_summary = +let run_test_corpus + (path : string) + (should_fail : syntax_test -> bool) + (filter_pred : syntax_test -> bool) + : test_run_summary = path |> get_all_tests_under |> List.filter filter_pred - |> List.map (control_test_run should_fail) - |> List.fold_left acc_test_summary test_summary_init + |> List.fold_left (control_test_run should_fail) test_summary_init (** Names of tests that are known to fail due to TLAPM parser bugs. *) let failing_test_names = [ @@ -146,4 +119,4 @@ let () = let should_fail = fun (test : syntax_test) -> List.mem test.info.name failing_test_names in let test_results = run_test_corpus "syntax_corpus" should_fail filter_pred in print_endline (show_test_run_summary test_results); - ignore (assert (0 == test_results.failed)); + assert_equal 0 test_results.failed; \ No newline at end of file From 93c084a98b3e44e959621dfd4dba81ea47eb9523 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Wed, 23 Oct 2024 08:37:51 -0400 Subject: [PATCH 18/28] Use List.partition for parsing test header Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/syntax_corpus_file_parser.ml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/parser/syntax_corpus_file_parser.ml b/test/parser/syntax_corpus_file_parser.ml index 4a3c7742..dae347fc 100644 --- a/test/parser/syntax_corpus_file_parser.ml +++ b/test/parser/syntax_corpus_file_parser.ml @@ -59,10 +59,9 @@ type syntax_test = { @return A tuple of (test_name, test_attributes). *) let parse_test_header (header : string list) : string * (test_attribute list) = - let is_attr (line : string) : bool = length line > 0 && ':' == get line 0 in - let test_name = List.find (fun line -> line |> is_attr |> not) header in - let test_attrs = header |> List.filter is_attr |> List.map str_to_test_attribute in - (test_name, test_attrs) + let is_attr = String.starts_with ~prefix: ":" in + let (test_attrs, test_name) = List.partition is_attr header in + (hd test_name, test_attrs |> List.map str_to_test_attribute) (** Given the body of a test as a string, split it into input and expected output; raise an error if this is not possible. From ee66bedcb5163be109d7dc32083451eb56d9d4c4 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Wed, 23 Oct 2024 08:45:57 -0400 Subject: [PATCH 19/28] Add test deps to dune-project Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- Makefile | 2 +- dune-project | 4 +++- tlapm.opam | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 95065820..c23f1454 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ opam-deps-opt: opam install --yes eio_main lsp opam-deps-dev: - opam install --yes ocamlformat ocaml-lsp-server earlybird ppx_deriving ounit2 + opam install --yes ocamlformat ocaml-lsp-server earlybird build: dune build diff --git a/dune-project b/dune-project index 5f370468..71b7406d 100644 --- a/dune-project +++ b/dune-project @@ -48,7 +48,9 @@ camlzip re2 ppx_inline_test - ppx_assert) + ppx_assert + ppx_deriving + ounit2) (depopts lsp ; https://github.com/ocaml/ocaml-lsp eio_main)) ; https://github.com/ocaml-multicore/eio, only available on OCaml version >= 5. diff --git a/tlapm.opam b/tlapm.opam index 94033dfb..cc5575ee 100644 --- a/tlapm.opam +++ b/tlapm.opam @@ -36,6 +36,8 @@ depends: [ "re2" "ppx_inline_test" "ppx_assert" + "ppx_deriving" + "ounit2" "odoc" {with-doc} ] depopts: ["lsp" "eio_main"] From a8b5f6a47746bfbba13ab1133d175096e974a56a Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Wed, 23 Oct 2024 08:56:28 -0400 Subject: [PATCH 20/28] Disambiguated parser tests filename Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/dune | 2 +- test/parser/{test_parser.ml => parser_tests.ml} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test/parser/{test_parser.ml => parser_tests.ml} (100%) diff --git a/test/parser/dune b/test/parser/dune index 80280744..edec5139 100644 --- a/test/parser/dune +++ b/test/parser/dune @@ -1,5 +1,5 @@ (test - (name test_parser) + (name parser_tests) (modes exe) (libraries tlapm_lib ounit2 sexplib) (deps (glob_files_rec syntax_corpus/*)) diff --git a/test/parser/test_parser.ml b/test/parser/parser_tests.ml similarity index 100% rename from test/parser/test_parser.ml rename to test/parser/parser_tests.ml From 9a8d99d859b83972364aca5f6c00261a54cfd97a Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Wed, 23 Oct 2024 10:50:58 -0400 Subject: [PATCH 21/28] Formalized test filter predicate Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/parser_tests.ml | 88 +++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 37 deletions(-) diff --git a/test/parser/parser_tests.ml b/test/parser/parser_tests.ml index 0987aa58..eec96321 100644 --- a/test/parser/parser_tests.ml +++ b/test/parser/parser_tests.ml @@ -37,7 +37,7 @@ let test_summary_init = { (** Runs a given syntax test by determining its type then sending the input into the TLAPM parser. - @param should_fail Whether this test should fail due to a TLAPM bug. + @param expect_failure Whether this test should fail due to a TLAPM bug. @param test Information about the test itself. @return Whether the test succeeded. *) @@ -49,19 +49,19 @@ let run_test (test : syntax_test) : bool = (** Controls run of a given syntax test. Checks whether test should be skipped and whether it is expected to fail, then runs test and returns summary. - @param should_fail Whether this test should fail due to a TLAPM bug. + @param expect_failure Whether this test should fail due to a TLAPM bug. @param acc Accumulation variable for test summarization. @param test Information about the test itself. @return Test run summary. *) let control_test_run - (should_fail : syntax_test -> bool) + (expect_failure : syntax_test -> bool) (acc : test_run_summary) (test : syntax_test) : test_run_summary = let acc = {acc with total = acc.total + 1} in if test.skip then {acc with skipped = acc.skipped + 1} else - if run_test test = should_fail test + if run_test test = expect_failure test then {acc with failed = acc.failed + 1; failures = test.info :: acc.failures} else {acc with succeeded = acc.succeeded + 1} @@ -69,54 +69,68 @@ let control_test_run the tests encoded in those files, filter them as appropriate, then run them all and collect the results. @param path Path to the directory containing the corpus of syntax tests. - @param should_fail Whether a test should fail due to a TLAPM bug. + @param expect_failure Whether a test should fail due to a TLAPM bug. @param filter_predicate Whether to actually execute a test. @return Accumulated summary of all test executions. *) let run_test_corpus (path : string) - (should_fail : syntax_test -> bool) + (expect_failure : syntax_test -> bool) (filter_pred : syntax_test -> bool) : test_run_summary = path |> get_all_tests_under |> List.filter filter_pred - |> List.fold_left (control_test_run should_fail) test_summary_init + |> List.fold_left (control_test_run expect_failure) test_summary_init -(** Names of tests that are known to fail due to TLAPM parser bugs. *) -let failing_test_names = [ - "Invalid parentheses use in jlist"; - "Bounded Quantification With Tuples"; - "Mixed Bounded Quantification With Tuples"; - "Bounded CHOOSE With Tuple"; - "Unbounded CHOOSE With Tuple"; - "Cartesian Product Infix Op Definition"; - "Cartesian Product Declaration as Parameter"; - "Infix Minus as Parameter"; - "RECURSIVE inside LET/IN"; - "Conjlist with RECURSIVE in LET/IN"; - "Disjlist with RECURSIVE in LET/IN"; - "Use & Hide Declarations"; - "Label interfering with precedence"; - "Bitfield Number Formats"; - "Proof by Module References"; - "Proof by QED with implicit step level"; - "Proof with INSTANCE step type"; - "Proof Containing Jlist"; - "Prefix Operator References"; - "Mistaken Set Filter Test"; - "Set Filter with Tuple"; - "Proof Step ID Subexpression Tree Navigation"; -] +(** Names of tests that are known to fail due to TLAPM parser bugs. + @param test Information about the test. + @return Whether the test is expected to fail. +*) +let expect_failure (test : syntax_test) : bool = + List.mem test.info.name [ + "Invalid parentheses use in jlist"; + "Bounded Quantification With Tuples"; + "Mixed Bounded Quantification With Tuples"; + "Bounded CHOOSE With Tuple"; + "Unbounded CHOOSE With Tuple"; + "Cartesian Product Infix Op Definition"; + "Cartesian Product Declaration as Parameter"; + "Infix Minus as Parameter"; + "RECURSIVE inside LET/IN"; + "Conjlist with RECURSIVE in LET/IN"; + "Disjlist with RECURSIVE in LET/IN"; + "Use & Hide Declarations"; + "Label interfering with precedence"; + "Bitfield Number Formats"; + "Proof by Module References"; + "Proof by QED with implicit step level"; + "Proof with INSTANCE step type"; + "Proof Containing Jlist"; + "Prefix Operator References"; + "Mistaken Set Filter Test"; + "Set Filter with Tuple"; + "Proof Step ID Subexpression Tree Navigation"; + ] + +(** Filter predicate to control which tests to run. + @param name Optional; a test name to filter on. + @return Predicate matching all tests or tests with given name. +*) +let should_run ?name test = + match name with + | Some name -> String.equal test.info.name name + | None -> true (** The top-level test; runs all syntax tests, prints summary, then fails with an assertion if any tests failed. *) let () = - (* Keeping this around because it's useful when wanting to run a single test. *) - (*let filter_pred = fun test -> String.equal test.info.name "Proof Containing Jlist" in*) - let filter_pred = fun _ -> true in - let should_fail = fun (test : syntax_test) -> List.mem test.info.name failing_test_names in - let test_results = run_test_corpus "syntax_corpus" should_fail filter_pred in + let test_results = + run_test_corpus + "syntax_corpus" + expect_failure + (should_run (*~name:"Set Filter with Tuple"*)) + in print_endline (show_test_run_summary test_results); assert_equal 0 test_results.failed; \ No newline at end of file From 894bd9cf2a3f266e6b99c1f0da944d8f5b4b6bee Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Thu, 24 Oct 2024 09:56:20 -0400 Subject: [PATCH 22/28] Added syntax tests for \forall and \exists Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/parser_tests.ml | 1 + test/parser/syntax_corpus/quantification.txt | 56 +++++++++++++++++++ .../rejected_syntax/blank_file.txt | 6 -- 3 files changed, 57 insertions(+), 6 deletions(-) delete mode 100644 test/parser/syntax_corpus/rejected_syntax/blank_file.txt diff --git a/test/parser/parser_tests.ml b/test/parser/parser_tests.ml index eec96321..91b2b196 100644 --- a/test/parser/parser_tests.ml +++ b/test/parser/parser_tests.ml @@ -89,6 +89,7 @@ let run_test_corpus *) let expect_failure (test : syntax_test) : bool = List.mem test.info.name [ + "Verbose Bounded Quantification"; "Invalid parentheses use in jlist"; "Bounded Quantification With Tuples"; "Mixed Bounded Quantification With Tuples"; diff --git a/test/parser/syntax_corpus/quantification.txt b/test/parser/syntax_corpus/quantification.txt index a85cea40..13533238 100644 --- a/test/parser/syntax_corpus/quantification.txt +++ b/test/parser/syntax_corpus/quantification.txt @@ -54,6 +54,62 @@ op == \E x, y \in Nat, a, b \in Int : TRUE ) (double_line))) +==============================||| +Verbose Bounded Quantification +==============================||| + +---- MODULE Test ---- +op == \forall x, y \in Nat, z \in Int, a, b, c \in Real : FALSE +op == \exists x, y \in Nat, a, b \in Int : TRUE +==== + +------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) + definition: (bounded_quantification + quantifier: (forall) + bound: (quantifier_bound + intro: (identifier) + intro: (identifier) + (set_in) + set: (nat_number_set) + ) + bound: (quantifier_bound + intro: (identifier) + (set_in) + set: (int_number_set) + ) + bound: (quantifier_bound + intro: (identifier) + intro: (identifier) + intro: (identifier) + (set_in) + set: (real_number_set) + ) + expression: (boolean) + ) + ) + (operator_definition name: (identifier) (def_eq) + definition: (bounded_quantification + quantifier: (exists) + bound: (quantifier_bound + intro: (identifier) + intro: (identifier) + (set_in) + set: (nat_number_set) + ) + bound: (quantifier_bound + intro: (identifier) + intro: (identifier) + (set_in) + set: (int_number_set) + ) + expression: (boolean) + ) + ) +(double_line))) + ==============================||| Bounded Quantification With Tuples ==============================||| diff --git a/test/parser/syntax_corpus/rejected_syntax/blank_file.txt b/test/parser/syntax_corpus/rejected_syntax/blank_file.txt deleted file mode 100644 index 246493c0..00000000 --- a/test/parser/syntax_corpus/rejected_syntax/blank_file.txt +++ /dev/null @@ -1,6 +0,0 @@ -=============||| -Blank File Parse Error -:error -=============||| --------------||| - From 7fd6b9b0c18a181c510d13bc08578faaf90647a3 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Thu, 24 Oct 2024 12:33:32 -0400 Subject: [PATCH 23/28] Tag test failures with github issues Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/parser_tests.ml | 42 +++++++--- test/parser/syntax_corpus/proofs.txt | 8 +- test/parser/syntax_corpus/recursive.txt | 18 +++++ test/parser/syntax_corpus/sets.txt | 11 +++ test/parser/syntax_corpus/use_or_hide.txt | 97 ++++++++++++++++++++++- 5 files changed, 160 insertions(+), 16 deletions(-) diff --git a/test/parser/parser_tests.ml b/test/parser/parser_tests.ml index 91b2b196..92414908 100644 --- a/test/parser/parser_tests.ml +++ b/test/parser/parser_tests.ml @@ -89,28 +89,48 @@ let run_test_corpus *) let expect_failure (test : syntax_test) : bool = List.mem test.info.name [ - "Verbose Bounded Quantification"; - "Invalid parentheses use in jlist"; + (* https://github.com/tlaplus/tlapm/issues/11 *) "Bounded Quantification With Tuples"; "Mixed Bounded Quantification With Tuples"; "Bounded CHOOSE With Tuple"; "Unbounded CHOOSE With Tuple"; - "Cartesian Product Infix Op Definition"; - "Cartesian Product Declaration as Parameter"; - "Infix Minus as Parameter"; + "Set Filter with Tuple"; + + (* https://github.com/tlaplus/tlapm/issues/54#issuecomment-2435515180 *) "RECURSIVE inside LET/IN"; "Conjlist with RECURSIVE in LET/IN"; "Disjlist with RECURSIVE in LET/IN"; - "Use & Hide Declarations"; - "Label interfering with precedence"; + + (* https://github.com/tlaplus/tlapm/issues/160 *) + "Verbose Bounded Quantification"; + + (* https://github.com/tlaplus/tlapm/issues/161 *) + "Infix Minus as Parameter"; + "Prefix Operator References"; + + (* https://github.com/tlaplus/tlapm/issues/162 *) + "Cartesian Product Infix Op Definition"; + "Cartesian Product Declaration as Parameter"; + + (* https://github.com/tlaplus/tlapm/issues/163 *) "Bitfield Number Formats"; - "Proof by Module References"; + + (* https://github.com/tlaplus/tlapm/issues/164 *) + "Mistaken Set Filter Test"; + + (* https://github.com/tlaplus/tlapm/issues/165 *) "Proof by QED with implicit step level"; + + (* https://github.com/tlaplus/tlapm/issues/166 *) + "Use & Hide Modules"; + "Proof by Module References"; + + (* https://github.com/tlaplus/tlapm/issues/167 *) "Proof with INSTANCE step type"; + + "Invalid parentheses use in jlist"; + "Label interfering with precedence"; "Proof Containing Jlist"; - "Prefix Operator References"; - "Mistaken Set Filter Test"; - "Set Filter with Tuple"; "Proof Step ID Subexpression Tree Navigation"; ] diff --git a/test/parser/syntax_corpus/proofs.txt b/test/parser/syntax_corpus/proofs.txt index 10f069cc..56a2f6fc 100644 --- a/test/parser/syntax_corpus/proofs.txt +++ b/test/parser/syntax_corpus/proofs.txt @@ -183,8 +183,10 @@ Proof by QED with implicit step level ===============================||| ---- MODULE Test ---- -COROLLARY TRUE -PROOF <1>a QED BY <1>a, <*>b +THEOREM TRUE +PROOF + <1>a TRUE + <1>b QED BY <*>a ==== -------------------------------||| @@ -192,10 +194,10 @@ PROOF <1>a QED BY <1>a, <*>b (source_file (module (header_line) (identifier) (header_line) (theorem (boolean) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (boolean))) (qed_step (proof_step_id (level) (name)) (terminal_proof (use_body (use_body_expr (proof_step_ref (level) (name)) - (proof_step_ref (level) (name)) ))) ) ) diff --git a/test/parser/syntax_corpus/recursive.txt b/test/parser/syntax_corpus/recursive.txt index 2f4f264d..31de4ba2 100644 --- a/test/parser/syntax_corpus/recursive.txt +++ b/test/parser/syntax_corpus/recursive.txt @@ -12,6 +12,24 @@ RECURSIVE f(_) (recursive_declaration (operator_declaration (identifier) (placeholder))) (double_line))) +=============||| +Recursive Declaration With Reference +=============||| + +---- MODULE Test ---- +RECURSIVE f(_) +f(x) == f(x) +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (recursive_declaration (operator_declaration name: (identifier) parameter: (placeholder))) + (operator_definition name: (identifier) parameter: (identifier) (def_eq) definition: + (bound_op name: (identifier_ref) parameter: (identifier_ref)) + ) +(double_line))) + =============||| Recursive Declaration Without Parameters =============||| diff --git a/test/parser/syntax_corpus/sets.txt b/test/parser/syntax_corpus/sets.txt index 1013fb86..6a9b90d6 100644 --- a/test/parser/syntax_corpus/sets.txt +++ b/test/parser/syntax_corpus/sets.txt @@ -162,6 +162,17 @@ op == {x \in Nat : P(x)} ) (double_line))) +======================||| +Set Filter With Too Many Quantifiers +:error +======================||| + +---- MODULE Test ---- +op == {x \in Nat, y \in Int : P(x, y)} +==== + +----------------------||| + ======================||| Set Filter with Tuple ======================||| diff --git a/test/parser/syntax_corpus/use_or_hide.txt b/test/parser/syntax_corpus/use_or_hide.txt index 1736a64f..7503f284 100644 --- a/test/parser/syntax_corpus/use_or_hide.txt +++ b/test/parser/syntax_corpus/use_or_hide.txt @@ -1,5 +1,99 @@ =============||| -Use & Hide Declarations +Simple Use or Hide +=============||| + +---- MODULE Test ---- +USE X, Y +HIDE X +HIDE Y +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (use_or_hide (use_body + (use_body_expr + (identifier_ref) + (identifier_ref) + ) + )) + (use_or_hide (use_body + (use_body_expr + (identifier_ref) + ) + )) + (use_or_hide (use_body + (use_body_expr + (identifier_ref) + ) + )) +(double_line))) + +=============||| +Hide Multiple Definitions +=============||| + +---- MODULE Test ---- +HIDE X, Y +HIDE DEFS X, Y +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (use_or_hide (use_body + (use_body_expr + (identifier_ref) + (identifier_ref) + ) + )) + (use_or_hide (use_body + (use_body_def + (identifier_ref) + (identifier_ref) + ) + )) +(double_line))) + +=============||| +Complicated Use & Hide +=============||| + +---- MODULE Test ---- +USE x, 1 + 3 +HIDE DEFS -., *, ^+ +USE x DEF z, x +==== + +-------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (use_or_hide (use_body + (use_body_expr + (identifier_ref) + (bound_infix_op lhs: (nat_number) symbol: (plus) rhs: (nat_number)) + ) + )) + (use_or_hide (use_body + (use_body_def + (prefix_op_symbol (negative)) + (infix_op_symbol (mul)) + (postfix_op_symbol (sup_plus)) + ) + )) + (use_or_hide (use_body + (use_body_expr + (identifier_ref) + ) + (use_body_def + (identifier_ref) + (identifier_ref) + ) + )) +(double_line))) + +=============||| +Use & Hide Modules =============||| ---- MODULE Test ---- @@ -37,4 +131,3 @@ USE x, MODULE M DEF MODULE M, x ) )) (double_line))) - From 7ab6f54d0d0c4eb24e49b0ad067d2bb8eda9fed6 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Thu, 24 Oct 2024 18:10:18 -0400 Subject: [PATCH 24/28] Added failing test for parameterized refinement in subscript Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/parser_tests.ml | 8 ++++++- .../parser/syntax_corpus/step_expressions.txt | 24 +++++++++++++++++++ test/parser/syntax_corpus/subexpressions.txt | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/test/parser/parser_tests.ml b/test/parser/parser_tests.ml index 92414908..8be57dea 100644 --- a/test/parser/parser_tests.ml +++ b/test/parser/parser_tests.ml @@ -128,10 +128,16 @@ let expect_failure (test : syntax_test) : bool = (* https://github.com/tlaplus/tlapm/issues/167 *) "Proof with INSTANCE step type"; + (* https://github.com/tlaplus/tlapm/issues/168 *) "Invalid parentheses use in jlist"; + + (* https://github.com/tlaplus/tlapm/issues/169 *) "Label interfering with precedence"; + + (* https://github.com/tlaplus/tlapm/issues/156 *) + "Step Expression With Parameterized Subscript"; + "Proof Containing Jlist"; - "Proof Step ID Subexpression Tree Navigation"; ] (** Filter predicate to control which tests to run. diff --git a/test/parser/syntax_corpus/step_expressions.txt b/test/parser/syntax_corpus/step_expressions.txt index 146cf333..7a02b475 100644 --- a/test/parser/syntax_corpus/step_expressions.txt +++ b/test/parser/syntax_corpus/step_expressions.txt @@ -38,6 +38,30 @@ op == <>_<> ) (double_line))) +=============||| +Step Expression With Parameterized Subscript +=============||| + +---- MODULE Test ---- +op == [A]_M(S)!vars +==== + +--------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (step_expr_or_stutter + (identifier_ref) + (prefixed_op + prefix: (subexpr_prefix (subexpr_component + (bound_op name: (identifier_ref) parameter: (identifier_ref)) + )) + op: (identifier_ref) + ) + ) + ) +(double_line))) + =============||| Step Expressions with Jlist =============||| diff --git a/test/parser/syntax_corpus/subexpressions.txt b/test/parser/syntax_corpus/subexpressions.txt index a7de2733..c463dd00 100644 --- a/test/parser/syntax_corpus/subexpressions.txt +++ b/test/parser/syntax_corpus/subexpressions.txt @@ -53,7 +53,7 @@ Proof Step ID Subexpression Tree Navigation ---- MODULE Test ---- COROLLARY TRUE -PROOF <1>a QED BY <1>a!<>!3!(x, y)!:!@, <*>a!<>!3!(x, y)!:!@ +PROOF <1>a QED BY <1>a!<>!3!(x, y)!:!@, <1>a!<>!3!(x, y)!:!@ ==== -------------------------------||| From 1da7b5b667a35ffc48e7a0c3de0debb6157efb96 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Thu, 24 Oct 2024 19:43:27 -0400 Subject: [PATCH 25/28] Added failing tests for implicit proof names Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/parser_tests.ml | 6 ++- test/parser/syntax_corpus/proofs.txt | 61 +++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/test/parser/parser_tests.ml b/test/parser/parser_tests.ml index 8be57dea..5853b4e5 100644 --- a/test/parser/parser_tests.ml +++ b/test/parser/parser_tests.ml @@ -137,7 +137,9 @@ let expect_failure (test : syntax_test) : bool = (* https://github.com/tlaplus/tlapm/issues/156 *) "Step Expression With Parameterized Subscript"; - "Proof Containing Jlist"; + (* https://github.com/tlaplus/tlapm/issues/170 *) + "Implicit Proof Steps With Names"; + "Plus Proof Step With Name"; ] (** Filter predicate to control which tests to run. @@ -157,7 +159,7 @@ let () = run_test_corpus "syntax_corpus" expect_failure - (should_run (*~name:"Set Filter with Tuple"*)) + (should_run (*~name:"Proof Containing Jlist"*)) in print_endline (show_test_run_summary test_results); assert_equal 0 test_results.failed; \ No newline at end of file diff --git a/test/parser/syntax_corpus/proofs.txt b/test/parser/syntax_corpus/proofs.txt index 56a2f6fc..9e799ce2 100644 --- a/test/parser/syntax_corpus/proofs.txt +++ b/test/parser/syntax_corpus/proofs.txt @@ -211,11 +211,11 @@ Extra QED ---- MODULE Test ---- THEOREM x == TRUE -<*> P +<1> P <+> Q <*> QED <*> QED -<*> QED +<1> QED ==== -------------------------------||| @@ -533,26 +533,75 @@ COROLLARY TRUE ) (double_line))) +===============================||| +Implicit Proof Steps With Names +===============================||| + +---- MODULE Test ---- +THEOREM TRUE +<*>abc 1 +<*>def QED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + +===============================||| +Plus Proof Step With Name +===============================||| + +---- MODULE Test ---- +THEOREM TRUE +<1>abc 1 + <+>def 2 + <2>ghi QED +<1>jkl QED +==== + +-------------------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number) + (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step (nat_number))) + (qed_step (proof_step_id (level) (name))) + ) + )) + (qed_step (proof_step_id (level) (name))) + ) + ) +(double_line))) + ==============================||| Proof Containing Jlist ==============================||| ---- MODULE Test ---- THEOREM TRUE -<*>a1a... +<*> /\ 1 /\ \/ 2 - <+>b2b... WITNESS + <+> WITNESS \/ 3 \/ /\ 4, /\ \/ 5 /\ 6 - <*>c3c... QED BY + <*> QED BY /\ 7 /\ \/ 8, \/ /\ 9 \/ 10 -<*>d4d... QED BY +<*> QED BY \/ 11 \/ /\ 12, /\ \/ 13 From 0cc1d87555d0ecbce465cf134749e09d77393fc1 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Thu, 24 Oct 2024 19:52:59 -0400 Subject: [PATCH 26/28] Added test for proof level changes terminating jlists Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/syntax_corpus/proofs.txt | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/parser/syntax_corpus/proofs.txt b/test/parser/syntax_corpus/proofs.txt index 9e799ce2..c0712789 100644 --- a/test/parser/syntax_corpus/proofs.txt +++ b/test/parser/syntax_corpus/proofs.txt @@ -654,3 +654,41 @@ THEOREM TRUE )) (double_line))) + +==============================||| +Proof Level Change Terminates Jlist +==============================||| + +---- MODULE Test ---- +THEOREM TRUE +<*> /\ 1 + /\ 2 + <+> QED BY + \/ 1 + \/ 2 + <*> QED +==== + +------------------------------||| + + +(source_file (module (header_line) (identifier) (header_line) + (theorem (boolean) (non_terminal_proof + (proof_step (proof_step_id (level) (name)) (suffices_proof_step + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + (non_terminal_proof + (qed_step (proof_step_id (level) (name)) (terminal_proof (use_body (use_body_expr + (disj_list + (disj_item (bullet_disj) (nat_number)) + (disj_item (bullet_disj) (nat_number)) + ) + )))) + ) + )) + (qed_step (proof_step_id (level) (name))) + )) +(double_line))) + From 86a046e5ab0b1af22bf3fa885ce4339655f8a093 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Tue, 29 Oct 2024 12:26:53 -0400 Subject: [PATCH 27/28] Added failing parse tests from SANY Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/parser_tests.ml | 12 ++ test/parser/syntax_corpus/case.txt | 107 ++++++++++ test/parser/syntax_corpus/jlist.txt | 10 +- test/parser/syntax_corpus/labels.txt | 12 ++ test/parser/syntax_corpus/let_in.txt | 12 ++ test/parser/syntax_corpus/modules.txt | 56 ++++- test/parser/syntax_corpus/number.txt | 13 ++ test/parser/syntax_corpus/operators.txt | 192 ++++++++++++++++++ test/parser/syntax_corpus/proofs.txt | 15 +- test/parser/syntax_corpus/quantification.txt | 11 + test/parser/syntax_corpus/regression.txt | 63 ------ test/parser/syntax_corpus/sets.txt | 26 ++- .../parser/syntax_corpus/step_expressions.txt | 104 +++++++++- test/parser/syntax_corpus/string.txt | 36 ++++ test/parser/syntax_corpus/unit.txt | 86 ++++++++ 15 files changed, 679 insertions(+), 76 deletions(-) delete mode 100644 test/parser/syntax_corpus/regression.txt diff --git a/test/parser/parser_tests.ml b/test/parser/parser_tests.ml index 5853b4e5..744dd269 100644 --- a/test/parser/parser_tests.ml +++ b/test/parser/parser_tests.ml @@ -140,6 +140,18 @@ let expect_failure (test : syntax_test) : bool = (* https://github.com/tlaplus/tlapm/issues/170 *) "Implicit Proof Steps With Names"; "Plus Proof Step With Name"; + + (* https://github.com/tlaplus/tlapm/issues/172 *) + "Invalid LOCAL Declaration of THEOREM"; + "Invalid LOCAL Declaration of ASSUME"; + "Invalid LOCAL Declaration of USE"; + + (* https://github.com/tlaplus/tlapm/issues/173 *) + "Decimal No Leading Zero (GH tlaplus/tlaplus #596)"; + + (* https://github.com/tlaplus/tlapm/issues/173 *) + "Nonfix Submodule Excl (GH tlaplus/tlaplus #GH884)"; + "Nonfix Double Exclamation Operator (GH TSTLA #GH97, GH tlaplus/tlaplus #884)"; ] (** Filter predicate to control which tests to run. diff --git a/test/parser/syntax_corpus/case.txt b/test/parser/syntax_corpus/case.txt index 516b7557..b3ce418f 100644 --- a/test/parser/syntax_corpus/case.txt +++ b/test/parser/syntax_corpus/case.txt @@ -215,3 +215,110 @@ op == ) (double_line))) +=============||| +CASE in jlist with weird indentation +=============||| + +---- MODULE Test ---- +op == + /\ CASE 1 -> + /\ 2 + /\ 3 + [] 4 -> 5 + /\ 6 +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item + (bullet_conj) + (case + (case_arm (nat_number) (case_arrow) + (conj_list + (conj_item (bullet_conj) (nat_number)) + (conj_item (bullet_conj) (nat_number)) + ) + ) + (case_box) + (case_arm (nat_number) (case_arrow) (nat_number)) + ) + ) + (conj_item (bullet_conj) (nat_number)) + ) + ) +(double_line))) + +===================||| +Conjunct Inside Ambiguous Case (GH tlaplus/tlaplus #487) +===================||| + +---- MODULE Test ---- +op == + CASE A -> + /\ CASE B -> C + [] D -> E + [] F -> G + +op2 == + CASE H -> + /\ CASE I -> J + [] OTHER -> K + [] L -> M + +op3 == + CASE N -> + /\ CASE O -> P + [] Q -> R + /\ S + [] T -> U +==== + +-------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (case + (case_arm (identifier_ref) (case_arrow) (conj_list (conj_item (bullet_conj) + (case + (case_arm (identifier_ref) (case_arrow) (identifier_ref)) + (case_box) + (case_arm (identifier_ref) (case_arrow) (identifier_ref)) + ) + ))) + (case_box) + (case_arm (identifier_ref) (case_arrow) (identifier_ref)) + ) + ) + (operator_definition (identifier) (def_eq) + (case + (case_arm (identifier_ref) (case_arrow) (conj_list (conj_item (bullet_conj) + (case + (case_arm (identifier_ref) (case_arrow) (identifier_ref)) + (case_box) + (other_arm (case_arrow) (identifier_ref)) + ) + ))) + (case_box) + (case_arm (identifier_ref) (case_arrow) (identifier_ref)) + ) + ) + (operator_definition (identifier) (def_eq) + (case + (case_arm (identifier_ref) (case_arrow) (conj_list + (conj_item (bullet_conj) + (case + (case_arm (identifier_ref) (case_arrow) (identifier_ref)) + (case_box) + (case_arm (identifier_ref) (case_arrow) (identifier_ref)) + ) + ) + (conj_item (bullet_conj) (identifier_ref)) + )) + (case_box) + (case_arm (identifier_ref) (case_arrow) (identifier_ref)) + ) + ) +(double_line))) diff --git a/test/parser/syntax_corpus/jlist.txt b/test/parser/syntax_corpus/jlist.txt index 18dfa258..3f44adda 100644 --- a/test/parser/syntax_corpus/jlist.txt +++ b/test/parser/syntax_corpus/jlist.txt @@ -8,7 +8,7 @@ op == /\ 2 \/ 3 ==== - + -------------||| (source_file (module (header_line) (identifier) (header_line) @@ -34,7 +34,7 @@ op == \/ 2 /\ 3 ==== - + -------------||| (source_file (module (header_line) (identifier) (header_line) @@ -65,7 +65,7 @@ opB == \/ 2 /\ 3 ==== - + -------------||| (source_file (module (header_line) (identifier) (header_line) @@ -104,7 +104,7 @@ op == /\ 5 /\ 6 ==== - + -------------||| (source_file (module (header_line) (identifier) (header_line) @@ -150,7 +150,7 @@ disj == \/ B := C \/ D ::= E ==== - + -------------||| (source_file (module (header_line) (identifier) (header_line) diff --git a/test/parser/syntax_corpus/labels.txt b/test/parser/syntax_corpus/labels.txt index 43df6cc6..e1608b91 100644 --- a/test/parser/syntax_corpus/labels.txt +++ b/test/parser/syntax_corpus/labels.txt @@ -68,3 +68,15 @@ op == a * lab :: b + c ==== -------------||| + +=============||| +Label with Subexpression Prefix (GH tlaplus/tlaplus #885) +:error +=============||| + +---- MODULE Test ---- +op == \A x \in {} : A!B!lbl(x) :: x +==== + +-------------||| + diff --git a/test/parser/syntax_corpus/let_in.txt b/test/parser/syntax_corpus/let_in.txt index 4c76b0e7..877a71d9 100644 --- a/test/parser/syntax_corpus/let_in.txt +++ b/test/parser/syntax_corpus/let_in.txt @@ -251,3 +251,15 @@ op == ) ) (double_line))) + +=============||| +Invalid Use of LOCAL in LET/IN +:error +=============||| + +---- MODULE LocalInLetIn ---- +foo == LET LOCAL bar == 5 IN TRUE +==== + +-------------||| + diff --git a/test/parser/syntax_corpus/modules.txt b/test/parser/syntax_corpus/modules.txt index 0f41a306..ce8868d0 100644 --- a/test/parser/syntax_corpus/modules.txt +++ b/test/parser/syntax_corpus/modules.txt @@ -26,24 +26,32 @@ EXTENDS M1, M2, M3 (double_line))) =============||| -Nested modules +Nested Modules =============||| ----- MODULE Test ---- +---- MODULE Outer ---- ---- MODULE Inner ---- +---- MODULE Inner2 ---- +---- MODULE Inner3 ---- +==== +==== ==== ==== -------------||| (source_file - (module (header_line) (identifier) (header_line) - (module (header_line) (identifier) (header_line) (double_line)) + (module (header_line) name: (identifier) (header_line) + (module (header_line) name: (identifier) (header_line) + (module (header_line) name: (identifier) (header_line) + (module (header_line) name: (identifier) (header_line) (double_line)) + (double_line)) + (double_line)) (double_line)) ) =============||| -Multiple Nested modules +Sequential Nested modules =============||| ---- MODULE Test ---- @@ -62,6 +70,44 @@ Multiple Nested modules (double_line)) ) +=============||| +Definition After Nested Module +=============||| + +---- MODULE Test ---- +---- MODULE Inner ---- +==== +op == x +==== + +-------------||| + +(source_file + (module (header_line) name: (identifier) (header_line) + (module (header_line) name: (identifier) (header_line) (double_line)) + (operator_definition name: (identifier) (def_eq) definition: (identifier_ref)) + (double_line)) +) + +=============||| +Named Theorem After Submodule (GH tlaplus/tlaplus #430) +=============||| + +---- MODULE Test ---- +---- MODULE Inner ---- +==== +THEOREM T == TRUE +==== + +--------------||| + +(source_file + (module (header_line) name: (identifier) (header_line) + (module (header_line) name: (identifier) (header_line) (double_line)) + (theorem name: (identifier) (def_eq) statement: (boolean)) + (double_line)) +) + =============||| Blank File Parse Error :error diff --git a/test/parser/syntax_corpus/number.txt b/test/parser/syntax_corpus/number.txt index a2016a81..fc74a025 100644 --- a/test/parser/syntax_corpus/number.txt +++ b/test/parser/syntax_corpus/number.txt @@ -89,3 +89,16 @@ op == A!Real )) (double_line))) +======================||| +Decimal No Leading Zero (GH tlaplus/tlaplus #596) +======================||| + +---- MODULE Test ---- +op == .5 +==== + +----------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) (real_number)) +(double_line))) diff --git a/test/parser/syntax_corpus/operators.txt b/test/parser/syntax_corpus/operators.txt index a8102537..74f55c68 100644 --- a/test/parser/syntax_corpus/operators.txt +++ b/test/parser/syntax_corpus/operators.txt @@ -77,3 +77,195 @@ op == f(LAMBDA x, y : x + y, LAMBDA x : 0) ) (double_line))) +=============||| +Nonfix Minus (GH tlaplus/tlaplus #GH884) +=============||| + +---- MODULE Test ---- +op == - (1,2) +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (bound_nonfix_op (infix_op_symbol (minus)) (nat_number) (nat_number)) + ) +(double_line))) + +=============||| +Nonfix Submodule Excl (GH tlaplus/tlaplus #GH884) +=============||| + +---- MODULE Test ---- +op == A!B!!!(x,y) +==== + +--------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref)) (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (excl)) (identifier_ref) (identifier_ref))) + ) +(double_line))) + +=============||| +Nonfix Double Exclamation Operator (GH TSTLA #GH97, GH tlaplus/tlaplus #884) +=============||| + +---- MODULE Test ---- +op == A!!!(1,2) +op == A!B!!!(1,2) +op == A!!! !!!(1,2) +op == !! !!! !!! !!! !!!(1,2) +op == A !! B +op == + /\ A + /\ B + !! C +op == + /\ A + /\ B + !! C +==== + +--------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (prefixed_op prefix: (subexpr_prefix (subexpr_component (identifier_ref))) op: + (bound_nonfix_op symbol: (infix_op_symbol (excl)) (nat_number) (nat_number))) + ) + (operator_definition name: (identifier) (def_eq) definition: + (prefixed_op + prefix: (subexpr_prefix + (subexpr_component (identifier_ref)) + (subexpr_component (identifier_ref)) + ) + op: (bound_nonfix_op symbol: (infix_op_symbol (excl)) (nat_number) (nat_number))) + ) + (operator_definition name: (identifier) (def_eq) definition: + (prefixed_op + prefix: (subexpr_prefix + (subexpr_component (identifier_ref)) + (subexpr_component (infix_op_symbol (excl))) + ) + op: (bound_nonfix_op symbol: (infix_op_symbol (excl)) (nat_number) (nat_number))) + ) + (operator_definition name: (identifier) (def_eq) definition: + (prefixed_op + prefix: (subexpr_prefix + (subexpr_component (infix_op_symbol (excl))) + (subexpr_component (infix_op_symbol (excl))) + (subexpr_component (infix_op_symbol (excl))) + (subexpr_component (infix_op_symbol (excl))) + ) + op: (bound_nonfix_op symbol: (infix_op_symbol (excl)) (nat_number) (nat_number))) + ) + (operator_definition name: (identifier) (def_eq) definition: + (bound_infix_op lhs: (identifier_ref) symbol: (excl) rhs: (identifier_ref)) + ) + (operator_definition name: (identifier) (def_eq) definition: + (bound_infix_op + lhs: (conj_list + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) (identifier_ref)) + ) + symbol: (excl) + rhs: (identifier_ref) + ) + ) + (operator_definition name: (identifier) (def_eq) definition: + (conj_list + (conj_item (bullet_conj) (identifier_ref)) + (conj_item (bullet_conj) + (bound_infix_op lhs: (identifier_ref) symbol: (excl) rhs: (identifier_ref)) + ) + ) + ) +(double_line))) + +=============||| +Operators with Colon Prefixes & Jlists (GH TSTLA #87) +=============||| + +---- MODULE Test ---- +op == + /\ A :> B + /\ A := B + /\ A ::= B + /\ A :: B + /\ A +==== + +--------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (conj_list + (conj_item (bullet_conj) + (bound_infix_op (identifier_ref) (map_to) (identifier_ref)) + ) + (conj_item (bullet_conj) + (bound_infix_op (identifier_ref) (assign) (identifier_ref)) + ) + (conj_item (bullet_conj) + (bound_infix_op (identifier_ref) (bnf_rule) (identifier_ref)) + ) + (conj_item (bullet_conj) + (label (identifier) (label_as) (identifier_ref)) + ) + (conj_item (bullet_conj) (identifier_ref)) + ) + ) +(double_line))) + +=============||| +Junct Tokens as Higher-Level Parameters (GH TSTLA #96) +=============||| + +---- MODULE Test ---- +op == op(/\, x, /\) +op == op(\/, x, \/) +==== + +--------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (bound_op name: (identifier_ref) + parameter: (infix_op_symbol (land)) + parameter: (identifier_ref) + parameter: (infix_op_symbol (land)) + ) + ) + (operator_definition name: (identifier) (def_eq) definition: + (bound_op name: (identifier_ref) + parameter: (infix_op_symbol (lor)) + parameter: (identifier_ref) + parameter: (infix_op_symbol (lor)) + ) + ) +(double_line))) + +=============||| +Negative Prefix Op on RHS of Infix (GH tlaplus/tlaplus #893) +=============||| + +---- MODULE Test ---- +op == A & -B +==== + +--------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (bound_infix_op + lhs: (identifier_ref) + symbol: (amp) + rhs: (bound_prefix_op symbol: (negative) rhs: (identifier_ref)) + ) + ) +(double_line))) + diff --git a/test/parser/syntax_corpus/proofs.txt b/test/parser/syntax_corpus/proofs.txt index c0712789..1ae8758d 100644 --- a/test/parser/syntax_corpus/proofs.txt +++ b/test/parser/syntax_corpus/proofs.txt @@ -671,7 +671,6 @@ THEOREM TRUE ------------------------------||| - (source_file (module (header_line) (identifier) (header_line) (theorem (boolean) (non_terminal_proof (proof_step (proof_step_id (level) (name)) (suffices_proof_step @@ -692,3 +691,17 @@ THEOREM TRUE )) (double_line))) +==============================||| +Invalid Use of LOCAL in Proof +:error +==============================||| + +---- MODULE LocalInDefStep ---- +THEOREM TRUE +PROOF + <1> DEFINE LOCAL x == 4 + <1> QED +==== + +------------------------------||| + diff --git a/test/parser/syntax_corpus/quantification.txt b/test/parser/syntax_corpus/quantification.txt index 13533238..b230287b 100644 --- a/test/parser/syntax_corpus/quantification.txt +++ b/test/parser/syntax_corpus/quantification.txt @@ -236,6 +236,17 @@ op == \E <> \in Nat, a, b \in Int : TRUE ) (double_line))) +==============================||| +Empty Tuple Quantification (GH tlaplus/tlaplus #888) +:error +==============================||| + +---- MODULE Test ---- +op == \A <<>> \in STRING : TRUE +==== + +------------------------------||| + ==============================||| Unbounded Quantification ==============================||| diff --git a/test/parser/syntax_corpus/regression.txt b/test/parser/syntax_corpus/regression.txt deleted file mode 100644 index 1077f76c..00000000 --- a/test/parser/syntax_corpus/regression.txt +++ /dev/null @@ -1,63 +0,0 @@ -=============||| -Operators with Colon Prefixes & Jlists (GH87) -=============||| - ----- MODULE Test ---- -op == - /\ A :> B - /\ A := B - /\ A ::= B - /\ A :: B - /\ A -==== - ---------------||| - -(source_file (module (header_line) (identifier) (header_line) - (operator_definition (identifier) (def_eq) - (conj_list - (conj_item (bullet_conj) - (bound_infix_op (identifier_ref) (map_to) (identifier_ref)) - ) - (conj_item (bullet_conj) - (bound_infix_op (identifier_ref) (assign) (identifier_ref)) - ) - (conj_item (bullet_conj) - (bound_infix_op (identifier_ref) (bnf_rule) (identifier_ref)) - ) - (conj_item (bullet_conj) - (label (identifier) (label_as) (identifier_ref)) - ) - (conj_item (bullet_conj) (identifier_ref)) - ) - ) -(double_line))) - -=============||| -Junct Tokens as Higher-Level Parameters (TSTLA#GH96) -=============||| - ----- MODULE Test ---- -op == op(/\, x, /\) -op == op(\/, x, \/) -==== - ---------------||| - -(source_file (module (header_line) name: (identifier) (header_line) - (operator_definition name: (identifier) (def_eq) definition: - (bound_op name: (identifier_ref) - parameter: (infix_op_symbol (land)) - parameter: (identifier_ref) - parameter: (infix_op_symbol (land)) - ) - ) - (operator_definition name: (identifier) (def_eq) definition: - (bound_op name: (identifier_ref) - parameter: (infix_op_symbol (lor)) - parameter: (identifier_ref) - parameter: (infix_op_symbol (lor)) - ) - ) -(double_line))) - diff --git a/test/parser/syntax_corpus/sets.txt b/test/parser/syntax_corpus/sets.txt index 6a9b90d6..7c445da6 100644 --- a/test/parser/syntax_corpus/sets.txt +++ b/test/parser/syntax_corpus/sets.txt @@ -41,6 +41,30 @@ op == {x \in BOOLEAN, y \in STRING} ) (double_line))) +======================||| +Mistaken Set Filter Tuples Test +======================||| + +---- MODULE Test ---- + +op == {<> \in Nat} + +==== + +----------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (finite_set_literal + (bound_infix_op + lhs: (tuple_literal (langle_bracket) (identifier_ref) (identifier_ref) (rangle_bracket)) + symbol: (in) + rhs: (nat_number_set) + ) + ) + ) +(double_line))) + ======================||| Set Literal ======================||| @@ -240,7 +264,7 @@ op == { : /\ D /\ E - /\ F + /\ F } ==== diff --git a/test/parser/syntax_corpus/step_expressions.txt b/test/parser/syntax_corpus/step_expressions.txt index 7a02b475..f1fb3b41 100644 --- a/test/parser/syntax_corpus/step_expressions.txt +++ b/test/parser/syntax_corpus/step_expressions.txt @@ -73,7 +73,7 @@ op == [ /\ 2 ]_x -op == << +op == << /\ 1 /\ 2 >>_x @@ -99,3 +99,105 @@ op == << ) (double_line))) +=============||| +Various Valid Step Expressions +=============||| + +---- MODULE Test ---- +Prop == [][x = {1, 2}]_x +Prop == [][1 \in {1, 2}]_x +Prop == [][LET S == {1, 2} IN x \in S]_x +Prop == [][LET S == {1, 2} IN x \in {1, 2}]_x +Prop == [][TRUE /\ x \in {1, 2}]_x +==== + +--------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (bound_prefix_op symbol: (always) rhs: (step_expr_or_stutter + (bound_infix_op + lhs: (identifier_ref) + symbol: (eq) + rhs: (finite_set_literal (nat_number) (nat_number)) + ) + (identifier_ref) + )) + ) + (operator_definition name: (identifier) (def_eq) definition: + (bound_prefix_op symbol: (always) rhs: (step_expr_or_stutter + (bound_infix_op + lhs: (nat_number) + symbol: (in) + rhs: (finite_set_literal (nat_number) (nat_number)) + ) + (identifier_ref) + )) + ) + (operator_definition name: (identifier) (def_eq) definition: + (bound_prefix_op symbol: (always) rhs: (step_expr_or_stutter + (let_in + definitions: + (operator_definition + name: (identifier) (def_eq) + definition: (finite_set_literal (nat_number) (nat_number)) + ) + expression: (bound_infix_op lhs: (identifier_ref) symbol: (in) rhs: (identifier_ref)) + ) + (identifier_ref) + )) + ) + (operator_definition name: (identifier) (def_eq) definition: + (bound_prefix_op symbol: (always) rhs: (step_expr_or_stutter + (let_in + definitions: + (operator_definition + name: (identifier) (def_eq) + definition: (finite_set_literal (nat_number) (nat_number)) + ) + expression: + (bound_infix_op + lhs: (identifier_ref) + symbol: (in) + rhs: (finite_set_literal (nat_number) (nat_number)) + ) + ) + (identifier_ref) + )) + ) + (operator_definition name: (identifier) (def_eq) definition: + (bound_prefix_op symbol: (always) rhs: (step_expr_or_stutter + (bound_infix_op lhs: (boolean) symbol: (land) rhs: + (bound_infix_op + lhs: (identifier_ref) + symbol: (in) + rhs: (finite_set_literal (nat_number) (nat_number)) + ) + ) + (identifier_ref) + )) + ) +(double_line))) + +=============||| +Step Expression Requiring Lookahead +=============||| + +---- MODULE Test ---- +Prop == [][x \in {1, 2}]_x +==== + +--------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (operator_definition name: (identifier) (def_eq) definition: + (bound_prefix_op symbol: (always) rhs: (step_expr_or_stutter + (bound_infix_op + lhs: (identifier_ref) + symbol: (in) + rhs: (finite_set_literal (nat_number) (nat_number)) + ) + (identifier_ref) + )) + ) +(double_line))) diff --git a/test/parser/syntax_corpus/string.txt b/test/parser/syntax_corpus/string.txt index 2adf8670..1b28d761 100644 --- a/test/parser/syntax_corpus/string.txt +++ b/test/parser/syntax_corpus/string.txt @@ -52,6 +52,28 @@ op == <<"/\\", "\\/">> ) (double_line))) +==================||| +String with comment start +==================||| + +---- MODULE Test ---- +op == "\*" +==== + +------------------||| + +(source_file + (module + (header_line) + (identifier) + (header_line) + (operator_definition + (identifier) + (def_eq) + (string + (escape_char))) + (double_line))) + ==================||| String with block comment start ==================||| @@ -110,3 +132,17 @@ op == "\\ \n \r \f \t \"" ) (double_line))) +==================||| +String with Backtick +==================||| + +---- MODULE Test ---- +op == "foo ` bar" +==== + +------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) (string)) +(double_line))) + diff --git a/test/parser/syntax_corpus/unit.txt b/test/parser/syntax_corpus/unit.txt index 8029dfe0..a13b2751 100644 --- a/test/parser/syntax_corpus/unit.txt +++ b/test/parser/syntax_corpus/unit.txt @@ -111,3 +111,89 @@ INSTANCE M WITH ) (double_line))) +=============||| +LOCAL Declarations +=============||| + +---- MODULE Test ---- +LOCAL op == x +LOCAL f[x \in Nat] == x +LOCAL INSTANCE M +LOCAL M == INSTANCE M +==== + +-------------------------------||| + +(source_file (module (header_line) name: (identifier) (header_line) + (local_definition (operator_definition name: (identifier) (def_eq) definition: (identifier_ref))) + (local_definition (function_definition name: (identifier) (quantifier_bound intro: (identifier) (set_in) set: (nat_number_set)) (def_eq) definition: (identifier_ref))) + (local_definition (instance (identifier_ref))) + (local_definition (module_definition name: (identifier) (def_eq) definition: (instance (identifier_ref)))) +(double_line))) + +=============||| +Invalid LOCAL Declaration of CONSTANT +:error +=============||| + +---- MODULE Test ---- +LOCAL CONSTANT x +==== + +-------------------------------||| + +=============||| +Invalid LOCAL Declaration of VARIABLE +:error +=============||| + +---- MODULE Test ---- +LOCAL VARIABLE x +==== + +-------------------------------||| + +=============||| +Invalid LOCAL Declaration of THEOREM +:error +=============||| + +---- MODULE Test ---- +LOCAL THEOREM x +==== + +-------------------------------||| + +=============||| +Invalid LOCAL Declaration of RECURSIVE +:error +=============||| + +---- MODULE Test ---- +LOCAL RECURSIVE x +==== + +-------------------------------||| + +=============||| +Invalid LOCAL Declaration of ASSUME +:error +=============||| + +---- MODULE Test ---- +LOCAL ASSUME x +==== + +-------------------------------||| + +=============||| +Invalid LOCAL Declaration of USE +:error +=============||| + +---- MODULE Test ---- +LOCAL USE x +==== + +-------------------------------||| + From 8a9533b543eb3f2a44d6e95a7d1e814465db5421 Mon Sep 17 00:00:00 2001 From: Andrew Helwer <2n8rn1w1f@mozmail.com> Date: Thu, 31 Oct 2024 10:05:10 -0400 Subject: [PATCH 28/28] Added syntax tests for tuples Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com> --- test/parser/syntax_corpus/tuples.txt | 82 ++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/parser/syntax_corpus/tuples.txt diff --git a/test/parser/syntax_corpus/tuples.txt b/test/parser/syntax_corpus/tuples.txt new file mode 100644 index 00000000..b7d47307 --- /dev/null +++ b/test/parser/syntax_corpus/tuples.txt @@ -0,0 +1,82 @@ +======================||| +Empty Tuple +======================||| + +---- MODULE Test ---- +op == <<>> +==== + +----------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (tuple_literal (langle_bracket) (rangle_bracket)) + ) +(double_line))) + +======================||| +Nonempty Tuple +======================||| + +---- MODULE Test ---- +op == <<1, 2, 3, 4, 5>> +==== + +----------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (tuple_literal (langle_bracket) + (nat_number) + (nat_number) + (nat_number) + (nat_number) + (nat_number) + (rangle_bracket)) + ) +(double_line))) + +======================||| +Tuple of Identifiers +======================||| + +---- MODULE Test ---- +op == <> +==== + +----------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (tuple_literal (langle_bracket) + (identifier_ref) + (identifier_ref) + (identifier_ref) + (rangle_bracket)) + ) +(double_line))) + +======================||| +Nested Tuple +======================||| + +---- MODULE Test ---- +op == <<<>, <>>> +==== + +----------------------||| + +(source_file (module (header_line) (identifier) (header_line) + (operator_definition (identifier) (def_eq) + (tuple_literal (langle_bracket) + (tuple_literal (langle_bracket) + (identifier_ref) + (identifier_ref) + (rangle_bracket)) + (tuple_literal (langle_bracket) + (identifier_ref) + (rangle_bracket)) + (rangle_bracket)) + ) +(double_line))) +