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:



427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/expressir/express/parser.rb', line 427

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:



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/expressir/express/parser.rb', line 452

def self.from_files(files, skip_references: nil, include_source: nil)
  schemas = files.each_with_index.map do |file, _i|
    # start = Time.now
    repository = 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