Class: EBNF::ABNF
- Includes:
- PEG::Parser
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/abnf.rb
Constant Summary collapse
- ALPHA =
Regular expressions for both "Core" and ABNF-specific terminals.
%r{[\x41-\x5A\x61-\x7A]}
- VCHAR =
%r{[\x20-\x7E]}
- WSP =
%r{[\x20\x09]}
- CRLF =
%r{\x0D?\x0A}
- COMMENT =
%r{;(?:#{WSP}|#{VCHAR})*#{CRLF}}
- C_NL =
%r{#{COMMENT}|#{CRLF}}
- C_WSP =
%r{#{WSP}|(?:#{C_NL}#{WSP})}
Instance Attribute Summary collapse
-
#parsed_rules ⇒ Hash{Symbol => EBNF::Rule}
readonly
Hash of generated Rule objects by symbol.
Attributes included from PEG::Parser
#packrat, #scanner, #whitespace
Instance Method Summary collapse
-
#ast ⇒ Array<EBNF::Rule>
The AST includes the parsed rules along with built-in rules for ABNF used within the parsed grammar.
-
#initialize(input, **options) ⇒ 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) ⇒ EBNFParser
Parser invocation.
On start, yield ourselves if a block is given, otherwise, return this parser instance
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/abnf.rb', line 235 def initialize(input, **) # 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 @parsed_rules = {} # Parses into `@parsed_rules` parse(@input, :rulelist, # Starting rule ABNFMeta::RULES, # PEG rules whitespace: '', # No implicit whitespace **) rescue EBNF::PEG::Parser::Error => e raise SyntaxError, e. end |
Instance Attribute Details
#parsed_rules ⇒ Hash{Symbol => EBNF::Rule} (readonly)
Hash of generated Rule objects by symbol
24 25 26 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/abnf.rb', line 24 def parsed_rules @parsed_rules end |
Instance Method Details
#ast ⇒ Array<EBNF::Rule>
The AST includes the parsed rules along with built-in rules for ABNF used within the parsed grammar.
262 263 264 265 266 267 268 269 270 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/abnf.rb', line 262 def ast # Add built-in rules for standard ABNF rules not parsed_rules.values.map(&:symbols).flatten.uniq.each do |sym| rule = ABNFCore::RULES.detect {|r| r.sym == sym} parsed_rules[sym] ||= rule if rule end parsed_rules.values end |