FFI::ClangSourceFFIClangToken

class Token

Represents a single token in the source code.

Nested

Definitions

def self.from_location(translation_unit, location)

Look up the token that starts at the given source location.

Signature

parameter translation_unit TranslationUnit

The translation unit to query.

parameter location SourceLocation

The source location where the token should start.

returns Token | Nil

The token at the location, or nil if no token starts there.

Implementation

def self.from_location(translation_unit, location)
	token_pointer = Lib.get_token(translation_unit, location.location)
	return nil if token_pointer.null?
	
	owner = Owner.new(token_pointer, translation_unit)
	Token.new(owner, translation_unit, owner)
end

def initialize(token, translation_unit, owner = nil)

Initialize a token.

Signature

parameter token FFI::Pointer

The token pointer.

parameter translation_unit TranslationUnit

The parent translation unit.

parameter owner Object | Nil

An object that keeps the token storage alive.

Implementation

def initialize(token, translation_unit, owner = nil)
	@token = token
	@translation_unit = translation_unit
	@owner = owner
end

def kind

Get the kind of this token.

Signature

returns Symbol

The token kind.

Implementation

def kind
	Lib.get_token_kind(@token)
end

def spelling

Get the spelling (text) of this token.

Signature

returns String

The token spelling.

Implementation

def spelling
	Lib.extract_string Lib.get_token_spelling(@translation_unit, @token)
end

def location

Get the location of this token.

Signature

returns ExpansionLocation

The token location.

Implementation

def location
	ExpansionLocation.new Lib.get_token_location(@translation_unit, @token)
end

def extent

Get the extent (source range) of this token.

Signature

returns SourceRange

The token extent.

Implementation

def extent
	SourceRange.new Lib.get_token_extent(@translation_unit, @token)
end