Method: EBNF::ISOEBNF#initialize
- Defined in:
- lib/ebnf/isoebnf.rb
#initialize(input, **options, &block) ⇒ EBNFParser
## Parser invocation. On start, yield ourselves if a block is given, otherwise, return this parser instance
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/ebnf/isoebnf.rb', line 197 def initialize(input, **, &block) # If the `level` option is set, instantiate a logger for collecting trace information. if .has_key?(:level) [:logger] = Logger.new(STDERR) [:logger].level = [:level] [:logger].formatter = lambda {|severity, datetime, progname, msg| "#{severity} #{msg}\n"} end # Read input, if necessary, which will be used in a Scanner. @input = input.respond_to?(:read) ? input.read : input.to_s parsing_terminals = false @ast = [] parse(@input, :syntax, ISOEBNFMeta::RULES, whitespace: %r{([\x09-\x0d\x20]|(?:\(\*(?:(?:\*[^\)])|[^*])*\*\)))+}, ** ) do |context, *data| rule = case context when :rule # A rule which has already been turned into a `Rule` object. rule = data.first rule.kind = :terminal if parsing_terminals rule end @ast << rule if rule end rescue EBNF::PEG::Parser::Error => e raise SyntaxError, e. end |