@nova-energy/openamx 0.0.0-stage → 0.11.0
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/COMMERCIAL-LICENSE.md +74 -0
- package/LICENSE.md +660 -0
- package/README.md +537 -3
- package/dist/ast/types.js +2 -0
- package/dist/cli.js +197 -0
- package/dist/diagnostics/errors.js +94 -0
- package/dist/editor/completion.js +313 -0
- package/dist/editor/highlighting.js +224 -0
- package/dist/editor/moduleAnalysis.js +206 -0
- package/dist/editor/refactoring.js +46 -0
- package/dist/editor/sourceRanges.js +50 -0
- package/dist/editor/symbols.js +203 -0
- package/dist/formatter/formatAmx.js +79 -0
- package/dist/index.js +10 -0
- package/dist/parser/parseDocument.js +114 -0
- package/dist/parser/parseExpression.js +768 -0
- package/dist/parser/parseFor.js +53 -0
- package/dist/parser/parseFrontMatter.js +65 -0
- package/dist/parser/parseStatements.js +667 -0
- package/dist/parser/stringScanner.js +71 -0
- package/dist/renderer/chartModel.js +476 -0
- package/dist/renderer/narrativeModel.js +561 -0
- package/dist/renderer/renderHtml.js +521 -0
- package/dist/renderer/reportDocx.js +725 -0
- package/dist/renderer/reportPaths.js +31 -0
- package/dist/renderer/reportPdf.js +314 -0
- package/dist/renderer/reportPreparation.js +196 -0
- package/dist/runtime/csvTextSerialization.js +8 -0
- package/dist/runtime/dataText.js +191 -0
- package/dist/runtime/docxDestination.js +55 -0
- package/dist/runtime/environment.js +105 -0
- package/dist/runtime/evaluateDocument.js +32 -0
- package/dist/runtime/evaluateExpression.js +888 -0
- package/dist/runtime/externalUnits.js +91 -0
- package/dist/runtime/inputData.js +508 -0
- package/dist/runtime/measurement.js +110 -0
- package/dist/runtime/moduleLoader.js +279 -0
- package/dist/runtime/outputData.js +303 -0
- package/dist/runtime/pdfDestination.js +57 -0
- package/dist/runtime/standardLibrary.js +145 -0
- package/dist/typechecker/checkDocument.js +1282 -0
- package/dist/typechecker/declarationRegistry.js +7 -0
- package/dist/typechecker/dimensionTypes.js +1 -0
- package/package.json +33 -4
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { parseExpression } from './parseExpression';
|
|
2
|
+
import { parseStatements } from './parseStatements';
|
|
3
|
+
function parseLoop(text, source) {
|
|
4
|
+
const lines = text.split(/\r?\n/);
|
|
5
|
+
const header = lines[0].match(/^\s*for\s+([A-Za-z][A-Za-z0-9_]*)\s+in\s+(.+?)\s*\{\s*$/);
|
|
6
|
+
if (!header) {
|
|
7
|
+
throw new Error(`Invalid for loop at ${source?.line ?? 1}:${source?.column ?? 1}`);
|
|
8
|
+
}
|
|
9
|
+
if (lines.length < 2 || !/^\s*}\s*$/.test(lines[lines.length - 1])) {
|
|
10
|
+
throw new Error(`Unclosed for loop at ${source?.line ?? 1}:${source?.column ?? 1}`);
|
|
11
|
+
}
|
|
12
|
+
if (lines.slice(1, -1).some(line => /^\s*for\b/.test(line))) {
|
|
13
|
+
throw new Error(`Nested loops are unsupported at ${source?.line ?? 1}:${source?.column ?? 1}`);
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
variable: header[1],
|
|
17
|
+
iterableText: header[2],
|
|
18
|
+
bodyText: lines.slice(1, -1).join('\n'),
|
|
19
|
+
bodySource: { line: (source?.line ?? 1) + 1, column: 1 }
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function parseForStatement(text, source) {
|
|
23
|
+
const loop = parseLoop(text, source);
|
|
24
|
+
if (/^\s*return\b/m.test(loop.bodyText)) {
|
|
25
|
+
throw new Error(`Statement-form for loops cannot contain return at ${source?.line ?? 1}:${source?.column ?? 1}`);
|
|
26
|
+
}
|
|
27
|
+
const body = parseStatements(loop.bodyText, loop.bodySource, { allowFor: false });
|
|
28
|
+
return {
|
|
29
|
+
type: 'forStatement',
|
|
30
|
+
variable: loop.variable,
|
|
31
|
+
iterable: parseExpression(loop.iterableText, source),
|
|
32
|
+
body,
|
|
33
|
+
source
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function parseForExpression(text, source) {
|
|
37
|
+
const loop = parseLoop(text, source);
|
|
38
|
+
const body = parseStatements(loop.bodyText, loop.bodySource, {
|
|
39
|
+
allowReturn: true,
|
|
40
|
+
allowFor: false
|
|
41
|
+
});
|
|
42
|
+
const returnCount = body.filter(statement => statement.type === 'returnStatement').length;
|
|
43
|
+
if (returnCount !== 1) {
|
|
44
|
+
throw new Error(`Expression-form for loops require exactly one return expression at ${source?.line ?? 1}:${source?.column ?? 1}`);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
type: 'forExpression',
|
|
48
|
+
variable: loop.variable,
|
|
49
|
+
iterable: parseExpression(loop.iterableText, source),
|
|
50
|
+
body,
|
|
51
|
+
source
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { parse as parseYaml } from "yaml";
|
|
2
|
+
/**
|
|
3
|
+
* Detects optional YAML front matter delimited by --- ... --- at the very start.
|
|
4
|
+
* Returns metadata (empty object if absent) and the remaining body.
|
|
5
|
+
* Uses the 'yaml' package for parsing.
|
|
6
|
+
*
|
|
7
|
+
* Malformed front matter (no closing delimiter or invalid YAML) yields an error message
|
|
8
|
+
* but still returns the original content as body so callers can decide how to surface it.
|
|
9
|
+
*/
|
|
10
|
+
export function parseFrontMatter(content) {
|
|
11
|
+
// Must start with --- on first line
|
|
12
|
+
const lines = content.split(/\r?\n/);
|
|
13
|
+
if (!lines.length || lines[0].trim() !== "---") {
|
|
14
|
+
return { metadata: {}, body: content, bodyStartLine: 1 };
|
|
15
|
+
}
|
|
16
|
+
// Find the closing ---
|
|
17
|
+
let closingIndex = -1;
|
|
18
|
+
for (let i = 1; i < lines.length; i++) {
|
|
19
|
+
if (lines[i].trim() === "---") {
|
|
20
|
+
closingIndex = i;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (closingIndex === -1) {
|
|
25
|
+
return {
|
|
26
|
+
metadata: {},
|
|
27
|
+
body: content,
|
|
28
|
+
bodyStartLine: 1,
|
|
29
|
+
error: "Malformed front matter: missing closing --- delimiter",
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const frontMatterText = lines.slice(1, closingIndex).join("\n");
|
|
33
|
+
const lineBreaks = [...content.matchAll(/\r?\n/g)];
|
|
34
|
+
const bodyOffset = lineBreaks[closingIndex]?.index !== undefined
|
|
35
|
+
? lineBreaks[closingIndex].index + lineBreaks[closingIndex][0].length
|
|
36
|
+
: content.length;
|
|
37
|
+
const body = content.slice(bodyOffset);
|
|
38
|
+
const bodyStartLine = bodyOffset < content.length ? closingIndex + 2 : closingIndex + 1;
|
|
39
|
+
let metadata = {};
|
|
40
|
+
if (frontMatterText.trim().length > 0) {
|
|
41
|
+
try {
|
|
42
|
+
const parsed = parseYaml(frontMatterText);
|
|
43
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
44
|
+
metadata = parsed;
|
|
45
|
+
}
|
|
46
|
+
else if (parsed != null) {
|
|
47
|
+
return {
|
|
48
|
+
metadata: {},
|
|
49
|
+
body,
|
|
50
|
+
bodyStartLine,
|
|
51
|
+
error: "Malformed front matter: front matter must be a mapping (key: value)",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return {
|
|
57
|
+
metadata: {},
|
|
58
|
+
body,
|
|
59
|
+
bodyStartLine,
|
|
60
|
+
error: `Malformed front matter: ${err?.message ?? "invalid YAML"}`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { metadata, body, bodyStartLine };
|
|
65
|
+
}
|