Class: Dhaka::Lexeme

Inherits:
Object
  • Object
show all
Defined in:
lib/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:



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

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

Instance Attribute Details

#charactersObject (readonly)

Returns the value of attribute characters.



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

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/lexer/lexeme.rb', line 8

def input_position
  @input_position
end

#patternObject

The pattern matched by this lexeme.



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

def pattern
  @pattern
end

Instance Method Details

#<<(char) ⇒ Object

:nodoc:



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

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

#accepted?Boolean

:nodoc:

Returns:

  • (Boolean)


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

def accepted? #:nodoc:
  pattern
end

#concat(chars) ⇒ Object

:nodoc:



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

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

#valueObject

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



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

def value
  characters.join
end