kaleidl 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +4 -3
- package/src/index.ts +1 -6
- package/src/lml-artifact.ts +8 -0
- package/src/lml.ts +71 -0
- package/src/node.ts +36 -0
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
MN 112 labeling engine — TypeScript port of the Ruby
|
|
4
4
|
[kaleidl](https://github.com/kaleidl/kaleidl) reference.
|
|
5
5
|
|
|
6
|
-
Conformance contract: [
|
|
6
|
+
Conformance contract: [kaleidl/kaleidl-testsuite](https://github.com/kaleidl/kaleidl-testsuite)
|
|
7
7
|
(vendored under `vectors/`). The golden-tree parity test
|
|
8
8
|
(`test/golden.test.ts`) is the acceptance target: the engine must
|
|
9
9
|
reproduce the reference label map exactly.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kaleidl",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "MN 112 labeling engine (TypeScript port of kaleidl)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "github:kaleidl/kaleidl-ts",
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
"main": "src/index.ts",
|
|
12
12
|
"types": "src/index.ts",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"test": "node --experimental-strip-types --import tsx test/golden.test.ts"
|
|
14
|
+
"test": "node --experimental-strip-types --import tsx test/golden.test.ts && node --experimental-strip-types --import tsx test/lml.test.ts"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"js-yaml": "^4.1.0"
|
|
17
|
+
"js-yaml": "^4.1.0",
|
|
18
|
+
"parsanol": "^1.5.36"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@types/js-yaml": "^4.0.9",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* kaleidl
|
|
2
|
+
* kaleidl — MN 112 labeling engine (TypeScript port of the Ruby kaleidl
|
|
3
3
|
* reference). Conformance contract: metanorma/ladl-testsuite.
|
|
4
4
|
*
|
|
5
5
|
* Faithful port of Ladl::Runtime::Engine: the element's label resolves
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
* vocabulary tokens resolved through the host labels dictionary and
|
|
13
13
|
* the English default vocabulary.
|
|
14
14
|
*/
|
|
15
|
-
import * as fs from "node:fs";
|
|
16
15
|
import * as yaml from "js-yaml";
|
|
17
16
|
|
|
18
17
|
export interface Instance {
|
|
@@ -174,10 +173,6 @@ export function loadProfile(text: string): Profile {
|
|
|
174
173
|
return { instances };
|
|
175
174
|
}
|
|
176
175
|
|
|
177
|
-
export function loadProfileFile(path: string): Profile {
|
|
178
|
-
return loadProfile(fs.readFileSync(path, "utf-8"));
|
|
179
|
-
}
|
|
180
|
-
|
|
181
176
|
export class SequenceExhaustedError extends Error {}
|
|
182
177
|
|
|
183
178
|
const CYRILLIC_UPPER = [
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sealed parsanol `lml` grammar artifact, byte-exact as baked
|
|
3
|
+
* by parsanol/grammars (grammar Lml, compiler 1.5.26, artifact
|
|
4
|
+
* sha256:2be6267c036caef844bb7abb7dd4f3d38613a9126647a1eb8c4b8cca4cfe2d4e).
|
|
5
|
+
* The seal is a raw-byte digest, so this travels as a string —
|
|
6
|
+
* re-vendor from parsanol/grammars on re-seal, never hand-edit.
|
|
7
|
+
*/
|
|
8
|
+
export const LML_ARTIFACT = "{\"bindings\":null,\"version\":\"1.0.0\",\"grammar\":\"Lml\",\"shape\":\"parsanol-tree/v2\",\"binding_version\":1,\"entries\":{\"main\":{\"root\":\"lml\",\"grammar\":{\"atoms\":[{\"Entity\":{\"atom\":13}},{\"Re\":{\"pattern\":\"[ ]\"}},{\"Re\":{\"pattern\":\"[\\\\x09]\"}},{\"Re\":{\"pattern\":\"[\\\\x0d]\"}},{\"Re\":{\"pattern\":\"[\\\\x0a]\"}},{\"Entity\":{\"atom\":11}},{\"Str\":{\"pattern\":\"//\"}},{\"Re\":{\"pattern\":\"[\\\\x20-\\\\u{10ffff}]\"}},{\"Repetition\":{\"atom\":7,\"min\":0,\"max\":null,\"tag\":\"Repetition\"}},{\"Re\":{\"pattern\":\"[\\\\x0a]\"}},{\"Repetition\":{\"atom\":9,\"min\":0,\"max\":1,\"tag\":\"Maybe\"}},{\"Sequence\":{\"atoms\":[6,8,10]}},{\"Alternative\":{\"atoms\":[1,2,3,4,5]}},{\"Repetition\":{\"atom\":12,\"min\":0,\"max\":null,\"tag\":\"Repetition\"}},{\"Entity\":{\"atom\":193}},{\"Re\":{\"pattern\":\"(?i:instance)\"}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":25}},{\"Entity\":{\"atom\":23}},{\"Re\":{\"pattern\":\"[\\\\x41-\\\\x5a]\"}},{\"Re\":{\"pattern\":\"[\\\\x61-\\\\x7a]\"}},{\"Re\":{\"pattern\":\"[\\\\x30-\\\\x39]\"}},{\"Re\":{\"pattern\":\"[_]\"}},{\"Alternative\":{\"atoms\":[19,20,21,22]}},{\"Repetition\":{\"atom\":18,\"min\":1,\"max\":null,\"tag\":\"Repetition\"}},{\"Named\":{\"name\":\"name\",\"atom\":24}},{\"Entity\":{\"atom\":13}},{\"Str\":{\"pattern\":\"<\"}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":32}},{\"Entity\":{\"atom\":23}},{\"Repetition\":{\"atom\":30,\"min\":1,\"max\":null,\"tag\":\"Repetition\"}},{\"Named\":{\"name\":\"type\",\"atom\":31}},{\"Sequence\":{\"atoms\":[15,16,17,26,27,28,29]}},{\"Entity\":{\"atom\":32}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":64}},{\"Re\":{\"pattern\":\"[\\\"]\"}},{\"Entity\":{\"atom\":61}},{\"Re\":{\"pattern\":\"[ !]\"}},{\"Re\":{\"pattern\":\"[\\\\x23-\\\\x5b]\"}},{\"Re\":{\"pattern\":\"[\\\\x5d-\\\\u{10ffff}]\"}},{\"Re\":{\"pattern\":\"[\\\\\\\\]\"}},{\"Re\":{\"pattern\":\"[\\\"]\"}},{\"Re\":{\"pattern\":\"[\\\\\\\\]\"}},{\"Re\":{\"pattern\":\"[/]\"}},{\"Re\":{\"pattern\":\"[b]\"}},{\"Re\":{\"pattern\":\"[f]\"}},{\"Re\":{\"pattern\":\"[n]\"}},{\"Re\":{\"pattern\":\"[r]\"}},{\"Re\":{\"pattern\":\"[t]\"}},{\"Re\":{\"pattern\":\"[u]\"}},{\"Re\":{\"pattern\":\"[\\\\x30-\\\\x39]\"}},{\"Re\":{\"pattern\":\"[\\\\x41-\\\\x46]\"}},{\"Re\":{\"pattern\":\"[\\\\x61-\\\\x66]\"}},{\"Alternative\":{\"atoms\":[52,53,54]}},{\"Repetition\":{\"atom\":55,\"min\":4,\"max\":null,\"tag\":\"Repetition\"}},{\"Sequence\":{\"atoms\":[51,56]}},{\"Alternative\":{\"atoms\":[43,44,45,46,47,48,49,50,57]}},{\"Sequence\":{\"atoms\":[42,58]}},{\"Alternative\":{\"atoms\":[39,40,41,59]}},{\"Repetition\":{\"atom\":60,\"min\":0,\"max\":null,\"tag\":\"Repetition\"}},{\"Re\":{\"pattern\":\"[\\\"]\"}},{\"Sequence\":{\"atoms\":[37,38,62]}},{\"Named\":{\"name\":\"name\",\"atom\":63}},{\"Sequence\":{\"atoms\":[34,35,36]}},{\"Alternative\":{\"atoms\":[33,65]}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":191}},{\"Str\":{\"pattern\":\"{\"}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":181}},{\"Entity\":{\"atom\":75}},{\"Entity\":{\"atom\":23}},{\"Repetition\":{\"atom\":73,\"min\":1,\"max\":null,\"tag\":\"Repetition\"}},{\"Named\":{\"name\":\"key\",\"atom\":74}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":178}},{\"Str\":{\"pattern\":\"=\"}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":177}},{\"Entity\":{\"atom\":86}},{\"Re\":{\"pattern\":\"[\\\"]\"}},{\"Entity\":{\"atom\":61}},{\"Re\":{\"pattern\":\"[\\\"]\"}},{\"Sequence\":{\"atoms\":[82,83,84]}},{\"Named\":{\"name\":\"string\",\"atom\":85}},{\"Entity\":{\"atom\":90}},{\"Re\":{\"pattern\":\"[\\\\x30-\\\\x39]\"}},{\"Repetition\":{\"atom\":88,\"min\":1,\"max\":null,\"tag\":\"Repetition\"}},{\"Named\":{\"name\":\"integer\",\"atom\":89}},{\"Entity\":{\"atom\":124}},{\"Str\":{\"pattern\":\"[\"}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":109}},{\"Entity\":{\"atom\":86}},{\"Entity\":{\"atom\":107}},{\"Str\":{\"pattern\":\"ref:\"}},{\"Str\":{\"pattern\":\"(\"}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":103}},{\"Entity\":{\"atom\":23}},{\"Repetition\":{\"atom\":101,\"min\":1,\"max\":null,\"tag\":\"Repetition\"}},{\"Named\":{\"name\":\"symbol\",\"atom\":102}},{\"Entity\":{\"atom\":13}},{\"Str\":{\"pattern\":\")\"}},{\"Sequence\":{\"atoms\":[97,98,99,100,104,105]}},{\"Named\":{\"name\":\"ref\",\"atom\":106}},{\"Entity\":{\"atom\":103}},{\"Alternative\":{\"atoms\":[95,96,108]}},{\"Entity\":{\"atom\":13}},{\"Str\":{\"pattern\":\",\"}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":109}},{\"Sequence\":{\"atoms\":[110,111,112,113]}},{\"Repetition\":{\"atom\":114,\"min\":0,\"max\":null,\"tag\":\"Repetition\"}},{\"Sequence\":{\"atoms\":[94,115]}},{\"Repetition\":{\"atom\":116,\"min\":0,\"max\":1,\"tag\":\"Maybe\"}},{\"Entity\":{\"atom\":13}},{\"Str\":{\"pattern\":\",\"}},{\"Repetition\":{\"atom\":119,\"min\":0,\"max\":1,\"tag\":\"Maybe\"}},{\"Entity\":{\"atom\":13}},{\"Str\":{\"pattern\":\"]\"}},{\"Sequence\":{\"atoms\":[92,93,117,118,120,121,122]}},{\"Named\":{\"name\":\"array\",\"atom\":123}},{\"Entity\":{\"atom\":174}},{\"Str\":{\"pattern\":\"{\"}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":164}},{\"Sequence\":{\"atoms\":[72,76,77]}},{\"Entity\":{\"atom\":75}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":161}},{\"Entity\":{\"atom\":159}},{\"Str\":{\"pattern\":\"{\"}},{\"Entity\":{\"atom\":155}},{\"Entity\":{\"atom\":153}},{\"Str\":{\"pattern\":\"{\"}},{\"Entity\":{\"atom\":150}},{\"Str\":{\"pattern\":\"{\"}},{\"Lookahead\":{\"atom\":139,\"positive\":false}},{\"Str\":{\"pattern\":\"}\"}},{\"Lookahead\":{\"atom\":141,\"positive\":false}},{\"Re\":{\"pattern\":\"[\\\\x20-\\\\u{10ffff}]\"}},{\"Sequence\":{\"atoms\":[140,142,143]}},{\"Re\":{\"pattern\":\"[\\\\x09]\"}},{\"Re\":{\"pattern\":\"[\\\\x0d]\"}},{\"Re\":{\"pattern\":\"[\\\\x0a]\"}},{\"Alternative\":{\"atoms\":[144,145,146,147]}},{\"Alternative\":{\"atoms\":[136,148]}},{\"Repetition\":{\"atom\":149,\"min\":0,\"max\":null,\"tag\":\"Repetition\"}},{\"Entity\":{\"atom\":13}},{\"Str\":{\"pattern\":\"}\"}},{\"Sequence\":{\"atoms\":[137,138,151,152]}},{\"Alternative\":{\"atoms\":[136,148]}},{\"Repetition\":{\"atom\":154,\"min\":0,\"max\":null,\"tag\":\"Repetition\"}},{\"Entity\":{\"atom\":13}},{\"Str\":{\"pattern\":\"}\"}},{\"Sequence\":{\"atoms\":[134,135,156,157]}},{\"Named\":{\"name\":\"prose\",\"atom\":158}},{\"Entity\":{\"atom\":86}},{\"Alternative\":{\"atoms\":[133,160]}},{\"Sequence\":{\"atoms\":[130,131,132]}},{\"Alternative\":{\"atoms\":[129,162]}},{\"Named\":{\"name\":\"attr\",\"atom\":163}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":164}},{\"Sequence\":{\"atoms\":[165,166]}},{\"Repetition\":{\"atom\":167,\"min\":0,\"max\":null,\"tag\":\"Repetition\"}},{\"Sequence\":{\"atoms\":[128,168]}},{\"Repetition\":{\"atom\":169,\"min\":0,\"max\":1,\"tag\":\"Maybe\"}},{\"Entity\":{\"atom\":13}},{\"Str\":{\"pattern\":\"}\"}},{\"Sequence\":{\"atoms\":[126,127,170,171,172]}},{\"Named\":{\"name\":\"block\",\"atom\":173}},{\"Entity\":{\"atom\":107}},{\"Entity\":{\"atom\":103}},{\"Alternative\":{\"atoms\":[81,87,91,125,175,176]}},{\"Sequence\":{\"atoms\":[78,79,80]}},{\"Sequence\":{\"atoms\":[72,76,77]}},{\"Alternative\":{\"atoms\":[179,162]}},{\"Named\":{\"name\":\"attr\",\"atom\":180}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":181}},{\"Sequence\":{\"atoms\":[182,183]}},{\"Repetition\":{\"atom\":184,\"min\":0,\"max\":null,\"tag\":\"Repetition\"}},{\"Sequence\":{\"atoms\":[71,185]}},{\"Repetition\":{\"atom\":186,\"min\":0,\"max\":1,\"tag\":\"Maybe\"}},{\"Entity\":{\"atom\":13}},{\"Str\":{\"pattern\":\"}\"}},{\"Sequence\":{\"atoms\":[69,70,187,188,189]}},{\"Named\":{\"name\":\"block\",\"atom\":190}},{\"Sequence\":{\"atoms\":[66,67,68]}},{\"Named\":{\"name\":\"instance\",\"atom\":192}},{\"Entity\":{\"atom\":13}},{\"Entity\":{\"atom\":193}},{\"Sequence\":{\"atoms\":[194,195]}},{\"Repetition\":{\"atom\":196,\"min\":0,\"max\":null,\"tag\":\"Repetition\"}},{\"Sequence\":{\"atoms\":[14,197]}},{\"Repetition\":{\"atom\":198,\"min\":0,\"max\":1,\"tag\":\"Maybe\"}},{\"Entity\":{\"atom\":13}},{\"Sequence\":{\"atoms\":[0,199,200]}}],\"root\":201},\"bindings\":[]}},\"preprocess\":{},\"tables\":{},\"lint\":{\"order_warnings\":[\"rule value: branches 2 and 6 are order-dependent (shared first bytes; ordered choice is decisive)\",\"rule value: branches 5 and 6 are order-dependent (shared first bytes; ordered choice is decisive)\",\"rule item: branches 2 and 3 are order-dependent (shared first bytes; ordered choice is decisive)\"]},\"default_entry\":\"main\",\"render\":{},\"derive\":{},\"tests\":[{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"instance A < LabelStyle {\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"instance A < LabelStyle {\\n name = \\\"A\\\"\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"instance A < LabelStyle {\\n pattern = \\\"{clause} %n\\\"\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"instance A < LabelTemplate {\\n pattern = \\\"%pn.%n\\\"\\n definition \\\"one-line string shorthand\\\"\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"instance A < LabelTemplate {\\n definition {\\n free prose with\\n * bullets\\n }\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"instance A < Labeller {\\n condition = {\\n type = \\\"element_count_gt\\\"\\n threshold = 1\\n }\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"instance A < LabelStyle {\\n sequences = [\\n DecimalNumericSequence,\\n AlphaUpperNumericSequence,\\n ]\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"instance A < LabelStyle {\\n labellers = [\\n \\\"id:clause_labeller\\\",\\n \\\"id:annex_labeller\\\"\\n ]\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"// leading comment\\ninstance A < LabelContext {\\n parent = B // trailing comment\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"instance A < LabelContext {\\n name = \\\"document\\\"\\n definition {\\n top context\\n }\\n}\\n\\ninstance B < LabelContext {\\n parent = A\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"instance AnnexLabeller < Labeller {\\n template = [NoteSingleLabelTemplate, NoteMultipleLabelTemplate]\\n global_template = [NoteSingleGlobalLabelTemplate, NoteMultipleGlobalLabelTemplate]\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"LabelStyle \\\"ISOIECLabelStyle\\\" {\\n name = \\\"ISO/IEC Label Style\\\"\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"LabelContext \\\"DocumentContext\\\" {\\n name = \\\"document\\\"\\n}\\n\\nLabelTemplate \\\"ClauseLabelTemplate\\\" {\\n pattern = \\\"{clause} %n\\\"\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"accept\",\"input\":\"LabelStyle \\\"S\\\" {\\n sequences = [\\n ref:(DecimalNumericSequence),\\n ref:(AlphaUpperNumericSequence)\\n ]\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"reject\",\"input\":\"instance A LabelStyle {\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"reject\",\"input\":\"instance A < LabelStyle {\\n name =\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"reject\",\"input\":\"instance A < LabelStyle {\\n = \\\"value\\\"\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"reject\",\"input\":\"stray text\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"reject\",\"input\":\"instance A < LabelStyle {\\n name = \\\"unterminated\\n}\",\"expect\":{}},{\"entry\":\"main\",\"kind\":\"reject\",\"input\":\"instance A < LabelStyle {\\n condition = {\\n threshold = 1\\n\",\"expect\":{}}],\"docs\":{\"sp\":\"sp = whitespace and comments \u2014 legal between all tokens.\",\"lml\":\"lml = sp [instance *(sp instance)] sp \u2014 the whole document.\\nRepetitions over capturing rules use the separated form\\n([ x *(sp x) ]); a bare repetition of a dict-producing rule\\ntrips the native VM's subtree merge.\",\"instance\":\"instance = a typed profile instance with a block body, in either\\nheader form: `instance Name < Type` (the LADL worked profile) or\\n`Type \\\"Name\\\"` (the spec-annex style). Both bind {name, type}.\",\"attr_block\":\"attr_block = the { ... } body of an instance: attributes and comments.\",\"attr\":\"attr = key = value, or a shorthand (prose block / one-line string).\",\"attr_eq\":\"attr_eq = the = value half of an attribute.\",\"attr_shorthand\":\"shorthand without \\\"=\\\": a prose block or a one-line string\",\"value\":\"value = string / integer / array / inline block / reference /\\nsymbol reference.\",\"reference\":\"reference = the explicit reference form ref:(Name) used by the\\nspec-annex style (bound as ref).\",\"inline_block\":\"inline_block = a nested attribute block as a value (conditional templates).\",\"array\":\"array = comma-separated strings and symbols; a trailing comma is legal.\",\"item\":\"item = one array element: a string, a reference, or a symbol\\nreference.\",\"prose_block\":\"prose = free text with balanced braces (definition blocks,\\nbullet lists); nests so {key} tokens cannot terminate the block.\",\"prose\":\"prose = free text with balanced braces (definition bodies).\",\"prose_nested\":\"prose_nested = a brace-nested span inside prose ({key} tokens cannot close a block).\",\"key\":\"key = an attribute name.\",\"instance_name\":\"instance_name = the declaring name of an instance (bound as name).\",\"instance_quoted_name\":\"instance_quoted_name = the quoted declaring name in the Type \\\"Name\\\"\\nheader form (bound as name, same capture as the keyword form).\",\"type_name\":\"type_name = the supertype after <, or the leading type of the\\nType \\\"Name\\\" header form (bound as type).\",\"symbol\":\"symbol = a bare reference to a sibling instance or a built-in sequence.\",\"integer\":\"integer = a bare non-negative integer (condition thresholds).\",\"string\":\"string = a single-line double-quoted string with backslash escapes.\",\"string_body\":\"string_body = the string character run (shared by string and the\\nquoted instance-name header form).\",\"comment\":\"comment = // to end of line, consuming the terminator.\",\"name_char\":\"name_char = the shared identifier class: A-Z a-z 0-9 _.\"},\"source\":\"# LML: the LutaML textual realization of the MN 112 (LADL) labeling\\n# profile \u2014 the kaleidl fleet's source format. A document is a stream\\n# of typed instances with two header forms \u2014 `instance Name < Type { }`\\n# (the LADL worked profile) and `Type \\\"Name\\\" { }` (the spec-annex\\n# style); both bind {name, type}. Attributes\\n# take five value shapes: quoted strings (label words carry {key}\\n# tokens and %n placeholders as plain string content), integers, bare\\n# symbol references (built-in sequences, sibling instances), arrays of\\n# strings and symbols (trailing comma allowed), and inline attribute\\n# blocks (conditional templates: condition = { type = ... threshold = 1 }).\\n# Two attribute shorthands bind without \\\"=\\\": a prose definition block\\n# (`definition { free text with * bullets }`) and a one-line string\\n# (`definition \\\"...\\\"`). \\\"//\\\" comments run to end of line and are legal\\n# wherever whitespace is. Instances may appear in any order; an empty\\n# document parses.\\n#\\n# Dialect notes: names are [A-Za-z0-9_] runs (instance names, types,\\n# keys, symbols share the class \u2014 the integer rule wins on ordered\\n# choice); strings are single-line with backslash escapes; braces\\n# balance recursively inside prose blocks; CRLF is tolerated as\\n# whitespace. Parsed but not validated: cross-references between\\n# instances (a name may reference an instance defined anywhere or a\\n# host-declared built-in sequence).\\n\\ngrammar Lml version \\\"1.0.0\\\" edition 2 {\\n ## sp = whitespace and comments \u2014 legal between all tokens.\\n sp = *( %x20 / %x09 / %x0D / %x0A / comment )\\n\\n ## lml = sp [instance *(sp instance)] sp \u2014 the whole document.\\n ## Repetitions over capturing rules use the separated form\\n ## ([ x *(sp x) ]); a bare repetition of a dict-producing rule\\n ## trips the native VM's subtree merge.\\n lml = sp [ instance *( sp instance ) ] sp\\n\\n ## instance = a typed profile instance with a block body, in either\\n ## header form: `instance Name < Type` (the LADL worked profile) or\\n ## `Type \\\"Name\\\"` (the spec-annex style). Both bind {name, type}.\\n instance = ( ( %i\\\"instance\\\" sp instance_name sp \\\"<\\\" sp type_name / type_name sp instance_quoted_name ) sp attr_block ) as instance\\n\\n ## attr_block = the { ... } body of an instance: attributes and comments.\\n attr_block = ( \\\"{\\\" sp [ attr *( sp attr ) ] sp \\\"}\\\" ) as block\\n\\n ## attr = key = value, or a shorthand (prose block / one-line string).\\n attr = ( key sp attr_eq / key sp attr_shorthand ) as attr\\n ## attr_eq = the = value half of an attribute.\\n attr_eq = \\\"=\\\" sp value\\n ## shorthand without \\\"=\\\": a prose block or a one-line string\\n attr_shorthand = prose_block / string\\n\\n ## value = string / integer / array / inline block / reference /\\n ## symbol reference.\\n value = string / integer / array / inline_block / reference / symbol\\n ## reference = the explicit reference form ref:(Name) used by the\\n ## spec-annex style (bound as ref).\\n reference = ( \\\"ref:\\\" \\\"(\\\" sp symbol sp \\\")\\\" ) as ref\\n ## inline_block = a nested attribute block as a value (conditional templates).\\n inline_block = ( \\\"{\\\" sp [ attr *( sp attr ) ] sp \\\"}\\\" ) as block\\n\\n ## array = comma-separated strings and symbols; a trailing comma is legal.\\n array = ( \\\"[\\\" sp [ item *( sp \\\",\\\" sp item ) ] sp [ \\\",\\\" ] sp \\\"]\\\" ) as array\\n ## item = one array element: a string, a reference, or a symbol\\n ## reference.\\n item = string / reference / symbol\\n\\n ## prose = free text with balanced braces (definition blocks,\\n ## bullet lists); nests so {key} tokens cannot terminate the block.\\n prose_block = ( \\\"{\\\" prose sp \\\"}\\\" ) as prose\\n ## prose = free text with balanced braces (definition bodies).\\n prose = *( prose_nested / ( !\\\"{\\\" !\\\"}\\\" %x20-10FFFF / %x09 / %x0D / %x0A ) )\\n ## prose_nested = a brace-nested span inside prose ({key} tokens cannot close a block).\\n prose_nested = \\\"{\\\" prose sp \\\"}\\\"\\n\\n ## key = an attribute name.\\n key = ( 1*name_char ) as key\\n ## instance_name = the declaring name of an instance (bound as name).\\n instance_name = ( 1*name_char ) as name\\n ## instance_quoted_name = the quoted declaring name in the Type \\\"Name\\\"\\n ## header form (bound as name, same capture as the keyword form).\\n instance_quoted_name = ( %x22 string_body %x22 ) as name\\n ## type_name = the supertype after <, or the leading type of the\\n ## Type \\\"Name\\\" header form (bound as type).\\n type_name = ( 1*name_char ) as type\\n ## symbol = a bare reference to a sibling instance or a built-in sequence.\\n symbol = ( 1*name_char ) as symbol\\n ## integer = a bare non-negative integer (condition thresholds).\\n integer = ( 1*%x30-39 ) as integer\\n\\n ## string = a single-line double-quoted string with backslash escapes.\\n string = ( %x22 string_body %x22 ) as string\\n ## string_body = the string character run (shared by string and the\\n ## quoted instance-name header form).\\n string_body = *( %x20-21 / %x23-5B / %x5D-10FFFF / %x5C ( %x22 / %x5C / %x2F / %x62 / %x66 / %x6E / %x72 / %x74 / ( %x75 4*( %x30-39 / %x41-46 / %x61-66 ) ) ) )\\n\\n ## comment = // to end of line, consuming the terminator.\\n comment = \\\"//\\\" *( %x20-10FFFF ) [ %x0A ]\\n\\n ## name_char = the shared identifier class: A-Z a-z 0-9 _.\\n name_char = %x41-5A / %x61-7A / %x30-39 / %x5F\\n\\n entry main: lml\\n\\n test {\\n accept \\\"instance A < LabelStyle {\\\\n}\\\"\\n accept \\\"instance A < LabelStyle {\\\\n name = \\\\\\\"A\\\\\\\"\\\\n}\\\"\\n accept \\\"instance A < LabelStyle {\\\\n pattern = \\\\\\\"{clause} %n\\\\\\\"\\\\n}\\\"\\n accept \\\"instance A < LabelTemplate {\\\\n pattern = \\\\\\\"%pn.%n\\\\\\\"\\\\n definition \\\\\\\"one-line string shorthand\\\\\\\"\\\\n}\\\"\\n accept \\\"instance A < LabelTemplate {\\\\n definition {\\\\n free prose with\\\\n * bullets\\\\n }\\\\n}\\\"\\n accept \\\"instance A < Labeller {\\\\n condition = {\\\\n type = \\\\\\\"element_count_gt\\\\\\\"\\\\n threshold = 1\\\\n }\\\\n}\\\"\\n accept \\\"instance A < LabelStyle {\\\\n sequences = [\\\\n DecimalNumericSequence,\\\\n AlphaUpperNumericSequence,\\\\n ]\\\\n}\\\"\\n accept \\\"instance A < LabelStyle {\\\\n labellers = [\\\\n \\\\\\\"id:clause_labeller\\\\\\\",\\\\n \\\\\\\"id:annex_labeller\\\\\\\"\\\\n ]\\\\n}\\\"\\n accept \\\"// leading comment\\\\ninstance A < LabelContext {\\\\n parent = B // trailing comment\\\\n}\\\"\\n accept \\\"instance A < LabelContext {\\\\n name = \\\\\\\"document\\\\\\\"\\\\n definition {\\\\n top context\\\\n }\\\\n}\\\\n\\\\ninstance B < LabelContext {\\\\n parent = A\\\\n}\\\"\\n accept \\\"instance AnnexLabeller < Labeller {\\\\n template = [NoteSingleLabelTemplate, NoteMultipleLabelTemplate]\\\\n global_template = [NoteSingleGlobalLabelTemplate, NoteMultipleGlobalLabelTemplate]\\\\n}\\\"\\n accept \\\"\\\"\\n accept \\\"LabelStyle \\\\\\\"ISOIECLabelStyle\\\\\\\" {\\\\n name = \\\\\\\"ISO/IEC Label Style\\\\\\\"\\\\n}\\\"\\n accept \\\"LabelContext \\\\\\\"DocumentContext\\\\\\\" {\\\\n name = \\\\\\\"document\\\\\\\"\\\\n}\\\\n\\\\nLabelTemplate \\\\\\\"ClauseLabelTemplate\\\\\\\" {\\\\n pattern = \\\\\\\"{clause} %n\\\\\\\"\\\\n}\\\"\\n accept \\\"LabelStyle \\\\\\\"S\\\\\\\" {\\\\n sequences = [\\\\n ref:(DecimalNumericSequence),\\\\n ref:(AlphaUpperNumericSequence)\\\\n ]\\\\n}\\\"\\n reject \\\"instance A LabelStyle {\\\\n}\\\"\\n reject \\\"instance A < LabelStyle {\\\\n name =\\\\n}\\\"\\n reject \\\"instance A < LabelStyle {\\\\n = \\\\\\\"value\\\\\\\"\\\\n}\\\"\\n reject \\\"stray text\\\"\\n reject \\\"instance A < LabelStyle {\\\\n name = \\\\\\\"unterminated\\\\n}\\\"\\n reject \\\"instance A < LabelStyle {\\\\n condition = {\\\\n threshold = 1\\\\n\\\"\\n }\\n}\\n\",\"source_hash\":\"3d1955259129bce3745d88fad983864853d94649c73f9626b2191592f5199e8a\",\"unicode_tables\":\"onigmo (Ruby 4.0.7)\",\"compiler_version\":\"1.5.26\",\"edition\":2,\"semantics_hash\":\"sha256:078b27121f2d50d096c68999311dd8a7058752450d4cd5d90f0439adcd754778\",\"checksum\":\"sha256:2be6267c036caef844bb7abb7dd4f3d38613a9126647a1eb8c4b8cca4cfe2d4e\",\"validated\":{\"lint_errors\":0,\"lint_warnings\":3,\"tests_total\":21,\"tests_failures\":0,\"self_test\":true},\"byte_checksum\":\"sha256:3a1f029e0e8716dc4680e29adb31ebfa0afea33755ec6ff5d6c815910d036f2b\"}\n";
|
package/src/lml.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LML (LutaML) profile loading — the textual MN 112 realization —
|
|
3
|
+
* through the sealed parsanol `lml` grammar artifact. This module is
|
|
4
|
+
* browser-pure: the artifact and the parse-tree mapper carry no
|
|
5
|
+
* platform I/O; runtimes (node.ts, the websites) own the wasm glue.
|
|
6
|
+
*
|
|
7
|
+
* Provenance: parsanol/grammars grammars/lml.parg, artifact
|
|
8
|
+
* sha256:2be6267c036caef844bb7abb7dd4f3d38613a9126647a1eb8c4b8cca4cfe2d4e,
|
|
9
|
+
* compiled with parsanol 1.5.26. The registry's corpus freezes the
|
|
10
|
+
* kaleidl golden fixtures. Re-vendor the artifact from parsanol/grammars
|
|
11
|
+
* when its seal changes — never hand-edit it here.
|
|
12
|
+
*/
|
|
13
|
+
import { LML_ARTIFACT } from "./lml-artifact.js";
|
|
14
|
+
import type { Instance, Profile } from "./index.js";
|
|
15
|
+
|
|
16
|
+
export { LML_ARTIFACT } from "./lml-artifact.js";
|
|
17
|
+
export const LML_ARTIFACT_CHECKSUM = "sha256:2be6267c036caef844bb7abb7dd4f3d38613a9126647a1eb8c4b8cca4cfe2d4e";
|
|
18
|
+
|
|
19
|
+
type Span = { value: string };
|
|
20
|
+
type ValueNode =
|
|
21
|
+
| { string: Span }
|
|
22
|
+
| { integer: Span }
|
|
23
|
+
| { symbol: Span }
|
|
24
|
+
| { ref: { symbol: Span } }
|
|
25
|
+
| { prose: Span }
|
|
26
|
+
| { array: ValueNode[] }
|
|
27
|
+
| { block: AttrNode[] };
|
|
28
|
+
type AttrNode = { attr: { key: Span } & ValueNode };
|
|
29
|
+
|
|
30
|
+
function unquote(raw: string): string {
|
|
31
|
+
return raw.slice(1, -1).replace(/\\(.)/g, "$1");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function mapValue(node: ValueNode): any {
|
|
35
|
+
if ("string" in node) return unquote(node.string.value);
|
|
36
|
+
if ("integer" in node) return Number(node.integer.value);
|
|
37
|
+
if ("symbol" in node) return { ref: node.symbol.value };
|
|
38
|
+
if ("ref" in node) return { ref: node.ref.symbol.value };
|
|
39
|
+
if ("prose" in node) return node.prose.value.replace(/^[{ \n\r\t]+/, "").replace(/[}\s]+$/, "");
|
|
40
|
+
if ("array" in node) return node.array.map(mapValue);
|
|
41
|
+
if ("block" in node) {
|
|
42
|
+
const out: Record<string, any> = {};
|
|
43
|
+
for (const entry of node.block) out[entry.attr.key.value] = mapValue(entry.attr as ValueNode);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
throw new Error("unreachable LML value kind");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Map a parsanol `lml` parse tree to the Profile the engine consumes. */
|
|
50
|
+
export function profileFromLmlTree(tree: any): Profile {
|
|
51
|
+
const instances: Record<string, Instance> = {};
|
|
52
|
+
const nodes = Array.isArray(tree) ? tree : [];
|
|
53
|
+
for (const node of nodes) {
|
|
54
|
+
const inst = node?.instance;
|
|
55
|
+
if (!inst) throw new Error("LML parse tree: expected an instance node");
|
|
56
|
+
// The quoted-name header form (Type "Name") captures the name with
|
|
57
|
+
// its quotes; normalize to the bare identifier.
|
|
58
|
+
const rawName = inst.name?.value ?? "";
|
|
59
|
+
const name = rawName.startsWith('"') ? unquote(rawName) : rawName;
|
|
60
|
+
const type = inst.type?.value;
|
|
61
|
+
if (!name || !type) throw new Error("LML parse tree: instance needs name and type");
|
|
62
|
+
const properties: Record<string, any> = {};
|
|
63
|
+
for (const entry of inst.block ?? []) {
|
|
64
|
+
const attr = entry?.attr;
|
|
65
|
+
if (!attr) continue;
|
|
66
|
+
properties[attr.key.value] = mapValue(attr as ValueNode);
|
|
67
|
+
}
|
|
68
|
+
instances[name] = { name, type, properties };
|
|
69
|
+
}
|
|
70
|
+
return { instances };
|
|
71
|
+
}
|
package/src/node.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kaleidl node entry: file-system loaders over the pure core. The
|
|
3
|
+
* browser-facing entry is src/index.ts — it must stay platform-free,
|
|
4
|
+
* the same split rhoella-ts uses.
|
|
5
|
+
*/
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import * as fs from "node:fs";
|
|
8
|
+
import { loadProfile, type Profile } from "./index.js";
|
|
9
|
+
import { LML_ARTIFACT, profileFromLmlTree } from "./lml.js";
|
|
10
|
+
|
|
11
|
+
export function loadProfileFile(path: string): Profile {
|
|
12
|
+
return loadProfile(fs.readFileSync(path, "utf-8"));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let lmlRuntime: Promise<any> | null = null;
|
|
16
|
+
|
|
17
|
+
async function lmlParse(source: string): Promise<any> {
|
|
18
|
+
if (!lmlRuntime) {
|
|
19
|
+
lmlRuntime = (async () => {
|
|
20
|
+
const require = createRequire(import.meta.url);
|
|
21
|
+
const { initialize, PargRuntime } = await import("parsanol/browser");
|
|
22
|
+
await initialize(fs.readFileSync(require.resolve("parsanol/wasm")));
|
|
23
|
+
return new PargRuntime(LML_ARTIFACT);
|
|
24
|
+
})();
|
|
25
|
+
}
|
|
26
|
+
const runtime = await lmlRuntime;
|
|
27
|
+
return runtime.parseShape(source, "main");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function loadLml(source: string): Promise<Profile> {
|
|
31
|
+
return profileFromLmlTree(await lmlParse(source));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function loadLmlFile(path: string): Promise<Profile> {
|
|
35
|
+
return loadLml(fs.readFileSync(path, "utf-8"));
|
|
36
|
+
}
|