Class: Lex::Lexeme
- Inherits:
-
Object
- Object
- Lex::Lexeme
- Defined in:
- lib/lex/lexeme.rb
Overview
Represents token definition
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, pattern, &action) ⇒ Lexeme
constructor
A new instance of Lexeme.
- #match(scanner) ⇒ Object
Constructor Details
#initialize(name, pattern, &action) ⇒ Lexeme
Returns a new instance of Lexeme.
8 9 10 11 12 |
# File 'lib/lex/lexeme.rb', line 8 def initialize(name, pattern, &action) @name = name @pattern = pattern @action = action end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
6 7 8 |
# File 'lib/lex/lexeme.rb', line 6 def action @action end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/lex/lexeme.rb', line 6 def name @name end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
6 7 8 |
# File 'lib/lex/lexeme.rb', line 6 def pattern @pattern end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 |
# File 'lib/lex/lexeme.rb', line 23 def ==(other) @name == other.name end |
#match(scanner) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/lex/lexeme.rb', line 14 def match(scanner) match = scanner.check(pattern) if match return Token.new(name, match.to_s, &action) end match end |