tla-ts 0.0.3-dev.4c8c06c → 0.0.3-dev.5e6ab4d

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.3-dev.4c8c06c",
3
+ "version": "0.0.3-dev.5e6ab4d",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",
@@ -128,7 +128,11 @@ const run = (start: StartMessage, parent: Port) => {
128
128
  if (isSharedFingerprintsFull(shared.fingerprints)) return "paused";
129
129
  const successor = successors[expansion.index];
130
130
  if (search.findViolatedActionProperty(state, successor.state)) return undefined;
131
- if (!search.satisfiesActionConstraints(state, successor.state)) continue;
131
+ if (!search.satisfiesActionConstraints(state, successor.state)) {
132
+ // TLC checks the invariants of every successor it has not seen, even outside the model.
133
+ if (search.findViolatedInvariant(successor.state, state)) return undefined;
134
+ continue;
135
+ }
132
136
  if (generatedStates) {
133
137
  writeStateFingerprint(successor.state, fingerprint);
134
138
  if (!generatedStates.insert(fingerprint[0], fingerprint[1])) continue;
package/src/parser.ts CHANGED
@@ -135,6 +135,8 @@ const INFIX_OPERATORS = new Map<string, InfixOperator>([
135
135
  ["^^", createInfix(14, 14, false)],
136
136
  ]);
137
137
 
138
+ const NEGATION_PRECEDENCE = 12;
139
+
138
140
  const POSTFIX_OPERATORS = new Set(["^+", "^*", "^#"]);
139
141
 
140
142
  const PREFIX_OPERATOR_REFERENCES = new Set(["-", "~", "-."]);
@@ -977,7 +979,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
977
979
  return { kind: "Apply", operator: "~", args: [parseExpression(5)], location };
978
980
  case "-":
979
981
  advance();
980
- return { kind: "Apply", operator: "-.", args: [parseExpression(13)], location };
982
+ return {
983
+ kind: "Apply",
984
+ operator: "-.",
985
+ args: [parseExpression(NEGATION_PRECEDENCE + 1)],
986
+ location,
987
+ };
981
988
  case "[]":
982
989
  advance();
983
990
  return { kind: "Always", expression: parseExpression(16), location };
@@ -1054,6 +1061,10 @@ const parse = (source: string, isTlapm: boolean): Module => {
1054
1061
  }
1055
1062
  }
1056
1063
  advance();
1064
+ // SANY reads - after an infix operator as prefix -, and rejects it after one that binds tighter.
1065
+ if (infix.low > NEGATION_PRECEDENCE && isAt("-")) {
1066
+ throw createError(`Precedence conflict between ${token.text} and -`, peek());
1067
+ }
1057
1068
  const right = parseExpression(infix.high + 1);
1058
1069
  const left = state.left;
1059
1070
  if (token.text === "/\\" || token.text === "\\/") {
package/src/tlc-order.ts CHANGED
@@ -184,9 +184,18 @@ const isAdjacent = (left: Token, right: Token | undefined) =>
184
184
  right.line === left.line &&
185
185
  right.column === left.column + left.text.length;
186
186
 
187
+ const STRING_ESCAPES: Record<string, string> = {
188
+ "\\": "\\\\",
189
+ '"': '\\"',
190
+ "\n": "\\n",
191
+ "\t": "\\t",
192
+ "\r": "\\r",
193
+ "\f": "\\f",
194
+ };
195
+
187
196
  // The texts SANY interns while parsing, in order. SANY reads a proof step label such as <1>2 and
188
- // a module header such as ---- MODULE as one token, and interns a string literal's contents only
189
- // during semantic analysis.
197
+ // a module header such as ---- MODULE as one token. It interns a string literal as written, quotes
198
+ // included, and interns the literal's contents only during semantic analysis.
190
199
  const getParsedTexts = (tokens: Token[]) => {
191
200
  const texts: string[] = [];
192
201
  for (let index = 0; index < tokens.length; index++) {
@@ -202,7 +211,12 @@ const getParsedTexts = (tokens: Token[]) => {
202
211
  continue;
203
212
  }
204
213
  const isHeader = token.text === "MODULE" && tokens[index - 1]?.kind === "Separator";
205
- if (token.kind !== "String" && !isHeader) texts.push(token.text);
214
+ if (isHeader) continue;
215
+ texts.push(
216
+ token.kind === "String"
217
+ ? `"${token.text.replace(/[\\"\n\t\r\f]/g, (character) => STRING_ESCAPES[character])}"`
218
+ : token.text,
219
+ );
206
220
  }
207
221
  return texts;
208
222
  };