Class: Ruby::Rego::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/rego/token.rb

Overview

Represents a single token emitted by the lexer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, value: nil, location: nil) ⇒ Token

Returns a new instance of Token.

Parameters:

  • type (Symbol)
  • value (Object, nil) (defaults to: nil)
  • location (Location, nil) (defaults to: nil)


168
169
170
171
172
# File 'lib/ruby/rego/token.rb', line 168

def initialize(type:, value: nil, location: nil)
  @type = type
  @value = value
  @location = location
end

Instance Attribute Details

#locationLocation? (readonly)

Returns:



181
182
183
# File 'lib/ruby/rego/token.rb', line 181

def location
  @location
end

#typeSymbol (readonly)

Returns:

  • (Symbol)


175
176
177
# File 'lib/ruby/rego/token.rb', line 175

def type
  @type
end

#valueObject? (readonly)

Returns:

  • (Object, nil)


178
179
180
# File 'lib/ruby/rego/token.rb', line 178

def value
  @value
end

Instance Method Details

#keyword?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/ruby/rego/token.rb', line 184

def keyword?
  TokenType.keyword?(type)
end

#literal?Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/ruby/rego/token.rb', line 194

def literal?
  TokenType.literal?(type)
end

#operator?Boolean

Returns:

  • (Boolean)


189
190
191
# File 'lib/ruby/rego/token.rb', line 189

def operator?
  TokenType.operator?(type)
end

#to_sString

Returns:

  • (String)


199
200
201
202
203
# File 'lib/ruby/rego/token.rb', line 199

def to_s
  parts = ["type=#{type}", "value=#{value.inspect}"]
  parts << "location=#{location}" if location
  "Token(#{parts.join(", ")})"
end