lutaml-lml 0.3.5 → 0.3.7

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.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lutaml-lml.rb +5 -0
  3. data/lib/lutaml_lml/version.rb +6 -0
  4. metadata +12 -164
  5. data/exe/lutaml-lml +0 -6
  6. data/exe/lutaml-lml-lsp +0 -11
  7. data/lib/lutaml/lml/association_label_resolver.rb +0 -52
  8. data/lib/lutaml/lml/cli.rb +0 -489
  9. data/lib/lutaml/lml/data_processor/attribute_processing.rb +0 -133
  10. data/lib/lutaml/lml/data_processor/collection_processing.rb +0 -37
  11. data/lib/lutaml/lml/data_processor/instance_processing.rb +0 -77
  12. data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +0 -70
  13. data/lib/lutaml/lml/data_processor/value_processing.rb +0 -103
  14. data/lib/lutaml/lml/data_processor/view_processing.rb +0 -26
  15. data/lib/lutaml/lml/data_processor.rb +0 -59
  16. data/lib/lutaml/lml/diagnostic.rb +0 -149
  17. data/lib/lutaml/lml/document_builder.rb +0 -481
  18. data/lib/lutaml/lml/entity_types.rb +0 -30
  19. data/lib/lutaml/lml/executor/adapter_helpers.rb +0 -45
  20. data/lib/lutaml/lml/executor/condition_evaluator.rb +0 -169
  21. data/lib/lutaml/lml/executor/csv_adapter.rb +0 -88
  22. data/lib/lutaml/lml/executor/format_adapter.rb +0 -54
  23. data/lib/lutaml/lml/executor/xml_adapter.rb +0 -102
  24. data/lib/lutaml/lml/executor.rb +0 -96
  25. data/lib/lutaml/lml/format/adapter/document.rb +0 -11
  26. data/lib/lutaml/lml/format/adapter/mapping.rb +0 -31
  27. data/lib/lutaml/lml/format/adapter/standard_adapter.rb +0 -162
  28. data/lib/lutaml/lml/format/adapter/transform.rb +0 -11
  29. data/lib/lutaml/lml/format.rb +0 -29
  30. data/lib/lutaml/lml/formatter/base.rb +0 -79
  31. data/lib/lutaml/lml/formatter/canonical.rb +0 -736
  32. data/lib/lutaml/lml/formatter/elk.rb +0 -45
  33. data/lib/lutaml/lml/formatter/graphviz/document_formatter.rb +0 -89
  34. data/lib/lutaml/lml/formatter/graphviz/html_builder.rb +0 -72
  35. data/lib/lutaml/lml/formatter/graphviz/node_formatter.rb +0 -89
  36. data/lib/lutaml/lml/formatter/graphviz/relationship_formatter.rb +0 -130
  37. data/lib/lutaml/lml/formatter/graphviz.rb +0 -90
  38. data/lib/lutaml/lml/formatter/svg_pdf/path_parser.rb +0 -134
  39. data/lib/lutaml/lml/formatter/svg_pdf.rb +0 -285
  40. data/lib/lutaml/lml/formatter.rb +0 -12
  41. data/lib/lutaml/lml/grammar/lml.artifact.json +0 -14993
  42. data/lib/lutaml/lml/grammar/lml.parg +0 -389
  43. data/lib/lutaml/lml/grammar.rb +0 -60
  44. data/lib/lutaml/lml/has_attributes.rb +0 -14
  45. data/lib/lutaml/lml/import_resolver.rb +0 -96
  46. data/lib/lutaml/lml/layout/elk_engine.rb +0 -15
  47. data/lib/lutaml/lml/layout/elk_graph_builder.rb +0 -129
  48. data/lib/lutaml/lml/layout/elk_svg_markers.rb +0 -45
  49. data/lib/lutaml/lml/layout/elk_svg_renderer.rb +0 -119
  50. data/lib/lutaml/lml/layout/engine.rb +0 -17
  51. data/lib/lutaml/lml/layout/graph_viz_engine.rb +0 -19
  52. data/lib/lutaml/lml/layout.rb +0 -12
  53. data/lib/lutaml/lml/literal_value.rb +0 -32
  54. data/lib/lutaml/lml/lsp/conversions.rb +0 -78
  55. data/lib/lutaml/lml/lsp/keywords.rb +0 -43
  56. data/lib/lutaml/lml/lsp/server.rb +0 -378
  57. data/lib/lutaml/lml/lsp/store.rb +0 -68
  58. data/lib/lutaml/lml/lsp/transport.rb +0 -53
  59. data/lib/lutaml/lml/lsp.rb +0 -16
  60. data/lib/lutaml/lml/model_compiler/enums.rb +0 -172
  61. data/lib/lutaml/lml/model_compiler/hydration.rb +0 -123
  62. data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +0 -188
  63. data/lib/lutaml/lml/model_compiler/string_formats.rb +0 -42
  64. data/lib/lutaml/lml/model_compiler/validation.rb +0 -65
  65. data/lib/lutaml/lml/model_compiler.rb +0 -323
  66. data/lib/lutaml/lml/models/action.rb +0 -10
  67. data/lib/lutaml/lml/models/association.rb +0 -29
  68. data/lib/lutaml/lml/models/cardinality.rb +0 -10
  69. data/lib/lutaml/lml/models/collection.rb +0 -11
  70. data/lib/lutaml/lml/models/constraint.rb +0 -23
  71. data/lib/lutaml/lml/models/data_type.rb +0 -41
  72. data/lib/lutaml/lml/models/derived_field.rb +0 -14
  73. data/lib/lutaml/lml/models/diagram.rb +0 -20
  74. data/lib/lutaml/lml/models/document.rb +0 -84
  75. data/lib/lutaml/lml/models/enum.rb +0 -38
  76. data/lib/lutaml/lml/models/fidelity.rb +0 -10
  77. data/lib/lutaml/lml/models/group.rb +0 -11
  78. data/lib/lutaml/lml/models/instance.rb +0 -26
  79. data/lib/lutaml/lml/models/instance_collection.rb +0 -16
  80. data/lib/lutaml/lml/models/instances_export.rb +0 -10
  81. data/lib/lutaml/lml/models/instances_import.rb +0 -11
  82. data/lib/lutaml/lml/models/mapping.rb +0 -15
  83. data/lib/lutaml/lml/models/mapping_rule.rb +0 -16
  84. data/lib/lutaml/lml/models/member_field.rb +0 -14
  85. data/lib/lutaml/lml/models/namespace.rb +0 -16
  86. data/lib/lutaml/lml/models/operation.rb +0 -26
  87. data/lib/lutaml/lml/models/operation_parameter.rb +0 -12
  88. data/lib/lutaml/lml/models/package.rb +0 -26
  89. data/lib/lutaml/lml/models/primitive_type.rb +0 -33
  90. data/lib/lutaml/lml/models/reference.rb +0 -23
  91. data/lib/lutaml/lml/models/serialization_mapping.rb +0 -19
  92. data/lib/lutaml/lml/models/string_format.rb +0 -16
  93. data/lib/lutaml/lml/models/top_element_attribute.rb +0 -116
  94. data/lib/lutaml/lml/models/uml_class.rb +0 -85
  95. data/lib/lutaml/lml/models/value.rb +0 -15
  96. data/lib/lutaml/lml/models/view_filter.rb +0 -11
  97. data/lib/lutaml/lml/models/view_import.rb +0 -11
  98. data/lib/lutaml/lml/parser.rb +0 -19
  99. data/lib/lutaml/lml/pipeline.rb +0 -73
  100. data/lib/lutaml/lml/positioned.rb +0 -13
  101. data/lib/lutaml/lml/preprocessor.rb +0 -130
  102. data/lib/lutaml/lml/quoting.rb +0 -60
  103. data/lib/lutaml/lml/source.rb +0 -49
  104. data/lib/lutaml/lml/source_position.rb +0 -20
  105. data/lib/lutaml/lml/symbol_index.rb +0 -200
  106. data/lib/lutaml/lml/transform.rb +0 -119
  107. data/lib/lutaml/lml/types/text_type.rb +0 -28
  108. data/lib/lutaml/lml/types.rb +0 -10
  109. data/lib/lutaml/lml/validator.rb +0 -458
  110. data/lib/lutaml/lml/version.rb +0 -7
  111. data/lib/lutaml/lml/view_resolution.rb +0 -32
  112. data/lib/lutaml/lml/view_resolver.rb +0 -48
  113. data/lib/lutaml/lml/yaml_parser.rb +0 -17
  114. data/lib/lutaml/lml.rb +0 -130
