Class: EBNF::LL1::Lexer::Terminal
- Inherits:
-
Object
- Object
- EBNF::LL1::Lexer::Terminal
- Defined in:
- 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.
Constructor Details
#initialize(type, regexp, **options) ⇒ Terminal
Returns a new instance of Terminal.
310 311 312 313 314 |
# File 'lib/ebnf/ll1/lexer.rb', line 310 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.
298 299 300 |
# File 'lib/ebnf/ll1/lexer.rb', line 298 def partial_regexp @partial_regexp end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
297 298 299 |
# File 'lib/ebnf/ll1/lexer.rb', line 297 def regexp @regexp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
296 297 298 |
# File 'lib/ebnf/ll1/lexer.rb', line 296 def type @type end |
Instance Method Details
#==(other) ⇒ Object
327 328 329 330 331 332 333 334 |
# File 'lib/ebnf/ll1/lexer.rb', line 327 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.
323 324 325 |
# File 'lib/ebnf/ll1/lexer.rb', line 323 def canonicalize(value) @map.fetch(value.downcase, unescape(value)) end |