Class: Dhaka::Lexeme

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

Overview

Represents a portion of the input string that has been recognized as matching a given lexer pattern.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_position) ⇒ Lexeme

:nodoc:



10
11
12
13
# File 'lib/dhaka/lexer/lexeme.rb', line 10

def initialize(input_position) #:nodoc:
  @input_position = input_position
  @characters = []
end

Instance Attribute Details

#charactersObject

The pattern matched by this lexeme.



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

def characters
  @characters
end

#input_positionObject (readonly)

input_position is the index in the input stream that this lexeme starts at.



8
9
10
# File 'lib/dhaka/lexer/lexeme.rb', line 8

def input_position
  @input_position
end

#patternObject

The pattern matched by this lexeme.



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

def pattern
  @pattern
end

Instance Method Details

#<<(char) ⇒ Object

:nodoc:



24
25
26
# File 'lib/dhaka/lexer/lexeme.rb', line 24

def << char #:nodoc:
  characters << char
end

#accepted?Boolean

:nodoc:

Returns:

  • (Boolean)


20
21
22
# File 'lib/dhaka/lexer/lexeme.rb', line 20

def accepted? #:nodoc:
  pattern
end

#concat(chars) ⇒ Object

:nodoc:



28
29
30
# File 'lib/dhaka/lexer/lexeme.rb', line 28

def concat chars #:nodoc:
  characters.concat chars
end

#valueObject

The substring of the input stream that this lexeme is comprised of.



16
17
18
# File 'lib/dhaka/lexer/lexeme.rb', line 16

def value
  characters.join
end