Class: RKelly::Lexeme

Inherits:
Object
  • Object
show all
Defined in:
lib/rkelly/lexeme.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, pattern, &block) ⇒ Lexeme

Returns a new instance of Lexeme.



6
7
8
9
10
# File 'lib/rkelly/lexeme.rb', line 6

def initialize(name, pattern, &block)
  @name       = name
  @pattern    = pattern
  @block      = block
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rkelly/lexeme.rb', line 5

def name
  @name
end

#patternObject (readonly)

Returns the value of attribute pattern.



5
6
7
# File 'lib/rkelly/lexeme.rb', line 5

def pattern
  @pattern
end

Instance Method Details

#match(string) ⇒ Object



12
13
14
15
16
# File 'lib/rkelly/lexeme.rb', line 12

def match(string)
  match = pattern.match(string)
  return Token.new(name, match.to_s, &@block) if match
  match
end