tla-ts 0.0.3-dev.fca2ca8 → 0.0.3-dev.fd18eec
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/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/run-cli.cjs +3 -2
- package/dist/run-cli.js +19 -18
- package/dist/transfer.cjs +23 -17
- package/dist/transfer.js +23 -17
- package/package.json +1 -1
- package/src/ast.ts +2 -0
- package/src/check.ts +1 -1
- package/src/config.ts +224 -170
- package/src/environment.ts +23 -5
- package/src/errors.ts +30 -1
- package/src/evaluate.ts +1 -5
- package/src/parser.ts +17 -9
- package/src/resolve.ts +45 -15
- package/src/run-cli.ts +27 -8
- package/src/spec-description.ts +1 -2
package/dist/index.d.cts
CHANGED
|
@@ -46,6 +46,7 @@ interface ApplyExpression {
|
|
|
46
46
|
operator: string;
|
|
47
47
|
args: Expression[];
|
|
48
48
|
argumentCounts?: number[];
|
|
49
|
+
argumentsRange?: SourceRange;
|
|
49
50
|
location: SourceLocation;
|
|
50
51
|
resolution?: LocalResolution;
|
|
51
52
|
}
|
|
@@ -589,9 +590,18 @@ interface SyntaxFailure {
|
|
|
589
590
|
column: number;
|
|
590
591
|
isEnd: boolean;
|
|
591
592
|
}
|
|
593
|
+
interface SanyError {
|
|
594
|
+
location: string;
|
|
595
|
+
message: string;
|
|
596
|
+
}
|
|
597
|
+
interface SanyReport {
|
|
598
|
+
errors: SanyError[];
|
|
599
|
+
isFatal: boolean;
|
|
600
|
+
}
|
|
592
601
|
export declare class TlaSyntaxError extends TlaError {
|
|
593
602
|
failure: SyntaxFailure | undefined;
|
|
594
|
-
|
|
603
|
+
sany: SanyReport | undefined;
|
|
604
|
+
constructor(message: string, cause?: unknown, failure?: SyntaxFailure, sany?: SanyReport);
|
|
595
605
|
}
|
|
596
606
|
export declare class TlaConfigError extends TlaError {
|
|
597
607
|
constructor(message: string, cause?: unknown);
|
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ interface ApplyExpression {
|
|
|
46
46
|
operator: string;
|
|
47
47
|
args: Expression[];
|
|
48
48
|
argumentCounts?: number[];
|
|
49
|
+
argumentsRange?: SourceRange;
|
|
49
50
|
location: SourceLocation;
|
|
50
51
|
resolution?: LocalResolution;
|
|
51
52
|
}
|
|
@@ -589,9 +590,18 @@ interface SyntaxFailure {
|
|
|
589
590
|
column: number;
|
|
590
591
|
isEnd: boolean;
|
|
591
592
|
}
|
|
593
|
+
interface SanyError {
|
|
594
|
+
location: string;
|
|
595
|
+
message: string;
|
|
596
|
+
}
|
|
597
|
+
interface SanyReport {
|
|
598
|
+
errors: SanyError[];
|
|
599
|
+
isFatal: boolean;
|
|
600
|
+
}
|
|
592
601
|
export declare class TlaSyntaxError extends TlaError {
|
|
593
602
|
failure: SyntaxFailure | undefined;
|
|
594
|
-
|
|
603
|
+
sany: SanyReport | undefined;
|
|
604
|
+
constructor(message: string, cause?: unknown, failure?: SyntaxFailure, sany?: SanyReport);
|
|
595
605
|
}
|
|
596
606
|
export declare class TlaConfigError extends TlaError {
|
|
597
607
|
constructor(message: string, cause?: unknown);
|
package/dist/run-cli.cjs
CHANGED
|
@@ -23,7 +23,8 @@ PROVE %a@]`,i)]};return{printSequent:p,printExpr:r}},Nt=(e,t)=>Mt(e).printExpr(
|
|
|
23
23
|
`).length,c=o-t.lastIndexOf(`
|
|
24
24
|
`,o-1),l=n.findLast(e=>e.kind!==`End`&&(e.line<s||e.line===s&&e.column<c));return{offset:o,line:s,column:c,end:{reason:Lr,line:l?.line??s,column:l?l.endColumn+1:c,isEnd:!0}}},Br=t=>{try{return t()}catch(t){if(!(t instanceof e.I)||!t.failure)throw t;return t.failure}},Vr=e=>typeof e==`object`&&!!e&&`reason`in e,Hr=t=>{let n=Br(()=>zr(t));if(Vr(n))return[n];let r=Br(()=>e.x(n?t.slice(0,n.offset):t));return n&&(!Vr(r)||r.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:n.line,column:n.column,isEnd:!1},Vr(r)&&r.reason===Lr?r:n.end]:Vr(r)?[r]:r},Ur=(t,n,r,i,a)=>{if(!Ir.test(t.source))throw new e.F(`No tokens in file`);let o=Hr(t.source);if(Array.isArray(o)){o.forEach(e=>{let n=`File ${JSON.stringify(t.file)}, line ${e.line}, character ${e.column}\n${e.reason}`;i({text:n,channel:`stderr`}),i({text:`${n}\n`,channel:`toolboxOnly`})});let n=`Could not parse ${JSON.stringify(t.file)} successfully.`;throw i({text:`${a}Error: ${n}`,channel:`stderr`}),new e.F(n,{failure:`Module.Parser.parse_file`})}let s=Pr(t.file,t.source,n,r).convertModule(o),c=t.file.slice(t.file.lastIndexOf(`/`)+1),l=c.replace(/\.tla$/,``);return s.name===l?s:(i({text:`${f(s.location)}Warning: module name ${JSON.stringify(s.name)} does not match file name ${JSON.stringify(c)}.`,channel:`toolbox`}),{...s,name:l})},Wr=t=>{let n=new Map([...t].map(([e,t])=>[e,Un(t).dependencies])),r=/* @__PURE__ */ new Set,i=[],a=o=>{if(r.has(o))return;r.add(o);let s=t.get(o);if(!s)throw new e.F(`Module "${o}" not found`);(n.get(o)??[]).forEach(a),i.push(s)};return[...t.keys()].sort(Gn).forEach(a),i},Gr=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${c(t)}`)],Kr=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?c({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...Gr(`missing`,e.absent,t),...Gr(`omitted`,e.omitted,n),` ====`]},qr=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...Kr(t,e.missing,e.omitted)],missing:e.missing+t.absent.length,omitted:e.omitted+t.omitted.length},{lines:[],missing:0,omitted:0});return[`---- summary of module ${JSON.stringify(e.name)} ----`,` obligations_count = ${t.total}`,...t.absent.length>0?[` missing_proofs_count = ${t.absent.length}`]:[],...t.omitted.length>0?[` omitted_proofs_count = ${t.omitted.length}`]:[],...n.lines,`====`].join(`
|
|
25
25
|
`)},Jr=(t,n,r={})=>{let i=r.lines??Fr,a=r.onWarning??(()=>{}),o={value:0},s=new Map(Ln);t.forEach(e=>{let t={...Ur(e,o,!0,a,`File "<unknown>":
|
|
26
|
-
`),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>Gn(e.name,t.name)),l=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=Un(c[e]);t.submodules.forEach((e,t)=>{f.add(t),s.has(t)||s.set(t,e)});for(let e of t.dependencies){if(s.has(e)&&!Ln.has(e))continue;let r=n(e);if(!r){!s.has(e)&&!l.has(e)&&l.set(e,t.locations.get(e));continue}let i=Ur(r,o,!1,a,u(t.locations.get(e)));s.set(e,i),c.push(i)}}let p=[...l.keys()].filter(e=>!f.has(e)).sort(Gn);if(p.forEach(e=>a(d(l.get(e),`Unknown module ${JSON.stringify(e)}`))),p.length>0)throw new e.F(`Unknown module ${JSON.stringify(p[0])}`,{failure:`Module.Parser.load_module`});let m={anonymizer:Be(o,(e,t)=>ar(m,e,t),a),generator:an(o,new Set(t.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},h=Wr(s).map(e=>e.isStandard?e:Hn(s,e,/* @__PURE__ */ new Set)),g=new Map(h.map(e=>[e.name,e]));return h.flatMap(e=>{if(e.isStandard)return[];let t=or(m,g,void 0,e);if(!e.isImportant)return[];let n=sr(m,[],t),r=n.obligations.flatMap((e,t)=>{let n=e.location;if(e.kind.kind===`Omitted`||n&&(n.startLine<i.start||n.endLine>i.end))return[];let r=e.kind.kind===`Error`?e.kind.message:`${Pt(e.sequent)}\n`;return[{id:t+1,location:Rr(n),text:r}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},Yr={success:e.
|
|
26
|
+
`),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>Gn(e.name,t.name)),l=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=Un(c[e]);t.submodules.forEach((e,t)=>{f.add(t),s.has(t)||s.set(t,e)});for(let e of t.dependencies){if(s.has(e)&&!Ln.has(e))continue;let r=n(e);if(!r){!s.has(e)&&!l.has(e)&&l.set(e,t.locations.get(e));continue}let i=Ur(r,o,!1,a,u(t.locations.get(e)));s.set(e,i),c.push(i)}}let p=[...l.keys()].filter(e=>!f.has(e)).sort(Gn);if(p.forEach(e=>a(d(l.get(e),`Unknown module ${JSON.stringify(e)}`))),p.length>0)throw new e.F(`Unknown module ${JSON.stringify(p[0])}`,{failure:`Module.Parser.load_module`});let m={anonymizer:Be(o,(e,t)=>ar(m,e,t),a),generator:an(o,new Set(t.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},h=Wr(s).map(e=>e.isStandard?e:Hn(s,e,/* @__PURE__ */ new Set)),g=new Map(h.map(e=>[e.name,e]));return h.flatMap(e=>{if(e.isStandard)return[];let t=or(m,g,void 0,e);if(!e.isImportant)return[];let n=sr(m,[],t),r=n.obligations.flatMap((e,t)=>{let n=e.location;if(e.kind.kind===`Omitted`||n&&(n.startLine<i.start||n.endLine>i.end))return[];let r=e.kind.kind===`Error`?e.kind.message:`${Pt(e.sequent)}\n`;return[{id:t+1,location:Rr(n),text:r}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},Yr={success:e.V.success,"assumption-violation":e.V.assumptionViolation,deadlock:e.V.deadlock,"invariant-violation":e.V.safetyViolation,"property-violation":e.V.safetyViolation,"liveness-violation":e.V.livenessViolation,"postcondition-violation":e.V.assumptionViolation,error:e.V.error},Xr=s(`tla-ts <Spec.tla|Spec.cfg|glob>... {options}`,[{flag:`-config <Spec.cfg>`},{flag:`-deadlock`},{flag:`-dump [<format>] <file>`,getArity:e=>e.length>1&&e[0].startsWith(`dot`)?2:1},{flag:`-lncheck <final|default>`},{flag:`-seed <num>`},{flag:`-workers <count|auto>`}]),Zr=s(`tla-ts prove {options} <Module.tla|glob>...`,[{flag:`-N`,isRequired:!0},{flag:`--toolbox <start> <end>`},{flag:`--line <num>`},{flag:`--printallobs`},{flag:`--summary`},{flag:`--strict`},{flag:`-I <directory>`,isRepeatable:!0}]),Qr=[`Usage: ${Xr.usage}`,` ${Zr.usage}`,` tla-ts prove [<tlapm option>]... <Module.tla|glob>...`].join(`
|
|
27
27
|
`),$r=/[*?[{]/,ei=e=>e.flatMap(e=>$r.test(e)?(0,n.globSync)(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),ti=e=>/^[+-]?\d+$/.test(e)&&BigInt.asIntN(64,BigInt(e))===BigInt(e),ni=e=>e?e[0]===`auto`?(0,a.availableParallelism)():Math.max(1,Number.parseInt(e[0],10)||1):1,ri=t=>console.log(e.E(t)),ii=[`constrained`,`stuttering`,`strict`],ai=(e,t)=>e.endsWith(t)?e:`${e}${t}`,oi=e=>{if(e.length===1)return{path:ai(e[0],`.dump`)};let t=e[0].toLowerCase();return{path:ai(e[1],`.dot`),dot:!0,colorize:t.includes(`colorize`),actionLabels:t.includes(`actionlabels`),snapshot:t.includes(`snapshot`)}},si=(e,t=`Error: The behavior up to this point is:`)=>{e.length>0&&console.log(t),e.forEach((e,t)=>{console.log(`State ${t+1}: <${e.label??e.action??`Initial predicate`}>`),ri(e.state)})},ci=e=>e.length===1?`Error: Temporal property ${e[0]} was violated.\n`:`Error: Temporal properties ${e.slice(0,-1).join(`, `)}${e.length>2?`,`:``} and ${e[e.length-1]} were violated.\n`,li=t=>{if(t.failure)console.log(`Error: ${t.failure.message}`),t.failure.initialState&&(console.log(`While working on the initial state:`),ri(t.failure.initialState)),si(t.failure.trace);else if(t.violation){let e=t.violation,n=e.name,r=e.loopStart,i=r===void 0&&e.trace.length===1&&(t.status===`invariant-violation`||t.status===`liveness-violation`),a={success:``,error:``,"assumption-violation":e.message?`Error: Evaluating assumption ${n} failed.\n${e.message}`:`Error: Assumption ${n} is false.`,deadlock:`Error: Deadlock reached.`,"invariant-violation":i?`Error: Invariant ${n} is violated by the initial state:`:`Error: Invariant ${n} is violated.`,"property-violation":ci(e.properties??[n]),"liveness-violation":r===void 0?i?`Error: Property ${n} is violated by the initial state:`:`Error: Action property ${n} is violated.`:ci(e.properties??[n]),"postcondition-violation":`Error: ${e.message??`Postcondition ${n} is false.`}`}[t.status];if(e.counts&&console.log(e.counts),console.log(a),i)ri(e.trace[0].state);else if(t.status===`property-violation`)si(e.trace,`Error: The following behavior constitutes a counter-example:
|
|
28
28
|
`);else if(r===void 0)si(e.trace);else{si(e.trace,`Error: The following behavior constitutes a counter-example:
|
|
29
|
-
`);let t=r===e.trace.length-1;console.log(t?`State ${r+2}: Stuttering`:`Back to state ${r+1}${e.loopLabel?`: <${e.loopLabel}>\n`:``}`)}let o=e.unwitnessed;if(o?.counts&&console.log(o.counts),o&&console.log(`Error: ${o.message}`),i||t.status===`assumption-violation`)return}else{let n=e.h(t.distinctStates,t.generatedStates);if(console.log(`Model checking completed. No error has been found.`),console.log(` Estimates of the probability that TLC did not check all reachable states`),console.log(` because two distinct states had the same fingerprint:`),console.log(` calculated (optimistic): val = ${e.f(n)}`),t.fingerprintDistance!==void 0){let n=e.p(t.fingerprintDistance);console.log(` based on the actual fingerprints: val = ${e.f(n)}`)}}console.log(`${t.generatedStates} states generated, ${t.distinctStates} distinct states found, ${t.queuedStates} states left on queue.`),console.log(`The depth of the complete state graph search is ${t.depth}.`);let n=t.outDegrees&&e.g(t.outDegrees);n&&console.log(n)},ui=async(r,a)=>{if(!(0,n.existsSync)(r))return console.error(`Cannot find the specification file ${r}`),e.
|
|
29
|
+
`);let t=r===e.trace.length-1;console.log(t?`State ${r+2}: Stuttering`:`Back to state ${r+1}${e.loopLabel?`: <${e.loopLabel}>\n`:``}`)}let o=e.unwitnessed;if(o?.counts&&console.log(o.counts),o&&console.log(`Error: ${o.message}`),i||t.status===`assumption-violation`)return}else{let n=e.h(t.distinctStates,t.generatedStates);if(console.log(`Model checking completed. No error has been found.`),console.log(` Estimates of the probability that TLC did not check all reachable states`),console.log(` because two distinct states had the same fingerprint:`),console.log(` calculated (optimistic): val = ${e.f(n)}`),t.fingerprintDistance!==void 0){let n=e.p(t.fingerprintDistance);console.log(` based on the actual fingerprints: val = ${e.f(n)}`)}}console.log(`${t.generatedStates} states generated, ${t.distinctStates} distinct states found, ${t.queuedStates} states left on queue.`),console.log(`The depth of the complete state graph search is ${t.depth}.`);let n=t.outDegrees&&e.g(t.outDegrees);n&&console.log(n)},ui=async(r,a)=>{if(!(0,n.existsSync)(r))return console.error(`Cannot find the specification file ${r}`),e.V.configParseError;let o=(0,n.readFileSync)(r,`utf8`),s=(0,i.basename)(r,`.tla`),c=e.b(o).name;if(c!==s)throw e.z([{location:`Unknown location`,message:`File name '${s}' does not match the name '${c}' of the top level module it contains.`}],!0);let l=a.get(`-config`)?.[0]??(a.has(`-config`)?void 0:r.replace(/\.tla$/,`.cfg`));if(!l||!(0,n.existsSync)(l))return console.error(`Cannot find the configuration file ${l??``}`),e.V.configParseError;let u=e.A((0,n.readFileSync)(l,`utf8`));a.has(`-deadlock`)&&(u.checkDeadlock=!1);let d=a.has(`-seed`)?a.get(`-seed`)?.[0]:`0`;if(d===void 0)return console.error(`Error: seed required.`),1;if(!ti(d))return console.error(`Error: An integer for seed required. But encountered ${d}`),1;let f=a.has(`-lncheck`)?a.get(`-lncheck`)?.[0]?.toLowerCase():`default`;if(f===void 0)return console.error(`Error: expect a strategy such as final for -lncheck option.`),1;let p=a.get(`-dump`);if(p?.length===0)return console.error(`Error: A file name for dumping states required.`),1;let m=p?.length===2&&ii.find(e=>p[0].toLowerCase().includes(e));if(m)return console.error(`Error: tla-ts does not support the -dump format ${m}.`),1;let h=(0,i.dirname)(r);console.log(`Checking ${(0,i.basename)(r)} with ${(0,i.basename)(l)}`);let g=await t.t({workers:ni(a.get(`-workers`)),livenessCheck:[`final`,`seqfinal`,`off`].includes(f)?`final`:`default`,seed:BigInt(d),dump:p&&oi(p),source:o,config:u,onPause:()=>(0,n.readSync)(0,Buffer.alloc(1)),loadModule:e=>{let t=(0,i.join)(h,`${e}.tla`);return(0,n.existsSync)(t)?(0,n.readFileSync)(t,`utf8`):void 0},loadClass:e=>{let t=(0,i.join)(h,`${e}.class`);return(0,n.existsSync)(t)?(0,n.readFileSync)(t):void 0},readFile:e=>(0,n.existsSync)(e)?(0,n.readFileSync)(e,`utf8`):void 0,writeFile:(e,t)=>{(0,n.mkdirSync)((0,i.dirname)((0,i.resolve)(e)),{recursive:!0}),(0,n.writeFileSync)(e,t)}});return li(g),g.failure?.exitCode??Yr[g.status]},di=e=>`*** Errors: ${e.errors.length}\n\n${e.errors.map(e=>`${e.location}\n\n${e.message}\n\n`).join(`
|
|
30
|
+
`)}`,fi=(t,n)=>{if(t instanceof e.M||t instanceof e.P)return console.log(`Error: ${t.message}`);let r=t instanceof e.I?t.sany:void 0;if(!r||n===void 0)return console.error(`${t.name}: ${t.message}`);console.log(r.isFatal?`\nFatal errors while parsing TLA+ spec in file ${(0,i.basename)(n,`.tla`)}\n\n${r.errors.map(e=>`${e.location}\n\n${e.message}\n`).join(``)}${di(r)}\n`:`Semantic errors:\n\n${di(r)}`),console.log(`Error: Parsing or semantic analysis failed.`)},pi=async(t,n)=>{try{return await t()}catch(t){if(!(t instanceof e.N))throw t;return fi(t,n),e.B(t)}},mi=async(t,n)=>{let r=[];for(let[e,i]of t.entries())e>0&&console.log(``),r.push(await pi(()=>n(i),i));return r.find(t=>t!==e.V.success)??e.V.success},hi=()=>(process.env.PATH??``).split(i.delimiter).map(e=>(0,i.join)(e,`tlapm`)).filter(e=>(0,n.existsSync)(e)),gi=()=>hi().map(e=>(0,i.join)((0,i.dirname)((0,i.dirname)((0,n.realpathSync)(e))),`lib/tlapm/stdlib`)).find(e=>(0,n.existsSync)(e)),_i=e=>e.flatMap(e=>$r.test(e)?(0,n.globSync)(e).sort():[e]),vi=e=>{let t=hi()[0];return t===void 0?(console.error(`Error: tla-ts prove runs tlapm to prove obligations, but tlapm isn't on your PATH. Install tlapm, or pass -N to only generate the obligations.`),1):(0,r.spawnSync)(t,_i(e),{stdio:`inherit`}).status??1},yi=e=>(0,n.existsSync)(e)?{file:e,source:(0,n.readFileSync)(e,`utf8`)}:void 0,bi=e=>console.error(`@!!BEGIN\n${e.map(e=>`@!!${e}\n`).join(``)}@!!END\n`),xi=e=>/^[+,\-./0-9:=@A-Z_a-z]+$/.test(e)?e:`'${e.replaceAll(`'`,`'\\''`)}'`,Si=e=>{let t=/* @__PURE__ */ new Date,n=e=>String(e).padStart(2,`0`),r=`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`,i=`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`;console.log(`\n\\* TLAPM version 5f5037f\n\\* launched at ${r} ${i} with command line:\n\\* ${[`tla-ts`,`prove`,...e].map(xi).join(` `)}\n`)},Ci={incomplete:11,emptyTarget:12},wi=(e,t,n)=>{let r=e.summary;n||(r.absent.forEach(e=>console.error(`Missing proof at ${l(e)}`)),r.omitted.forEach(e=>console.error(`Omitted proof at ${l(e)}`)));let i=r.absent.length+r.omitted.length>0;i&&console.error(`${u(e.location)}[ERROR]: Proof incomplete in module ${JSON.stringify(e.name)}: ${r.absent.length} missing, ${r.omitted.length} omitted proof step(s).`);let a=t&&e.obligations.length===0;return a&&console.error(`${u(e.location)}[ERROR]: No proof obligation found for the selected target.`),[...i?[Ci.incomplete]:[],...a?[Ci.emptyTarget]:[]]},Ti=t=>{try{return t()}catch(t){if(!(t instanceof e.F))throw t;console.error(` tlapm ending abnormally with ${t.exception}\n`);return}},Ei=t=>{if(!t.includes(`-N`)&&!t.includes(`--summary`))return vi(t);let r=Zr.parse(t),a=r.unknown[0];if(a!==void 0)return console.error(`Error: tla-ts prove does not support the tlapm option ${a}.`),1;if(r.incomplete)return console.error(`Error: option '${r.incomplete.name}' needs an argument.`),1;let o=r.options.find(e=>e.name!==`-I`&&e.values.some(e=>!/^-?\d+$/.test(e)));if(o)return console.error(`Error: option '${o.name}' expects an integer.`),1;let s=_i(r.positionals),c=s.map(e=>e.endsWith(`.tla`)?e:`${e}.tla`);if(c.length===0)return console.error(Qr),1;let l=r.has(`--toolbox`)||r.has(`--line`);l&&Si(t);let u=r.options.reduce((e,t)=>{let[n,r]=t.values.map(Number);return t.name===`--toolbox`?{start:n,end:r===0?1/0:r}:t.name===`--line`?n===0?Fr:{start:n,end:n}:e},Fr),d=gi(),f=r.options.flatMap(e=>e.name===`-I`?e.values:[]),p=c.reduce((e,t)=>e.includes((0,i.dirname)(t))?e:[(0,i.dirname)(t),...e],[`.`,...d?[d]:[],...f.toReversed()]),m=Ti(()=>{let t=c.findIndex(e=>!(0,n.existsSync)(e));if(t!==-1){let n=s[t];throw console.error(`File "<unknown>":\nError: File ${JSON.stringify(n)} not found`),new e.F(`File ${n} not found`,{failure:`Module.Parser.parse_file`})}return Jr(c.map(e=>({file:`./${e}`,source:(0,n.readFileSync)(e,`utf8`)})),e=>p.map(t=>yi(`${t}/${e}.tla`)).find(Boolean),{lines:u,onWarning:e=>{if(e.channel===`stdout`)return console.log(e.text);let t=e.channel===`toolbox`||e.channel===`toolboxOnly`;if(l&&t)return bi([`type:warning`,`msg:${e.text}`]);e.channel!==`toolboxOnly`&&console.error(e.text)}})});if(!m)return 3;let h=m.flatMap(e=>(r.has(`--summary`)&&console.log(qr(e)),l&&(e.obligations.forEach(e=>bi([`type:obligation`,`id:${e.id}`,`loc:${e.location}`,`status:to be proved`,...r.has(`--printallobs`)?[`obl:${e.text}`]:[]])),bi([`type:obligationsnumber`,`count:${e.obligations.length}`])),r.has(`--strict`)?wi(e,u.start>0||u.end<1/0,r.has(`--summary`)):[]));return h.includes(Ci.incomplete)?Ci.incomplete:h[0]??e.V.success},Di=async e=>{if(e[0]===`prove`)return pi(()=>Ei(e.slice(1)));let t=Xr.parse(e),r=ei(t.positionals),i=t.has(`-config`),a=r.map(e=>({...e,path:e.path.replace(/\.cfg$/,`.tla`)})).filter(e=>e.path.endsWith(`.tla`)&&(!e.isGlobbed||i||(0,n.existsSync)(e.path.replace(/\.tla$/,`.cfg`)))).map(e=>e.path);return a.length===0?(console.error(Qr),1):i&&a.length>1?(console.error(`Error: -config applies to one specification, but several were given.`),1):mi([...new Set(a)],e=>ui(e,t))},Oi=async()=>{process.exitCode=await Di(process.argv.slice(2))};exports.runCli=Oi;
|