@tsplc/typegen 0.5.13 → 0.5.15

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.
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/codegen/declarations.ts", "../src/codegen/generate.ts", "../src/codegen/constants.ts", "../src/codegen/parser.ts"],
3
+ "sources": ["../src/codegen/declarations.ts", "../src/files.ts", "../src/codegen/parser.ts", "../src/codegen/resolution.ts", "../src/codegen/constants.ts"],
4
4
  "sourcesContent": [
5
- "import { readFile } from \"node:fs/promises\";\nimport { basename } from \"node:path\";\nimport { blockCommentEnd, lineCommentEnd } from \"@tsplc/iec/st\";\nimport { stFiles } from \"./generate\";\nimport {\n\ttype Declaration,\n\ttype GlobalList,\n\tparseDeclarations,\n\tparseGlobals,\n} from \"./parser\";\n\nexport type {\n\tDeclaration,\n\tGlobalList,\n\tMember,\n\tSymbolAccess,\n\tTypeReference,\n} from \"./parser\";\n\n/** Where ST code begins at or after `offset`: past whitespace, comments and pragmas. */\nconst codeStart = (text: string, offset: number): number => {\n\tconst start = offset + text.slice(offset).search(/\\S|$/);\n\tif (text.startsWith(\"(*\", start)) {\n\t\tconst end = blockCommentEnd(text, start);\n\t\treturn end === null ? start : codeStart(text, end);\n\t}\n\tif (text.startsWith(\"//\", start)) {\n\t\treturn codeStart(text, lineCommentEnd(text, start));\n\t}\n\tif (text.startsWith(\"{\", start)) {\n\t\tconst end = text.indexOf(\"}\", start);\n\t\treturn end < 0 ? start : codeStart(text, end + 1);\n\t}\n\treturn start;\n};\n\n/** The files among `files` that declare TYPEs and those that declare VAR_GLOBAL lists; other POUs are neither. */\nexport const declarationFiles = async (files: readonly string[]) => {\n\tconst sorted: { types: string[]; globals: string[] } = {\n\t\ttypes: [],\n\t\tglobals: [],\n\t};\n\tfor (const file of files) {\n\t\tconst text = await readFile(file, \"utf8\");\n\t\tconst code = text.slice(codeStart(text, 0));\n\t\tif (/^TYPE\\b/i.test(code)) {\n\t\t\tsorted.types.push(file);\n\t\t} else if (/^VAR_GLOBAL\\b/i.test(code)) {\n\t\t\tsorted.globals.push(file);\n\t\t}\n\t}\n\treturn sorted;\n};\n\n/**\n * The TYPE declarations and global lists of a directory of Structured Text, such as the\n * compiler's emitted ST: what CODESYS compiles, each list named after its file.\n */\nexport const readDeclarations = async (\n\tdirectory: string,\n): Promise<{ types: Declaration[]; globals: GlobalList[] }> => {\n\tconst files = await declarationFiles(await stFiles(directory));\n\tconst read = (file: string) =>\n\t\treadFile(file, \"utf8\").then((text) => ({ name: file, text }));\n\treturn {\n\t\ttypes: (await Promise.all(files.types.map(read))).flatMap(\n\t\t\tparseDeclarations,\n\t\t),\n\t\tglobals: (await Promise.all(files.globals.map(read))).map((source) =>\n\t\t\tparseGlobals(source, basename(source.name).replace(/\\.st$/i, \"\")),\n\t\t),\n\t};\n};\n",
6
- "import { readdir, readFile } from \"node:fs/promises\";\nimport { basename, join } from \"node:path\";\nimport type { Publication } from \"@tsplc/config\";\nimport { type ElementaryType, elementaryTypesByName } from \"@tsplc/iec\";\nimport { identifierPattern } from \"@tsplc/iec/st\";\nimport {\n\tconstantResolver,\n\tintegerExpression,\n\tisNumberInteger,\n} from \"./constants\";\nimport {\n\ttype Declaration,\n\ttype GlobalList,\n\tparseDeclarations,\n\tparseGlobals,\n\ttype Source,\n\ttype TypeReference,\n} from \"./parser\";\n\nexport interface GenerateOptions {\n\t/** Directory searched recursively, or an explicit list of TYPE source files. */\n\ttypes: string | readonly string[];\n\t/** Directory or explicit GVL files; each list is named after its .st filename. */\n\tglobals?: string | readonly string[];\n\t/** Inferred contracts select published globals and supported integer constants. */\n\tpublishedGlobalsOnly?: boolean;\n\tpublication?: Publication;\n\t/**\n\t * Also emit TypeScript declarations for the PLC's types, enums, constants and globals.\n\t * Turn off when host code imports them from the TypeScript program itself; the field and\n\t * symbol tables are still emitted, because TypeScript types don't exist at runtime.\n\t */\n\tdeclarations?: boolean;\n}\n\n/** The TypeScript type a scalar is read as; the 64-bit date and time types have none. */\nconst scalarType = (type: ElementaryType) => {\n\tswitch (type.family) {\n\t\tcase \"bool\":\n\t\t\treturn \"boolean\";\n\t\tcase \"integer\":\n\t\tcase \"bits\":\n\t\t\treturn type.bits === 64 ? \"bigint\" : \"number\";\n\t\tcase \"real\":\n\t\t\treturn \"number\";\n\t\tcase \"duration\":\n\t\tcase \"date\":\n\t\tcase \"timeOfDay\":\n\t\tcase \"dateTime\":\n\t\t\treturn type.bits === 32 ? \"number\" : undefined;\n\t\tcase \"char\":\n\t\tcase \"string\":\n\t\t\treturn undefined;\n\t}\n};\n\nconst scalars: Record<string, string> = Object.fromEntries(\n\t[...elementaryTypesByName].flatMap(([name, type]) => {\n\t\tconst typescript = scalarType(type);\n\t\treturn typescript ? [[name, typescript]] : [];\n\t}),\n);\n\n/** Recursively lists .st files in name order. */\nexport async function stFiles(directory: string): Promise<string[]> {\n\tconst entries = await readdir(directory, { withFileTypes: true });\n\tconst paths = await Promise.all(\n\t\tentries\n\t\t\t.sort((a, b) => {\n\t\t\t\tif (a.name === b.name) {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\treturn a.name < b.name ? -1 : 1;\n\t\t\t})\n\t\t\t.map(async (entry) => {\n\t\t\t\tconst file = join(directory, entry.name);\n\t\t\t\tif (entry.isDirectory()) {\n\t\t\t\t\treturn stFiles(file);\n\t\t\t\t}\n\t\t\t\treturn entry.isFile() && /\\.st$/i.test(file) ? [file] : [];\n\t\t\t}),\n\t);\n\treturn paths.flat();\n}\n\nconst quote = (value: string) => JSON.stringify(value);\nconst documentation = (value: string) =>\n\tvalue\n\t\t? `/** ${value.replace(/\\*\\//g, \"* /\").replace(/\\r?\\n/g, \"\\n * \")} */\\n`\n\t\t: \"\";\n\nfunction unique<T extends { name: string; source: string }>(\n\titems: T[],\n): Map<string, T> {\n\tconst result = new Map<string, T>();\n\tfor (const item of items) {\n\t\tconst key = item.name.toUpperCase();\n\t\tif (result.has(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`${item.source}: duplicate declaration ${item.name} (also in ${result.get(key)?.source})`,\n\t\t\t);\n\t\t}\n\t\tresult.set(key, item);\n\t}\n\treturn result;\n}\n\n/** Reads files concurrently, so they can be parsed in order and the first invalid one is reported. */\nconst readSources = (files: readonly string[]): Promise<Source[]> =>\n\tPromise.all(\n\t\tfiles.map(async (name) => ({ name, text: await readFile(name, \"utf8\") })),\n\t);\n\nexport async function generateTypes(options: GenerateOptions): Promise<string> {\n\tconst typeFiles =\n\t\ttypeof options.types === \"string\"\n\t\t\t? await stFiles(options.types)\n\t\t\t: options.types;\n\tconst declarations = (await readSources(typeFiles)).flatMap((source) =>\n\t\tparseDeclarations(source),\n\t);\n\tconst globalFiles =\n\t\ttypeof options.globals === \"string\"\n\t\t\t? await stFiles(options.globals)\n\t\t\t: (options.globals ?? []);\n\t// Program-only projects have a valid empty export selection. Directory\n\t// discovery still rejects empty input rather than hiding a bad setting.\n\tif (\n\t\t!typeFiles.length &&\n\t\t!globalFiles.length &&\n\t\t(typeof options.types === \"string\" || typeof options.globals === \"string\")\n\t) {\n\t\tthrow new Error(\n\t\t\t`no .st declarations found in ${typeof options.types === \"string\" ? options.types : \"the selected source files\"}`,\n\t\t);\n\t}\n\tconst globals = (await readSources(globalFiles)).map((source) =>\n\t\tparseGlobals(source, basename(source.name).replace(/\\.st$/i, \"\")),\n\t);\n\tconst publishedGlobalsOnly = options.publishedGlobalsOnly ?? false;\n\tconst contract = emit(\n\t\tdeclarations,\n\t\tpublishedGlobalsOnly ? published(globals, options.publication) : globals,\n\t\t{ publishedGlobalsOnly, emitDeclarations: options.declarations ?? true },\n\t);\n\treturn options.publication\n\t\t? `${contract}\\nexport const publication = ${JSON.stringify(options.publication, null, 2)} as const;\\n`\n\t\t: contract;\n}\n\n/**\n * Constant lists stay whole; a variable list keeps the members the publication names,\n * or without one those a symbol attribute publishes, and is dropped when none remain.\n */\nfunction published(\n\tglobals: GlobalList[],\n\tpublication: Publication | undefined,\n): GlobalList[] {\n\treturn globals\n\t\t.map((list) =>\n\t\t\tlist.constant\n\t\t\t\t? list\n\t\t\t\t: {\n\t\t\t\t\t\t...list,\n\t\t\t\t\t\tmembers: list.members.filter((member) =>\n\t\t\t\t\t\t\tpublication\n\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t...publication.production,\n\t\t\t\t\t\t\t\t\t\t...publication.development,\n\t\t\t\t\t\t\t\t\t].includes(`${list.name}.${member.name}`)\n\t\t\t\t\t\t\t\t: member.symbol !== undefined,\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t)\n\t\t.filter((list) => list.constant || list.members.length);\n}\n\nfunction emit(\n\tdeclarations: Declaration[],\n\tglobals: GlobalList[],\n\t{\n\t\tpublishedGlobalsOnly,\n\t\temitDeclarations,\n\t}: { publishedGlobalsOnly: boolean; emitDeclarations: boolean },\n): string {\n\tconst types = unique(declarations);\n\tunique(globals);\n\tconst constants = globals.filter((list) => list.constant);\n\t// Keep integer constants useful to host clients, including declaration bounds.\n\t// Private block presets and labels cannot use this integer-only export format.\n\t// Their declarations still remain available to the lazy bound resolver below.\n\tconst constantLists = publishedGlobalsOnly\n\t\t? constants\n\t\t\t\t.map((list) => ({\n\t\t\t\t\t...list,\n\t\t\t\t\tmembers: list.members.filter(\n\t\t\t\t\t\t(member) =>\n\t\t\t\t\t\t\tmember.type.kind === \"named\" &&\n\t\t\t\t\t\t\tisNumberInteger(member.type.name.toUpperCase()),\n\t\t\t\t\t),\n\t\t\t\t}))\n\t\t\t\t.filter((list) => list.members.length)\n\t\t: constants;\n\tconst variableLists = globals.filter((list) => !list.constant);\n\tconst constant = constantResolver(constants);\n\n\tfunction bound(expression: string): number {\n\t\treturn integerExpression(expression, (name) => constant(name, null));\n\t}\n\tfunction dimensions(type: Extract<TypeReference, { kind: \"array\" }>) {\n\t\treturn type.dimensions.map(({ lower, upper }) => {\n\t\t\tconst start = bound(lower);\n\t\t\tconst end = bound(upper);\n\t\t\tif (end < start || !Number.isSafeInteger(end - start + 1)) {\n\t\t\t\tthrow new Error(`invalid array bounds ${lower}..${upper}`);\n\t\t\t}\n\t\t\treturn { start, end };\n\t\t});\n\t}\n\tfunction declaration(name: string): Declaration {\n\t\tconst found = types.get(name.toUpperCase());\n\t\tif (!found) {\n\t\t\tthrow new Error(`unknown IEC type ${name}`);\n\t\t}\n\t\treturn found;\n\t}\n\tfunction tsType(type: TypeReference): string {\n\t\tif (type.kind === \"array\") {\n\t\t\tdimensions(type);\n\t\t\treturn type.dimensions.reduce(\n\t\t\t\t(child) => `Array<${child}>`,\n\t\t\t\ttsType(type.element),\n\t\t\t);\n\t\t}\n\t\tif (type.kind === \"string\") {\n\t\t\tconst length = bound(type.length);\n\t\t\tif (length < 1) {\n\t\t\t\tthrow new Error(`invalid ${type.name} length ${length}`);\n\t\t\t}\n\t\t\treturn \"string\";\n\t\t}\n\t\treturn scalars[type.name.toUpperCase()] ?? declaration(type.name).name;\n\t}\n\tfunction resolved(type: TypeReference): TypeReference {\n\t\tif (type.kind !== \"named\" || scalars[type.name.toUpperCase()]) {\n\t\t\treturn type;\n\t\t}\n\t\tconst definition = declaration(type.name);\n\t\tif (definition.kind === \"alias\") {\n\t\t\treturn resolved(definition.type);\n\t\t}\n\t\tif (definition.kind === \"enum\") {\n\t\t\treturn { kind: \"named\", name: definition.base };\n\t\t}\n\t\treturn type;\n\t}\n\tfunction iecType(type: TypeReference): string {\n\t\tconst actual = resolved(type);\n\t\tif (actual.kind === \"string\") {\n\t\t\treturn `${actual.name}(${bound(actual.length)})`;\n\t\t}\n\t\tif (actual.kind === \"array\") {\n\t\t\treturn `ARRAY[${dimensions(actual)\n\t\t\t\t.map(({ start, end }) => `${start}..${end}`)\n\t\t\t\t.join(\", \")}] OF ${iecType(actual.element)}`;\n\t\t}\n\t\treturn scalars[actual.name.toUpperCase()]\n\t\t\t? actual.name.toUpperCase()\n\t\t\t: declaration(actual.name).name;\n\t}\n\n\t// Topological order makes generated field lists reusable without duplicating child fields.\n\tconst ordered: Declaration[] = [];\n\tconst visiting = new Set<string>();\n\tconst visited = new Set<string>();\n\tfunction visitReference(type: TypeReference): void {\n\t\tif (type.kind === \"array\") {\n\t\t\tvisitReference(type.element);\n\t\t\treturn;\n\t\t}\n\t\tif (type.kind === \"named\" && !scalars[type.name.toUpperCase()]) {\n\t\t\tvisit(declaration(type.name));\n\t\t}\n\t}\n\tfunction visit(type: Declaration): void {\n\t\tif (visited.has(type.name)) {\n\t\t\treturn;\n\t\t}\n\t\tif (visiting.has(type.name)) {\n\t\t\tthrow new Error(\n\t\t\t\t`${type.source}: cyclic type reference involving ${type.name}`,\n\t\t\t);\n\t\t}\n\t\tvisiting.add(type.name);\n\t\tif (type.kind === \"struct\") {\n\t\t\ttype.members.forEach((member) => {\n\t\t\t\tvisitReference(member.type);\n\t\t\t});\n\t\t}\n\t\tif (type.kind === \"alias\") {\n\t\t\tvisitReference(type.type);\n\t\t}\n\t\tvisiting.delete(type.name);\n\t\tvisited.add(type.name);\n\t\tordered.push(type);\n\t}\n\tdeclarations.forEach(visit);\n\n\tconst reserved = new Set(\n\t\t\"break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with yield let static implements interface package private protected public await arguments eval PlcGlobals PlcField typeFields symbols globalVariableLists publication\".split(\n\t\t\t\" \",\n\t\t),\n\t);\n\tfor (const name of [\n\t\t...declarations.map((type) => type.name),\n\t\t...constantLists.map((list) => list.name),\n\t]) {\n\t\tif (\n\t\t\t!identifierPattern.test(name) ||\n\t\t\treserved.has(name) ||\n\t\t\t/^_fields\\d+$/.test(name)\n\t\t) {\n\t\t\tthrow new Error(`name cannot be exported to TypeScript: ${name}`);\n\t\t}\n\t\treserved.add(name);\n\t}\n\tconst indexes = new Map(ordered.map((type, index) => [type.name, index]));\n\tfunction complex(type: TypeReference): boolean {\n\t\tconst actual = resolved(type);\n\t\tif (actual.kind === \"array\") {\n\t\t\treturn complex(actual.element);\n\t\t}\n\t\treturn actual.kind === \"named\" && !scalars[actual.name.toUpperCase()];\n\t}\n\t/** An enum-keyed array: like a record's fields, each key is its own contract variable. */\n\tfunction keyed(type: TypeReference): boolean {\n\t\tif (type.kind !== \"named\" || scalars[type.name.toUpperCase()]) {\n\t\t\treturn false;\n\t\t}\n\t\tconst definition = declaration(type.name);\n\t\treturn (\n\t\t\tdefinition.kind === \"alias\" &&\n\t\t\t(!!definition.keyed || keyed(definition.type))\n\t\t);\n\t}\n\tfunction fields(\n\t\ttype: TypeReference,\n\t\tpath: string,\n\t\tdescription: string,\n\t\tdepth = 0,\n\t): string {\n\t\tconst actual = resolved(type);\n\t\tif (actual.kind === \"named\" && complex(actual)) {\n\t\t\tconst children = `_fields${indexes.get(declaration(actual.name).name)}`;\n\t\t\tif (path === '\"\"') {\n\t\t\t\treturn children;\n\t\t\t}\n\t\t\treturn `${children}.map((member) => ({ ...member, field: ${path} + \".\" + member.field }))`;\n\t\t}\n\t\tif (actual.kind === \"array\" && (complex(actual.element) || keyed(type))) {\n\t\t\tconst ranges = dimensions(actual);\n\t\t\tconst coordinates = ranges.map(\n\t\t\t\t(range, index) => `String(i${depth}_${index} + (${range.start}))`,\n\t\t\t);\n\t\t\tconst arrayPath = `${path} + \"[\" + ${coordinates.join(' + \",\" + ')} + \"]\"`;\n\t\t\treturn ranges.reduceRight(\n\t\t\t\t(child, range, index) =>\n\t\t\t\t\t`Array.from({ length: ${range.end - range.start + 1} }, (_, i${depth}_${index}) => ${child}).flat()`,\n\t\t\t\tfields(actual.element, `(${arrayPath})`, description, depth + 1),\n\t\t\t);\n\t\t}\n\t\treturn `[{ field: ${path}, type: ${quote(iecType(actual))}, description: ${quote(description)} }]`;\n\t}\n\n\tconst declare = (text: string) => (emitDeclarations ? [text] : []);\n\tconst output = [\n\t\t\"// Generated by @tsplc/typegen. Edit the PLC sources and regenerate.\\n\",\n\t\t\"export interface PlcField { field: string; type: string; description: string; }\\n\",\n\t];\n\tfor (const type of ordered) {\n\t\ttry {\n\t\t\tconst doc = documentation(type.description);\n\t\t\tif (type.kind === \"struct\") {\n\t\t\t\toutput.push(\n\t\t\t\t\t...declare(\n\t\t\t\t\t\t`${doc}export interface ${type.name} {\\n${type.members.map((member) => `${documentation(member.description)}${quote(member.name)}: ${tsType(member.type)};`).join(\"\\n\")}\\n}\\n`,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\toutput.push(\n\t\t\t\t\t`const _fields${indexes.get(type.name)}: PlcField[] = [\\n${type.members.map((member) => `...${fields(member.type, quote(member.name), member.description)},`).join(\"\\n\")}\\n];\\n`,\n\t\t\t\t);\n\t\t\t} else if (type.kind === \"alias\") {\n\t\t\t\toutput.push(\n\t\t\t\t\t...declare(\n\t\t\t\t\t\t`${doc}export type ${type.name} = ${tsType(type.type)};\\n`,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\toutput.push(\n\t\t\t\t\t`const _fields${indexes.get(type.name)}: PlcField[] = ${fields({ kind: \"named\", name: type.name }, '\"\"', type.description)};\\n`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tif (!isNumberInteger(type.base)) {\n\t\t\t\t\tthrow new Error(`unsupported enum base ${type.base}`);\n\t\t\t\t}\n\t\t\t\tconst entries = new Map<string, number>();\n\t\t\t\tfor (const member of type.members) {\n\t\t\t\t\tconst previous = [...entries.values()].at(-1) ?? -1;\n\t\t\t\t\tconst value =\n\t\t\t\t\t\tmember.value === undefined\n\t\t\t\t\t\t\t? previous + 1\n\t\t\t\t\t\t\t: integerExpression(\n\t\t\t\t\t\t\t\t\tmember.value,\n\t\t\t\t\t\t\t\t\t(name) =>\n\t\t\t\t\t\t\t\t\t\tentries.get(name.toUpperCase()) ?? constant(name, null),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\tentries.set(member.name.toUpperCase(), value);\n\t\t\t\t}\n\t\t\t\toutput.push(\n\t\t\t\t\t...declare(\n\t\t\t\t\t\t`${doc}export const ${type.name} = { ${type.members.map((member) => `${quote(member.name)}: ${entries.get(member.name.toUpperCase())}`).join(\", \")} } as const;\\nexport type ${type.name} = (typeof ${type.name})[keyof typeof ${type.name}];\\n`,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\toutput.push(\n\t\t\t\t\t`const _fields${indexes.get(type.name)}: PlcField[] = ${fields({ kind: \"named\", name: type.base }, '\"\"', type.description)};\\n`,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`${type.source} (${type.name}): ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\t}\n\t// A global declared as an array of structs in place, rather than through an alias, is\n\t// published element by element too, under its type's text.\n\tconst inlineArrays = new Map(\n\t\tvariableLists\n\t\t\t.flatMap((list) => list.members)\n\t\t\t.filter(\n\t\t\t\t(member) =>\n\t\t\t\t\tmember.type.kind === \"array\" && complex(member.type.element),\n\t\t\t)\n\t\t\t.map((member) => [\n\t\t\t\tiecType(member.type),\n\t\t\t\tfields(member.type, '\"\"', member.description),\n\t\t\t]),\n\t);\n\toutput.push(\n\t\t`export const typeFields = {\\n${[\n\t\t\t...ordered.map(\n\t\t\t\t(type) => `${quote(type.name)}: _fields${indexes.get(type.name)},`,\n\t\t\t),\n\t\t\t...[...inlineArrays].map(\n\t\t\t\t([type, members]) => `${quote(type)}: ${members},`,\n\t\t\t),\n\t\t].join(\"\\n\")}\\n};\\n`,\n\t);\n\tfor (const list of emitDeclarations ? constantLists : []) {\n\t\toutput.push(\n\t\t\t`${documentation(list.description)}export const ${list.name} = {\\n${list.members.map((member) => `${documentation(member.description)}${quote(member.name)}: ${constant(`${list.name}.${member.name}`, null)},`).join(\"\\n\")}\\n} as const;\\n`,\n\t\t);\n\t}\n\toutput.push(\n\t\t...declare(\n\t\t\t`export interface PlcGlobals {\\n${variableLists.map((list) => `${documentation(list.description)}${quote(list.name)}: {\\n${list.members.map((member) => `${documentation(member.description)}${quote(member.name)}: ${tsType(member.type)};`).join(\"\\n\")}\\n};`).join(\"\\n\")}\\n}\\n`,\n\t\t),\n\t);\n\toutput.push(\n\t\t`export const globalVariableLists = ${JSON.stringify(Object.fromEntries(variableLists.map((list) => [list.name, list.description])), null, \"\\t\")} as const;\\n`,\n\t);\n\toutput.push(\n\t\t`export const symbols = ${JSON.stringify(\n\t\t\tvariableLists.flatMap((list) =>\n\t\t\t\tlist.members.map((member) => ({\n\t\t\t\t\tname: member.name,\n\t\t\t\t\tgvl: list.name,\n\t\t\t\t\ttype:\n\t\t\t\t\t\tmember.type.kind === \"named\" &&\n\t\t\t\t\t\t!scalars[member.type.name.toUpperCase()]\n\t\t\t\t\t\t\t? declaration(member.type.name).name\n\t\t\t\t\t\t\t: iecType(member.type),\n\t\t\t\t\tdescription: member.description,\n\t\t\t\t})),\n\t\t\t),\n\t\t\tnull,\n\t\t\t\"\\t\",\n\t\t)} as const;\\n`,\n\t);\n\treturn output.join(\"\\n\");\n}\n",
7
- "import {\n\telementaryType,\n\telementaryTypes,\n\tintegerRange,\n\tisIntegerValued,\n} from \"@tsplc/iec\";\nimport type { GlobalList } from \"./parser\";\n\n// Constants and enum values are emitted as numbers, so they take integer types of 32 bits and under.\nexport const isNumberInteger = (name: string) => {\n\tconst type = elementaryType(name);\n\treturn isIntegerValued(type) && type.bits <= 32;\n};\n\nconst integerRanges = new Map(\n\telementaryTypes\n\t\t.filter(isIntegerValued)\n\t\t.map((type) => [type.name, integerRange(type)] as const),\n);\nconst integerToken = new RegExp(\n\tString.raw`(?:${[...integerRanges.keys()].join(\"|\")})\\s*#\\s*[+-]?(?:(?:2|8|16)#[\\da-fA-F_]+|\\d[\\d_]*)|(?:2|8|16)#[\\da-fA-F_]+|\\d[\\d_]*|[A-Za-z_]\\w*(?:\\s*\\.\\s*[A-Za-z_]\\w*)?|[()+\\-*/]`,\n\t\"g\",\n);\n\n/** Evaluate the integer-expression subset used for array bounds and constants. Never executes PLC text. */\nexport function integerExpression(\n\ttext: string,\n\tlookup: (name: string) => number,\n): number {\n\tconst compact = text.replace(/\\s+/g, \"\");\n\tconst tokens = (text.match(integerToken) ?? []).map((token) =>\n\t\ttoken.replace(/\\s+/g, \"\"),\n\t);\n\tif (tokens.join(\"\") !== compact || !tokens.length) {\n\t\tthrow new Error(`unsupported integer expression: ${text}`);\n\t}\n\tconst safe = (value: number) => {\n\t\tif (!Number.isSafeInteger(value)) {\n\t\t\tthrow new Error(`integer outside JavaScript's safe range: ${text}`);\n\t\t}\n\t\treturn value;\n\t};\n\tlet position = 0;\n\tfunction atom(): number {\n\t\tconst token = tokens[position++];\n\t\tif (token === \"+\") {\n\t\t\treturn atom();\n\t\t}\n\t\tif (token === \"-\") {\n\t\t\treturn -atom();\n\t\t}\n\t\tif (token === \"(\") {\n\t\t\tconst value = sum();\n\t\t\tif (tokens[position++] !== \")\") {\n\t\t\t\tthrow new Error(`unclosed integer expression: ${text}`);\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tconst typed =\n\t\t\ttoken &&\n\t\t\t[...integerRanges].find(([name]) =>\n\t\t\t\ttoken.toUpperCase().startsWith(`${name}#`),\n\t\t\t);\n\t\tif (typed) {\n\t\t\tconst [name, [minimum, maximum]] = typed;\n\t\t\tconst value = integerExpression(token.slice(name.length + 1), lookup);\n\t\t\tif (BigInt(value) < minimum || BigInt(value) > maximum) {\n\t\t\t\tthrow new Error(`typed integer outside ${name}: ${token}`);\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tif (token && /^\\d/.test(token)) {\n\t\t\tconst [base, digits] = token.replace(/_/g, \"\").split(\"#\");\n\t\t\tif (\n\t\t\t\tdigits !== undefined &&\n\t\t\t\t![...digits].every((digit) => parseInt(digit, 16) < Number(base))\n\t\t\t) {\n\t\t\t\tthrow new Error(`invalid base-${base} literal: ${token}`);\n\t\t\t}\n\t\t\treturn safe(\n\t\t\t\tdigits === undefined ? Number(base) : parseInt(digits, Number(base)),\n\t\t\t);\n\t\t}\n\t\tif (token && /^[A-Za-z_]/.test(token)) {\n\t\t\treturn lookup(token);\n\t\t}\n\t\tthrow new Error(`invalid integer expression: ${text}`);\n\t}\n\tfunction product(): number {\n\t\tlet value = atom();\n\t\twhile (tokens[position] === \"*\" || tokens[position] === \"/\") {\n\t\t\tconst operator = tokens[position++];\n\t\t\tconst right = atom();\n\t\t\tif (operator === \"/\" && right === 0) {\n\t\t\t\tthrow new Error(`division by zero: ${text}`);\n\t\t\t}\n\t\t\tvalue = safe(\n\t\t\t\toperator === \"*\" ? value * right : Math.trunc(value / right),\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\tfunction sum(): number {\n\t\tlet value = product();\n\t\twhile (tokens[position] === \"+\" || tokens[position] === \"-\") {\n\t\t\tconst operator = tokens[position++];\n\t\t\tconst right = product();\n\t\t\tvalue = safe(operator === \"+\" ? value + right : value - right);\n\t\t}\n\t\treturn value;\n\t}\n\tconst value = sum();\n\tif (position !== tokens.length || !Number.isSafeInteger(value)) {\n\t\tthrow new Error(`invalid or unsafe integer expression: ${text}`);\n\t}\n\treturn value;\n}\n\n/**\n * Looks constants of CONSTANT global lists up by qualified name, or by a bare name that\n * only one list declares; inside a list's own initializers (`scope`), its members come\n * first. Each is evaluated once, when first used, so they may refer to each other in\n * any order.\n */\nexport function constantResolver(\n\tlists: readonly GlobalList[],\n): (name: string, scope: string | null) => number {\n\tconst values = new Map<string, number>();\n\tconst resolving = new Set<string>();\n\tconst definitions = lists.flatMap((list) =>\n\t\tlist.members.map((member) => ({\n\t\t\tlist,\n\t\t\tmember,\n\t\t\tkey: `${list.name}.${member.name}`.toUpperCase(),\n\t\t})),\n\t);\n\tconst constant = (name: string, scope: string | null): number => {\n\t\tconst key = name.toUpperCase();\n\t\tconst scoped =\n\t\t\tscope === null\n\t\t\t\t? undefined\n\t\t\t\t: definitions.find(\n\t\t\t\t\t\t(item) => item.key === `${scope}.${name}`.toUpperCase(),\n\t\t\t\t\t);\n\t\tconst [definition, ...others] = scoped\n\t\t\t? [scoped]\n\t\t\t: definitions.filter(\n\t\t\t\t\t(item) =>\n\t\t\t\t\t\titem.key === key ||\n\t\t\t\t\t\t(!name.includes(\".\") && item.member.name.toUpperCase() === key),\n\t\t\t\t);\n\t\tif (!definition || others.length) {\n\t\t\tthrow new Error(`unknown or ambiguous constant ${name}`);\n\t\t}\n\t\tconst cached = values.get(definition.key);\n\t\tif (cached !== undefined) {\n\t\t\treturn cached;\n\t\t}\n\t\tif (resolving.has(definition.key)) {\n\t\t\tthrow new Error(`cyclic constant ${name}`);\n\t\t}\n\t\tconst { member, list } = definition;\n\t\tif (\n\t\t\tmember.initial === undefined ||\n\t\t\tmember.type.kind !== \"named\" ||\n\t\t\t!isNumberInteger(member.type.name.toUpperCase())\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`${list.source}: constant ${member.name} must have an integer type and initializer`,\n\t\t\t);\n\t\t}\n\t\tresolving.add(definition.key);\n\t\tconst value = integerExpression(member.initial, (reference) =>\n\t\t\tconstant(reference, list.name),\n\t\t);\n\t\tresolving.delete(definition.key);\n\t\tvalues.set(definition.key, value);\n\t\treturn value;\n\t};\n\treturn constant;\n}\n",
8
- "import {\n\tblockCommentEnd,\n\tdirectAddressEnd,\n\tidentifierPattern,\n\tlineCommentEnd,\n\tqualifiers,\n} from \"@tsplc/iec/st\";\n\nexport interface Source {\n\tname: string;\n\ttext: string;\n}\n\nexport type TypeReference =\n\t| { kind: \"named\"; name: string }\n\t| { kind: \"string\"; name: \"STRING\" | \"WSTRING\"; length: string }\n\t| {\n\t\t\tkind: \"array\";\n\t\t\tdimensions: { lower: string; upper: string }[];\n\t\t\telement: TypeReference;\n\t };\n\nexport interface Member {\n\tname: string;\n\tdescription: string;\n\ttype: TypeReference;\n\tinitial?: string;\n\t/** The CODESYS symbol attribute that publishes this global for clients, and the access it grants them. */\n\tsymbol?: SymbolAccess;\n\t/** Declared in a `RETAIN` or `PERSISTENT` global section. */\n\tretain?: true;\n}\n\n/** What a published global's `{attribute 'symbol'}` lets clients do. */\nexport type SymbolAccess = \"read\" | \"write\" | \"readwrite\";\n\nexport type Declaration = {\n\tname: string;\n\tdescription: string;\n\tsource: string;\n} & (\n\t| { kind: \"struct\"; members: Member[] }\n\t| {\n\t\t\tkind: \"alias\";\n\t\t\ttype: TypeReference;\n\t\t\t/** `{attribute 'tsplc_keyed'}`: an array whose indexes are enum keys, so each element is its own contract variable. */\n\t\t\tkeyed?: boolean;\n\t }\n\t| {\n\t\t\tkind: \"enum\";\n\t\t\tmembers: { name: string; value?: string }[];\n\t\t\tbase: string;\n\t }\n);\n\nexport interface GlobalList {\n\tname: string;\n\tdescription: string;\n\tsource: string;\n\tconstant: boolean;\n\tmembers: Member[];\n}\n\ninterface Token {\n\ttext: string;\n\toffset: number;\n\tkind: \"code\" | \"comment\" | \"attribute\";\n}\n\nfunction tokenize(source: Source): Token[] {\n\tconst tokens: Token[] = [];\n\tlet offset = 0;\n\twhile (offset < source.text.length) {\n\t\tconst rest = source.text.slice(offset);\n\t\tconst whitespace = /^\\s+/.exec(rest);\n\t\tif (whitespace) {\n\t\t\toffset += whitespace[0].length;\n\t\t\tcontinue;\n\t\t}\n\t\tif (rest.startsWith(\"(*\")) {\n\t\t\tconst end = blockCommentEnd(source.text, offset);\n\t\t\tif (end === null) {\n\t\t\t\tthrow new Error(`${source.name}: unterminated comment`);\n\t\t\t}\n\t\t\ttokens.push({\n\t\t\t\ttext: source.text.slice(offset + 2, end - 2).trim(),\n\t\t\t\toffset,\n\t\t\t\tkind: \"comment\",\n\t\t\t});\n\t\t\toffset = end;\n\t\t\tcontinue;\n\t\t}\n\t\tif (rest.startsWith(\"//\")) {\n\t\t\tconst end = lineCommentEnd(source.text, offset);\n\t\t\ttokens.push({\n\t\t\t\ttext: source.text.slice(offset + 2, end).trim(),\n\t\t\t\toffset,\n\t\t\t\tkind: \"comment\",\n\t\t\t});\n\t\t\toffset = end;\n\t\t\tcontinue;\n\t\t}\n\t\tconst attribute =\n\t\t\t/^\\{(?:[^}'\"]|'(?:\\$[\\s\\S]|''|[^'])*'|\"(?:\\$[\\s\\S]|\"\"|[^\"])*\")*\\}/.exec(\n\t\t\t\trest,\n\t\t\t);\n\t\tif (attribute) {\n\t\t\ttokens.push({ text: attribute[0], offset, kind: \"attribute\" });\n\t\t\toffset += attribute[0].length;\n\t\t\tcontinue;\n\t\t}\n\t\tconst addressEnd = directAddressEnd(source.text, offset);\n\t\tif (addressEnd !== null) {\n\t\t\ttokens.push({\n\t\t\t\ttext: source.text.slice(offset, addressEnd),\n\t\t\t\toffset,\n\t\t\t\tkind: \"code\",\n\t\t\t});\n\t\t\toffset = addressEnd;\n\t\t\tcontinue;\n\t\t}\n\t\tconst code =\n\t\t\t/^(?:'(?:\\$[\\s\\S]|''|[^'])*'|\"(?:\\$[\\s\\S]|\"\"|[^\"])*\"|\\d[\\d_]*#[\\da-fA-F_]+|\\d[\\d_]*(?:\\.(?!\\.)[\\d_]+)?(?:[eE][+-]?\\d+)?|[A-Za-z_]\\w*|:=|\\.\\.|[[\\]():;,.+\\-*/#])/i.exec(\n\t\t\t\trest,\n\t\t\t);\n\t\tif (!code) {\n\t\t\tthrow new Error(\n\t\t\t\t`${source.name}:${source.text.slice(0, offset).split(\"\\n\").length}: unsupported token ${JSON.stringify(rest.slice(0, 24))}`,\n\t\t\t);\n\t\t}\n\t\ttokens.push({ text: code[0], offset, kind: \"code\" });\n\t\toffset += code[0].length;\n\t}\n\treturn tokens;\n}\n\nclass Parser {\n\tprivate position = 0;\n\tprivate readonly tokens: Token[];\n\tconstructor(private readonly source: Source) {\n\t\tthis.tokens = tokenize(source);\n\t}\n\n\tprivate nextIndex(): number {\n\t\tlet index = this.position;\n\t\twhile (index < this.tokens.length && this.tokens[index]?.kind !== \"code\") {\n\t\t\tindex++;\n\t\t}\n\t\treturn index;\n\t}\n\n\tpeek(): string {\n\t\treturn this.tokens[this.nextIndex()]?.text.toUpperCase() ?? \"\";\n\t}\n\n\terror(message: string): never {\n\t\tconst offset =\n\t\t\tthis.tokens[this.nextIndex()]?.offset ?? this.source.text.length;\n\t\tthrow new Error(\n\t\t\t`${this.source.name}:${this.source.text.slice(0, offset).split(\"\\n\").length}: ${message}`,\n\t\t);\n\t}\n\n\tprivate take(): string {\n\t\tthis.position = this.nextIndex();\n\t\tconst token = this.tokens[this.position++];\n\t\tif (!token) {\n\t\t\tthis.error(\"unexpected end of declaration\");\n\t\t}\n\t\treturn token.text;\n\t}\n\n\tprivate accept(value: string): boolean {\n\t\tif (this.peek() !== value) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.take();\n\t\treturn true;\n\t}\n\n\tprivate expect(value: string): void {\n\t\tif (!this.accept(value)) {\n\t\t\tthis.error(`expected ${value}, found ${this.peek() || \"end of file\"}`);\n\t\t}\n\t}\n\n\tprivate identifier(): string {\n\t\tconst name = this.take();\n\t\tif (!identifierPattern.test(name)) {\n\t\t\tthis.error(`expected identifier, found ${name}`);\n\t\t}\n\t\treturn name;\n\t}\n\n\tprivate documentation(): string {\n\t\tconst end = this.nextIndex();\n\t\tconst text = this.tokens\n\t\t\t.slice(this.position, end)\n\t\t\t.filter((token) => token.kind === \"comment\")\n\t\t\t.map((token) => token.text)\n\t\t\t.join(\"\\n\");\n\t\tthis.position = end;\n\t\treturn text;\n\t}\n\n\tprivate expression(stops: string[]): string {\n\t\tconst values: string[] = [];\n\t\tconst closing: string[] = [];\n\t\twhile (this.peek() && (closing.length || !stops.includes(this.peek()))) {\n\t\t\tconst token = this.take();\n\t\t\tif (token === \"(\" || token === \"[\") {\n\t\t\t\tclosing.push(token === \"(\" ? \")\" : \"]\");\n\t\t\t}\n\t\t\tif (token === \")\" || token === \"]\") {\n\t\t\t\tif (closing.pop() !== token) {\n\t\t\t\t\tthis.error(`unmatched ${token}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tvalues.push(token);\n\t\t}\n\t\tif (!values.length || closing.length) {\n\t\t\tthis.error(\"incomplete expression\");\n\t\t}\n\t\treturn values.join(\" \");\n\t}\n\n\tprivate reference(): TypeReference {\n\t\tif (this.accept(\"ARRAY\")) {\n\t\t\tthis.expect(\"[\");\n\t\t\tconst dimensions: { lower: string; upper: string }[] = [];\n\t\t\tdo {\n\t\t\t\tconst lower = this.expression([\"..\"]);\n\t\t\t\tthis.expect(\"..\");\n\t\t\t\tconst upper = this.expression([\",\", \"]\"]);\n\t\t\t\tdimensions.push({ lower, upper });\n\t\t\t} while (this.accept(\",\"));\n\t\t\tthis.expect(\"]\");\n\t\t\tthis.expect(\"OF\");\n\t\t\treturn { kind: \"array\", dimensions, element: this.reference() };\n\t\t}\n\t\tconst parts = [this.identifier()];\n\t\twhile (this.accept(\".\")) {\n\t\t\tparts.push(this.identifier());\n\t\t}\n\t\tconst name = parts.join(\".\");\n\t\tconst upper = name.toUpperCase();\n\t\tif (upper === \"STRING\" || upper === \"WSTRING\") {\n\t\t\tconst opening = this.peek();\n\t\t\tif (opening !== \"(\" && opening !== \"[\") {\n\t\t\t\treturn { kind: \"string\", name: upper, length: \"80\" };\n\t\t\t}\n\t\t\tthis.take();\n\t\t\tconst closing = opening === \"(\" ? \")\" : \"]\";\n\t\t\tconst length = this.expression([closing]);\n\t\t\tthis.expect(closing);\n\t\t\treturn { kind: \"string\", name: upper, length };\n\t\t}\n\t\treturn { kind: \"named\", name };\n\t}\n\n\tprivate members(end: string, { retain }: { retain: boolean }): Member[] {\n\t\tconst members: Member[] = [];\n\t\twhile (this.peek() !== end) {\n\t\t\tconst symbol = this.tokens\n\t\t\t\t.slice(this.position, this.nextIndex())\n\t\t\t\t.flatMap((token) =>\n\t\t\t\t\ttoken.kind === \"attribute\" ? symbolAccess(token.text) : [],\n\t\t\t\t)\n\t\t\t\t.at(-1);\n\t\t\tconst description = this.documentation();\n\t\t\tconst names = [this.identifier()];\n\t\t\twhile (this.accept(\",\")) {\n\t\t\t\tnames.push(this.identifier());\n\t\t\t}\n\t\t\tif (this.accept(\"AT\")) {\n\t\t\t\t// Location belongs to the hardware/build mapping; it does not alter the\n\t\t\t\t// scalar type that application consumers receive from type generation.\n\t\t\t\tconst address = this.take();\n\t\t\t\tif (directAddressEnd(address, 0) !== address.length) {\n\t\t\t\t\tthis.error(`expected direct address after AT, found ${address}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.expect(\":\");\n\t\t\tconst type = this.reference();\n\t\t\tconst initial = this.accept(\":=\") ? this.expression([\";\"]) : undefined;\n\t\t\tthis.expect(\";\");\n\t\t\tfor (const name of names) {\n\t\t\t\tif (\n\t\t\t\t\tmembers.some(\n\t\t\t\t\t\t(member) => member.name.toUpperCase() === name.toUpperCase(),\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthis.error(`duplicate member ${name}`);\n\t\t\t\t}\n\t\t\t\tmembers.push({\n\t\t\t\t\tname,\n\t\t\t\t\tdescription,\n\t\t\t\t\ttype,\n\t\t\t\t\t...(initial === undefined ? {} : { initial }),\n\t\t\t\t\t...(symbol ? { symbol } : {}),\n\t\t\t\t\t...(retain ? { retain } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthis.expect(end);\n\t\treturn members;\n\t}\n\n\tdeclarations(): Declaration[] {\n\t\tconst declarations: Declaration[] = [];\n\t\twhile (this.peek()) {\n\t\t\tconst keyed = this.tokens\n\t\t\t\t.slice(this.position, this.nextIndex())\n\t\t\t\t.some(\n\t\t\t\t\t(token) =>\n\t\t\t\t\t\ttoken.kind === \"attribute\" &&\n\t\t\t\t\t\t/^\\{\\s*attribute\\s+'tsplc_keyed'\\s*\\}$/i.test(token.text),\n\t\t\t\t);\n\t\t\tconst description = this.documentation();\n\t\t\tthis.expect(\"TYPE\");\n\t\t\tconst name = this.identifier();\n\t\t\tthis.expect(\":\");\n\t\t\tconst common = { name, description, source: this.source.name };\n\t\t\tif (this.accept(\"STRUCT\")) {\n\t\t\t\tdeclarations.push({\n\t\t\t\t\t...common,\n\t\t\t\t\tkind: \"struct\",\n\t\t\t\t\tmembers: this.members(\"END_STRUCT\", { retain: false }),\n\t\t\t\t});\n\t\t\t\tthis.accept(\";\");\n\t\t\t} else if (this.accept(\"(\")) {\n\t\t\t\tconst members: { name: string; value?: string }[] = [];\n\t\t\t\tdo {\n\t\t\t\t\tconst member = this.identifier();\n\t\t\t\t\tconst value = this.accept(\":=\")\n\t\t\t\t\t\t? this.expression([\",\", \")\"])\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\tif (\n\t\t\t\t\t\tmembers.some(\n\t\t\t\t\t\t\t(item) => item.name.toUpperCase() === member.toUpperCase(),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.error(`duplicate enum member ${member}`);\n\t\t\t\t\t}\n\t\t\t\t\tmembers.push({ name: member, value });\n\t\t\t\t} while (this.accept(\",\") && this.peek() !== \")\");\n\t\t\t\tthis.expect(\")\");\n\t\t\t\tconst base =\n\t\t\t\t\tthis.peek() === \";\" ? \"INT\" : this.identifier().toUpperCase();\n\t\t\t\tthis.expect(\";\");\n\t\t\t\tdeclarations.push({ ...common, kind: \"enum\", members, base });\n\t\t\t} else {\n\t\t\t\tconst type = this.reference();\n\t\t\t\tthis.expect(\";\");\n\t\t\t\tdeclarations.push({\n\t\t\t\t\t...common,\n\t\t\t\t\tkind: \"alias\",\n\t\t\t\t\ttype,\n\t\t\t\t\t...(keyed ? { keyed } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis.expect(\"END_TYPE\");\n\t\t\tthis.accept(\";\");\n\t\t}\n\t\tif (!declarations.length) {\n\t\t\tthis.error(\"no TYPE declarations found\");\n\t\t}\n\t\treturn declarations;\n\t}\n\n\tglobals(name: string): GlobalList {\n\t\tconst description = this.documentation();\n\t\tconst sections: { constant: boolean; members: Member[] }[] = [];\n\t\tdo {\n\t\t\tsections.push(this.globalSection());\n\t\t} while (this.peek());\n\t\tconst constant = sections.every((section) => section.constant);\n\t\t// Typed access is per list: a list can't be read-only for some of its members.\n\t\tif (!constant && sections.some((section) => section.constant)) {\n\t\t\tthis.error(\"a list mixes CONSTANT and writable VAR_GLOBAL sections\");\n\t\t}\n\t\treturn {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\tsource: this.source.name,\n\t\t\tconstant,\n\t\t\tmembers: sections.flatMap((section) => section.members),\n\t\t};\n\t}\n\n\t/** One `VAR_GLOBAL … END_VAR` section of a list. A list keeps retained state in a section of its own. */\n\tprivate globalSection(): { constant: boolean; members: Member[] } {\n\t\tthis.expect(\"VAR_GLOBAL\");\n\t\tconst written = new Set<string>();\n\t\twhile (qualifiers.has(this.peek())) {\n\t\t\tconst qualifier = this.take().toUpperCase();\n\t\t\tif (written.has(qualifier)) {\n\t\t\t\tthis.error(`duplicate ${qualifier} qualifier`);\n\t\t\t}\n\t\t\twritten.add(qualifier);\n\t\t}\n\t\tconst members = this.members(\"END_VAR\", {\n\t\t\tretain: written.has(\"RETAIN\") || written.has(\"PERSISTENT\"),\n\t\t});\n\t\tthis.accept(\";\");\n\t\treturn { constant: written.has(\"CONSTANT\"), members };\n\t}\n}\n\nconst symbolAccess = (attribute: string): SymbolAccess[] => {\n\tconst access =\n\t\t/^\\{\\s*attribute\\s+'symbol'\\s*:=\\s*'(read|write|readwrite)'\\s*\\}$/i\n\t\t\t.exec(attribute)?.[1]\n\t\t\t?.toLowerCase();\n\treturn access === \"read\" || access === \"write\" || access === \"readwrite\"\n\t\t? [access]\n\t\t: [];\n};\n\nexport function parseDeclarations(source: Source): Declaration[] {\n\treturn new Parser(source).declarations();\n}\n\nexport function parseGlobals(source: Source, name: string): GlobalList {\n\treturn new Parser(source).globals(name);\n}\n"
5
+ "import { readFile } from \"node:fs/promises\";\nimport { stFiles } from \"../files\";\nimport {\n\ttype Declaration,\n\tfirstCodeToken,\n\ttype GlobalList,\n\tparseSources,\n} from \"./parser\";\n\nexport type {\n\tDeclaration,\n\tGlobalList,\n\tMember,\n\tSymbolAccess,\n\tTypeReference,\n} from \"./parser\";\nexport { resolveDeclarations } from \"./resolution\";\n\n/** The files among `files` that declare TYPEs and those that declare VAR_GLOBAL lists; other POUs are neither. */\nexport const declarationFiles = async (files: readonly string[]) => {\n\tconst sorted: { types: string[]; globals: string[] } = {\n\t\ttypes: [],\n\t\tglobals: [],\n\t};\n\tfor (const file of files) {\n\t\tconst keyword = firstCodeToken({\n\t\t\tname: file,\n\t\t\ttext: await readFile(file, \"utf8\"),\n\t\t})?.toUpperCase();\n\t\tif (keyword === \"TYPE\") {\n\t\t\tsorted.types.push(file);\n\t\t} else if (keyword === \"VAR_GLOBAL\") {\n\t\t\tsorted.globals.push(file);\n\t\t}\n\t}\n\treturn sorted;\n};\n\n/**\n * The TYPE declarations and global lists of a directory of Structured Text, such as the\n * compiler's emitted ST: what CODESYS compiles, each list named after its file.\n */\nexport const readDeclarations = async (\n\tdirectory: string,\n): Promise<{ types: Declaration[]; globals: GlobalList[] }> =>\n\tparseSources(await declarationFiles(await stFiles(directory)));\n",
6
+ "import { readdir, readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nexport const isMissingFile = (error: unknown) =>\n\terror instanceof Error && \"code\" in error && error.code === \"ENOENT\";\n\n/** The text of the file at `path`, or null when there is none. */\nexport const readIfPresent = (path: string) =>\n\treadFile(path, \"utf8\").catch((error: unknown) => {\n\t\tif (isMissingFile(error)) {\n\t\t\treturn null;\n\t\t}\n\t\tthrow error;\n\t});\n\n/** Every file under `directory` whose name ends in `.extension`, any case, each directory's entries in `order`. */\nexport async function filesUnder(\n\tdirectory: string,\n\textension: string,\n\torder: (a: string, b: string) => number,\n): Promise<string[]> {\n\tconst pattern = new RegExp(`\\\\.${extension}$`, \"i\");\n\tconst entries = await readdir(directory, { withFileTypes: true });\n\tconst paths = await Promise.all(\n\t\tentries\n\t\t\t.sort((a, b) => order(a.name, b.name))\n\t\t\t.map(async (entry) => {\n\t\t\t\tconst path = join(directory, entry.name);\n\t\t\t\tif (entry.isDirectory()) {\n\t\t\t\t\treturn filesUnder(path, extension, order);\n\t\t\t\t}\n\t\t\t\treturn entry.isFile() && pattern.test(entry.name) ? [path] : [];\n\t\t\t}),\n\t);\n\treturn paths.flat();\n}\n\n/** Every Structured Text source under `directory`, in name order. */\nexport const stFiles = (directory: string) =>\n\tfilesUnder(directory, \"st\", (a, b) => (a < b ? -1 : 1));\n",
7
+ "import { readFile } from \"node:fs/promises\";\nimport { basename } from \"node:path\";\nimport { defaultStringLength } from \"@tsplc/iec\";\nimport {\n\tblockCommentEnd,\n\tdirectAddressEnd,\n\tidentifierPart,\n\tidentifierPattern,\n\tidentifierStart,\n\tlineCommentEnd,\n\tqualifiers,\n\tstringEnd,\n} from \"@tsplc/iec/st\";\n\nexport interface Source {\n\tname: string;\n\ttext: string;\n}\n\nexport type TypeReference =\n\t| { kind: \"named\"; name: string }\n\t| { kind: \"string\"; name: \"STRING\" | \"WSTRING\"; length: string }\n\t| {\n\t\t\tkind: \"array\";\n\t\t\tdimensions: { lower: string; upper: string }[];\n\t\t\telement: TypeReference;\n\t };\n\nexport interface Member {\n\tname: string;\n\tdescription: string;\n\ttype: TypeReference;\n\tinitial?: string;\n\t/** The CODESYS symbol attribute that publishes this global for clients, and the access it grants them. */\n\tsymbol?: SymbolAccess;\n\t/** Declared in a `RETAIN` or `PERSISTENT` global section. */\n\tretain?: true;\n}\n\n/** What a published global's `{attribute 'symbol'}` lets clients do. */\nexport type SymbolAccess = \"read\" | \"write\" | \"readwrite\";\n\nexport type Declaration = {\n\tname: string;\n\tdescription: string;\n\tsource: string;\n} & (\n\t| { kind: \"struct\"; members: Member[] }\n\t| {\n\t\t\tkind: \"alias\";\n\t\t\ttype: TypeReference;\n\t\t\t/** `{attribute 'tsplc_keyed'}`: an array whose indexes are enum keys, so each element is its own contract variable. */\n\t\t\tkeyed?: boolean;\n\t }\n\t| {\n\t\t\tkind: \"enum\";\n\t\t\tmembers: { name: string; value?: string }[];\n\t\t\tbase: string;\n\t }\n);\n\nexport interface GlobalList {\n\tname: string;\n\tdescription: string;\n\tsource: string;\n\tconstant: boolean;\n\tmembers: Member[];\n}\n\ninterface Token {\n\ttext: string;\n\toffset: number;\n\tend: number;\n\tkind: \"code\" | \"comment\" | \"attribute\";\n}\n\n/** Offset just past a `{…}` pragma whose body starts at `offset`, or `null` when it never closes. */\nconst pragmaEnd = (text: string, offset: number): number | null => {\n\tconst next = text.slice(offset).search(/[}'\"]/);\n\tif (next < 0) {\n\t\treturn null;\n\t}\n\tconst at = offset + next;\n\tif (text[at] === \"}\") {\n\t\treturn at + 1;\n\t}\n\tconst end = stringEnd(text, at);\n\treturn end === null ? null : pragmaEnd(text, end);\n};\n\nconst codeToken = new RegExp(\n\tString.raw`^(?:\\d[\\d_]*#[\\da-fA-F_]+|\\d[\\d_]*(?:\\.(?!\\.)[\\d_]+)?(?:[eE][+-]?\\d+)?|${identifierStart}${identifierPart}*|:=|\\.\\.|[[\\]():;,.+\\-*/#])`,\n\t\"i\",\n);\n\n/** The token at or after `start`, past whitespace, or undefined at the end of the text. */\nfunction tokenAt(source: Source, start: number): Token | undefined {\n\tconst { text } = source;\n\tconst offset = start + text.slice(start).search(/\\S|$/);\n\tif (offset === text.length) {\n\t\treturn undefined;\n\t}\n\tconst rest = text.slice(offset);\n\tif (rest.startsWith(\"(*\")) {\n\t\tconst end = blockCommentEnd(text, offset);\n\t\tif (end === null) {\n\t\t\tthrow new Error(`${source.name}: unterminated comment`);\n\t\t}\n\t\tconst comment = text.slice(offset + 2, end - 2).trim();\n\t\treturn { text: comment, offset, end, kind: \"comment\" };\n\t}\n\tif (rest.startsWith(\"//\")) {\n\t\tconst end = lineCommentEnd(text, offset);\n\t\tconst comment = text.slice(offset + 2, end).trim();\n\t\treturn { text: comment, offset, end, kind: \"comment\" };\n\t}\n\tconst code = (kind: \"code\" | \"attribute\", end: number): Token => ({\n\t\ttext: text.slice(offset, end),\n\t\toffset,\n\t\tend,\n\t\tkind,\n\t});\n\tconst attributeEnd = rest.startsWith(\"{\")\n\t\t? pragmaEnd(text, offset + 1)\n\t\t: null;\n\tif (attributeEnd !== null) {\n\t\treturn code(\"attribute\", attributeEnd);\n\t}\n\tconst addressEnd = directAddressEnd(text, offset);\n\tif (addressEnd !== null) {\n\t\treturn code(\"code\", addressEnd);\n\t}\n\tconst literalEnd =\n\t\trest.startsWith(\"'\") || rest.startsWith('\"')\n\t\t\t? stringEnd(text, offset)\n\t\t\t: null;\n\tif (literalEnd !== null) {\n\t\treturn code(\"code\", literalEnd);\n\t}\n\tconst word = codeToken.exec(rest);\n\tif (!word) {\n\t\tthrow new Error(\n\t\t\t`${source.name}:${text.slice(0, offset).split(\"\\n\").length}: unsupported token ${JSON.stringify(rest.slice(0, 24))}`,\n\t\t);\n\t}\n\treturn code(\"code\", offset + word[0].length);\n}\n\nfunction tokenize(source: Source): Token[] {\n\tconst tokens: Token[] = [];\n\tfor (\n\t\tlet token = tokenAt(source, 0);\n\t\ttoken;\n\t\ttoken = tokenAt(source, token.end)\n\t) {\n\t\ttokens.push(token);\n\t}\n\treturn tokens;\n}\n\nconst codeTokenAt = (source: Source, offset: number): Token | undefined => {\n\tconst token = tokenAt(source, offset);\n\treturn token && token.kind !== \"code\"\n\t\t? codeTokenAt(source, token.end)\n\t\t: token;\n};\n\n/** The first code token of a source, past comments and pragmas. */\nexport const firstCodeToken = (source: Source) => codeTokenAt(source, 0)?.text;\n\nclass Parser {\n\tprivate position = 0;\n\tprivate readonly tokens: Token[];\n\tconstructor(private readonly source: Source) {\n\t\tthis.tokens = tokenize(source);\n\t}\n\n\tprivate nextIndex(): number {\n\t\tlet index = this.position;\n\t\twhile (index < this.tokens.length && this.tokens[index]?.kind !== \"code\") {\n\t\t\tindex++;\n\t\t}\n\t\treturn index;\n\t}\n\n\tpeek(): string {\n\t\treturn this.tokens[this.nextIndex()]?.text.toUpperCase() ?? \"\";\n\t}\n\n\terror(message: string): never {\n\t\tconst offset =\n\t\t\tthis.tokens[this.nextIndex()]?.offset ?? this.source.text.length;\n\t\tthrow new Error(\n\t\t\t`${this.source.name}:${this.source.text.slice(0, offset).split(\"\\n\").length}: ${message}`,\n\t\t);\n\t}\n\n\tprivate take(): string {\n\t\tthis.position = this.nextIndex();\n\t\tconst token = this.tokens[this.position++];\n\t\tif (!token) {\n\t\t\tthis.error(\"unexpected end of declaration\");\n\t\t}\n\t\treturn token.text;\n\t}\n\n\tprivate accept(value: string): boolean {\n\t\tif (this.peek() !== value) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.take();\n\t\treturn true;\n\t}\n\n\tprivate expect(value: string): void {\n\t\tif (!this.accept(value)) {\n\t\t\tthis.error(`expected ${value}, found ${this.peek() || \"end of file\"}`);\n\t\t}\n\t}\n\n\tprivate identifier(): string {\n\t\tconst name = this.take();\n\t\tif (!identifierPattern.test(name)) {\n\t\t\tthis.error(`expected identifier, found ${name}`);\n\t\t}\n\t\treturn name;\n\t}\n\n\tprivate documentation(): string {\n\t\tconst end = this.nextIndex();\n\t\tconst text = this.tokens\n\t\t\t.slice(this.position, end)\n\t\t\t.filter((token) => token.kind === \"comment\")\n\t\t\t.map((token) => token.text)\n\t\t\t.join(\"\\n\");\n\t\tthis.position = end;\n\t\treturn text;\n\t}\n\n\tprivate expression(stops: string[]): string {\n\t\tconst values: string[] = [];\n\t\tconst closing: string[] = [];\n\t\twhile (this.peek() && (closing.length || !stops.includes(this.peek()))) {\n\t\t\tconst token = this.take();\n\t\t\tif (token === \"(\" || token === \"[\") {\n\t\t\t\tclosing.push(token === \"(\" ? \")\" : \"]\");\n\t\t\t}\n\t\t\tif (token === \")\" || token === \"]\") {\n\t\t\t\tif (closing.pop() !== token) {\n\t\t\t\t\tthis.error(`unmatched ${token}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tvalues.push(token);\n\t\t}\n\t\tif (!values.length || closing.length) {\n\t\t\tthis.error(\"incomplete expression\");\n\t\t}\n\t\treturn values.join(\" \");\n\t}\n\n\tprivate reference(): TypeReference {\n\t\tif (this.accept(\"ARRAY\")) {\n\t\t\tthis.expect(\"[\");\n\t\t\tconst dimensions: { lower: string; upper: string }[] = [];\n\t\t\tdo {\n\t\t\t\tconst lower = this.expression([\"..\"]);\n\t\t\t\tthis.expect(\"..\");\n\t\t\t\tconst upper = this.expression([\",\", \"]\"]);\n\t\t\t\tdimensions.push({ lower, upper });\n\t\t\t} while (this.accept(\",\"));\n\t\t\tthis.expect(\"]\");\n\t\t\tthis.expect(\"OF\");\n\t\t\treturn { kind: \"array\", dimensions, element: this.reference() };\n\t\t}\n\t\tconst parts = [this.identifier()];\n\t\twhile (this.accept(\".\")) {\n\t\t\tparts.push(this.identifier());\n\t\t}\n\t\tconst name = parts.join(\".\");\n\t\tconst upper = name.toUpperCase();\n\t\tif (upper === \"STRING\" || upper === \"WSTRING\") {\n\t\t\tconst opening = this.peek();\n\t\t\tif (opening !== \"(\" && opening !== \"[\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"string\",\n\t\t\t\t\tname: upper,\n\t\t\t\t\tlength: String(defaultStringLength),\n\t\t\t\t};\n\t\t\t}\n\t\t\tthis.take();\n\t\t\tconst closing = opening === \"(\" ? \")\" : \"]\";\n\t\t\tconst length = this.expression([closing]);\n\t\t\tthis.expect(closing);\n\t\t\treturn { kind: \"string\", name: upper, length };\n\t\t}\n\t\treturn { kind: \"named\", name };\n\t}\n\n\tprivate members(end: string, { retain }: { retain: boolean }): Member[] {\n\t\tconst members: Member[] = [];\n\t\twhile (this.peek() !== end) {\n\t\t\tconst symbol = this.tokens\n\t\t\t\t.slice(this.position, this.nextIndex())\n\t\t\t\t.flatMap((token) =>\n\t\t\t\t\ttoken.kind === \"attribute\" ? symbolAccess(token.text) : [],\n\t\t\t\t)\n\t\t\t\t.at(-1);\n\t\t\tconst description = this.documentation();\n\t\t\tconst names = [this.identifier()];\n\t\t\twhile (this.accept(\",\")) {\n\t\t\t\tnames.push(this.identifier());\n\t\t\t}\n\t\t\tif (this.accept(\"AT\")) {\n\t\t\t\t// Location belongs to the hardware/build mapping; it does not alter the\n\t\t\t\t// scalar type that application consumers receive from type generation.\n\t\t\t\tconst address = this.take();\n\t\t\t\tif (directAddressEnd(address, 0) !== address.length) {\n\t\t\t\t\tthis.error(`expected direct address after AT, found ${address}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.expect(\":\");\n\t\t\tconst type = this.reference();\n\t\t\tconst initial = this.accept(\":=\") ? this.expression([\";\"]) : undefined;\n\t\t\tthis.expect(\";\");\n\t\t\tfor (const name of names) {\n\t\t\t\tif (\n\t\t\t\t\tmembers.some(\n\t\t\t\t\t\t(member) => member.name.toUpperCase() === name.toUpperCase(),\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthis.error(`duplicate member ${name}`);\n\t\t\t\t}\n\t\t\t\tmembers.push({\n\t\t\t\t\tname,\n\t\t\t\t\tdescription,\n\t\t\t\t\ttype,\n\t\t\t\t\t...(initial === undefined ? {} : { initial }),\n\t\t\t\t\t...(symbol ? { symbol } : {}),\n\t\t\t\t\t...(retain ? { retain } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthis.expect(end);\n\t\treturn members;\n\t}\n\n\tdeclarations(): Declaration[] {\n\t\tconst declarations: Declaration[] = [];\n\t\twhile (this.peek()) {\n\t\t\tconst keyed = this.tokens\n\t\t\t\t.slice(this.position, this.nextIndex())\n\t\t\t\t.some(\n\t\t\t\t\t(token) =>\n\t\t\t\t\t\ttoken.kind === \"attribute\" &&\n\t\t\t\t\t\t/^\\{\\s*attribute\\s+'tsplc_keyed'\\s*\\}$/i.test(token.text),\n\t\t\t\t);\n\t\t\tconst description = this.documentation();\n\t\t\tthis.expect(\"TYPE\");\n\t\t\tconst name = this.identifier();\n\t\t\tthis.expect(\":\");\n\t\t\tconst common = { name, description, source: this.source.name };\n\t\t\tif (this.accept(\"STRUCT\")) {\n\t\t\t\tdeclarations.push({\n\t\t\t\t\t...common,\n\t\t\t\t\tkind: \"struct\",\n\t\t\t\t\tmembers: this.members(\"END_STRUCT\", { retain: false }),\n\t\t\t\t});\n\t\t\t\tthis.accept(\";\");\n\t\t\t} else if (this.accept(\"(\")) {\n\t\t\t\tconst members: { name: string; value?: string }[] = [];\n\t\t\t\tdo {\n\t\t\t\t\tconst member = this.identifier();\n\t\t\t\t\tconst value = this.accept(\":=\")\n\t\t\t\t\t\t? this.expression([\",\", \")\"])\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\tif (\n\t\t\t\t\t\tmembers.some(\n\t\t\t\t\t\t\t(item) => item.name.toUpperCase() === member.toUpperCase(),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.error(`duplicate enum member ${member}`);\n\t\t\t\t\t}\n\t\t\t\t\tmembers.push({ name: member, value });\n\t\t\t\t} while (this.accept(\",\") && this.peek() !== \")\");\n\t\t\t\tthis.expect(\")\");\n\t\t\t\tconst base =\n\t\t\t\t\tthis.peek() === \";\" ? \"INT\" : this.identifier().toUpperCase();\n\t\t\t\tthis.expect(\";\");\n\t\t\t\tdeclarations.push({ ...common, kind: \"enum\", members, base });\n\t\t\t} else {\n\t\t\t\tconst type = this.reference();\n\t\t\t\tthis.expect(\";\");\n\t\t\t\tdeclarations.push({\n\t\t\t\t\t...common,\n\t\t\t\t\tkind: \"alias\",\n\t\t\t\t\ttype,\n\t\t\t\t\t...(keyed ? { keyed } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis.expect(\"END_TYPE\");\n\t\t\tthis.accept(\";\");\n\t\t}\n\t\tif (!declarations.length) {\n\t\t\tthis.error(\"no TYPE declarations found\");\n\t\t}\n\t\treturn declarations;\n\t}\n\n\tglobals(name: string): GlobalList {\n\t\tconst description = this.documentation();\n\t\tconst sections: { constant: boolean; members: Member[] }[] = [];\n\t\tdo {\n\t\t\tsections.push(this.globalSection());\n\t\t} while (this.peek());\n\t\tconst constant = sections.every((section) => section.constant);\n\t\t// Typed access is per list: a list can't be read-only for some of its members.\n\t\tif (!constant && sections.some((section) => section.constant)) {\n\t\t\tthis.error(\"a list mixes CONSTANT and writable VAR_GLOBAL sections\");\n\t\t}\n\t\treturn {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\tsource: this.source.name,\n\t\t\tconstant,\n\t\t\tmembers: sections.flatMap((section) => section.members),\n\t\t};\n\t}\n\n\t/** One `VAR_GLOBAL … END_VAR` section of a list. A list keeps retained state in a section of its own. */\n\tprivate globalSection(): { constant: boolean; members: Member[] } {\n\t\tthis.expect(\"VAR_GLOBAL\");\n\t\tconst written = new Set<string>();\n\t\twhile (qualifiers.has(this.peek())) {\n\t\t\tconst qualifier = this.take().toUpperCase();\n\t\t\tif (written.has(qualifier)) {\n\t\t\t\tthis.error(`duplicate ${qualifier} qualifier`);\n\t\t\t}\n\t\t\twritten.add(qualifier);\n\t\t}\n\t\tconst members = this.members(\"END_VAR\", {\n\t\t\tretain: written.has(\"RETAIN\") || written.has(\"PERSISTENT\"),\n\t\t});\n\t\tthis.accept(\";\");\n\t\treturn { constant: written.has(\"CONSTANT\"), members };\n\t}\n}\n\nconst symbolAccess = (attribute: string): SymbolAccess[] => {\n\tconst access =\n\t\t/^\\{\\s*attribute\\s+'symbol'\\s*:=\\s*'(read|write|readwrite)'\\s*\\}$/i\n\t\t\t.exec(attribute)?.[1]\n\t\t\t?.toLowerCase();\n\treturn access === \"read\" || access === \"write\" || access === \"readwrite\"\n\t\t? [access]\n\t\t: [];\n};\n\nfunction parseDeclarations(source: Source): Declaration[] {\n\treturn new Parser(source).declarations();\n}\n\nexport function parseGlobals(source: Source, name: string): GlobalList {\n\treturn new Parser(source).globals(name);\n}\n\nconst readSource = async (name: string): Promise<Source> => ({\n\tname,\n\ttext: await readFile(name, \"utf8\"),\n});\n\n/** The TYPE declarations of `types` and the global lists of `globals`, each list named after its file. */\nexport async function parseSources(files: {\n\ttypes: readonly string[];\n\tglobals: readonly string[];\n}): Promise<{ types: Declaration[]; globals: GlobalList[] }> {\n\treturn {\n\t\ttypes: (await Promise.all(files.types.map(readSource))).flatMap(\n\t\t\tparseDeclarations,\n\t\t),\n\t\tglobals: (await Promise.all(files.globals.map(readSource))).map((source) =>\n\t\t\tparseGlobals(source, basename(source.name).replace(/\\.st$/i, \"\")),\n\t\t),\n\t};\n}\n",
8
+ "import { elementaryType } from \"@tsplc/iec\";\nimport { constantResolver, integerExpression } from \"./constants\";\nimport type { Declaration, GlobalList, TypeReference } from \"./parser\";\n\n/**\n * What parsed TYPE declarations mean once their names are looked up: the declaration a\n * name refers to, the type an alias stands for, array bounds and enum member values, with\n * integers evaluated against the CONSTANT global lists.\n */\nexport function resolveDeclarations({\n\ttypes,\n\tglobals,\n}: {\n\ttypes: readonly Declaration[];\n\tglobals: readonly GlobalList[];\n}) {\n\tconst declarations = new Map(\n\t\ttypes.map((declaration) => [declaration.name.toUpperCase(), declaration]),\n\t);\n\tconst constant = constantResolver(globals.filter((list) => list.constant));\n\tconst integer = (expression: string) =>\n\t\tintegerExpression(expression, (name) => constant(name, null));\n\tconst declaration = (name: string): Declaration => {\n\t\tconst found = declarations.get(name.toUpperCase());\n\t\tif (!found) {\n\t\t\tthrow new Error(`unknown IEC type ${name}`);\n\t\t}\n\t\treturn found;\n\t};\n\tconst aliasTarget = (reference: TypeReference): TypeReference => {\n\t\tif (\n\t\t\treference.kind !== \"named\" ||\n\t\t\telementaryType(reference.name.toUpperCase())\n\t\t) {\n\t\t\treturn reference;\n\t\t}\n\t\tconst named = declaration(reference.name);\n\t\treturn named.kind === \"alias\" ? aliasTarget(named.type) : reference;\n\t};\n\tconst bounds = (array: Extract<TypeReference, { kind: \"array\" }>) =>\n\t\tarray.dimensions.map(({ lower, upper }) => {\n\t\t\tconst start = integer(lower);\n\t\t\tconst end = integer(upper);\n\t\t\tif (end < start || !Number.isSafeInteger(end - start + 1)) {\n\t\t\t\tthrow new Error(`invalid array bounds ${lower}..${upper}`);\n\t\t\t}\n\t\t\treturn { start, end };\n\t\t});\n\t/** A member without a value follows the one before it; a value may name an earlier member. */\n\tconst enumMembers = (enumeration: Extract<Declaration, { kind: \"enum\" }>) => {\n\t\tconst members: { name: string; value: number }[] = [];\n\t\tfor (const member of enumeration.members) {\n\t\t\tconst value =\n\t\t\t\tmember.value === undefined\n\t\t\t\t\t? (members.at(-1)?.value ?? -1) + 1\n\t\t\t\t\t: integerExpression(\n\t\t\t\t\t\t\tmember.value,\n\t\t\t\t\t\t\t(name) =>\n\t\t\t\t\t\t\t\tmembers.find(\n\t\t\t\t\t\t\t\t\t(item) => item.name.toUpperCase() === name.toUpperCase(),\n\t\t\t\t\t\t\t\t)?.value ?? constant(name, null),\n\t\t\t\t\t\t);\n\t\t\tmembers.push({ name: member.name, value });\n\t\t}\n\t\treturn members;\n\t};\n\treturn { constant, integer, declaration, aliasTarget, bounds, enumMembers };\n}\n",
9
+ "import {\n\telementaryType,\n\telementaryTypes,\n\tfitsNumber,\n\tintegerRange,\n\tisIntegerValued,\n} from \"@tsplc/iec\";\nimport { identifierPart, identifierStart, integerLiteral } from \"@tsplc/iec/st\";\nimport type { GlobalList, Member } from \"./parser\";\n\nconst integerRanges = new Map(\n\telementaryTypes\n\t\t.filter(isIntegerValued)\n\t\t.map((type) => [type.name, integerRange(type)] as const),\n);\nconst identifier = `${identifierStart}${identifierPart}*`;\nconst startsWithIdentifier = new RegExp(`^${identifierStart}`);\nconst integerToken = new RegExp(\n\tString.raw`(?:${[...integerRanges.keys()].join(\"|\")})\\s*#\\s*[+-]?(?:(?:2|8|16)#[\\da-fA-F_]+|\\d[\\d_]*)|(?:2|8|16)#[\\da-fA-F_]+|\\d[\\d_]*|${identifier}(?:\\s*\\.\\s*${identifier})?|[()+\\-*/]`,\n\t\"g\",\n);\n\n/** Evaluate the integer-expression subset used for array bounds and constants. Never executes PLC text. */\nexport function integerExpression(\n\ttext: string,\n\tlookup: (name: string) => number,\n): number {\n\tconst compact = text.replace(/\\s+/g, \"\");\n\tconst tokens = (text.match(integerToken) ?? []).map((token) =>\n\t\ttoken.replace(/\\s+/g, \"\"),\n\t);\n\tif (tokens.join(\"\") !== compact || !tokens.length) {\n\t\tthrow new Error(`unsupported integer expression: ${text}`);\n\t}\n\tconst safe = (value: number) => {\n\t\tif (!Number.isSafeInteger(value)) {\n\t\t\tthrow new Error(`integer outside JavaScript's safe range: ${text}`);\n\t\t}\n\t\treturn value;\n\t};\n\tlet position = 0;\n\tfunction atom(): number {\n\t\tconst token = tokens[position++];\n\t\tif (token === \"+\") {\n\t\t\treturn atom();\n\t\t}\n\t\tif (token === \"-\") {\n\t\t\treturn -atom();\n\t\t}\n\t\tif (token === \"(\") {\n\t\t\tconst value = sum();\n\t\t\tif (tokens[position++] !== \")\") {\n\t\t\t\tthrow new Error(`unclosed integer expression: ${text}`);\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tconst typed =\n\t\t\ttoken &&\n\t\t\t[...integerRanges].find(([name]) =>\n\t\t\t\ttoken.toUpperCase().startsWith(`${name}#`),\n\t\t\t);\n\t\tif (typed) {\n\t\t\tconst [name, [minimum, maximum]] = typed;\n\t\t\tconst value = integerExpression(token.slice(name.length + 1), lookup);\n\t\t\tif (BigInt(value) < minimum || BigInt(value) > maximum) {\n\t\t\t\tthrow new Error(`typed integer outside ${name}: ${token}`);\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tif (token && /^\\d/.test(token)) {\n\t\t\tconst literal = integerLiteral(token);\n\t\t\tif (literal === undefined) {\n\t\t\t\tthrow new Error(`invalid integer literal: ${token}`);\n\t\t\t}\n\t\t\treturn safe(Number(literal));\n\t\t}\n\t\tif (token && startsWithIdentifier.test(token)) {\n\t\t\treturn lookup(token);\n\t\t}\n\t\tthrow new Error(`invalid integer expression: ${text}`);\n\t}\n\tfunction product(): number {\n\t\tlet value = atom();\n\t\twhile (tokens[position] === \"*\" || tokens[position] === \"/\") {\n\t\t\tconst operator = tokens[position++];\n\t\t\tconst right = atom();\n\t\t\tif (operator === \"/\" && right === 0) {\n\t\t\t\tthrow new Error(`division by zero: ${text}`);\n\t\t\t}\n\t\t\tvalue = safe(\n\t\t\t\toperator === \"*\" ? value * right : Math.trunc(value / right),\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\tfunction sum(): number {\n\t\tlet value = product();\n\t\twhile (tokens[position] === \"+\" || tokens[position] === \"-\") {\n\t\t\tconst operator = tokens[position++];\n\t\t\tconst right = product();\n\t\t\tvalue = safe(operator === \"+\" ? value + right : value - right);\n\t\t}\n\t\treturn value;\n\t}\n\tconst value = sum();\n\tif (position !== tokens.length) {\n\t\tthrow new Error(`invalid integer expression: ${text}`);\n\t}\n\treturn value;\n}\n\n/** Whether a constant has a type a JavaScript number holds exactly: the only constants typegen evaluates and exports. */\nexport const isIntegerConstant = (member: Member) =>\n\tmember.type.kind === \"named\" &&\n\tfitsNumber(elementaryType(member.type.name.toUpperCase()));\n\n/**\n * Looks constants of CONSTANT global lists up by qualified name, or by a bare name that\n * only one list declares; inside a list's own initializers (`scope`), its members come\n * first. Each is evaluated once, when first used, so they may refer to each other in\n * any order.\n */\nexport function constantResolver(\n\tlists: readonly GlobalList[],\n): (name: string, scope: string | null) => number {\n\tconst values = new Map<string, number>();\n\tconst resolving = new Set<string>();\n\tconst definitions = lists.flatMap((list) =>\n\t\tlist.members.map((member) => ({\n\t\t\tlist,\n\t\t\tmember,\n\t\t\tkey: `${list.name}.${member.name}`.toUpperCase(),\n\t\t})),\n\t);\n\tconst constant = (name: string, scope: string | null): number => {\n\t\tconst key = name.toUpperCase();\n\t\tconst scoped =\n\t\t\tscope === null\n\t\t\t\t? undefined\n\t\t\t\t: definitions.find(\n\t\t\t\t\t\t(item) => item.key === `${scope}.${name}`.toUpperCase(),\n\t\t\t\t\t);\n\t\tconst [definition, ...others] = scoped\n\t\t\t? [scoped]\n\t\t\t: definitions.filter(\n\t\t\t\t\t(item) =>\n\t\t\t\t\t\titem.key === key ||\n\t\t\t\t\t\t(!name.includes(\".\") && item.member.name.toUpperCase() === key),\n\t\t\t\t);\n\t\tif (!definition || others.length) {\n\t\t\tthrow new Error(`unknown or ambiguous constant ${name}`);\n\t\t}\n\t\tconst cached = values.get(definition.key);\n\t\tif (cached !== undefined) {\n\t\t\treturn cached;\n\t\t}\n\t\tif (resolving.has(definition.key)) {\n\t\t\tthrow new Error(`cyclic constant ${name}`);\n\t\t}\n\t\tconst { member, list } = definition;\n\t\tif (member.initial === undefined || !isIntegerConstant(member)) {\n\t\t\tthrow new Error(\n\t\t\t\t`${list.source}: constant ${member.name} must have an integer type and initializer`,\n\t\t\t);\n\t\t}\n\t\tresolving.add(definition.key);\n\t\tconst value = integerExpression(member.initial, (reference) =>\n\t\t\tconstant(reference, list.name),\n\t\t);\n\t\tresolving.delete(definition.key);\n\t\tvalues.set(definition.key, value);\n\t\treturn value;\n\t};\n\treturn constant;\n}\n"
9
10
  ],
