lemmascript 0.6.6 → 0.6.7

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 CHANGED
@@ -4,6 +4,8 @@ A verification toolchain for TypeScript. Write ordinary TypeScript with `//@ ` s
4
4
 
5
5
  See [SPEC.md](SPEC.md), [DESIGN.md](DESIGN.md), and [GETTING_STARTED.md](GETTING_STARTED.md).
6
6
 
7
+ For changes to LemmaScript itself, see [CONTRIBUTING.md](CONTRIBUTING.md).
8
+
7
9
  This is a **Tech Preview**: the core idea is there, but support, semantics, and ergonomics are still evolving.
8
10
 
9
11
  See our [blog post](https://midspiral.com/blog/lemmascript-a-verification-toolchain-for-typescript/).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lemmascript",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "A verification toolchain for TypeScript — generates Lean 4 or Dafny from annotated TS",
5
5
  "type": "module",
6
6
  "engines": {
@@ -49,6 +49,13 @@ export const OPTION_SPECS = {
49
49
  fileOverride: false,
50
50
  description: "Record lsc check and regen runs in .lemmascript/.",
51
51
  },
52
+ "unread-annotations": {
53
+ type: "enum",
54
+ values: ["off", "warn", "error"],
55
+ default: "warn",
56
+ fileOverride: true,
57
+ description: "What lsc does with a //@ annotation it does not read: ignore it, warn, or fail.",
58
+ },
52
59
  };
53
60
  export const DEFAULT_OPTIONS = Object.freeze(Object.fromEntries(Object.entries(OPTION_SPECS).map(([key, spec]) => [key, spec.default])));
54
61
  const KNOWN_KEYS = Object.keys(OPTION_SPECS);
@@ -110,13 +117,14 @@ function parseDirectiveValue(key, text, source) {
110
117
  return parseOptionValue(key, text, source);
111
118
  }
112
119
  /**
113
- * Find comment lines, marking those that occur before any code.
120
+ * Find comment lines and the comment on each, marking those that occur before
121
+ * any code.
114
122
  *
115
123
  * Use the parsed syntax tree to skip strings, regexes, and template text.
116
124
  * Without those boundaries, the scanner can read /[/*]/ as a block comment
117
125
  * or treat a template's closing backtick as the start of another template.
118
126
  */
119
- function* fileCommentLines(sourceText) {
127
+ export function* fileCommentLines(sourceText) {
120
128
  // Normalize once so a leading BOM also works before a shebang.
121
129
  sourceText = sourceText.replace(/^\uFEFF/, "");
122
130
  const lines = sourceText.split(/\r\n|[\n\r\u2028\u2029]/);
@@ -139,8 +147,9 @@ function* fileCommentLines(sourceText) {
139
147
  if (token === ts.SyntaxKind.SingleLineCommentTrivia || token === ts.SyntaxKind.MultiLineCommentTrivia) {
140
148
  const firstLine = sourceFile.getLineAndCharacterOfPosition(scanner.getTokenStart()).line;
141
149
  const lastLine = sourceFile.getLineAndCharacterOfPosition(scanner.getTokenEnd() - 1).line;
150
+ const comment = scanner.getTokenText();
142
151
  for (let index = firstLine; index <= lastLine; index++) {
143
- yield { text: lines[index], index, inLeadingRegion };
152
+ yield { text: lines[index], comment, index, inLeadingRegion };
144
153
  }
145
154
  }
146
155
  else if (token !== ts.SyntaxKind.WhitespaceTrivia && token !== ts.SyntaxKind.NewLineTrivia &&
@@ -152,6 +161,20 @@ function* fileCommentLines(sourceText) {
152
161
  }
153
162
  }
154
163
  }
164
+ const OPTION_DIRECTIVE = /^[ \t]*\/\/@[ \t]+option(?:[ \t]+(.*?))?[ \t]*$/;
165
+ const ALIAS_DIRECTIVE = /^[ \t]*\/\/@[ \t]+([A-Za-z][A-Za-z0-9-]*)[ \t]*$/;
166
+ /** The option a legacy alias such as `//@ safe-slice` sets, if `line` is one. */
167
+ function aliasedOption(line) {
168
+ const alias = line.match(ALIAS_DIRECTIVE)?.[1];
169
+ if (alias === undefined)
170
+ return undefined;
171
+ return KNOWN_KEYS.find(key => "directiveAliases" in OPTION_SPECS[key] &&
172
+ OPTION_SPECS[key].directiveAliases.includes(alias));
173
+ }
174
+ /** Whether `parseFileOptions` reads `line` as an option directive or a legacy alias. */
175
+ export function isOptionDirective(line) {
176
+ return OPTION_DIRECTIVE.test(line) || aliasedOption(line) !== undefined;
177
+ }
155
178
  /** Parse top-of-file `//@ option key value` directives and legacy aliases. */
156
179
  export function parseFileOptions(sourceText, source) {
157
180
  const seen = new Map();
@@ -166,7 +189,7 @@ export function parseFileOptions(sourceText, source) {
166
189
  };
167
190
  const parseLine = (lineText, index, inLeadingRegion) => {
168
191
  const line = index + 1;
169
- const optionMatch = lineText.match(/^[ \t]*\/\/@[ \t]+option(?:[ \t]+(.*?))?[ \t]*$/);
192
+ const optionMatch = lineText.match(OPTION_DIRECTIVE);
170
193
  if (optionMatch) {
171
194
  if (!inLeadingRegion)
172
195
  fail(`${source}:${line}`, "//@ option directives must appear before the first source statement");
@@ -183,21 +206,11 @@ export function parseFileOptions(sourceText, source) {
183
206
  setOption(rawKey, parseDirectiveValue(rawKey, rawValue, `${source}:${line}`), line);
184
207
  return;
185
208
  }
186
- const aliasMatch = lineText.match(/^[ \t]*\/\/@[ \t]+([A-Za-z][A-Za-z0-9-]*)[ \t]*$/);
187
- if (!aliasMatch)
188
- return;
189
- const alias = aliasMatch[1];
190
- for (const key of KNOWN_KEYS) {
191
- const aliases = "directiveAliases" in OPTION_SPECS[key]
192
- ? OPTION_SPECS[key].directiveAliases
193
- : [];
194
- if (!aliases.includes(alias))
195
- continue;
196
- // Legacy aliases retain their pre-config placement behavior. New generic
197
- // option directives are deliberately restricted to the file preamble.
209
+ // Legacy aliases retain their pre-config placement behavior. New generic
210
+ // option directives are deliberately restricted to the file preamble.
211
+ const key = aliasedOption(lineText);
212
+ if (key)
198
213
  setOption(key, true, line);
199
- return;
200
- }
201
214
  };
202
215
  for (const { text, index, inLeadingRegion } of fileCommentLines(sourceText)) {
203
216
  parseLine(text, index, inLeadingRegion);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Dafny emitter — IR → Dafny text.
3
3
  */
4
- import { exactIntegerLiteral, usesName, usesNameInDecl, usesNameInStmts } from "./ir.js";
4
+ import { decimalNumberLiteral, exactIntegerLiteral, usesName, usesNameInDecl, usesNameInStmts } from "./ir.js";
5
5
  import { freshNameWhere, userNames } from "./names.js";
6
6
  import { renameFreeVar } from "./transform.js";
7
7
  import { DEFAULT_OPTIONS, resolveOptions } from "./config.js";
@@ -268,7 +268,7 @@ function wrapQuantifier(sub) {
268
268
  function emitExpr(e) {
269
269
  switch (e.kind) {
270
270
  case "var": return e.name === "undefined" ? "None" : escapeName(e.name);
271
- case "num": return `${e.value}`;
271
+ case "num": return decimalNumberLiteral(e.value);
272
272
  // Already canonical decimal; Dafny's `int` is mathematical, so no `n` suffix.
273
273
  case "bigint": return e.value;
274
274
  case "bool": return e.value ? "true" : "false";