Class: BELParser::Expression::Parser

Inherits:
Object
  • Object
show all
Includes:
Model::Converters, Parsers::AST
Defined in:
lib/bel_parser/expression/parser.rb

Overview

Parser for BEL expressions that return common objects.

Constant Summary

Constants included from Quoting

Quoting::KeywordMatcher, Quoting::Keywords, Quoting::LenientQuotedMatcher, Quoting::NonWordMatcher, Quoting::QuoteNotEscapedMatcher, Quoting::StrictQuotedMatcher

Instance Method Summary collapse

Methods included from Parsers::AST

assert_is_a

Methods included from Model::Converters

#ast_to_namespace, #ast_to_parameter, #ast_to_statement, #ast_to_term, #convert_argument, #convert_function, #convert_object, #convert_relationship

Methods included from Quoting

#identifier_value?, #quote, #quote_if_needed, #quoted?, #string_value?, #unquote, #unquoted?

Constructor Details

#initialize(input, filter = Expression.filter, spec = BELParser::Language.default_specification, namespaces = {}) ⇒ Parser

Returns a new instance of Parser.



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bel_parser/expression/parser.rb', line 53

def initialize(
  input,
  filter     = Expression.filter,
  spec       = BELParser::Language.default_specification,
  namespaces = {})

  @input      = input
  @filter     = filter
  @spec       = spec
  @namespaces = namespaces
end

Instance Method Details

#parseObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/bel_parser/expression/parser.rb', line 65

def parse
  case @input
  when ::String # conflicts with ...AST::String
    results = parse_string(@input, @filter)
    return nil if results.nil?
    convert_ast(
      @spec,
      @namespaces,
      results.first)
  when Array
    convert_multiple(
      parse_array(@input, @filter),
      @spec,
      @namespaces)
  when IO, StringIO
    convert_stream(
      parse_io(@input, @filter),
      @spec,
      @namespaces)
  else
    raise ArgumentError,
      %(expected "input" to be one of String, Array, IO: #{@input.class})
  end
end