Class: Lex::Lexeme

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

Overview

Represents token definition

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionObject (readonly)

Returns the value of attribute action.



6
7
8
# File 'lib/lex/lexeme.rb', line 6

def action
  @action
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/lex/lexeme.rb', line 6

def name
  @name
end

#patternObject (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