Class: Lutaml::Uml::Parsers::Dsl

Inherits:
Parslet::Parser
  • Object
show all
Defined in:
lib/lutaml/uml/parsers/dsl.rb

Overview

Class for parsing LutaML dsl into Lutaml::Uml::Document

Constant Summary collapse

KEYWORDS =
%w[
  abstract
  aggregation
  association
  association
  attribute
  bidirectional
  class
  composition
  data_type
  dependency
  diagram
  directional
  enum
  fontname
  generalizes
  include
  interface
  member
  member_type
  method
  owner
  owner_type
  primitive
  private
  protected
  public
  realizes
  static
  title
  caption
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(io, options = {}) ⇒ Lutaml::Uml::Document

Parameters:

  • io (String)
    • LutaML string representation

    Hash

    options - options for parsing

Returns:



20
21
22
# File 'lib/lutaml/uml/parsers/dsl.rb', line 20

def self.parse(io, options = {})
  new.parse(io, options)
end

Instance Method Details

#parse(input_file, _options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lutaml/uml/parsers/dsl.rb', line 24

def parse(input_file, _options = {})
  data = Lutaml::Uml::Parsers::DslPreprocessor.call(input_file)
  # https://kschiess.github.io/parslet/tricks.html#Reporter engines
  # Parslet::ErrorReporter::Deepest allows more
  # detailed display of error
  reporter = Parslet::ErrorReporter::Deepest.new
  ::Lutaml::Uml::Document
    .new(DslTransform.new.apply(super(data, reporter: reporter)))
rescue Parslet::ParseFailed => e
  raise(ParsingError,
        "#{e.message}\ncause: #{e.parse_failure_cause.ascii_tree}")
end