@@ -1,129 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Layout
5
- # Builds an Elkrb::Graph: a node per classifier (name, definition,
6
- # members); an edge per association and parent specializer.
7
- class ElkGraphBuilder
8
- CHAR_WIDTH = 7.2
9
- LINE_HEIGHT = 16.0
10
- PADDING = 14.0
11
- MIN_WIDTH = 120.0
12
- COLLECTIONS = %i[classes enums primitives data_types].freeze
13
- def build(document)
14
- graph = elkrb_graph
15
- add_entities(graph, document)
16
- add_association_edges(graph, document)
17
- add_parent_edges(graph, document)
18
- graph
19
- end
20
-
21
- private
22
-
23
- def elkrb_graph
24
- require 'elkrb'
25
- Elkrb::Graph::Graph.new(id: 'diagram')
26
- rescue LoadError
27
- raise Error, 'The elkrb gem is required for ELK layout: add `gem "elkrb"` to your Gemfile'
28
- end
29
-
30
- def entities(document)
31
- ([document] + Array(document.packages)).flat_map { |scope| scope_entities(scope) }.flatten.compact
32
- end
33
-
34
- def scope_entities(scope)
35
- COLLECTIONS.filter_map do |collection|
36
- next unless scope.respond_to?(collection)
37
-
38
- scope.public_send(collection)
39
- end
40
- end
41
-
42
- def node_for(entity)
43
- lines = label_lines(entity)
44
- Elkrb::Graph::Node.new(
45
- id: entity_id_for(entity.name),
46
- width: node_width(lines),
47
- height: PADDING + lines.size * LINE_HEIGHT,
48
- labels: lines.each_with_index.map do |line, i|
49
- Elkrb::Graph::Label.new(text: line, x: 0, y: i * LINE_HEIGHT)
50
- end
51
- )
52
- end
53
-
54
- def label_lines(entity)
55
- lines = [entity.name.to_s]
56
- if entity.respond_to?(:definition) && !entity.definition.to_s.empty?
57
- lines << entity.definition.to_s.gsub("\n", ' ')
58
- end
59
- Array(entity.attributes).each do |attr|
60
- lines << attr_line(attr)
61
- end
62
- lines
63
- end
64
-
65
- def attr_line(attr)
66
- line = "+ #{attr.name}"
67
- line += ": #{attr.type}" if attr.type && !attr.type.to_s.empty?
68
- line
69
- end
70
-
71
- def node_width(lines)
72
- widest = lines.map(&:length).max || 0
73
- [widest * CHAR_WIDTH + PADDING, MIN_WIDTH].max
74
- end
75
-
76
- def entity_id(entity)
77
- entity.name.to_s.gsub(/[^0-9a-zA-Z_]/, '_')
78
- end
79
-
80
- def associations(document)
81
- Array(document.associations)
82
- end
83
-
84
- def parent_edges(document)
85
- Array(document.classes).filter_map do |klass|
86
- next unless klass.respond_to?(:parent_class) && klass.parent_class
87
-
88
- { owner: klass.parent_class, member: klass.name.to_s,
89
- member_end_type: 'generalization', name: nil }
90
- end
91
- end
92
-
93
- def add_entities(graph, document)
94
- entities(document).each { |entity| graph.children << node_for(entity) }
95
- end
96
-
97
- def add_association_edges(graph, document)
98
- associations(document).each { |assoc| graph.edges << edge_for(association_spec(assoc)) }
99
- end
100
-
101
- def add_parent_edges(graph, document)
102
- parent_edges(document).each { |edge| graph.edges << edge_for(edge) }
103
- end
104
-
105
- def edge_for(spec)
106
- edge = elkrb_edge(spec)
107
- edge.properties = { 'member_end_type' => spec[:member_end_type].to_s }
108
- edge.labels = [Elkrb::Graph::Label.new(text: spec[:name].to_s)] if spec[:name]
109
- edge
110
- end
111
-
112
- def elkrb_edge(spec)
113
- require 'elkrb'
114
- Elkrb::Graph::Edge.new(
115
- id: "edge_#{spec[:owner]}_#{spec[:member]}",
116
- sources: [entity_id_for(spec[:owner])],
117
- targets: [entity_id_for(spec[:member])]
118
- )
119
- end
120
-
121
- def association_spec(assoc)
122
- { owner: assoc.owner_end.to_s, member: assoc.member_end.to_s,
123
- member_end_type: assoc.member_end_type.to_s, name: assoc.name }
124
- end
125
-
126
- def entity_id_for(name) = name.to_s.gsub(/[^0-9a-zA-Z_]/, '_')
127
- end
128
- end
129
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Layout
5
- # SVG arrow-marker vocabulary and the <defs> block for ElkSvgRenderer.
6
- # Marker ids are keyed by association member_end_type.
7
- module ElkSvgMarkers
8
- EDGE_STROKE = '#666666'
9
-
10
- ARROW_MARKERS = {
11
- 'association' => 'arrow',
12
- 'aggregation' => 'diamond',
13
- 'composition' => 'diamond_filled',
14
- 'generalization' => 'triangle',
15
- 'uses' => 'arrow',
16
- 'direct' => 'arrow'
17
- }.freeze
18
-
19
- MARKER_SHAPES = {
20
- 'arrow' => %(<path d="M 0 0 L 10 5 L 0 10 z" fill="#{EDGE_STROKE}"/>),
21
- 'triangle' => %(<path d="M 0 0 L 12 5 L 0 10 z" fill="white" stroke="#{EDGE_STROKE}"/>),
22
- 'diamond' => %(<path d="M 0 4 L 7 0 L 14 4 L 7 8 z" fill="white" stroke="#{EDGE_STROKE}"/>),
23
- 'diamond_filled' => %(<path d="M 0 4 L 7 0 L 14 4 L 7 8 z" fill="#{EDGE_STROKE}"/>)
24
- }.freeze
25
-
26
- def arrow_marker(edge)
27
- edge_type = edge.properties&.fetch('member_end_type', nil)
28
- ARROW_MARKERS.fetch(edge_type.to_s, 'arrow')
29
- end
30
-
31
- def defs
32
- MARKER_SHAPES.filter_map { |id, path| marker_def(id, path) }.join("\n")
33
- end
34
-
35
- private
36
-
37
- def marker_def(id, path)
38
- w, h = id.start_with?('diamond') ? %w[14 8] : %w[10 10]
39
- %(<marker id="#{id}" viewBox="0 0 #{w} #{h}" refX="9" refY="4" ) +
40
- %(markerWidth="#{w}" markerHeight="#{h}" ) +
41
- %(orient="auto-start-reverse">#{path}</marker>)
42
- end
43
- end
44
- end
45
- end
@@ -1,119 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Layout
5
- # Renders a laid-out Elkrb::Graph (nodes positioned by the layout) as
6
- # standalone SVG: rounded-rect nodes with text-line labels and
7
- # polyline edges with per-type arrow markers.
8
- class ElkSvgRenderer
9
- include ElkSvgMarkers
10
-
11
- EDGE_STROKE = ElkSvgMarkers::EDGE_STROKE
12
-
13
- HEADER = <<~XML
14
- <?xml version="1.0" encoding="UTF-8"?>
15
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="%<width>s" height="%<height>s" viewBox="0 0 %<width>s %<height>s">
16
- XML
17
- NODE_FILL = '#f8f8f8'
18
- NODE_STROKE = '#333333'
19
-
20
- def render(graph)
21
- @graph = graph
22
- @out = +''
23
- @out << format(HEADER, width: bounds_width, height: bounds_height)
24
- @out << "<defs>\n#{defs}\n</defs>\n"
25
- nodes
26
- edges
27
- @out << "</svg>\n"
28
- @out
29
- end
30
-
31
- private
32
-
33
- def nodes
34
- @graph.children.each { |node| render_node(node) }
35
- end
36
-
37
- def render_node(node)
38
- @out << %(<g transform="translate(#{node.x.to_i},#{node.y.to_i})">)
39
- @out << node_rect(node)
40
- node.labels.each_with_index { |label, i| @out << node_label(label, i) }
41
- @out << '</g>'
42
- end
43
-
44
- def node_rect(node)
45
- %(<rect width="#{node.width.to_i}" height="#{node.height.to_i}" rx="6" ) +
46
- %(fill="#{NODE_FILL}" stroke="#{NODE_STROKE}"/>)
47
- end
48
-
49
- def node_label(label, index)
50
- y = ((index + 0.7) * ElkGraphBuilder::LINE_HEIGHT).round(1)
51
- weight = index.zero? ? ' font-weight="bold"' : ''
52
- %(<text x="7" y="#{y}" font-family="Helvetica" font-size="12"#{weight}>#{escape(label.text)}</text>)
53
- end
54
-
55
- def edges
56
- @graph.edges.each { |edge| render_edge(edge) }
57
- end
58
-
59
- def render_edge(edge)
60
- points = edge_points(edge)
61
- return if points.empty?
62
-
63
- @out << edge_polyline(edge, points)
64
- edge_label(edge, points)
65
- end
66
-
67
- def edge_polyline(edge, points)
68
- pts = points.map { |p| "#{p.x.round(1)},#{p.y.round(1)}" }.join(' ')
69
- %(<polyline fill="none" stroke="#{EDGE_STROKE}" marker-end="url(##{arrow_marker(edge)})" points="#{pts}"/>)
70
- end
71
-
72
- def edge_label(edge, points)
73
- label = Array(edge.labels).first
74
- return unless label&.text
75
-
76
- @out << edge_label_text(label, edge_anchor(points))
77
- end
78
-
79
- def edge_anchor(points)
80
- mid = points[points.size / 2]
81
- { x: (mid.x + 4).round(1), y: (mid.y - 4).round(1) }
82
- end
83
-
84
- def edge_label_text(label, anchor)
85
- %(<text x="#{anchor[:x]}" y="#{anchor[:y]}" font-family="Helvetica" ) +
86
- %(font-size="10" fill="#{EDGE_STROKE}">#{escape(label.text)}</text>)
87
- end
88
-
89
- def edge_points(edge)
90
- sections = Array(edge.sections)
91
- return [] if sections.empty?
92
-
93
- points = [sections.first.start_point]
94
- sections.each do |section|
95
- points.concat(Array(section.bend_points))
96
- points << section.end_point
97
- end
98
- points.compact
99
- end
100
-
101
- def bounds_width
102
- extent(:x, :width) + 20
103
- end
104
-
105
- def bounds_height
106
- extent(:y, :height) + 20
107
- end
108
-
109
- def extent(pos, size)
110
- values = @graph.children.map { |n| n.public_send(pos).to_f + n.public_send(size).to_f }
111
- [values.max || 0, 0].max.round
112
- end
113
-
114
- def escape(text)
115
- text.to_s.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;')
116
- end
117
- end
118
- end
119
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Layout
5
- class Engine
6
- attr_accessor :input
7
-
8
- def initialize(input:)
9
- @input = input
10
- end
11
-
12
- def render(_type)
13
- raise ArgumentError, "Implement render method"
14
- end
15
- end
16
- end
17
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "ruby-graphviz"
4
- require "open3"
5
-
6
- module Lutaml
7
- module Layout
8
- class GraphVizEngine < Engine
9
- def render(type)
10
- Open3.popen3("dot", "-T#{type}") do |stdin, stdout, _stderr, _wait|
11
- stdout.binmode
12
- stdin.puts(input)
13
- stdin.close
14
- stdout.read
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Layout
5
- autoload :Engine, "lutaml/lml/layout/engine"
6
- autoload :GraphVizEngine, "lutaml/lml/layout/graph_viz_engine"
7
- autoload :ElkEngine, "lutaml/lml/layout/elk_engine"
8
- autoload :ElkGraphBuilder, "lutaml/lml/layout/elk_graph_builder"
9
- autoload :ElkSvgRenderer, "lutaml/lml/layout/elk_svg_renderer"
10
- autoload :ElkSvgMarkers, "lutaml/lml/layout/elk_svg_markers"
11
- end
12
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "lutaml/model"
4
-
5
- module Lutaml
6
- module Lml
7
- # The type of an LML attribute literal: a scalar, a list, or a map.
8
- #
9
- # This exists as a subclass rather than using Lutaml::Model::Type::Value
10
- # directly because lutaml-model's key-value serializer tests the declared
11
- # attribute type with a strict `attribute_type < Type::Value`. Type::Value
12
- # is not a strict subclass of itself, so declaring it hands the serializer
13
- # the raw wrapper object: JSON calls to_json(state) on it and raises
14
- # ArgumentError, and Psych emits a !ruby/object tag that from_yaml then
15
- # refuses to load. A subclass puts the attribute on the working path, where
16
- # the serializer asks the wrapper for its value instead.
17
- #
18
- # Deleting this class needs two upstream changes, not one: that `<` widened
19
- # to `<=`, and the serializer no longer re-wrapping a value it already
20
- # wrapped. Widening `<` alone still leaves the nested wrapper below.
21
- class LiteralValue < Lutaml::Model::Type::Value
22
- # The serializer re-wraps an already-wrapped value before asking it for a
23
- # format, so #value has to see through that extra layer. Every to_<format>
24
- # method lutaml-model generates reads through here, which is why this is
25
- # one override rather than one per format.
26
- def value
27
- wrapped = super
28
- wrapped.is_a?(LiteralValue) ? wrapped.value : wrapped
29
- end
30
- end
31
- end
32
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "cgi"
4
-
5
- module Lutaml
6
- module Lml
7
- module Lsp
8
- # Conversions between the parser's 1-based positions and LSP's
9
- # 0-based positions, plus diagnostic records.
10
- module Conversions
11
- module_function
12
-
13
- def position(source_position)
14
- return { line: 0, character: 0 } unless source_position
15
-
16
- {
17
- line: source_position.line.to_i - 1,
18
- character: source_position.column.to_i - 1,
19
- }
20
- end
21
-
22
- def range(source_position)
23
- start = position(source_position)
24
- {
25
- start: start,
26
- end: {
27
- line: start[:line],
28
- character: start[:character] + source_position.length.to_i,
29
- },
30
- }
31
- end
32
-
33
- def diagnostic(record)
34
- {
35
- range: diagnostic_range(record),
36
- severity: severity(record.severity),
37
- code: record.code,
38
- source: "lutaml-lml",
39
- message: diagnostic_message(record),
40
- }
41
- end
42
-
43
- def diagnostic_range(record)
44
- line = [record.line.to_i - 1, 0].max
45
- character = [record.column.to_i - 1, 0].max
46
- length = record.length.to_i
47
- length = 1 if length.zero?
48
- {
49
- start: { line: line, character: character },
50
- end: { line: line, character: character + length },
51
- }
52
- end
53
-
54
- def diagnostic_message(record)
55
- return record.message.to_s if record.remedy.to_s.empty?
56
-
57
- "#{record.message}\nremedy: #{record.remedy}"
58
- end
59
-
60
- def severity(value)
61
- value.to_s == "warning" ? 2 : 1
62
- end
63
-
64
- # file:///path → local path. Windows drive paths lose the leading
65
- # slash (file:///C:/x → C:/x).
66
- def uri_to_path(uri)
67
- path = uri.to_s.sub(%r{\Afile://}, "")
68
- path = CGI.unescape(path)
69
- path.sub(%r{\A/([A-Za-z]:/)}, '\1')
70
- end
71
-
72
- def path_to_uri(path)
73
- "file://#{CGI.escape(path.to_s).gsub('+', '%20')}"
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "json"
4
-
5
- module Lutaml
6
- module Lml
7
- module Lsp
8
- # The completion keyword list, read from the compiled grammar
9
- # artifact so it cannot drift from the language.
10
- module Keywords
11
- ARTIFACT = File.expand_path("../grammar/lml.artifact.json", __dir__)
12
-
13
- module_function
14
-
15
- def all
16
- @all ||= begin
17
- artifact = JSON.parse(File.read(ARTIFACT))
18
- literals = []
19
- collect(artifact["entries"], literals)
20
- literals.grep(/\A[a-z][a-z0-9_]*\z/)
21
- .uniq
22
- .sort
23
- end
24
- end
25
-
26
- def collect(node, literals)
27
- case node
28
- when Hash
29
- node.each do |key, value|
30
- if key.to_s == "Str" && value.is_a?(Hash)
31
- literals << value["pattern"].to_s
32
- else
33
- collect(value, literals)
34
- end
35
- end
36
- when Array
37
- node.each { |item| collect(item, literals) }
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end