class Lutaml::Uml::Parsers::DslPreprocessor

Class for preprocessing dsl ascii file special directives:

Attributes

input_file[R]

Public Class Methods

call(input_file) click to toggle source
# File lib/lutaml/uml/parsers/dsl_preprocessor.rb, line 16
def call(input_file)
  new(input_file).call
end
new(input_file) click to toggle source
# File lib/lutaml/uml/parsers/dsl_preprocessor.rb, line 11
def initialize(input_file)
  @input_file = input_file
end

Public Instance Methods

call() click to toggle source
# File lib/lutaml/uml/parsers/dsl_preprocessor.rb, line 21
def call
  include_root = File.dirname(input_file.path)
  input_file.read.split("\n").reduce([]) do |res, line|
    res.push(*process_dsl_line(include_root, line))
  end.join("\n")
end

Private Instance Methods

process_comment_line(line) click to toggle source
# File lib/lutaml/uml/parsers/dsl_preprocessor.rb, line 34
def process_comment_line(line)
  has_comment = line.match(Regexp.new("//.+"))
  return line if has_comment.nil?

  line.gsub(Regexp.new("//.+"), "")
end
process_dsl_line(include_root, line) click to toggle source
# File lib/lutaml/uml/parsers/dsl_preprocessor.rb, line 30
def process_dsl_line(include_root, line)
  process_include_line(include_root, process_comment_line(line))
end
process_include_line(include_root, line) click to toggle source
# File lib/lutaml/uml/parsers/dsl_preprocessor.rb, line 41
def process_include_line(include_root, line)
  include_path_match = line.match(/^\s*include\s+(.+)/)
  return line if include_path_match.nil? || line =~ /^\s\*\*/

  path_to_file = include_path_match[1].strip
  path_to_file = if path_to_file.match?(/^\//)
                   path_to_file
                 else
                   File.join(include_root, path_to_file)
                 end
  File.read(path_to_file).split("\n")
rescue Errno::ENOENT
  puts("No such file or directory @ rb_sysopen - #{path_to_file}, \
    include file paths need to be supplied relative to the main document")
end