Class: Lrama::Lexer::Token::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/lrama/lexer/token/base.rb

Direct Known Subclasses

Char, Empty, Ident, InstantiateRule, Int, Str, Tag, Token, UserCode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s_value:, alias_name: nil, location: nil) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
# File 'lib/lrama/lexer/token/base.rb', line 15

def initialize(s_value:, alias_name: nil, location: nil)
  s_value.freeze
  @s_value = s_value
  @alias_name = alias_name
  @location = location
  @errors = []
end

Instance Attribute Details

#alias_nameObject

: String



10
11
12
# File 'lib/lrama/lexer/token/base.rb', line 10

def alias_name
  @alias_name
end

#errorsObject (readonly)

: Array



12
13
14
# File 'lib/lrama/lexer/token/base.rb', line 12

def errors
  @errors
end

#locationObject (readonly)

: Location



9
10
11
# File 'lib/lrama/lexer/token/base.rb', line 9

def location
  @location
end

#referredObject

: bool



11
12
13
# File 'lib/lrama/lexer/token/base.rb', line 11

def referred
  @referred
end

#s_valueObject (readonly)

: String



8
9
10
# File 'lib/lrama/lexer/token/base.rb', line 8

def s_value
  @s_value
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
# File 'lib/lrama/lexer/token/base.rb', line 34

def ==(other)
  self.class == other.class && self.s_value == other.s_value
end

#first_columnObject Also known as: column



45
46
47
# File 'lib/lrama/lexer/token/base.rb', line 45

def first_column
  location.first_column
end

#first_lineObject Also known as: line



39
40
41
# File 'lib/lrama/lexer/token/base.rb', line 39

def first_line
  location.first_line
end

#invalid_ref(ref, message) ⇒ Object



61
62
63
64
# File 'lib/lrama/lexer/token/base.rb', line 61

def invalid_ref(ref, message)
  location = self.location.partial_location(ref.first_column, ref.last_column)
  raise location.generate_error_message(message)
end

#last_columnObject



56
57
58
# File 'lib/lrama/lexer/token/base.rb', line 56

def last_column
  location.last_column
end

#last_lineObject



51
52
53
# File 'lib/lrama/lexer/token/base.rb', line 51

def last_line
  location.last_line
end

#referred_by?(string) ⇒ Boolean

Returns:



29
30
31
# File 'lib/lrama/lexer/token/base.rb', line 29

def referred_by?(string)
  [self.s_value, self.alias_name].compact.include?(string)
end

#to_sObject



24
25
26
# File 'lib/lrama/lexer/token/base.rb', line 24

def to_s
  "value: `#{s_value}`, location: #{location}"
end

#validateObject



67
68
69
# File 'lib/lrama/lexer/token/base.rb', line 67

def validate
  true
end