Class: EBNF::LL1::Lexer::Terminal
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/lexer.rb
Overview
Terminal class, representing the terminal identifier and matching regular expression. Optionally, a Terminal may include a map to turn case-insensitively matched terminals into their canonical form
Instance Attribute Summary collapse
-
#partial_regexp ⇒ Object
readonly
Returns the value of attribute partial_regexp.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#canonicalize(value) ⇒ String
Map a terminal to it's canonical form.
-
#initialize(type, regexp, **options) ⇒ Terminal
constructor
A new instance of Terminal.
-
#unescape(string) ⇒ String
protected
Perform string and codepoint unescaping if defined for this terminal.
Constructor Details
#initialize(type, regexp, **options) ⇒ Terminal
Returns a new instance of Terminal.
284 285 286 287 288 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/lexer.rb', line 284 def initialize(type, regexp, **) @type, @regexp, @options = type, regexp, @partial_regexp = [:partial_regexp] @map = .fetch(:map, {}) end |
Instance Attribute Details
#partial_regexp ⇒ Object (readonly)
Returns the value of attribute partial_regexp.
272 273 274 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/lexer.rb', line 272 def partial_regexp @partial_regexp end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
271 272 273 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/lexer.rb', line 271 def regexp @regexp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
270 271 272 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/lexer.rb', line 270 def type @type end |
Instance Method Details
#==(other) ⇒ Object
301 302 303 304 305 306 307 308 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/lexer.rb', line 301 def ==(other) case other when Array @type == other.first && @regexp == other.last when Terminal @type == other.type && @regexp == other.regexp end end |
#canonicalize(value) ⇒ String
Map a terminal to it's canonical form. If there is no
map, value
is returned. value
is unescaped if there
is no canonical mapping, and the :unescape
option is set.
297 298 299 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/lexer.rb', line 297 def canonicalize(value) @map.fetch(value.downcase, unescape(value)) end |
#unescape(string) ⇒ String (protected)
Perform string and codepoint unescaping if defined for this terminal
315 316 317 318 319 320 321 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/lexer.rb', line 315 def unescape(string) if @options[:unescape] EBNF::Unescape.unescape(string) else string end end |