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
-
#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.
288 289 290 291 |
# File 'lib/ebnf/ll1/lexer.rb', line 288 def initialize(type, regexp, = {}) @type, @regexp, @options = type, regexp, @map = .fetch(:map, {}) end |
Instance Attribute Details
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
278 279 280 |
# File 'lib/ebnf/ll1/lexer.rb', line 278 def regexp @regexp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
277 278 279 |
# File 'lib/ebnf/ll1/lexer.rb', line 277 def type @type end |
Instance Method Details
#==(other) ⇒ Object
304 305 306 307 308 309 310 311 |
# File 'lib/ebnf/ll1/lexer.rb', line 304 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.
300 301 302 |
# File 'lib/ebnf/ll1/lexer.rb', line 300 def canonicalize(value) @map.fetch(value.downcase, unescape(value)) end |