lutaml-diagram 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8b4453d67214235761624875ef86290a1a9e613dc0f9d8e5f6f891d8e8fdcb85
4
+ data.tar.gz: 17eaf23388fc5aed9a150a241304d1a8efa4aa7a778ff3db631bdeeaa79ff2d1
5
+ SHA512:
6
+ metadata.gz: 7659f7938fb2fbc45b6b4d422da672a7a4d37b463229629adddab4277e54e7d06b338ba52caedb55e2738c029e55a476bd02c91b6dbfefab2361afe76affdeea
7
+ data.tar.gz: 318fcfe006d0c711c576fa8ee9cc2e87e5f36fb4ac5069d67219596da9c4e8add67056bc90560a10292f7a014d238007fafaff2146c693ffb47f58f96748aa94
@@ -0,0 +1,39 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: release
4
+
5
+ on:
6
+ workflow_dispatch:
7
+ inputs:
8
+ next_version:
9
+ description: |
10
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
11
+ required: true
12
+ default: 'skip'
13
+ repository_dispatch:
14
+ types: [ do-release ]
15
+ # The publish leg: when the release PR (head branch release/v*) merges,
16
+ # metanorma/ci tags the merge commit and publishes (metanorma/ci#515).
17
+ pull_request:
18
+ types:
19
+ - closed
20
+
21
+ permissions:
22
+ contents: write
23
+ id-token: write
24
+ pull-requests: write
25
+
26
+ concurrency:
27
+ group: release
28
+ cancel-in-progress: false
29
+
30
+ jobs:
31
+ release:
32
+ uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
33
+ with:
34
+ next_version: ${{ github.event.inputs.next_version }}
35
+ secrets:
36
+ # OMIT rubygems-api-key: OIDC Trusted Publishing (USE_OIDC =
37
+ # rubygems-api-key == ''), configured for the lutaml gems on
38
+ # rubygems.org.
39
+ pat_token: ${{ secrets.LUTAML_CI_PAT_TOKEN }}
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .bundle
2
+ Gemfile.lock
3
+ pkg/
4
+ coverage/
5
+ .rspec_status
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "elkrb", "~> 2.0"
8
+ gem "pdfrb"
9
+ gem "vectory"
10
+ gem "svg_conform"
11
+ gem "rantly", "~> 2.0"
12
+ gem "rspec"
13
+ gem "rake"
data/README.adoc ADDED
@@ -0,0 +1,205 @@
1
+ = lutaml-lml
2
+
3
+ LutaML Model Language (LML) — a text DSL for describing UML-style
4
+ models and their data instances, parsed into typed domain models and
5
+ rendered as diagrams via GraphViz.
6
+
7
+ == Status
8
+
9
+ RS 3001 (LutaML language, `lutaml-lang.adoc`) is the authoritative
10
+ base and is fully implemented: classes, enums, data types, attributes
11
+ (including `values` sets, `pattern`, cardinality, defaults), the
12
+ canonical `value` construct, packages, namespacing, instances and
13
+ instance collections with references, and the validation rules
14
+ (uniqueness, mandatory attributes, type and pattern conformity,
15
+ reference validity and circularity). Every normative example of the
16
+ specification is vendored as a conformance corpus and runs in CI.
17
+
18
+ RS 3010 (declarations extension, `lml-declarations.adoc`) covers
19
+ serialization mappings (XML elements/attributes/content, key-value
20
+ wire names, namespaces), `isa`, `derive`, `string_format`, enum
21
+ member payloads and `from_table` artifact references.
22
+
23
+ Tooling: a canonical form with a `lutaml format [--check]` formatter and
24
+ an idempotence guarantee; structured diagnostics (code, position,
25
+ remedy) across parse, validation, and hydration; a stdio language
26
+ server (`lutaml-lml-lsp`); language-version negotiation via the
27
+ `lml "x.y"` prologue; and seeded generative round-trip laws (value,
28
+ key, document, idempotence) that run at reduced depth in CI and
29
+ nightly at full depth.
30
+
31
+ == Installation
32
+
33
+ ....
34
+ gem install lutaml-lml
35
+ ....
36
+
37
+ == Usage
38
+
39
+ Parse an LML document:
40
+
41
+ ....
42
+ require "lutaml/lml"
43
+
44
+ # parse_document: pipeline only — raw collections, unresolved imports.
45
+ doc = Lutaml::Lml.parse_document(File.new("model.lml"))
46
+ # parse: pipeline + view resolution (imports expanded, show/hide
47
+ # filters applied, association labels enriched).
48
+ doc = Lutaml::Lml.parse(File.new("model.lml"))
49
+ doc.classes.first.attributes.map(&:name)
50
+ ....
51
+
52
+ Validate against the RS 3001 rules:
53
+
54
+ ....
55
+ violations = Lutaml::Lml::Validator.diagnostics(doc)
56
+ violations.each { |diagnostic| puts diagnostic }
57
+ # 1:7: [validation/LML-V01] 'Tile' is defined 2 times in the document root
58
+ # remedy: Rename or remove the duplicate definition.
59
+ ....
60
+
61
+ == Diagnostics
62
+
63
+ Parse, validation, hydration, and contract failures are
64
+ `Lutaml::Lml::Diagnostic` records: `code`, `severity`, `file`, `line`,
65
+ `column`, `length`, `message`, and `remedy`. Parse failures raise an
66
+ error carrying the record (`error.diagnostic`); validation returns them
67
+ from `Lutaml::Lml::Validator.diagnostics`. `lutaml validate --format
68
+ json` emits the diagnostic array machine-readably.
69
+
70
+ [cols="1,2,2",options="header"]
71
+ |===
72
+ |Code |Meaning |Remedy
73
+
74
+ |`parse/LML-001` |Syntax error |Fix the syntax at the reported position.
75
+ |`parse/LML-002` |Unterminated block comment |Terminate the block comment with `*/`.
76
+ |`parse/LML-003` |Include could not be read or is circular |Check the include path and the included file.
77
+ |`validation/LML-V01` |Duplicate definition in a scope |Rename or remove the duplicate definition.
78
+ |`validation/LML-V02` |Duplicate attribute in a definition |Rename or remove the duplicate attribute.
79
+ |`validation/LML-V03` |Mandatory attribute not populated |Populate the mandatory attribute on the instance.
80
+ |`validation/LML-V04` |Value does not match the declared primitive type |Use a value matching the declared primitive type.
81
+ |`validation/LML-V05` |Value outside the declared value set |Use one of the values declared for the attribute.
82
+ |`validation/LML-V06` |Instance attribute is not declared |Declare the attribute or remove it from the instance.
83
+ |`validation/LML-V07` |Reference does not resolve |Point the reference at an existing instance or attribute.
84
+ |`validation/LML-V08` |Circular reference |Break the reference cycle.
85
+ |`validation/LML-V09` |Value does not match the attribute pattern |Use a value matching the attribute pattern.
86
+ |`validation/LML-V10` |Attribute pattern does not compile |Fix the attribute pattern so that it compiles.
87
+ |`hydration/LML-H01` |Instance data could not be hydrated |Check the instance data against the compiled model.
88
+ |`contract/LML-C01` |Input file not found |Check the path of the input file.
89
+ |`contract/LML-C02` |Unsupported input format |Use one of the supported input formats.
90
+ |`contract/LML-C03` |Input file could not be read or parsed in its format |Check the input file and its format.
91
+ |`contract/LML-C04` |Invalid cardinality token while compiling |Use a cardinality token such as `1`, `0..1`, or `0..n`.
92
+ |`contract/LML-C05` |View import could not be resolved |Check the imported view path and the imported files.
93
+ |`contract/LML-C06` |Document declares a newer language version |Use a supported language version or upgrade lutaml-lml.
94
+ |===
95
+
96
+ == Value semantics
97
+
98
+ String values are quoted (double or single) with exactly two escape
99
+ sequences — `\"` and `\\` — strict in both quote kinds; a backslash
100
+ before anything else does not form a string. Quoted content is
101
+ verbatim: padding, embedded quotes, and backslashes survive
102
+ parse/emit round-trips (the emitter escapes values and attribute
103
+ keys; attribute keys may be quoted whenever they are not bare words).
104
+
105
+ `null` is a value: an explicit `null` assignment denotes the null
106
+ value, an unassigned optional attribute is absent, and the empty
107
+ string `""` is a present, zero-length value — the three are distinct.
108
+
109
+ ....
110
+ instance R {
111
+ name = "Raku \"kiln\" fired" // escapes
112
+ note = "" // present, empty
113
+ retired = null // null value
114
+ // an attribute simply not assigned here is absent
115
+ }
116
+ ....
117
+
118
+ Compile model definitions into `Lutaml::Model::Serializable` classes and
119
+ hydrate instance data. Pass `namespace:` to register the compiled classes
120
+ as constants (a String namespace is created if absent) — named classes are
121
+ what JSON Schema / YAML Schema generation requires:
122
+
123
+ ....
124
+ compiler = Lutaml::Lml::ModelCompiler.new(namespace: "MyModels")
125
+ compiler.compile(File.new("model.lml"))
126
+ klass = compiler.compiled_classes["Ceramic"]
127
+ instance = compiler.hydrate(File.new("data.lml"))
128
+
129
+ Lutaml::Model::Schema.to_json(klass) # JSON Schema document
130
+ Lutaml::Model::Schema.to_yaml(klass) # YAML Schema document
131
+ ....
132
+
133
+ Command line:
134
+
135
+ ....
136
+ lutaml generate model.lml # diagram via GraphViz
137
+ lutaml generate model.lml --layout elk -o diagram.pdf # in-process ELK layout; PDF via pdfrb (also svg, ps, eps, emf)
138
+ lutaml validate model.lml # parse + RS 3001 rule violations
139
+ lutaml format model.lml # rewrite into the RS 3001 canonical form
140
+ lutaml format model.lml --check # report non-canonical files with a diff; exit 1
141
+ lutaml compile model.lml # lutaml-model classes
142
+ lutaml compile model.lml --schema json -o schemas/
143
+ lutaml compile model.lml --schema yaml -o ceramic.schema.yaml
144
+ ....
145
+
146
+ == Language version
147
+
148
+ A document may declare the LML grammar version it speaks with an
149
+ optional first line:
150
+
151
+ ....
152
+ lml "1.0"
153
+
154
+ class Ceramic { }
155
+ ....
156
+
157
+ The supported version is the version compiled into the grammar artifact.
158
+ A document declaring a newer version parses, with a warning diagnostic
159
+ (`contract/LML-C06`): forward compatibility is preserved and the
160
+ declaration is recorded on `Document#lml_version`.
161
+
162
+ == Editor support (LSP)
163
+
164
+ The gem ships `lutaml-lml-lsp`, a Language Server Protocol server over
165
+ stdin/stdout:
166
+
167
+ ....
168
+ lutaml-lml-lsp
169
+ ....
170
+
171
+ It provides push and pull diagnostics (`Lutaml::Lml::Diagnostic`
172
+ records), document symbols (packages, classes, enums, attributes,
173
+ instances, values), go-to-definition and find-references (types,
174
+ values-set references, `ref:(path)` targets), hover (type, cardinality,
175
+ default, pattern, definitions, and the null/empty/absence note),
176
+ completion (keywords read from the compiled grammar artifact plus model
177
+ names), and canonical formatting through the formatter. Unparseable
178
+ documents publish a parse diagnostic and leave the server running.
179
+
180
+ == Architecture
181
+
182
+ The language grammar is written in PARG
183
+ (`lib/lutaml/lml/grammar/lml.parg`) and compiled by
184
+ https://github.com/parsanol/parsanol-ruby[parsanol]; the compiled
185
+ artifact is committed for fast cold loads (`rake parg` regenerates it).
186
+ Comments and whitespace are grammar-level skip trivia. Comments are
187
+ consumed between any two tokens; quoted strings never start comments.
188
+
189
+ Pipeline: preprocessor (include expansion) → PARG parser → transform →
190
+ data processor → document builder → post-parse resolvers (imports,
191
+ views, association labels).
192
+
193
+ == Development
194
+
195
+ ....
196
+ bundle install
197
+ bundle exec rake spec # test suite incl. the RS 3001 corpus
198
+ bundle exec rake parg # regenerate the compiled grammar artifact
199
+ bundle exec rubocop
200
+ ....
201
+
202
+ == Documentation
203
+
204
+ * RS 3001 — LutaML language: link:../docs/sources/lutaml-lang.adoc[lutaml-lang.adoc]
205
+ * RS 3010 — declarations extension: link:../docs/sources/lml-declarations.adoc[lml-declarations.adoc]
data/exe/lutaml-lml ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "lutaml/diagram"
5
+
6
+ Lutaml::Cli::LmlCommands.start(ARGV)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Diagram
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Lutaml
6
+ # Diagram rendering for the LutaML Model Language: the Graphviz, ELK
7
+ # and SVG/PDF formatters, the layout engines, and the `lutaml-lml`
8
+ # CLI. The LML language core itself lives in lutaml-model
9
+ # (`Lutaml::Lml`); this gem reopens the same seam namespaces and
10
+ # ships the render backends against it.
11
+ module Diagram
12
+ end
13
+ end
14
+
15
+ require "lutaml/lml"
16
+
17
+ module Lutaml
18
+ # Render formatters (Graphviz, ELK, SVG/PDF) alongside the core's
19
+ # Base and Canonical.
20
+ module Formatter
21
+ autoload :Base, "lutaml/lml/formatter/base"
22
+ autoload :Graphviz, "lutaml/lml/formatter/graphviz"
23
+ autoload :Elk, "lutaml/lml/formatter/elk"
24
+ autoload :SvgPdf, "lutaml/lml/formatter/svg_pdf"
25
+ autoload :Canonical, "lutaml/lml/formatter/canonical"
26
+ end
27
+
28
+ # Layout engines (GraphViz, ELK) against the core's Engine seam.
29
+ module Layout
30
+ autoload :Engine, "lutaml/lml/layout/engine"
31
+ autoload :GraphVizEngine, "lutaml/lml/layout/graph_viz_engine"
32
+ autoload :ElkEngine, "lutaml/lml/layout/elk_engine"
33
+ autoload :ElkGraphBuilder, "lutaml/lml/layout/elk_graph_builder"
34
+ autoload :ElkSvgRenderer, "lutaml/lml/layout/elk_svg_renderer"
35
+ autoload :ElkSvgMarkers, "lutaml/lml/layout/elk_svg_markers"
36
+ end
37
+ end
38
+
39
+ require "lutaml/lml/cli"