Class: PgVerify::EbnfParser::ExpressionParser2

Inherits:
Object
  • Object
show all
Includes:
EBNF::PEG::Parser
Defined in:
lib/pg-verify/ebnf_parser/expression_parser2.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: :Expression) ⇒ ExpressionParser2

Returns a new instance of ExpressionParser2.



386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/pg-verify/ebnf_parser/expression_parser2.rb', line 386

def initialize(type: :Expression)
    @type = type
    @options = {}
    # @options[:logger] = Logger.new(STDERR)
    # @options[:logger].level = :info
    # @options[:logger].formatter = lambda {|severity, datetime, progname, msg| "#{severity} #{msg}\n"}
        
    # Intantiate the grammar
    ebnf_file = File.expand_path("expressions.ebnf", __dir__)
    # Perform PEG-specific transformation to the associated rules, which will be passed directly to the parser.
    @rules = EBNF.parse(File.open(ebnf_file)).make_peg.ast

end

Instance Attribute Details

#astObject (readonly)

Abstract syntax tree from parse



8
9
10
# File 'lib/pg-verify/ebnf_parser/expression_parser2.rb', line 8

def ast
  @ast
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/pg-verify/ebnf_parser/expression_parser2.rb', line 10

def options
  @options
end

#rulesObject

Returns the value of attribute rules.



9
10
11
# File 'lib/pg-verify/ebnf_parser/expression_parser2.rb', line 9

def rules
  @rules
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/pg-verify/ebnf_parser/expression_parser2.rb', line 11

def type
  @type
end

Instance Method Details

#parse!(input) ⇒ Object



400
401
402
403
404
# File 'lib/pg-verify/ebnf_parser/expression_parser2.rb', line 400

def parse!(input)
    raise "Empty expression!" if input.nil? || input.empty?
    ast_map = parse(input, @type, @rules, **@options)
    Ast.new(ast_map)
end