Class: EBNF::ISOEBNF
- Inherits:
-
Object
- Object
- EBNF::ISOEBNF
- Includes:
- PEG::Parser
- Defined in:
- lib/ebnf/isoebnf.rb
Constant Summary collapse
- TERMINAL_CHARACTER_BASE =
The base for terminal-character, which omits “‘”, ’“‘, and ’?‘. Could be more optimized, and one might quible with the overly-strictly defined character set, but it is correct.
%r{ [a-zA-Z0-9] | # letter | decimal digit , | # concatenate symbol = | # defining symbol [\|\/!] | # definition separator symbol \*\) | # end comment symbol \) | # end group symbol \] | # end option symbol \} | # end repeat symbol \- | # except symbol #\' | # first quote symbol \* | # repetition symbol #\" | # second quote symbol #\? | # special sequence symbol \(\* | # start comment symbol \( | # start group symbol \[ | # start option symbol \{ | # start repeat symbol [;\.] | # terminator symbol [:+_%@&$<>^\x20\x23\\`~] # other character }x
- TERMINAL_CHARACTER =
%r{#{TERMINAL_CHARACTER_BASE}|['"\?]}
- FIRST_TERMINAL_CHARACTER =
%r{#{TERMINAL_CHARACTER_BASE}|["\?]}
- SECOND_TERMINAL_CHARACTER =
%r{#{TERMINAL_CHARACTER_BASE}|['\?]}
- SPECIAL_SEQUENCE_CHARACTER =
%r{#{TERMINAL_CHARACTER_BASE}|['"]}
Instance Attribute Summary collapse
-
#ast ⇒ Array<EBNF::Rule>
readonly
Abstract syntax tree from parse.
Attributes included from PEG::Parser
#packrat, #scanner, #whitespace
Instance Method Summary collapse
-
#initialize(input, **options, &block) ⇒ EBNFParser
constructor
Parser invocation.
Methods included from PEG::Parser
#clear_packrat, #debug, #depth, #error, #find_rule, #onFinish, #onStart, #onTerminal, #parse, #prod_data, #progress, #terminal_options, #terminal_regexp, #update_furthest_failure, #warn
Constructor Details
#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 |
Instance Attribute Details
#ast ⇒ Array<EBNF::Rule> (readonly)
Abstract syntax tree from parse
44 45 46 |
# File 'lib/ebnf/isoebnf.rb', line 44 def ast @ast end |