Module: BEL::Script::Parser

Defined in:
lib/bel/script.rb,
lib/bel/grammar/lexer.rb,
lib/bel/grammar/parser.rb

Defined Under Namespace

Modules: TokenData Classes: Lexer, Parser

Class Method Summary collapse

Class Method Details

.parse(source) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/bel/script.rb', line 32

def self.parse(source)
  return nil if not source

  antlr_parser = BEL::Script::Parser::Parser.new(source)
  if block_given? then
    yield from_tree(antlr_parser.document.tree)
  else
    from_tree(antlr_parser.document.tree)
  end
end

.parse_record(source) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bel/script.rb', line 43

def self.parse_record(source)
  return nil if not source

  BEL::Script::Parser::Parser.new(source)
  if block_given?
    source.each_line do |line|
      antlr_parser = BEL::Script::Parser::Parser.new(line)
      record_ret = antlr_parser.record
      if record_ret.tree.length > 0
        yield from_tree(record_ret.tree)
      end
    end
  else
    parsed_lines = []
    source.each_line do |line|
      line.tr!("\r\n", '')
      antlr_parser = BEL::Script::Parser::Parser.new(line)
      record_ret = antlr_parser.record
      if record_ret.tree.length > 0
        parsed_lines << from_tree(record_ret.tree)
      end
    end
    return parsed_lines
  end
end