Class: PgVerify::EbnfParser::ExpressionParser
- Inherits:
-
Object
- Object
- PgVerify::EbnfParser::ExpressionParser
- Includes:
- EBNF::PEG::Parser
- Defined in:
- lib/pg-verify/ebnf_parser/expression_parser.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Abstract syntax tree from parse.
-
#options ⇒ Object
Returns the value of attribute options.
-
#rules ⇒ Object
Returns the value of attribute rules.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type: :Expression) ⇒ ExpressionParser
constructor
A new instance of ExpressionParser.
- #parse!(input) ⇒ Object
Constructor Details
#initialize(type: :Expression) ⇒ ExpressionParser
Returns a new instance of ExpressionParser.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/pg-verify/ebnf_parser/expression_parser.rb', line 129 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.("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 skeletton = EBNF.parse(File.open(ebnf_file)).make_peg.to_s.split("\n").reverse.map { |line| rule = line.split(/\s+/)[1] comment = "# Rule: '#{line.split(/\s+/).join(" ")}'" puts_line = 'puts "' + rule + ': \'#{input}\' -> \'#{output}\'"' body = "\toutput = input\n\t#{puts_line}\n\toutput" method = "production(:#{rule}) do |input|\n#{body}\nend" [comment, method].join("\n") }.join("\n\n") File.write(File.("expressions.rb", __dir__), skeletton) # TODO: Remove File.write(File.("expressions.peg", __dir__), EBNF.parse(File.open(ebnf_file)).make_peg) end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Abstract syntax tree from parse
8 9 10 |
# File 'lib/pg-verify/ebnf_parser/expression_parser.rb', line 8 def ast @ast end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/pg-verify/ebnf_parser/expression_parser.rb', line 10 def @options end |
#rules ⇒ Object
Returns the value of attribute rules.
9 10 11 |
# File 'lib/pg-verify/ebnf_parser/expression_parser.rb', line 9 def rules @rules end |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/pg-verify/ebnf_parser/expression_parser.rb', line 11 def type @type end |