10
- "mappings": ";AAAA,qBAAS;AACT,qBAAS;AACT,4BAAS,oCAAiB;;;ACF1B;AACA;AAEA;AACA,8BAAS;;;ACJT;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,IAAM,gBAAgB,IAAI,IACzB,gBACE,OAAO,eAAe,EACtB,IAAI,CAAC,SAAS,CAAC,KAAK,MAAM,aAAa,IAAI,CAAC,CAAU,CACzD;AACA,IAAM,eAAe,IAAI,OACxB,OAAO,SAAS,CAAC,GAAG,cAAc,KAAK,CAAC,EAAE,KAAK,GAAG,uIAClD,GACD;;;ACtBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqEA,SAAS,QAAQ,CAAC,QAAyB;AAAA,EAC1C,MAAM,SAAkB,CAAC;AAAA,EACzB,IAAI,SAAS;AAAA,EACb,OAAO,SAAS,OAAO,KAAK,QAAQ;AAAA,IACnC,MAAM,OAAO,OAAO,KAAK,MAAM,MAAM;AAAA,IACrC,MAAM,aAAa,OAAO,KAAK,IAAI;AAAA,IACnC,IAAI,YAAY;AAAA,MACf,UAAU,WAAW,GAAG;AAAA,MACxB;AAAA,IACD;AAAA,IACA,IAAI,KAAK,WAAW,IAAI,GAAG;AAAA,MAC1B,MAAM,MAAM,gBAAgB,OAAO,MAAM,MAAM;AAAA,MAC/C,IAAI,QAAQ,MAAM;AAAA,Q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