Sha256: e66133c167b6f2cbc04c5091936ac0b8f4e4fa71b1c3cf63cd581ec3d3ad7a02

Contents?: true

Size: 1.6 KB

Versions: 21

Compression:

Stored size: 1.6 KB

Contents

begin
  RUBY_VERSION =~ /(\d+\.\d+)/
  require_relative "#{$1}/express_parser"
rescue LoadError
  require_relative "express_parser"
end
require 'expressir/express_exp/visitor'

=begin
char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
lexer = ::ExpressParser::Lexer.new(char_stream)
token_stream = Antlr4::Runtime::CommonTokenStream.new(lexer)
parser = ::ExpressParser::Parser.new(token_stream)

# don't attempt to recover from any parsing error
parser.instance_variable_set(:@_err_handler, Antlr4::Runtime::BailErrorStrategy.new)

parse_tree = parser.syntax()

visitor = Visitor.new(token_stream)
repo = visitor.visit(parse_tree)
=end

module Expressir
  module ExpressExp
    class Parser
      def self.from_file(file, options = {})
        input = File.read(file)

        parser = ::ExpressParser::Parser.parse(input)

        parse_tree = parser.syntax()

        visitor = Visitor.new(parser.tokens, options)
        repository = visitor.visit(parse_tree)

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

        repository
      end

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

        repository = Model::Repository.new({
          schemas: schemas
        })

        repository.schemas.each do |schema|
          schema.parent = repository
        end

        repository
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
expressir-0.2.24 lib/expressir/express_exp/parser.rb
expressir-0.2.24-x86_64-linux lib/expressir/express_exp/parser.rb
expressir-0.2.24-x86_64-darwin lib/expressir/express_exp/parser.rb
expressir-0.2.24-x86-mingw32 lib/expressir/express_exp/parser.rb
expressir-0.2.24-x86-linux lib/expressir/express_exp/parser.rb
expressir-0.2.24-x64-mingw32 lib/expressir/express_exp/parser.rb
expressir-0.2.24-arm64-darwin lib/expressir/express_exp/parser.rb
expressir-0.2.21 lib/expressir/express_exp/parser.rb
expressir-0.2.21-x86_64-linux lib/expressir/express_exp/parser.rb
expressir-0.2.21-x86_64-darwin lib/expressir/express_exp/parser.rb
expressir-0.2.21-x86-mingw32 lib/expressir/express_exp/parser.rb
expressir-0.2.21-x86-linux lib/expressir/express_exp/parser.rb
expressir-0.2.21-x64-mingw32 lib/expressir/express_exp/parser.rb
expressir-0.2.21-arm64-darwin lib/expressir/express_exp/parser.rb
expressir-0.2.19 lib/expressir/express_exp/parser.rb
expressir-0.2.19-x86_64-linux lib/expressir/express_exp/parser.rb
expressir-0.2.19-x86_64-darwin lib/expressir/express_exp/parser.rb
expressir-0.2.19-x86-mingw32 lib/expressir/express_exp/parser.rb
expressir-0.2.19-x86-linux lib/expressir/express_exp/parser.rb
expressir-0.2.19-x64-mingw32 lib/expressir/express_exp/parser.rb