tla-ts 0.0.9 → 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 +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +72 -10
- package/dist/index.d.ts +72 -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 +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- 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 +3 -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 +576 -300
- package/src/cli/options.ts +11 -6
- 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 +538 -220
- package/src/cli/typescript.ts +23 -0
- 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 +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +630 -297
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +79 -11
- 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 +10 -18
- package/src/liveness.ts +121 -49
- 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 +29 -39
- package/src/parallel.ts +29 -13
- 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 +23 -34
- 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 +267 -77
- 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 +481 -0
- package/src/typescript/collections.ts +600 -0
- package/src/typescript/compile.ts +65 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +152 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +163 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +165 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +826 -276
- package/src/worker.ts +7 -8
package/src/json.ts
CHANGED
|
@@ -1,210 +1,333 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createJavaOverrideError,
|
|
3
2
|
createModuleArgumentError,
|
|
3
|
+
defineLazyOperator,
|
|
4
4
|
defineStateOperator,
|
|
5
5
|
getJavaClassName,
|
|
6
|
+
getThunk,
|
|
6
7
|
getValue,
|
|
8
|
+
isOutOfRange,
|
|
9
|
+
overrideWithJava,
|
|
7
10
|
} from "./builtins";
|
|
8
|
-
import
|
|
11
|
+
import { TlaEvaluationError, TlaUnsupportedError } from "./errors";
|
|
12
|
+
import type { Builtin, BuiltinArgument, Context } from "./evaluate";
|
|
13
|
+
import { readJson, type JsonElement } from "./json-reader";
|
|
9
14
|
import {
|
|
15
|
+
applyFunction,
|
|
10
16
|
createRecord,
|
|
11
17
|
createTuple,
|
|
12
18
|
formatValue,
|
|
13
19
|
getSequenceElements,
|
|
20
|
+
getPrintedPairs,
|
|
14
21
|
isFunctionValue,
|
|
15
|
-
|
|
22
|
+
isTlcEnumerable,
|
|
16
23
|
toFiniteFunction,
|
|
17
24
|
toFiniteSet,
|
|
25
|
+
type FunctionValue,
|
|
18
26
|
type Value,
|
|
19
27
|
rankString,
|
|
20
28
|
} from "./values";
|
|
21
29
|
|
|
22
30
|
export interface FileSystem {
|
|
23
31
|
readFile: ((path: string) => string | undefined) | undefined;
|
|
24
|
-
writeFile: ((path: string, content: string) => void) | undefined;
|
|
32
|
+
writeFile: ((path: string, content: string | Uint8Array) => void) | undefined;
|
|
33
|
+
makeDirectory: ((path: string) => void) | undefined;
|
|
25
34
|
}
|
|
26
35
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
const OPEN_OPTIONS = new Set([
|
|
37
|
+
"READ",
|
|
38
|
+
"WRITE",
|
|
39
|
+
"APPEND",
|
|
40
|
+
"TRUNCATE_EXISTING",
|
|
41
|
+
"CREATE",
|
|
42
|
+
"CREATE_NEW",
|
|
43
|
+
"DELETE_ON_CLOSE",
|
|
44
|
+
"SPARSE",
|
|
45
|
+
"SYNC",
|
|
46
|
+
"DSYNC",
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
const UTF_8_NAMES = new Set(["utf-8", "utf8", "unicode-1-1-utf-8"]);
|
|
50
|
+
|
|
51
|
+
const STANDARD_CHARSETS = new Set(["us-ascii", "iso-8859-1", "utf-16", "utf-16be", "utf-16le"]);
|
|
52
|
+
|
|
53
|
+
const toRecord = (value: Value) => {
|
|
54
|
+
if (!isFunctionValue(value)) return undefined;
|
|
55
|
+
const functionValue = toFiniteFunction(value);
|
|
56
|
+
const fields = functionValue.domain.flatMap((key, index): [string, Value][] =>
|
|
57
|
+
typeof key === "string" ? [[key, functionValue.range[index]]] : [],
|
|
58
|
+
);
|
|
59
|
+
return fields.length === functionValue.domain.length ? createRecord(fields) : undefined;
|
|
60
|
+
};
|
|
30
61
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const SERIALIZE_SIGNATURE =
|
|
38
|
-
"public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.serialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException";
|
|
39
|
-
const ND_SERIALIZE_SIGNATURE =
|
|
40
|
-
"public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException";
|
|
41
|
-
const DESERIALIZE_SIGNATURE =
|
|
42
|
-
"public static tlc2.value.IValue tlc2.module.Json.deserialize(tlc2.value.impl.StringValue) throws java.io.IOException";
|
|
43
|
-
const ND_DESERIALIZE_SIGNATURE =
|
|
44
|
-
"public static tlc2.value.IValue tlc2.module.Json.ndDeserialize(tlc2.value.impl.StringValue) throws java.io.IOException";
|
|
45
|
-
|
|
46
|
-
const isRecord = (value: Value) => {
|
|
47
|
-
if (!isFunctionValue(value)) return false;
|
|
48
|
-
const domain = toFiniteFunction(value).domain;
|
|
49
|
-
return domain.length > 0 && domain.every((key) => typeof key === "string");
|
|
62
|
+
const createClassCastError = (value: Value, javaClass: string) => {
|
|
63
|
+
const valueClass = `tlc2.value.impl.${getJavaClassName(value)}`;
|
|
64
|
+
const targetClass = `tlc2.value.impl.${javaClass}`;
|
|
65
|
+
return new TlaEvaluationError(
|
|
66
|
+
`class ${valueClass} cannot be cast to class ${targetClass} (${valueClass} and ${targetClass} are in unnamed module of loader 'app')`,
|
|
67
|
+
);
|
|
50
68
|
};
|
|
51
69
|
|
|
52
|
-
const createUnsupportedError = (
|
|
53
|
-
|
|
54
|
-
method,
|
|
70
|
+
const createUnsupportedError = (value: Value) =>
|
|
71
|
+
new TlaEvaluationError(
|
|
55
72
|
`Cannot convert value: unsupported value type tlc2.value.impl.${getJavaClassName(value)}`,
|
|
56
73
|
);
|
|
57
74
|
|
|
58
75
|
const toJsonString = (text: string) =>
|
|
59
76
|
JSON.stringify(text).replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
|
|
60
77
|
|
|
61
|
-
const
|
|
62
|
-
if (typeof value === "object" && (value.kind === "InfiniteSet" || value.kind === "SequenceSet")) {
|
|
63
|
-
throw createUnsupportedError(method, value);
|
|
64
|
-
}
|
|
65
|
-
return `[${toFiniteSet(value)
|
|
66
|
-
.elements.map((element) => toJson(element, method))
|
|
67
|
-
.join(",")}]`;
|
|
68
|
-
};
|
|
78
|
+
const toArrayJson = (elements: Value[]) => `[${elements.map(toJson).join(",")}]`;
|
|
69
79
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const elements = getSequenceElements(functionValue);
|
|
73
|
-
if (elements) return `[${elements.map((element) => toJson(element, method)).join(",")}]`;
|
|
74
|
-
return `{${functionValue.domain
|
|
80
|
+
const toObjectJson = (functionValue: FunctionValue) =>
|
|
81
|
+
`{${getPrintedPairs(functionValue)
|
|
75
82
|
.map(
|
|
76
|
-
(
|
|
77
|
-
`${toJsonString(typeof
|
|
83
|
+
(pair) =>
|
|
84
|
+
`${toJsonString(typeof pair[0] === "string" ? pair[0] : formatValue(pair[0]))}:${toJson(pair[1])}`,
|
|
78
85
|
)
|
|
79
86
|
.join(",")}}`;
|
|
87
|
+
|
|
88
|
+
const toFunctionJson = (value: Value) => {
|
|
89
|
+
const functionValue = toFiniteFunction(value);
|
|
90
|
+
const elements = getSequenceElements(functionValue);
|
|
91
|
+
return elements ? toArrayJson(elements) : toObjectJson(functionValue);
|
|
80
92
|
};
|
|
81
93
|
|
|
82
|
-
const
|
|
94
|
+
const isFunctionClass = (className: string) =>
|
|
95
|
+
className === "FcnRcdValue" || className === "FcnLambdaValue";
|
|
96
|
+
|
|
97
|
+
const toJson = (value: Value): string => {
|
|
83
98
|
if (typeof value === "string") return toJsonString(value);
|
|
84
99
|
if (typeof value !== "object") return String(value);
|
|
85
100
|
if (value.kind === "ModelValue") return toJsonString(value.name);
|
|
86
|
-
|
|
87
|
-
return
|
|
101
|
+
const className = getJavaClassName(value);
|
|
102
|
+
if (className === "RecordValue") return toObjectJson(toFiniteFunction(value));
|
|
103
|
+
if (className === "TupleValue") return toArrayJson(toFiniteFunction(value).range);
|
|
104
|
+
if (isFunctionClass(className)) return toFunctionJson(value);
|
|
105
|
+
if (isTlcEnumerable(value)) return toArrayJson(toFiniteSet(value).elements);
|
|
106
|
+
throw createUnsupportedError(value);
|
|
88
107
|
};
|
|
89
108
|
|
|
90
109
|
const toJsonArray = (value: Value) => {
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
return
|
|
110
|
+
const className = getJavaClassName(value);
|
|
111
|
+
if (className === "TupleValue") return toArrayJson(toFiniteFunction(value).range);
|
|
112
|
+
if (isFunctionClass(className)) return toFunctionJson(value);
|
|
113
|
+
if (isTlcEnumerable(value)) return toArrayJson(toFiniteSet(value).elements);
|
|
114
|
+
throw createUnsupportedError(value);
|
|
95
115
|
};
|
|
96
116
|
|
|
97
117
|
const toJsonObject = (value: Value) => {
|
|
98
|
-
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const digits = BigInt(whole + fraction);
|
|
108
|
-
const shift = Number(exponent) - fraction.length;
|
|
109
|
-
const magnitude = shift >= 0 ? digits * 10n ** BigInt(shift) : digits / 10n ** BigInt(-shift);
|
|
110
|
-
return Number(BigInt.asIntN(32, sign === "-" ? -magnitude : magnitude));
|
|
118
|
+
const className = getJavaClassName(value);
|
|
119
|
+
if (className === "RecordValue") return toObjectJson(toFiniteFunction(value));
|
|
120
|
+
if (className === "TupleValue") {
|
|
121
|
+
return `{${toFiniteFunction(value)
|
|
122
|
+
.range.map((element, index) => `"${index}":${toJson(element)}`)
|
|
123
|
+
.join(",")}}`;
|
|
124
|
+
}
|
|
125
|
+
if (isFunctionClass(className)) return toFunctionJson(value);
|
|
126
|
+
throw createUnsupportedError(value);
|
|
111
127
|
};
|
|
112
128
|
|
|
113
|
-
const fromJson = (
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
129
|
+
const fromJson = (element: JsonElement): Value => {
|
|
130
|
+
if (element === null) {
|
|
131
|
+
throw new TlaEvaluationError("Cannot convert value: unsupported JSON value null");
|
|
132
|
+
}
|
|
133
|
+
if (typeof element === "boolean") return element;
|
|
134
|
+
if (typeof element === "string") return rankString(element);
|
|
135
|
+
if (Array.isArray(element)) return createTuple(element.map(fromJson));
|
|
136
|
+
if (element instanceof Map) {
|
|
118
137
|
return createRecord(
|
|
119
|
-
|
|
120
|
-
rankString(key),
|
|
121
|
-
fromJson(field, method),
|
|
122
|
-
]),
|
|
138
|
+
[...element].map((member): [string, Value] => [rankString(member[0]), fromJson(member[1])]),
|
|
123
139
|
);
|
|
124
140
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const parseJson = (text: string, method: string) => {
|
|
132
|
-
if (text.trim() === "") return fromJson(null, method);
|
|
133
|
-
try {
|
|
134
|
-
return fromJson(
|
|
135
|
-
JSON.parse(text, (_, value: unknown, context?: ParseContext) =>
|
|
136
|
-
typeof value === "number" ? toInteger(context?.source ?? String(value)) : value,
|
|
137
|
-
),
|
|
138
|
-
method,
|
|
141
|
+
const value = Number(element.literal);
|
|
142
|
+
if (!/^-?\d+$/.test(element.literal) || isOutOfRange(value)) {
|
|
143
|
+
throw new TlaEvaluationError(
|
|
144
|
+
`Cannot convert value: expected a 32-bit integer JSON number, but found ${element.literal}`,
|
|
139
145
|
);
|
|
140
|
-
} catch (error) {
|
|
141
|
-
if (!(error instanceof SyntaxError)) throw error;
|
|
142
|
-
throw createJavaOverrideError(method, error.message);
|
|
143
146
|
}
|
|
147
|
+
return value || 0;
|
|
144
148
|
};
|
|
145
149
|
|
|
146
|
-
const getPath = (value: Value
|
|
150
|
+
export const getPath = (value: Value) => {
|
|
147
151
|
if (typeof value !== "string") {
|
|
148
|
-
throw
|
|
149
|
-
method,
|
|
152
|
+
throw new TlaEvaluationError(
|
|
150
153
|
`Cannot cast tlc2.value.impl.${getJavaClassName(value)} to tlc2.value.impl.StringValue`,
|
|
151
154
|
);
|
|
152
155
|
}
|
|
153
156
|
return value;
|
|
154
157
|
};
|
|
155
158
|
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
|
|
159
|
+
const getStringOption = (options: Value, field: string) => {
|
|
160
|
+
const value = applyFunction(options, field);
|
|
161
|
+
if (typeof value !== "string") throw createClassCastError(value, "StringValue");
|
|
162
|
+
return value;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const checkCharset = (charset: string) => {
|
|
166
|
+
if (UTF_8_NAMES.has(charset.toLowerCase())) return;
|
|
167
|
+
if (STANDARD_CHARSETS.has(charset.toLowerCase())) {
|
|
168
|
+
throw new TlaUnsupportedError(`IOUtils!Serialize does not support the charset ${charset}`);
|
|
160
169
|
}
|
|
170
|
+
throw new TlaEvaluationError(
|
|
171
|
+
/^[a-zA-Z\d][\w.:+-]*$/.test(charset)
|
|
172
|
+
? `java.nio.charset.UnsupportedCharsetException: ${charset}`
|
|
173
|
+
: `java.nio.charset.IllegalCharsetNameException: ${charset}`,
|
|
174
|
+
);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// Files.newBufferedWriter with the given StandardOpenOption names, which writes the text over the
|
|
178
|
+
// start of a file that it neither truncates nor appends to.
|
|
179
|
+
const writeWithOptions = (files: FileSystem, path: string, names: string[], text: string) => {
|
|
180
|
+
const unknown = names.find((name) => !OPEN_OPTIONS.has(name));
|
|
181
|
+
if (unknown !== undefined) {
|
|
182
|
+
throw new TlaEvaluationError(
|
|
183
|
+
`java.lang.IllegalArgumentException: No enum constant java.nio.file.StandardOpenOption.${unknown}`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
if (names.includes("READ")) {
|
|
187
|
+
throw new TlaEvaluationError("java.lang.IllegalArgumentException: READ not allowed");
|
|
188
|
+
}
|
|
189
|
+
const options = new Set(names.length === 0 ? ["CREATE", "TRUNCATE_EXISTING"] : names);
|
|
190
|
+
if (options.has("APPEND") && options.has("TRUNCATE_EXISTING")) {
|
|
191
|
+
throw new TlaEvaluationError(
|
|
192
|
+
"java.lang.IllegalArgumentException: APPEND + TRUNCATE_EXISTING not allowed",
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
if (options.has("DELETE_ON_CLOSE")) {
|
|
196
|
+
throw new TlaUnsupportedError("IOUtils!Serialize does not support DELETE_ON_CLOSE");
|
|
197
|
+
}
|
|
198
|
+
const existing = files.readFile?.(path);
|
|
199
|
+
if (existing === undefined && !options.has("CREATE") && !options.has("CREATE_NEW")) {
|
|
200
|
+
throw new TlaEvaluationError(`java.nio.file.NoSuchFileException: ${path}`);
|
|
201
|
+
}
|
|
202
|
+
if (existing !== undefined && options.has("CREATE_NEW")) {
|
|
203
|
+
throw new TlaEvaluationError(`java.nio.file.FileAlreadyExistsException: ${path}`);
|
|
204
|
+
}
|
|
205
|
+
if (existing === undefined || options.has("TRUNCATE_EXISTING")) {
|
|
206
|
+
files.writeFile?.(path, text);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
files.writeFile?.(
|
|
210
|
+
path,
|
|
211
|
+
options.has("APPEND") ? existing + text : text + existing.slice(text.length),
|
|
212
|
+
);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// Java's File#getParentFile has no parent for a file name without a directory.
|
|
216
|
+
const makeParentDirectory = (files: FileSystem, path: string) => {
|
|
217
|
+
const separator = path.lastIndexOf("/");
|
|
218
|
+
if (separator !== -1) files.makeDirectory?.(path.slice(0, Math.max(separator, 1)));
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const readText = (files: FileSystem, path: string) => {
|
|
222
|
+
const text = files.readFile?.(path);
|
|
223
|
+
if (text === undefined) throw new TlaEvaluationError(`${path} (No such file or directory)`);
|
|
161
224
|
return text;
|
|
162
225
|
};
|
|
163
226
|
|
|
164
227
|
export const createJsonOperators = (files: FileSystem): Builtin[] => [
|
|
165
|
-
|
|
166
|
-
rankString(toJson(getValue(args, 0, "ToJson")
|
|
228
|
+
overrideWithJava(
|
|
229
|
+
defineStateOperator("ToJson", 1, (args) => rankString(toJson(getValue(args, 0, "ToJson")))),
|
|
230
|
+
"public static tlc2.value.impl.StringValue tlc2.module.Json.toJson(tlc2.value.IValue) throws java.io.IOException",
|
|
167
231
|
),
|
|
168
|
-
|
|
169
|
-
|
|
232
|
+
overrideWithJava(
|
|
233
|
+
defineStateOperator("ToJsonArray", 1, (args) =>
|
|
234
|
+
rankString(toJsonArray(getValue(args, 0, "ToJsonArray"))),
|
|
235
|
+
),
|
|
236
|
+
"public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonArray(tlc2.value.IValue) throws java.io.IOException",
|
|
170
237
|
),
|
|
171
|
-
|
|
172
|
-
|
|
238
|
+
overrideWithJava(
|
|
239
|
+
defineStateOperator("ToJsonObject", 1, (args) =>
|
|
240
|
+
rankString(toJsonObject(getValue(args, 0, "ToJsonObject"))),
|
|
241
|
+
),
|
|
242
|
+
"public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonObject(tlc2.value.IValue) throws java.io.IOException",
|
|
243
|
+
),
|
|
244
|
+
overrideWithJava(
|
|
245
|
+
defineStateOperator("JsonSerialize", 2, (args) => {
|
|
246
|
+
const path = getPath(getValue(args, 0, "JsonSerialize"));
|
|
247
|
+
const value = getValue(args, 1, "JsonSerialize");
|
|
248
|
+
if (!getSequenceElements(value) && !toRecord(value)) {
|
|
249
|
+
throw createModuleArgumentError("second", "JsonSerialize", "sequence or record", value);
|
|
250
|
+
}
|
|
251
|
+
makeParentDirectory(files, path);
|
|
252
|
+
files.writeFile?.(path, toJson(value));
|
|
253
|
+
return true;
|
|
254
|
+
}),
|
|
255
|
+
"public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.serialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException",
|
|
256
|
+
),
|
|
257
|
+
overrideWithJava(
|
|
258
|
+
defineStateOperator("ndJsonSerialize", 2, (args) => {
|
|
259
|
+
const path = getPath(getValue(args, 0, "ndJsonSerialize"));
|
|
260
|
+
const value = getValue(args, 1, "ndJsonSerialize");
|
|
261
|
+
const elements = getSequenceElements(value);
|
|
262
|
+
if (!elements) {
|
|
263
|
+
throw createModuleArgumentError("second", "ndJsonSerialize", "sequence", value);
|
|
264
|
+
}
|
|
265
|
+
makeParentDirectory(files, path);
|
|
266
|
+
files.writeFile?.(path, elements.map((element) => `${toJson(element)}\n`).join(""));
|
|
267
|
+
return true;
|
|
268
|
+
}),
|
|
269
|
+
"public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException",
|
|
270
|
+
),
|
|
271
|
+
overrideWithJava(
|
|
272
|
+
defineStateOperator("JsonDeserialize", 1, (args) =>
|
|
273
|
+
fromJson(readJson(readText(files, getPath(getValue(args, 0, "JsonDeserialize"))))),
|
|
274
|
+
),
|
|
275
|
+
"public static tlc2.value.IValue tlc2.module.Json.deserialize(tlc2.value.impl.StringValue) throws java.io.IOException",
|
|
276
|
+
),
|
|
277
|
+
overrideWithJava(
|
|
278
|
+
defineStateOperator("ndJsonDeserialize", 1, (args) =>
|
|
279
|
+
createTuple(
|
|
280
|
+
readText(files, getPath(getValue(args, 0, "ndJsonDeserialize")))
|
|
281
|
+
.split(/\r\n|\r|\n/)
|
|
282
|
+
// Java's String#trim strips every character up to the space.
|
|
283
|
+
.map((line) => line.replace(/^[^!-\uffff]+|[^!-\uffff]+$/g, ""))
|
|
284
|
+
.filter((line) => line !== "")
|
|
285
|
+
.map((line) => fromJson(readJson(line))),
|
|
286
|
+
),
|
|
287
|
+
),
|
|
288
|
+
"public static tlc2.value.IValue tlc2.module.Json.ndDeserialize(tlc2.value.impl.StringValue) throws java.io.IOException",
|
|
289
|
+
),
|
|
290
|
+
];
|
|
291
|
+
|
|
292
|
+
// TLC's Json overrides IOUtils!Serialize, as the CommunityModules define it, for the NDJSON format
|
|
293
|
+
// and falls back to its definition for any other.
|
|
294
|
+
export const createIoUtilsOperators = (
|
|
295
|
+
files: FileSystem,
|
|
296
|
+
evaluateReplaced: (name: string, args: BuiltinArgument[], context: Context | undefined) => Value,
|
|
297
|
+
): Builtin[] => [
|
|
298
|
+
overrideWithJava(
|
|
299
|
+
defineLazyOperator("Serialize", 3, (args, context) => {
|
|
300
|
+
const third = getThunk(args, 2, "Serialize")();
|
|
301
|
+
const options = toRecord(third);
|
|
302
|
+
if (!options) throw createModuleArgumentError("third", "ndJsonSerialize", "sequence", third);
|
|
303
|
+
if (getStringOption(options, "format") !== "NDJSON") {
|
|
304
|
+
return evaluateReplaced("Serialize", args, context);
|
|
305
|
+
}
|
|
306
|
+
const payload = getThunk(args, 0, "Serialize")();
|
|
307
|
+
const elements = getSequenceElements(payload);
|
|
308
|
+
if (!elements) throw createModuleArgumentError("first", "Serialize", "sequence", payload);
|
|
309
|
+
const path = getThunk(args, 1, "Serialize")();
|
|
310
|
+
if (typeof path !== "string") {
|
|
311
|
+
throw createModuleArgumentError("second", "ndJsonSerialize", "sequence", path);
|
|
312
|
+
}
|
|
313
|
+
const openOptions = applyFunction(options, "openOptions");
|
|
314
|
+
if (getJavaClassName(openOptions) !== "TupleValue") {
|
|
315
|
+
throw createClassCastError(openOptions, "TupleValue");
|
|
316
|
+
}
|
|
317
|
+
const charset = getStringOption(options, "charset");
|
|
318
|
+
const names = toFiniteFunction(openOptions).range.map((option) => {
|
|
319
|
+
if (typeof option !== "string") throw createClassCastError(option, "StringValue");
|
|
320
|
+
return option;
|
|
321
|
+
});
|
|
322
|
+
checkCharset(charset);
|
|
323
|
+
writeWithOptions(
|
|
324
|
+
files,
|
|
325
|
+
path,
|
|
326
|
+
names,
|
|
327
|
+
elements.map((element) => `${toJson(element)}\n`).join(""),
|
|
328
|
+
);
|
|
329
|
+
return true;
|
|
330
|
+
}),
|
|
331
|
+
"public static synchronized tlc2.value.impl.Value tlc2.module.Json.textSerialize(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
|
|
173
332
|
),
|
|
174
|
-
defineStateOperator("JsonSerialize", 2, (args) => {
|
|
175
|
-
const path = getPath(getValue(args, 0, "JsonSerialize"), SERIALIZE_SIGNATURE);
|
|
176
|
-
const value = getValue(args, 1, "JsonSerialize");
|
|
177
|
-
if (!getSequenceElements(value) && !isRecord(value)) {
|
|
178
|
-
throw createModuleArgumentError("second", "JsonSerialize", "sequence or record", value);
|
|
179
|
-
}
|
|
180
|
-
files.writeFile?.(path, toJson(value, SERIALIZE_SIGNATURE));
|
|
181
|
-
return true;
|
|
182
|
-
}),
|
|
183
|
-
defineStateOperator("ndJsonSerialize", 2, (args) => {
|
|
184
|
-
const path = getPath(getValue(args, 0, "ndJsonSerialize"), ND_SERIALIZE_SIGNATURE);
|
|
185
|
-
const value = getValue(args, 1, "ndJsonSerialize");
|
|
186
|
-
const elements = getSequenceElements(value);
|
|
187
|
-
if (!elements) {
|
|
188
|
-
throw createModuleArgumentError("second", "ndJsonSerialize", "sequence", value);
|
|
189
|
-
}
|
|
190
|
-
files.writeFile?.(
|
|
191
|
-
path,
|
|
192
|
-
elements.map((element) => `${toJson(element, ND_SERIALIZE_SIGNATURE)}\n`).join(""),
|
|
193
|
-
);
|
|
194
|
-
return true;
|
|
195
|
-
}),
|
|
196
|
-
defineStateOperator("JsonDeserialize", 1, (args) => {
|
|
197
|
-
const path = getPath(getValue(args, 0, "JsonDeserialize"), DESERIALIZE_SIGNATURE);
|
|
198
|
-
return parseJson(readText(files, path, DESERIALIZE_SIGNATURE), DESERIALIZE_SIGNATURE);
|
|
199
|
-
}),
|
|
200
|
-
defineStateOperator("ndJsonDeserialize", 1, (args) => {
|
|
201
|
-
const path = getPath(getValue(args, 0, "ndJsonDeserialize"), ND_DESERIALIZE_SIGNATURE);
|
|
202
|
-
return createTuple(
|
|
203
|
-
readText(files, path, ND_DESERIALIZE_SIGNATURE)
|
|
204
|
-
.split(/\r\n|\r|\n/)
|
|
205
|
-
.map((line) => line.trim())
|
|
206
|
-
.filter((line) => line !== "")
|
|
207
|
-
.map((line) => parseJson(line, ND_DESERIALIZE_SIGNATURE)),
|
|
208
|
-
);
|
|
209
|
-
}),
|
|
210
333
|
];
|
package/src/levels.ts
CHANGED
|
@@ -61,7 +61,6 @@ interface Operand {
|
|
|
61
61
|
declared?: OperatorParam;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
// The levels of tla2sany.semantic.LevelConstants.
|
|
65
64
|
export const CONSTANT_LEVEL = 0;
|
|
66
65
|
export const VARIABLE_LEVEL = 1;
|
|
67
66
|
export const ACTION_LEVEL = 2;
|
|
@@ -185,7 +184,6 @@ const bindFormals = (scope: Scope, formals: OperatorParam[]) =>
|
|
|
185
184
|
|
|
186
185
|
const toFormals = (names: string[]) => names.map((name) => ({ name, arity: 0 }));
|
|
187
186
|
|
|
188
|
-
// SANY reports a level error at the range of the expression it rejects.
|
|
189
187
|
const createLevelError = (message: string, expression: Expression) =>
|
|
190
188
|
expression.location.range
|
|
191
189
|
? createSemanticError(`${message}.`, expression.location.range)
|
|
@@ -436,6 +434,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
436
434
|
data.params.add(name);
|
|
437
435
|
return { data, declared: { name, arity: resolved.arity } };
|
|
438
436
|
}
|
|
437
|
+
if (expression.kind === "OperatorReference") return { data: createData() };
|
|
439
438
|
}
|
|
440
439
|
return { data: analyze(expression, scope) };
|
|
441
440
|
};
|
|
@@ -905,7 +904,7 @@ export const checkModuleLevels = (
|
|
|
905
904
|
? analyzeAssumeProve(body.statement, new Map(), analyzer).level
|
|
906
905
|
: getLevel([body.statement]);
|
|
907
906
|
};
|
|
908
|
-
//
|
|
907
|
+
// The proof of a temporal goal may only assume constants.
|
|
909
908
|
const checkTemporalGoal = (proof: Proof | undefined): SanyError[] =>
|
|
910
909
|
proof?.kind !== "Steps"
|
|
911
910
|
? []
|
package/src/lexer.ts
CHANGED
|
@@ -234,7 +234,6 @@ const SYMBOL_OPERATORS = [
|
|
|
234
234
|
"?",
|
|
235
235
|
];
|
|
236
236
|
|
|
237
|
-
// The Unicode forms of the operators SANY's grammar, javacc/tla+.jj, reads, as their ASCII forms.
|
|
238
237
|
const UNICODE_OPERATORS = new Map([
|
|
239
238
|
["∃", "\\E"],
|
|
240
239
|
["∀", "\\A"],
|
|
@@ -320,13 +319,13 @@ const NUMBER_BASES = new Map([
|
|
|
320
319
|
["h", 16],
|
|
321
320
|
]);
|
|
322
321
|
|
|
323
|
-
// A numeral token keeps its text
|
|
322
|
+
// A numeral token keeps its text, such as \hFF, so errors can quote it as TLC does.
|
|
324
323
|
export const getNumeralValue = (text: string) =>
|
|
325
324
|
text.startsWith("\\")
|
|
326
325
|
? parseInt(text.slice(2), NUMBER_BASES.get(text[1].toLowerCase()))
|
|
327
326
|
: Number(text);
|
|
328
327
|
|
|
329
|
-
const MODULE_HEADER = /-{4,}
|
|
328
|
+
const MODULE_HEADER = /-{4,} *MODULE\b/;
|
|
330
329
|
|
|
331
330
|
const CODE_TAB = 9;
|
|
332
331
|
const CODE_NEWLINE = 10;
|
|
@@ -352,7 +351,6 @@ const IDENTIFIER = DIGIT | LETTER | UNDERSCORE;
|
|
|
352
351
|
|
|
353
352
|
const LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
|
|
354
353
|
|
|
355
|
-
// The classes each ASCII character belongs to, as a bit each.
|
|
356
354
|
const CHARACTER_CLASSES = new Uint8Array(128);
|
|
357
355
|
new Map([
|
|
358
356
|
["0123456789", DIGIT | HEX_DIGIT],
|
|
@@ -382,8 +380,7 @@ interface OperatorMatch {
|
|
|
382
380
|
length: number;
|
|
383
381
|
}
|
|
384
382
|
|
|
385
|
-
//
|
|
386
|
-
// lists a longer operator before the operators it starts with.
|
|
383
|
+
// In the order of SYMBOL_OPERATORS, which lists a longer operator before its prefixes.
|
|
387
384
|
const SYMBOL_OPERATORS_BY_START = new Map<number, string[]>();
|
|
388
385
|
SYMBOL_OPERATORS.forEach((symbol) => {
|
|
389
386
|
const start = symbol.charCodeAt(0);
|
|
@@ -430,8 +427,7 @@ export const matchOperator = (source: string, index: number): OperatorMatch | un
|
|
|
430
427
|
return code === CODE_BACKSLASH ? { text: "\\", length: 1 } : undefined;
|
|
431
428
|
};
|
|
432
429
|
|
|
433
|
-
// TLC's
|
|
434
|
-
// ℕ, ℤ, or ℝ, as one token, which it compares as written with the words it expects.
|
|
430
|
+
// TLC's config parser reads ℕ, ℤ, ℝ, or a Unicode operator as one token, compared as written.
|
|
435
431
|
const UNICODE_NAMES = new Set(["ℕ", "ℤ", "ℝ"]);
|
|
436
432
|
export const matchUnicodeToken = (source: string, index: number): OperatorMatch | undefined => {
|
|
437
433
|
const token = [source.slice(index, index + 2), source[index]].find(
|
|
@@ -450,14 +446,15 @@ export const skipWhile = (
|
|
|
450
446
|
return end.value;
|
|
451
447
|
};
|
|
452
448
|
|
|
453
|
-
//
|
|
454
|
-
|
|
455
|
-
const matchStep = (source: string, index: number) => {
|
|
449
|
+
// SANY reads a step number as one token anywhere, and tlapm reads no name after <*> or <+>.
|
|
450
|
+
const matchStep = (source: string, index: number, isTlapm: boolean) => {
|
|
456
451
|
const isImplicit = source[index + 1] === "+" || source[index + 1] === "*";
|
|
457
452
|
const levelEnd = isImplicit ? index + 2 : skipClass(source, index + 1, DIGIT);
|
|
458
453
|
if (levelEnd === index + 1 || source[levelEnd] !== ">") return 0;
|
|
459
|
-
const
|
|
460
|
-
const
|
|
454
|
+
const isNamed = !isImplicit || !isTlapm;
|
|
455
|
+
const nameEnd = isNamed ? skipClass(source, levelEnd + 1, IDENTIFIER) : levelEnd + 1;
|
|
456
|
+
const isDash =
|
|
457
|
+
isNamed && nameEnd === levelEnd + 1 && (source[nameEnd] === "*" || source[nameEnd] === "-");
|
|
461
458
|
return (
|
|
462
459
|
skipWhile(source, isDash ? nameEnd + 1 : nameEnd, (character) => character === ".") - index
|
|
463
460
|
);
|
|
@@ -480,8 +477,7 @@ const BASED_NUMBER_DIGITS = new Map([
|
|
|
480
477
|
["h", HEX_DIGIT],
|
|
481
478
|
]);
|
|
482
479
|
|
|
483
|
-
|
|
484
|
-
const matchBasedNumber = (source: string, index: number) => {
|
|
480
|
+
export const matchBasedNumber = (source: string, index: number) => {
|
|
485
481
|
if (source.charCodeAt(index) !== CODE_BACKSLASH) return 0;
|
|
486
482
|
const digits = BASED_NUMBER_DIGITS.get(source.charAt(index + 1).toLowerCase());
|
|
487
483
|
if (digits === undefined) return 0;
|
|
@@ -489,7 +485,7 @@ const matchBasedNumber = (source: string, index: number) => {
|
|
|
489
485
|
return end === index + 2 ? 0 : end - index;
|
|
490
486
|
};
|
|
491
487
|
|
|
492
|
-
export const tokenize = (source: string): Token[] => {
|
|
488
|
+
export const tokenize = (source: string, isTlapm = false): Token[] => {
|
|
493
489
|
const headerMatch = MODULE_HEADER.exec(source);
|
|
494
490
|
if (!headerMatch)
|
|
495
491
|
throw new TlaSyntaxError("Expected a module header such as ---- MODULE Name ----");
|
|
@@ -553,8 +549,8 @@ export const tokenize = (source: string): Token[] => {
|
|
|
553
549
|
continue;
|
|
554
550
|
}
|
|
555
551
|
if (code === CODE_BACKSLASH && source.charCodeAt(cursor.index + 1) === CODE_STAR) {
|
|
556
|
-
const lineEnd = source.
|
|
557
|
-
advanceOver(
|
|
552
|
+
const lineEnd = skipWhile(source, cursor.index, (next) => next !== "\n" && next !== "\r");
|
|
553
|
+
advanceOver(lineEnd - cursor.index);
|
|
558
554
|
continue;
|
|
559
555
|
}
|
|
560
556
|
if (code === CODE_OPEN_PAREN && source.charCodeAt(cursor.index + 1) === CODE_STAR) {
|
|
@@ -575,13 +571,8 @@ export const tokenize = (source: string): Token[] => {
|
|
|
575
571
|
}
|
|
576
572
|
if (code === CODE_DASH && source.startsWith("----", cursor.index)) {
|
|
577
573
|
const length = skipWhile(source, cursor.index, (next) => next === "-") - cursor.index;
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
.slice(cursor.index + length)
|
|
581
|
-
.trimStart()
|
|
582
|
-
.startsWith("MODULE")
|
|
583
|
-
)
|
|
584
|
-
cursor.moduleDepth++;
|
|
574
|
+
const keyword = skipWhile(source, cursor.index + length, (next) => next === " ");
|
|
575
|
+
if (source.startsWith("MODULE", keyword)) cursor.moduleDepth++;
|
|
585
576
|
pushToken("Separator", "----", length);
|
|
586
577
|
continue;
|
|
587
578
|
}
|
|
@@ -663,7 +654,7 @@ export const tokenize = (source: string): Token[] => {
|
|
|
663
654
|
continue;
|
|
664
655
|
}
|
|
665
656
|
if (code === CODE_LESS_THAN) {
|
|
666
|
-
const stepLength = matchStep(source, cursor.index);
|
|
657
|
+
const stepLength = matchStep(source, cursor.index, isTlapm);
|
|
667
658
|
if (stepLength > 0) {
|
|
668
659
|
pushToken("Step", source.slice(cursor.index, cursor.index + stepLength), stepLength);
|
|
669
660
|
continue;
|