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.
308 309 310 311 312 |
# File 'lib/ebnf/ll1/lexer.rb', line 308 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.
296 297 298 |
# File 'lib/ebnf/ll1/lexer.rb', line 296 def partial_regexp @partial_regexp end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
295 296 297 |
# File 'lib/ebnf/ll1/lexer.rb', line 295 def regexp @regexp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
294 295 296 |
# File 'lib/ebnf/ll1/lexer.rb', line 294 def type @type end |
Instance Method Details
#==(other) ⇒ Object
325 326 327 328 329 330 331 332 |
# File 'lib/ebnf/ll1/lexer.rb', line 325 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.
321 322 323 |
# File 'lib/ebnf/ll1/lexer.rb', line 321 def canonicalize(value) @map.fetch(value.downcase, unescape(value)) end |