Class: Expressir::Express::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/expressir/express/parser.rb

Defined Under Namespace

Classes: Parser

Class Method Summary collapse

Class Method Details

.from_file(file, skip_references: nil, include_source: nil) ⇒ Model::Repository

Parses Express file into an Express model

Parameters:

  • file (String)

    Express file path

  • skip_references (Boolean) (defaults to: nil)

    skip resolving references

  • include_source (Boolean) (defaults to: nil)

    attach original source code to model elements

Returns:



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/expressir/express/parser.rb', line 303

def self.from_file(file, skip_references: nil, include_source: nil)
  source = File.read file
  ast = Parser.new.parse source

  visitor = Expressir::Express::Visitor.new(source, include_source: include_source)
  transformed = visitor.visit_ast ast, :top
  @repository = transformed

  @repository.schemas.each do |schema|
    schema.file = file.to_s
  end

  unless skip_references
    @resolve_references_model_visitor = ResolveReferencesModelVisitor.new
    @resolve_references_model_visitor.visit(@repository)
  end

  @repository
end

.from_files(files, skip_references: nil, include_source: nil) ⇒ Model::Repository

Parses Express files into an Express model

Parameters:

  • files (Array<String>)

    Express file paths

  • skip_references (Boolean) (defaults to: nil)

    skip resolving references

  • include_source (Boolean) (defaults to: nil)

    attach original source code to model elements

Returns:



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/expressir/express/parser.rb', line 328

def self.from_files(files, skip_references: nil, include_source: nil)
  schemas = files.each_with_index.map do |file, i|
    # start = Time.now
    repository = self.from_file(file, skip_references: true)
    # STDERR.puts "#{i+1}/#{files.length} #{file} #{Time.now - start}"
    repository.schemas
  end.flatten

  @repository = Model::Repository.new(
    schemas: schemas,
  )

  unless @skip_references
    @resolve_references_model_visitor = ResolveReferencesModelVisitor.new
    @resolve_references_model_visitor.visit(@repository)
  end

  @repository
end