tla-ts 0.0.9-dev.8298a52 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/compile.cjs +3 -3
- package/dist/compile.js +3 -3
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +52 -52
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +71 -10
- package/dist/index.d.ts +71 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +141 -29
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +539 -276
- package/src/cli/options.ts +10 -5
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +525 -216
- package/src/cli/typescript.ts +0 -3
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +237 -119
- package/src/errors.ts +56 -56
- package/src/evaluate.ts +567 -289
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +38 -31
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +4 -15
- package/src/liveness.ts +115 -47
- package/src/obligations/action.ts +4 -28
- package/src/obligations/anonymize.ts +84 -80
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +2 -19
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +1 -11
- package/src/obligations/index.ts +0 -11
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +1 -15
- package/src/obligations/normalize.ts +5 -24
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +3 -14
- package/src/obligations/source.ts +1 -21
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +8 -14
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +24 -33
- package/src/parallel.ts +24 -9
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- package/src/prover/decide-pool.ts +5 -10
- package/src/prover/deciders.ts +0 -4
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
- package/src/prover/isabelle/isar/method.ts +25 -38
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +15 -26
- package/src/prover/isabelle/isar/type-check.ts +11 -25
- package/src/prover/isabelle/provers/blast/blast.ts +10 -41
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +11 -25
- package/src/prover/isabelle/pure/bicompose.ts +16 -13
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +1 -9
- package/src/prover/isabelle/pure/drule.ts +24 -40
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +1 -14
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
- package/src/prover/isabelle/pure/rewriter.ts +26 -58
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +1 -31
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +6 -12
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +13 -36
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +9 -19
- package/src/prover/isabelle/tla/context.ts +8 -16
- package/src/prover/isabelle/tla/logic.ts +4 -11
- package/src/prover/isabelle/tla/simpdata.ts +46 -34
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +4 -36
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +0 -16
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +9 -36
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +0 -36
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +19 -26
- package/src/prover/smt/data.ts +51 -54
- package/src/prover/smt/encode.ts +14 -35
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +66 -101
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -143
- package/src/prover/smt/solver/auf-solver.ts +6 -39
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +4 -61
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +3 -34
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +6 -98
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +35 -130
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +14 -56
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +2 -36
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +3 -15
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +12 -69
- package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
- package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +3 -47
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
- package/src/prover/smt/solver/nlsat/solver.ts +7 -67
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -48
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
- package/src/prover/smt/solver/quantifier-manager.ts +1 -8
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +2 -37
- package/src/prover/smt/solver/solver.ts +1 -16
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +20 -25
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +12 -17
- package/src/prover/verdict.ts +0 -2
- package/src/prover/zenon/check/check.ts +0 -9
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +0 -5
- package/src/prover/zenon/check/relations.ts +0 -13
- package/src/prover/zenon/check/rewrites.ts +0 -6
- package/src/prover/zenon/check/sets.ts +0 -3
- package/src/prover/zenon/check/terms.ts +0 -17
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +0 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +1 -26
- package/src/prover/zenon/index-table.ts +17 -38
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +1 -29
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +0 -9
- package/src/prover/zenon/mltoll.ts +54 -76
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +2 -7
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +1 -17
- package/src/prover/zenon/tla/functions.ts +57 -29
- package/src/prover/zenon/tla/llproof.ts +63 -70
- package/src/prover/zenon/tla/records.ts +56 -27
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +68 -39
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +59 -58
- package/src/randomization.ts +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +119 -169
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +1 -8
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +0 -31
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +29 -63
- package/src/sany/selectors.ts +15 -39
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +13 -63
- package/src/search.ts +494 -154
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +264 -74
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +8 -21
- package/src/typescript/collections.ts +0 -15
- package/src/typescript/compile.ts +0 -5
- package/src/typescript/context.ts +0 -12
- package/src/typescript/emit.ts +0 -1
- package/src/typescript/expressions.ts +0 -12
- package/src/typescript/formula.ts +4 -12
- package/src/typescript/functions.ts +6 -17
- package/src/typescript/model.ts +10 -11
- package/src/typescript/names.ts +0 -2
- package/src/typescript/program.ts +0 -3
- package/src/typescript/properties.ts +6 -8
- package/src/typescript/scope.ts +0 -5
- package/src/typescript/steps.ts +0 -10
- package/src/typescript/types.ts +1 -8
- package/src/values.ts +793 -267
- package/src/worker.ts +7 -8
package/src/parser.ts
CHANGED
|
@@ -35,8 +35,6 @@ interface InfixOperator extends Precedence {
|
|
|
35
35
|
isAssociative: boolean;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// TLAplusParser.lastOp, the operator parsed last, and the operator an operand being parsed follows
|
|
39
|
-
// in its expression.
|
|
40
38
|
interface OperatorContext {
|
|
41
39
|
last?: Precedence;
|
|
42
40
|
preceding?: Precedence;
|
|
@@ -154,9 +152,10 @@ const NEGATION_PRECEDENCE = 12;
|
|
|
154
152
|
|
|
155
153
|
const POSTFIX_OPERATORS = new Set(["^+", "^*", "^#"]);
|
|
156
154
|
|
|
155
|
+
const DEFINABLE_POSTFIX_OPERATORS = new Set([...POSTFIX_OPERATORS, "'"]);
|
|
156
|
+
|
|
157
157
|
const PREFIX_OPERATOR_REFERENCES = new Set(["-", "~", "-."]);
|
|
158
158
|
|
|
159
|
-
// The prefix operators SANY reads in a definition's left-hand side, built-in ones included.
|
|
160
159
|
const DEFINABLE_PREFIX_OPERATORS = new Set([
|
|
161
160
|
"-.",
|
|
162
161
|
"~",
|
|
@@ -193,8 +192,7 @@ const OPERATOR_ARGUMENTS = new Set([
|
|
|
193
192
|
"UNCHANGED",
|
|
194
193
|
"[]",
|
|
195
194
|
"<>",
|
|
196
|
-
|
|
197
|
-
...POSTFIX_OPERATORS,
|
|
195
|
+
...DEFINABLE_POSTFIX_OPERATORS,
|
|
198
196
|
]);
|
|
199
197
|
|
|
200
198
|
const SELECTOR_SYMBOLS = new Set(["<<", ">>", ":", "@", "("]);
|
|
@@ -259,6 +257,77 @@ const TLAPM_PUNCTUATION = new Set([
|
|
|
259
257
|
|
|
260
258
|
const UNNAMED_STEP_LABELS = new Set(["", "*", "-"]);
|
|
261
259
|
|
|
260
|
+
interface Point {
|
|
261
|
+
line: number;
|
|
262
|
+
column: number;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// A location as tlapm's Loc.locus has it, with stop just past the end.
|
|
266
|
+
interface Span {
|
|
267
|
+
start: Point;
|
|
268
|
+
stop: Point;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// tlapm reads a proof as leaf proofs and steps without their proofs, then nests them. first is the
|
|
272
|
+
// index of the first token, before any PROOF.
|
|
273
|
+
type Preproof =
|
|
274
|
+
| { kind: "Leaf"; proof: Proof; span: Span; first: number; end: number }
|
|
275
|
+
| {
|
|
276
|
+
kind: "Step";
|
|
277
|
+
token: Token;
|
|
278
|
+
isProof: boolean;
|
|
279
|
+
body: StepBody;
|
|
280
|
+
head: SourceRange;
|
|
281
|
+
statement: SourceRange;
|
|
282
|
+
span: Span;
|
|
283
|
+
first: number;
|
|
284
|
+
start: number;
|
|
285
|
+
end: number;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
interface NestedProof {
|
|
289
|
+
proof: Proof | undefined;
|
|
290
|
+
span: Span;
|
|
291
|
+
next: number;
|
|
292
|
+
end: number | undefined;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
interface NestedSteps {
|
|
296
|
+
level: number;
|
|
297
|
+
steps: ProofStep[];
|
|
298
|
+
span: Span;
|
|
299
|
+
next: number;
|
|
300
|
+
end: number;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const LEAF_NAMES: Record<string, string> = {
|
|
304
|
+
Obvious: "n OBVIOUS",
|
|
305
|
+
Omitted: "n OMITTED",
|
|
306
|
+
By: " BY",
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const comparePoints = (left: Point, right: Point) =>
|
|
310
|
+
left.line - right.line || left.column - right.column;
|
|
311
|
+
|
|
312
|
+
const mergeSpans = (left: Span, right: Span): Span => ({
|
|
313
|
+
start: comparePoints(left.start, right.start) <= 0 ? left.start : right.start,
|
|
314
|
+
stop: comparePoints(left.stop, right.stop) >= 0 ? left.stop : right.stop,
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
const getSpan = (range: SourceRange): Span => ({
|
|
318
|
+
start: { line: range.start.line, column: range.start.column },
|
|
319
|
+
stop: { line: range.end.line, column: range.end.column + 1 },
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
const createProofError = (message: string, span: Span, exception = "Proof.Parser") =>
|
|
323
|
+
new TlaSyntaxError(message, undefined, {
|
|
324
|
+
reason: message,
|
|
325
|
+
line: span.start.line,
|
|
326
|
+
column: span.start.column,
|
|
327
|
+
isEnd: false,
|
|
328
|
+
proof: { stop: span.stop, exception },
|
|
329
|
+
});
|
|
330
|
+
|
|
262
331
|
const FACT_KEYWORDS = new Set([
|
|
263
332
|
"CASE",
|
|
264
333
|
"CHOOSE",
|
|
@@ -297,7 +366,6 @@ const BUILTIN_CONSTANTS = new Set(["TRUE", "FALSE", "BOOLEAN", "STRING"]);
|
|
|
297
366
|
|
|
298
367
|
const NO_OFFSIDE = -1;
|
|
299
368
|
|
|
300
|
-
// A SANY InfixExpr or PostfixExpr.
|
|
301
369
|
const isOperatorExpression = (expression: Expression) =>
|
|
302
370
|
expression.kind === "Prime" ||
|
|
303
371
|
expression.kind === "Product" ||
|
|
@@ -307,6 +375,12 @@ const isOperatorExpression = (expression: Expression) =>
|
|
|
307
375
|
? INFIX_OPERATORS.has(expression.operator)
|
|
308
376
|
: POSTFIX_OPERATORS.has(expression.operator)));
|
|
309
377
|
|
|
378
|
+
// SANY's \land and \lor are infix operators only, not bullets.
|
|
379
|
+
const isBullet = (token: Token) =>
|
|
380
|
+
(token.text === "/\\" || token.text === "\\/") &&
|
|
381
|
+
token.spelling !== "\\land" &&
|
|
382
|
+
token.spelling !== "\\lor";
|
|
383
|
+
|
|
310
384
|
const isOperatorName = (text: string) =>
|
|
311
385
|
INFIX_OPERATORS.has(text) || POSTFIX_OPERATORS.has(text) || text === "-.";
|
|
312
386
|
|
|
@@ -335,24 +409,27 @@ const getOperatorApplication = (
|
|
|
335
409
|
// root module's file, from its ---- MODULE line to the next ==== line.
|
|
336
410
|
export const extractModule = (source: string, name: string) => {
|
|
337
411
|
const header = new RegExp(`^-{4,}\\s*MODULE\\s+${name}\\s*-{3,}$`);
|
|
338
|
-
|
|
412
|
+
// MonolithSpecExtractor.module writes each line it reads, with its own line terminator.
|
|
413
|
+
const lines = source.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
339
414
|
const start = lines.findIndex((line) => header.test(line));
|
|
340
415
|
if (start === -1) return undefined;
|
|
341
416
|
const end = lines.findIndex((line, index) => index > start && line.startsWith("===="));
|
|
342
417
|
return `${lines.slice(start, end === -1 ? undefined : end + 1).join("\n")}\n`;
|
|
343
418
|
};
|
|
344
419
|
|
|
345
|
-
// The tlapm mode parses as tlapm does for proof obligations, which accepts and rejects some
|
|
346
|
-
// that SANY does not. The sany mode leaves
|
|
347
|
-
// generator.
|
|
420
|
+
// The tlapm mode parses as tlapm does for proof obligations, which accepts and rejects some
|
|
421
|
+
// modules that SANY does not. The sany mode leaves SANY's post-parse checks to the SANY generator.
|
|
348
422
|
type ParseMode = "tlc" | "tlapm" | "sany";
|
|
349
423
|
|
|
350
|
-
const parse = (
|
|
424
|
+
const parse = (
|
|
425
|
+
source: string,
|
|
426
|
+
mode: ParseMode,
|
|
427
|
+
sourceTokens = tokenize(source, mode === "tlapm"),
|
|
428
|
+
): Module => {
|
|
351
429
|
const isTlapm = mode === "tlapm";
|
|
352
430
|
const tokens = isTlapm ? sourceTokens : sourceTokens.map(readAtAsIdentifier);
|
|
353
431
|
const cursor = { index: 0, offsideColumns: [] as number[] };
|
|
354
432
|
const operators: OperatorContext = {};
|
|
355
|
-
// A RECURSIVE declaration covers the definitions of its own LET or module.
|
|
356
433
|
const recursiveScopes: Set<string>[] = [];
|
|
357
434
|
const factNames = new Set<string>();
|
|
358
435
|
// The NEW, TAKE, and PICK names in scope, which a DEF clause cannot cite.
|
|
@@ -436,6 +513,7 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
436
513
|
if (TLAPM_PUNCTUATION.has(token.text) || token.kind === "Number" || token.kind === "Decimal")
|
|
437
514
|
return token.text;
|
|
438
515
|
if (token.kind === "String") return JSON.stringify(token.text);
|
|
516
|
+
if (token.kind === "Step") return token.text;
|
|
439
517
|
if (isTlapmKeyword(token)) return `keyword ${token.text}`;
|
|
440
518
|
return token.kind === "Identifier" ? `identifier ${token.text}` : `operator ${token.text}`;
|
|
441
519
|
};
|
|
@@ -528,15 +606,13 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
528
606
|
ranges: names.map((item) => item.range),
|
|
529
607
|
});
|
|
530
608
|
|
|
531
|
-
// TLAplusParser.Substitution: an identifier, or a prefix, infix or postfix operator.
|
|
532
609
|
const expectSubstitutionTarget = () => {
|
|
533
610
|
const token = peek();
|
|
534
611
|
const isOperator =
|
|
535
612
|
token.kind !== "String" &&
|
|
536
613
|
(DEFINABLE_PREFIX_OPERATORS.has(token.text) ||
|
|
537
614
|
INFIX_OPERATORS.has(token.text) ||
|
|
538
|
-
|
|
539
|
-
token.text === "'");
|
|
615
|
+
DEFINABLE_POSTFIX_OPERATORS.has(token.text));
|
|
540
616
|
if (!isOperator) return expectIdentifier();
|
|
541
617
|
cursor.index++;
|
|
542
618
|
return token.text;
|
|
@@ -599,7 +675,7 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
599
675
|
const named = expectName();
|
|
600
676
|
return { kind: "Name", name: named.name, ranges: [named.range] };
|
|
601
677
|
}
|
|
602
|
-
const names = getNames(parseSeparated(expectName));
|
|
678
|
+
const names = getNames(isAt(">>") ? [] : parseSeparated(expectName));
|
|
603
679
|
expect(">>");
|
|
604
680
|
return { kind: "Tuple", names: names.names, ranges: names.ranges };
|
|
605
681
|
};
|
|
@@ -612,21 +688,61 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
612
688
|
return patterns.map((pattern) => ({ pattern, set }));
|
|
613
689
|
}).flat();
|
|
614
690
|
|
|
615
|
-
|
|
691
|
+
// TLAplusParser.NoOpExtension, which leaves the arguments of the subscript's last name for a
|
|
692
|
+
// fairness expression to take as its action.
|
|
693
|
+
const parseSubscript = (): { subscript: Expression; lastArgs: Expression[] } => {
|
|
616
694
|
const token = peek();
|
|
695
|
+
if (isTlapm && BUILTIN_CONSTANTS.has(token.text)) {
|
|
696
|
+
const start = cursor.index;
|
|
697
|
+
advance();
|
|
698
|
+
const constant: Expression = {
|
|
699
|
+
kind: "Identifier",
|
|
700
|
+
name: token.text,
|
|
701
|
+
location: getLocation(token),
|
|
702
|
+
};
|
|
703
|
+
return { subscript: withRange(constant, start), lastArgs: [] };
|
|
704
|
+
}
|
|
705
|
+
const isTlapmAtom =
|
|
706
|
+
isTlapm && (token.kind === "Number" || token.kind === "String" || isAt("@"));
|
|
617
707
|
if (token.kind === "Identifier") {
|
|
618
708
|
const start = cursor.index;
|
|
619
|
-
const names = [
|
|
709
|
+
const names: string[] = [];
|
|
710
|
+
const selectorRanges: SourceRange[] = [];
|
|
711
|
+
const parseElement = (isApplicable: boolean) => {
|
|
712
|
+
selectorRanges.push(getRange(cursor.index, cursor.index));
|
|
713
|
+
names.push(expectIdentifier());
|
|
714
|
+
return isApplicable && isAt("(") ? parseArguments() : [];
|
|
715
|
+
};
|
|
716
|
+
const elementArgs = [parseElement(!isTlapm)];
|
|
620
717
|
while (isAt("!") && peek(1).kind === "Identifier") {
|
|
621
718
|
advance();
|
|
622
|
-
|
|
719
|
+
elementArgs.push(parseElement(true));
|
|
623
720
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
);
|
|
721
|
+
const prefixArgs = elementArgs.slice(0, -1);
|
|
722
|
+
const location = getLocation(token);
|
|
723
|
+
location.range = { ...getRange(start), end: selectorRanges[selectorRanges.length - 1].end };
|
|
724
|
+
const name = names.join("!");
|
|
725
|
+
const subscript: Expression = prefixArgs.every((args) => args.length === 0)
|
|
726
|
+
? { kind: "Identifier", name, location }
|
|
727
|
+
: {
|
|
728
|
+
kind: "Apply",
|
|
729
|
+
operator: name,
|
|
730
|
+
args: prefixArgs.flat(),
|
|
731
|
+
argumentCounts: [...prefixArgs.map((args) => args.length), 0],
|
|
732
|
+
argumentsRange: location.range,
|
|
733
|
+
selectorRanges,
|
|
734
|
+
location,
|
|
735
|
+
};
|
|
736
|
+
return { subscript, lastArgs: elementArgs[elementArgs.length - 1] };
|
|
737
|
+
}
|
|
738
|
+
if (isAt("<<") || isAt("(") || isAt("{") || isAt("[") || isTlapmAtom) {
|
|
739
|
+
const start = cursor.index;
|
|
740
|
+
const subscript = parsePrimary();
|
|
741
|
+
return {
|
|
742
|
+
subscript: subscript.location.range ? subscript : withRange(subscript, start),
|
|
743
|
+
lastArgs: [],
|
|
744
|
+
};
|
|
628
745
|
}
|
|
629
|
-
if (isAt("<<") || isAt("(")) return parsePrimary();
|
|
630
746
|
throw createUnexpected(`Expected a subscript but found ${describeToken(token)}`);
|
|
631
747
|
};
|
|
632
748
|
|
|
@@ -640,7 +756,8 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
640
756
|
token.kind === "Identifier" &&
|
|
641
757
|
(next.text === "(" ||
|
|
642
758
|
next.text === "[" ||
|
|
643
|
-
(next.kind === "Operator" &&
|
|
759
|
+
(next.kind === "Operator" &&
|
|
760
|
+
isAt("==", DEFINABLE_POSTFIX_OPERATORS.has(next.text) ? 3 : 4)))
|
|
644
761
|
);
|
|
645
762
|
};
|
|
646
763
|
|
|
@@ -682,6 +799,9 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
682
799
|
peek(1).line === token.line &&
|
|
683
800
|
peek(1).column === token.endColumn + 1));
|
|
684
801
|
if (isTlapmIncomplete && isStandalone(token)) throw createError("incomplete expression", token);
|
|
802
|
+
if (isOperatorAlone && !isTlapm && token.text === "\\X" && token.spelling !== "×") {
|
|
803
|
+
throw createError("\\X may not be used as an infix operator", token);
|
|
804
|
+
}
|
|
685
805
|
if (isOperatorAlone) {
|
|
686
806
|
cursor.index++;
|
|
687
807
|
return withRange(
|
|
@@ -753,7 +873,11 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
753
873
|
const bullet = advance();
|
|
754
874
|
cursor.offsideColumns.push(bullet.column);
|
|
755
875
|
const operands = [parseExpression()];
|
|
756
|
-
while (
|
|
876
|
+
while (
|
|
877
|
+
isBullet(peekRaw()) &&
|
|
878
|
+
peekRaw().text === bullet.text &&
|
|
879
|
+
peekRaw().column === bullet.column
|
|
880
|
+
) {
|
|
757
881
|
cursor.index++;
|
|
758
882
|
operands.push(parseExpression());
|
|
759
883
|
}
|
|
@@ -790,11 +914,15 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
790
914
|
return { kind, fields, location };
|
|
791
915
|
}
|
|
792
916
|
if (isBoundAhead()) {
|
|
917
|
+
const checkpoint = cursor.index;
|
|
793
918
|
const bounds = parseBounds();
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
919
|
+
if (!isTlapm || isAt("|->")) {
|
|
920
|
+
expect("|->");
|
|
921
|
+
const body = parseExpression();
|
|
922
|
+
expect("]");
|
|
923
|
+
return { kind: "FunctionConstruction", bounds, body, location };
|
|
924
|
+
}
|
|
925
|
+
cursor.index = checkpoint;
|
|
798
926
|
}
|
|
799
927
|
const expression = parseExpression();
|
|
800
928
|
if (accept("->")) {
|
|
@@ -810,6 +938,7 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
810
938
|
if (accept(".")) {
|
|
811
939
|
if (!isFieldName(peek()))
|
|
812
940
|
throw createUnexpected(`Expected a field name but found ${describeToken(peek())}`);
|
|
941
|
+
if (!isTlapm && isAt("@")) throw createUnexpected("@ used in !.@");
|
|
813
942
|
path.push({ kind: "Field", name: advance().text });
|
|
814
943
|
continue;
|
|
815
944
|
}
|
|
@@ -830,7 +959,12 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
830
959
|
return { kind: "Bracket", args, location };
|
|
831
960
|
}
|
|
832
961
|
expect("]_");
|
|
833
|
-
return {
|
|
962
|
+
return {
|
|
963
|
+
kind: "BoxAction",
|
|
964
|
+
action: expression,
|
|
965
|
+
subscript: parseSubscript().subscript,
|
|
966
|
+
location,
|
|
967
|
+
};
|
|
834
968
|
});
|
|
835
969
|
|
|
836
970
|
// SANY reads the set after the \in of {x \in S} as a whole expression, whatever operators it has.
|
|
@@ -881,7 +1015,12 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
881
1015
|
if (accept(">>_")) {
|
|
882
1016
|
if (elements.length !== 1)
|
|
883
1017
|
throw createError("Expected a single action inside <<A>>_v", start);
|
|
884
|
-
return {
|
|
1018
|
+
return {
|
|
1019
|
+
kind: "AngleAction",
|
|
1020
|
+
action: elements[0],
|
|
1021
|
+
subscript: parseSubscript().subscript,
|
|
1022
|
+
location,
|
|
1023
|
+
};
|
|
885
1024
|
}
|
|
886
1025
|
expect(">>");
|
|
887
1026
|
return { kind: "Tuple", elements, location };
|
|
@@ -912,9 +1051,17 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
912
1051
|
const parseCase = (start: Token): Expression => {
|
|
913
1052
|
const arms: CaseArm[] = [];
|
|
914
1053
|
do {
|
|
1054
|
+
const otherStart = cursor.index;
|
|
915
1055
|
if (accept("OTHER")) {
|
|
916
1056
|
expect("->");
|
|
917
|
-
|
|
1057
|
+
const other = parseExpression();
|
|
1058
|
+
return {
|
|
1059
|
+
kind: "Case",
|
|
1060
|
+
arms,
|
|
1061
|
+
other,
|
|
1062
|
+
otherRange: getRange(otherStart),
|
|
1063
|
+
location: getLocation(start),
|
|
1064
|
+
};
|
|
918
1065
|
}
|
|
919
1066
|
const condition = parseExpression();
|
|
920
1067
|
expect("->");
|
|
@@ -931,9 +1078,9 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
931
1078
|
next.kind === "Number" ||
|
|
932
1079
|
SELECTOR_SYMBOLS.has(next.text) ||
|
|
933
1080
|
(next.kind === "Operator" &&
|
|
934
|
-
(INFIX_OPERATORS.has(next.text) ||
|
|
935
|
-
|
|
936
|
-
|
|
1081
|
+
(INFIX_OPERATORS.has(next.text) || DEFINABLE_POSTFIX_OPERATORS.has(next.text))) ||
|
|
1082
|
+
((next.kind === "Operator" || next.kind === "Keyword") &&
|
|
1083
|
+
DEFINABLE_PREFIX_OPERATORS.has(next.text)))
|
|
937
1084
|
);
|
|
938
1085
|
};
|
|
939
1086
|
|
|
@@ -972,7 +1119,7 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
972
1119
|
if (token.kind === "Decimal") return { kind: "Decimal", text: token.text, location };
|
|
973
1120
|
if (token.kind === "String") return { kind: "String", value: token.text, location };
|
|
974
1121
|
const isStep = token.kind === "Step" && isStepReference(token);
|
|
975
|
-
if (isStep && getProofLevel() < 0 && proofLevels.length <= 1) {
|
|
1122
|
+
if (!isTlapm && isStep && getProofLevel() < 0 && proofLevels.length <= 1) {
|
|
976
1123
|
throw createError("Step number used outside proof", token);
|
|
977
1124
|
}
|
|
978
1125
|
if (isStep && token.text[1] === "+") {
|
|
@@ -984,8 +1131,8 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
984
1131
|
const params = getNames(accept("(") ? parseSeparated(expectName) : []);
|
|
985
1132
|
if (params.names.length > 0) expect(")");
|
|
986
1133
|
expect("::");
|
|
1134
|
+
const head = getRange(start);
|
|
987
1135
|
const body = parseExpression();
|
|
988
|
-
// TLAplusParser.labelDoesNotChangeParse.
|
|
989
1136
|
if (
|
|
990
1137
|
!isTlapm &&
|
|
991
1138
|
preceding !== undefined &&
|
|
@@ -1000,6 +1147,7 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1000
1147
|
name,
|
|
1001
1148
|
params: params.names,
|
|
1002
1149
|
paramRanges: params.ranges,
|
|
1150
|
+
head,
|
|
1003
1151
|
body,
|
|
1004
1152
|
location,
|
|
1005
1153
|
};
|
|
@@ -1051,13 +1199,11 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1051
1199
|
}
|
|
1052
1200
|
// SANY reads an infix or postfix operator as a primary expression, with or without arguments.
|
|
1053
1201
|
if (token.kind === "Operator" && isOperatorName(token.text) && isAt("(")) {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
location,
|
|
1060
|
-
};
|
|
1202
|
+
const args = parseArguments();
|
|
1203
|
+
// SANY's built-in \X has no definition for TLC to evaluate, a TLC bug.
|
|
1204
|
+
return mode === "tlc" && token.text === "\\X" && args.length === 2
|
|
1205
|
+
? { kind: "Product", factors: args, location }
|
|
1206
|
+
: { kind: "Apply", operator: token.text, spelling: token.spelling, args, location };
|
|
1061
1207
|
}
|
|
1062
1208
|
if (token.kind === "Operator" && isOperatorName(token.text) && !isTlapm) {
|
|
1063
1209
|
return { kind: "Identifier", name: token.text, spelling: token.spelling, location };
|
|
@@ -1101,7 +1247,7 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1101
1247
|
declareRecursive();
|
|
1102
1248
|
continue;
|
|
1103
1249
|
}
|
|
1104
|
-
const unit = parseDefinition(
|
|
1250
|
+
const unit = parseDefinition(!isTlapm && accept("LOCAL"));
|
|
1105
1251
|
if (unit.kind === "Instance") instances.push(unit);
|
|
1106
1252
|
else definitions.push(unit);
|
|
1107
1253
|
}
|
|
@@ -1120,15 +1266,18 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1120
1266
|
case "WF_":
|
|
1121
1267
|
case "SF_": {
|
|
1122
1268
|
const subscript = parseSubscript();
|
|
1123
|
-
const action =
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1269
|
+
const action =
|
|
1270
|
+
!isAt("(") && subscript.lastArgs.length === 1
|
|
1271
|
+
? subscript.lastArgs[0]
|
|
1272
|
+
: withBracketLayout(() => {
|
|
1273
|
+
expect("(");
|
|
1274
|
+
const expression = parseExpression();
|
|
1275
|
+
expect(")");
|
|
1276
|
+
return expression;
|
|
1277
|
+
});
|
|
1129
1278
|
return {
|
|
1130
1279
|
kind: token.text === "WF_" ? "WeakFairness" : "StrongFairness",
|
|
1131
|
-
subscript,
|
|
1280
|
+
subscript: subscript.subscript,
|
|
1132
1281
|
action,
|
|
1133
1282
|
location,
|
|
1134
1283
|
};
|
|
@@ -1141,12 +1290,14 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1141
1290
|
// prefix operator.
|
|
1142
1291
|
const parsePrefixOperand = (operator: Token, low: number, high: number) => {
|
|
1143
1292
|
operators.last = operators.preceding = { low, high };
|
|
1144
|
-
|
|
1293
|
+
// tlapm applies a postfix operator to the operand, as no prefix operator binds above it.
|
|
1294
|
+
const operand = parseExpression(
|
|
1295
|
+
isTlapm ? Math.min(high + 1, POSTFIX_PRECEDENCE.low) : high + 1,
|
|
1296
|
+
);
|
|
1145
1297
|
const next = peek();
|
|
1146
|
-
const nextHigh =
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
: INFIX_OPERATORS.get(next.text)?.high;
|
|
1298
|
+
const nextHigh = DEFINABLE_POSTFIX_OPERATORS.has(next.text)
|
|
1299
|
+
? POSTFIX_PRECEDENCE.high
|
|
1300
|
+
: INFIX_OPERATORS.get(next.text)?.high;
|
|
1150
1301
|
if (!isTlapm && next.kind === "Operator" && nextHigh !== undefined && nextHigh >= low) {
|
|
1151
1302
|
throw createError(`Precedence conflict between ${operator.text} and ${next.text}`, next);
|
|
1152
1303
|
}
|
|
@@ -1158,9 +1309,29 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1158
1309
|
operators.preceding = undefined;
|
|
1159
1310
|
const token = peek();
|
|
1160
1311
|
const location = getLocation(token);
|
|
1161
|
-
if (token.kind === "Operator" && (token
|
|
1312
|
+
if (token.kind === "Operator" && isBullet(token)) {
|
|
1162
1313
|
return parseJunctionList();
|
|
1163
1314
|
}
|
|
1315
|
+
if (isTlapm && INFIX_OPERATORS.has(token.text) && isAt("(", 1)) {
|
|
1316
|
+
const start = cursor.index;
|
|
1317
|
+
const nonfix = withBracketLayout(() => {
|
|
1318
|
+
advance();
|
|
1319
|
+
advance();
|
|
1320
|
+
const left = parseExpression();
|
|
1321
|
+
if (!accept(",")) return undefined;
|
|
1322
|
+
const right = parseExpression();
|
|
1323
|
+
expect(")");
|
|
1324
|
+
const apply: Expression = {
|
|
1325
|
+
kind: "Apply",
|
|
1326
|
+
operator: token.text,
|
|
1327
|
+
args: [left, right],
|
|
1328
|
+
location,
|
|
1329
|
+
};
|
|
1330
|
+
return withRange(apply, start);
|
|
1331
|
+
});
|
|
1332
|
+
if (nonfix !== undefined) return nonfix;
|
|
1333
|
+
cursor.index = start;
|
|
1334
|
+
}
|
|
1164
1335
|
if (token.kind === "Operator" || token.kind === "Keyword") {
|
|
1165
1336
|
switch (token.text) {
|
|
1166
1337
|
case "~":
|
|
@@ -1172,6 +1343,8 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1172
1343
|
location,
|
|
1173
1344
|
};
|
|
1174
1345
|
case "-":
|
|
1346
|
+
case "-.":
|
|
1347
|
+
if (token.text === "-." && !isTlapm) break;
|
|
1175
1348
|
advance();
|
|
1176
1349
|
return {
|
|
1177
1350
|
kind: "Apply",
|
|
@@ -1271,7 +1444,7 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1271
1444
|
}
|
|
1272
1445
|
advance();
|
|
1273
1446
|
// SANY reads - after an infix operator as prefix -, and rejects it after one that binds tighter.
|
|
1274
|
-
if (infix.low > NEGATION_PRECEDENCE && isAt("-")) {
|
|
1447
|
+
if (!isTlapm && infix.low > NEGATION_PRECEDENCE && isAt("-")) {
|
|
1275
1448
|
throw createError(`Precedence conflict between ${token.text} and -`, peek());
|
|
1276
1449
|
}
|
|
1277
1450
|
operators.last = operators.preceding = infix;
|
|
@@ -1340,11 +1513,13 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1340
1513
|
|
|
1341
1514
|
const parseDefinitionUnit = (isLocal: boolean): Definition | Instance => {
|
|
1342
1515
|
const token = peek();
|
|
1516
|
+
const start = cursor.index;
|
|
1343
1517
|
const location = getLocation(token);
|
|
1344
1518
|
const parseOperator = (name: string, params: OperatorParam[]): Definition => ({
|
|
1345
1519
|
kind: "Operator",
|
|
1346
1520
|
name,
|
|
1347
1521
|
params,
|
|
1522
|
+
head: getRange(start, cursor.index - 2),
|
|
1348
1523
|
...parseBody(),
|
|
1349
1524
|
isLocal,
|
|
1350
1525
|
isRecursive: isRecursiveName(name),
|
|
@@ -1366,7 +1541,7 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1366
1541
|
const isPrefixDefinition =
|
|
1367
1542
|
token.kind !== "String" && DEFINABLE_PREFIX_OPERATORS.has(token.text);
|
|
1368
1543
|
const isPostfixDefinition =
|
|
1369
|
-
token.kind === "Identifier" &&
|
|
1544
|
+
token.kind === "Identifier" && DEFINABLE_POSTFIX_OPERATORS.has(peek(1).text) && isAt("==", 2);
|
|
1370
1545
|
if (isPrefixDefinition || isPostfixDefinition) {
|
|
1371
1546
|
const operator = isPrefixDefinition ? token.text : peek(1).text;
|
|
1372
1547
|
if (isPrefixDefinition) advance();
|
|
@@ -1442,7 +1617,10 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1442
1617
|
const name = advance().text;
|
|
1443
1618
|
return { name, arity: accept("_") ? 2 : 1, location };
|
|
1444
1619
|
}
|
|
1445
|
-
|
|
1620
|
+
const isPrefixOperator =
|
|
1621
|
+
peek().kind !== "String" &&
|
|
1622
|
+
(DEFINABLE_PREFIX_OPERATORS.has(peek().text) || (isTlapm && peek().kind === "Operator"));
|
|
1623
|
+
if (isPrefixOperator && isAt("_", 1)) {
|
|
1446
1624
|
const operator = advance().text;
|
|
1447
1625
|
advance();
|
|
1448
1626
|
return { name: operator === "-" ? "-." : operator, arity: 1, location };
|
|
@@ -1489,7 +1667,8 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1489
1667
|
);
|
|
1490
1668
|
}
|
|
1491
1669
|
if (isAt("(", 1) || isAt("[", 1)) return isAt("==", getClosingOffset(1));
|
|
1492
|
-
if (next.kind === "Operator" &&
|
|
1670
|
+
if (next.kind === "Operator" && DEFINABLE_POSTFIX_OPERATORS.has(next.text))
|
|
1671
|
+
return isAt("==", 2);
|
|
1493
1672
|
if (next.kind === "Operator" && INFIX_OPERATORS.has(next.text)) {
|
|
1494
1673
|
return peek(2).kind === "Identifier" && isAt("==", 3);
|
|
1495
1674
|
}
|
|
@@ -1619,7 +1798,6 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1619
1798
|
module.variables.some((variable) => variable.name === name),
|
|
1620
1799
|
);
|
|
1621
1800
|
|
|
1622
|
-
// tlapm's definable: names and operators joined by !.
|
|
1623
1801
|
const parseDefinable = (): Fact => {
|
|
1624
1802
|
const start = cursor.index;
|
|
1625
1803
|
const token = peek();
|
|
@@ -1654,10 +1832,12 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1654
1832
|
return defs;
|
|
1655
1833
|
};
|
|
1656
1834
|
|
|
1657
|
-
const parseFacts = () =>
|
|
1658
|
-
facts
|
|
1659
|
-
|
|
1660
|
-
|
|
1835
|
+
const parseFacts = () => {
|
|
1836
|
+
const facts = isFactAhead() ? parseSeparated(parseFact) : [];
|
|
1837
|
+
const isDef = accept("DEF") || accept("DEFS");
|
|
1838
|
+
if (isTlapm && facts.length === 0 && !isDef) throw createUnexpected("Expected a fact");
|
|
1839
|
+
return { facts, defs: isDef ? parseDefs() : [] };
|
|
1840
|
+
};
|
|
1661
1841
|
|
|
1662
1842
|
const parseUseOrHide = (): UseOrHide => {
|
|
1663
1843
|
const start = cursor.index;
|
|
@@ -1686,9 +1866,12 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1686
1866
|
};
|
|
1687
1867
|
|
|
1688
1868
|
const parseNewSymbol = (): NewSymbol => {
|
|
1689
|
-
const
|
|
1690
|
-
const
|
|
1869
|
+
const newStart = cursor.index;
|
|
1870
|
+
const newLocation = getLocation(peek());
|
|
1691
1871
|
const isNew = accept("NEW");
|
|
1872
|
+
// tlapm locates a declaration without its NEW.
|
|
1873
|
+
const start = isTlapm ? cursor.index : newStart;
|
|
1874
|
+
const location = isTlapm ? getLocation(peek()) : newLocation;
|
|
1692
1875
|
const level = peek().kind === "Keyword" ? NEW_SYMBOL_LEVELS.get(peek().text) : undefined;
|
|
1693
1876
|
if (!isNew && level === undefined) {
|
|
1694
1877
|
throw createUnexpected(`Expected a declaration but found ${describeToken(peek())}`);
|
|
@@ -1735,6 +1918,10 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1735
1918
|
const start = cursor.index;
|
|
1736
1919
|
const location = getLocation(expect("ASSUME"));
|
|
1737
1920
|
const assumptions = parseSeparated(() => {
|
|
1921
|
+
if (peek().kind === "Identifier" && isAt("::", 1) && isAt("ASSUME", 2)) {
|
|
1922
|
+
advance();
|
|
1923
|
+
advance();
|
|
1924
|
+
}
|
|
1738
1925
|
if (isAt("ASSUME")) return withProofScope(parseAssumeProve);
|
|
1739
1926
|
if (peek().kind === "Keyword" && NEW_SYMBOL_STARTS.has(peek().text)) return parseNewSymbol();
|
|
1740
1927
|
return parseExpression();
|
|
@@ -1819,7 +2006,7 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1819
2006
|
if (!isCorrectLevel(step)) {
|
|
1820
2007
|
throw createError(`${isQed ? "QED step" : "step"}'s number has bad level`, step);
|
|
1821
2008
|
}
|
|
1822
|
-
if (getStepLevel(step) < 0 && getStepName(step) !== undefined) {
|
|
2009
|
+
if (mode !== "sany" && getStepLevel(step) < 0 && getStepName(step) !== undefined) {
|
|
1823
2010
|
throw createError("<*> and <+> cannot be used for a named step", step);
|
|
1824
2011
|
}
|
|
1825
2012
|
cursor.index++;
|
|
@@ -1847,25 +2034,26 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1847
2034
|
return withRange({ ...step, body, head, statement, proof }, start);
|
|
1848
2035
|
};
|
|
1849
2036
|
|
|
1850
|
-
const
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
advance();
|
|
2037
|
+
const parseLeafProof = (
|
|
2038
|
+
location: SourceLocation,
|
|
2039
|
+
): Exclude<Proof, { kind: "Steps" }> | undefined => {
|
|
2040
|
+
if (accept("BY")) {
|
|
1855
2041
|
const keyword = getRange(cursor.index - 1);
|
|
1856
2042
|
return { kind: "By", isOnly: accept("ONLY"), ...parseFacts(), keyword, location };
|
|
1857
2043
|
}
|
|
1858
|
-
const terminal = peek(
|
|
1859
|
-
if (
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
)
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
2044
|
+
const terminal = peek();
|
|
2045
|
+
if (terminal.kind !== "Keyword" || (terminal.text !== "OBVIOUS" && terminal.text !== "OMITTED"))
|
|
2046
|
+
return undefined;
|
|
2047
|
+
advance();
|
|
2048
|
+
const keyword = getRange(cursor.index - 1);
|
|
2049
|
+
return { kind: terminal.text === "OBVIOUS" ? "Obvious" : "Omitted", keyword, location };
|
|
2050
|
+
};
|
|
2051
|
+
|
|
2052
|
+
const parseProofBody = (): Proof => {
|
|
2053
|
+
const location = getLocation(peek());
|
|
1868
2054
|
accept("PROOF");
|
|
2055
|
+
const leaf = parseLeafProof(location);
|
|
2056
|
+
if (leaf) return leaf;
|
|
1869
2057
|
const steps = [parseStep()];
|
|
1870
2058
|
while (steps[steps.length - 1].body.kind !== "Qed") steps.push(parseStep());
|
|
1871
2059
|
return { kind: "Steps", level: getProofLevel(), steps, location };
|
|
@@ -1879,6 +2067,161 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1879
2067
|
return withRange(proof, start);
|
|
1880
2068
|
};
|
|
1881
2069
|
|
|
2070
|
+
const isPreproofStart = () =>
|
|
2071
|
+
peek().kind === "Step" || (peek().kind === "Keyword" && PROOF_STARTS.has(peek().text));
|
|
2072
|
+
|
|
2073
|
+
// tlapm locates a USE or HIDE step by its keywords and DEF clause.
|
|
2074
|
+
const getStepSpan = (head: SourceRange, body: StepBody) => {
|
|
2075
|
+
if (body.kind !== "Use" && body.kind !== "Hide") return getSpan(head);
|
|
2076
|
+
const lastDef = body.defs[body.defs.length - 1]?.location.range;
|
|
2077
|
+
return mergeSpans(getSpan({ ...head, end: head.start }), getSpan(lastDef ?? body.keyword));
|
|
2078
|
+
};
|
|
2079
|
+
|
|
2080
|
+
const parsePreproof = (): Preproof => {
|
|
2081
|
+
const first = cursor.index;
|
|
2082
|
+
const location = getLocation(peek());
|
|
2083
|
+
const isProof = accept("PROOF");
|
|
2084
|
+
const leaf = parseLeafProof(location);
|
|
2085
|
+
if (leaf) {
|
|
2086
|
+
const proof = withRange(leaf, first);
|
|
2087
|
+
return { kind: "Leaf", proof, span: getSpan(proof.keyword), first, end: cursor.index - 1 };
|
|
2088
|
+
}
|
|
2089
|
+
const token = peek();
|
|
2090
|
+
if (token.kind !== "Step") {
|
|
2091
|
+
throw createUnexpected(`Expected a step number but found ${describeToken(token)}`);
|
|
2092
|
+
}
|
|
2093
|
+
const start = cursor.index;
|
|
2094
|
+
advance();
|
|
2095
|
+
const statementStart = cursor.index;
|
|
2096
|
+
const body: StepBody = accept("QED") ? { kind: "Qed" } : parseStepBody();
|
|
2097
|
+
const head = getRange(start);
|
|
2098
|
+
return {
|
|
2099
|
+
kind: "Step",
|
|
2100
|
+
token,
|
|
2101
|
+
isProof,
|
|
2102
|
+
body,
|
|
2103
|
+
head,
|
|
2104
|
+
statement: getRange(statementStart),
|
|
2105
|
+
span: getStepSpan(head, body),
|
|
2106
|
+
first,
|
|
2107
|
+
start,
|
|
2108
|
+
end: cursor.index - 1,
|
|
2109
|
+
};
|
|
2110
|
+
};
|
|
2111
|
+
|
|
2112
|
+
// A backtrack leaves the proof implicitly omitted.
|
|
2113
|
+
const nestProof = (
|
|
2114
|
+
items: Preproof[],
|
|
2115
|
+
index: number,
|
|
2116
|
+
level: number,
|
|
2117
|
+
levelSpan: Span,
|
|
2118
|
+
): NestedProof => {
|
|
2119
|
+
const item = items[index];
|
|
2120
|
+
if (!item) return { proof: undefined, span: levelSpan, next: index, end: undefined };
|
|
2121
|
+
if (item.kind === "Leaf")
|
|
2122
|
+
return { proof: item.proof, span: item.span, next: index + 1, end: item.end };
|
|
2123
|
+
const nested = nestSteps(items, index, level, levelSpan, true);
|
|
2124
|
+
if (!nested) return { proof: undefined, span: levelSpan, next: index, end: undefined };
|
|
2125
|
+
const location = {
|
|
2126
|
+
...getLocation(tokens[item.first]),
|
|
2127
|
+
range: getRange(item.first, nested.end),
|
|
2128
|
+
};
|
|
2129
|
+
return {
|
|
2130
|
+
proof: { kind: "Steps", level: nested.level, steps: nested.steps, location },
|
|
2131
|
+
span: nested.span,
|
|
2132
|
+
next: nested.next,
|
|
2133
|
+
end: nested.end,
|
|
2134
|
+
};
|
|
2135
|
+
};
|
|
2136
|
+
|
|
2137
|
+
const nestSteps = (
|
|
2138
|
+
items: Preproof[],
|
|
2139
|
+
index: number,
|
|
2140
|
+
level: number,
|
|
2141
|
+
levelSpan: Span,
|
|
2142
|
+
isFirst: boolean,
|
|
2143
|
+
): NestedSteps | undefined => {
|
|
2144
|
+
const item = items[index];
|
|
2145
|
+
if (!item) {
|
|
2146
|
+
throw createProofError(
|
|
2147
|
+
`Unexpected end of (sub)proof at level ${level} before QED step`,
|
|
2148
|
+
levelSpan,
|
|
2149
|
+
);
|
|
2150
|
+
}
|
|
2151
|
+
if (item.kind === "Leaf") {
|
|
2152
|
+
throw createProofError(
|
|
2153
|
+
`Expecting a proof step but found a${LEAF_NAMES[item.proof.kind]} leaf proof`,
|
|
2154
|
+
item.span,
|
|
2155
|
+
);
|
|
2156
|
+
}
|
|
2157
|
+
if (!isFirst && item.isProof) {
|
|
2158
|
+
throw createProofError("PROOF keyword found in step that does not begin subproof", item.span);
|
|
2159
|
+
}
|
|
2160
|
+
const implicit = item.token.text[1];
|
|
2161
|
+
if (implicit === "+" && !isFirst) {
|
|
2162
|
+
throw createProofError("<+> used but no subproof expected", item.span);
|
|
2163
|
+
}
|
|
2164
|
+
const stepLevel =
|
|
2165
|
+
implicit === "*"
|
|
2166
|
+
? level - (isFirst && !item.isProof ? 1 : 0)
|
|
2167
|
+
: implicit === "+"
|
|
2168
|
+
? level
|
|
2169
|
+
: getStepLevel(item.token);
|
|
2170
|
+
if (stepLevel < level || (!isFirst && stepLevel > level)) return undefined;
|
|
2171
|
+
const proof = PROVABLE_STEPS.has(item.body.kind)
|
|
2172
|
+
? nestProof(items, index + 1, stepLevel + 1, item.span)
|
|
2173
|
+
: { proof: undefined, span: item.span, next: index + 1, end: undefined };
|
|
2174
|
+
const end = proof.end ?? item.end;
|
|
2175
|
+
const step: ProofStep = {
|
|
2176
|
+
name: getStepName(item.token),
|
|
2177
|
+
token: item.token.text,
|
|
2178
|
+
body: item.body,
|
|
2179
|
+
head: item.head,
|
|
2180
|
+
statement: item.statement,
|
|
2181
|
+
proof: proof.proof,
|
|
2182
|
+
location: { ...getLocation(item.token), range: getRange(item.start, end) },
|
|
2183
|
+
};
|
|
2184
|
+
const span = mergeSpans(item.span, proof.span);
|
|
2185
|
+
if (item.body.kind === "Qed") {
|
|
2186
|
+
return { level: stepLevel, steps: [step], span, next: proof.next, end };
|
|
2187
|
+
}
|
|
2188
|
+
const rest = nestSteps(
|
|
2189
|
+
items,
|
|
2190
|
+
proof.next,
|
|
2191
|
+
stepLevel,
|
|
2192
|
+
{ start: span.stop, stop: span.stop },
|
|
2193
|
+
false,
|
|
2194
|
+
);
|
|
2195
|
+
return (
|
|
2196
|
+
rest && {
|
|
2197
|
+
...rest,
|
|
2198
|
+
level: stepLevel,
|
|
2199
|
+
steps: [step, ...rest.steps],
|
|
2200
|
+
span: mergeSpans(span, rest.span),
|
|
2201
|
+
}
|
|
2202
|
+
);
|
|
2203
|
+
};
|
|
2204
|
+
|
|
2205
|
+
// tlapm reads every step and leaf proof that follows, then nests them by level, where the first
|
|
2206
|
+
// step counts as having PROOF.
|
|
2207
|
+
const parseTlapmProof = () => {
|
|
2208
|
+
if (!isPreproofStart()) return undefined;
|
|
2209
|
+
const items: Preproof[] = [];
|
|
2210
|
+
while (isPreproofStart()) items.push(parsePreproof());
|
|
2211
|
+
const first = items[0];
|
|
2212
|
+
if (first.kind === "Step") items[0] = { ...first, isProof: true };
|
|
2213
|
+
const nested = nestProof(items, 0, 0, first.span);
|
|
2214
|
+
const extra = items[nested.next];
|
|
2215
|
+
if (extra) {
|
|
2216
|
+
throw createProofError(
|
|
2217
|
+
"extra step(s) after finished proof",
|
|
2218
|
+
extra.span,
|
|
2219
|
+
"Proof.Parser.toplevel",
|
|
2220
|
+
);
|
|
2221
|
+
}
|
|
2222
|
+
return nested.proof;
|
|
2223
|
+
};
|
|
2224
|
+
|
|
1882
2225
|
// SANY binds the name of a theorem or assumption that a module already defines to the first
|
|
1883
2226
|
// definition, warning of the second.
|
|
1884
2227
|
const addFactDefinition = (module: Module, definition: Definition) => {
|
|
@@ -1897,6 +2240,7 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
1897
2240
|
}
|
|
1898
2241
|
const parsed = withProofScope(() => {
|
|
1899
2242
|
const statement = isAt("ASSUME") ? parseAssumeProve() : parseExpression();
|
|
2243
|
+
if (isTlapm) return { statement, proof: parseTlapmProof() };
|
|
1900
2244
|
return { statement, proof: isProofStart(peek()) ? parseProof() : undefined };
|
|
1901
2245
|
});
|
|
1902
2246
|
const statement = parsed.statement;
|
|
@@ -2051,10 +2395,13 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
2051
2395
|
module.units.push({ kind: "Use", use });
|
|
2052
2396
|
continue;
|
|
2053
2397
|
}
|
|
2054
|
-
case "RECURSIVE":
|
|
2055
|
-
advance();
|
|
2056
|
-
|
|
2398
|
+
case "RECURSIVE": {
|
|
2399
|
+
const unitLocation = getLocation(advance());
|
|
2400
|
+
const declarations = declareRecursive();
|
|
2401
|
+
unitLocation.range = getRange(tokenIndex);
|
|
2402
|
+
module.units.push({ kind: "Recursive", declarations, location: unitLocation });
|
|
2057
2403
|
continue;
|
|
2404
|
+
}
|
|
2058
2405
|
case "INSTANCE":
|
|
2059
2406
|
addDefinitionUnit(
|
|
2060
2407
|
module,
|
|
@@ -2102,7 +2449,6 @@ const parse = (source: string, mode: ParseMode, sourceTokens = tokenize(source))
|
|
|
2102
2449
|
|
|
2103
2450
|
export const parseModule = (source: string) => parse(source, "tlc");
|
|
2104
2451
|
|
|
2105
|
-
// Parses a module the caller has tokenized already.
|
|
2106
2452
|
export const parseModuleTokens = (source: string, tokens: Token[]) => parse(source, "tlc", tokens);
|
|
2107
2453
|
|
|
2108
2454
|
export const parseTlapmModule = (source: string) => parse(source, "tlapm");
|