The Psyche Project
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
psy::C::SyntaxToken Class Reference

The SyntaxToken class. More...

#include <SyntaxToken.h>

Public Types

enum  Category {
  Keywords, Identifiers, Constants, StringLiterals,
  Punctuators, Unrecognized
}
 The existing SyntaxToken categories. More...
 

Public Member Functions

SyntaxKind kind () const
 
bool isKind (SyntaxKind k)
 
unsigned int rawKind () const
 
bool isRawKind (unsigned int rawKind) const
 
Category category () const
 
SyntaxLexemevalueLexeme () const
 
std::string valueText () const
 
const char * valueText_c_str () const
 
bool isAtStartOfLine () const
 
bool hasLeadingTrivia () const
 
bool isJoined () const
 
bool isPPExpanded () const
 
bool isPPGenerated () const
 
bool isComment () const
 
bool isMissing () const
 
bool isValid () const
 
Location location () const
 
TextSpan span () const
 

Static Public Member Functions

static Category category (SyntaxKind k)
 
static SyntaxToken invalid ()
 

Detailed Description

The SyntaxToken class.

Note
This API is inspired by that of Microsoft.CodeAnalysis.SyntaxToken from Roslyn, the .NET Compiler Platform.
Influence by the API of Clang/LLVM is present as well; specifically: clang::Token and clang::Preprocessor.

Member Enumeration Documentation

◆ Category

The existing SyntaxToken categories.

Remarks
6.4-3

Member Function Documentation

◆ category() [1/2]

SyntaxToken::Category SyntaxToken::category ( ) const

The Category of this SyntaxToken.

◆ category() [2/2]

SyntaxToken::Category SyntaxToken::category ( SyntaxKind  k)
static

The Category of the SyntaxToken of kind k.

◆ hasLeadingTrivia()

bool psy::C::SyntaxToken::hasLeadingTrivia ( ) const
inline

Whether this SyntaxToken has any leading trivia (e.g., a whitespace).

◆ invalid()

SyntaxToken SyntaxToken::invalid ( )
static

An invalid SyntaxToken.

◆ isAtStartOfLine()

bool psy::C::SyntaxToken::isAtStartOfLine ( ) const
inline

Whether this SyntaxToken is at the start of a line.

◆ isComment()

bool SyntaxToken::isComment ( ) const

Whether this SyntaxToken is a comment.

◆ isJoined()

bool psy::C::SyntaxToken::isJoined ( ) const
inline

Whether this SyntaxToken is joined with the previous one.

◆ isKind()

bool psy::C::SyntaxToken::isKind ( SyntaxKind  k)
inline

Whether this SyntaxToken is of SyntaxKind k.

◆ isMissing()

bool psy::C::SyntaxToken::isMissing ( ) const
inline

Whether this SyntaxToken is missing from the source.

◆ isPPExpanded()

bool psy::C::SyntaxToken::isPPExpanded ( ) const
inline

Whether this SyntaxToken is the result of a preprocessor expansion.

See also
SyntaxToken::isPPGenerated

◆ isPPGenerated()

bool psy::C::SyntaxToken::isPPGenerated ( ) const
inline

Whether this SyntaxToken is the result of a preprocessor expansion and generated. Consider:

#define FOO(a, b) a + b;
FOO(1, 2)

After preprocessing, we have:

1 + 2;

Tokens 1, +, 2, and ; are all preprocessor-expanded; but only + and ; are both expanded and generated.

See also
SyntaxToken::isPPExpanded

◆ isRawKind()

bool psy::C::SyntaxToken::isRawKind ( unsigned int  rawKind) const
inline

Whether this SyntaxToken is of the given rawKind.

◆ isValid()

bool SyntaxToken::isValid ( ) const

Whether this SyntaxToken is valid.

See also
SyntaxToken::invalid

◆ kind()

SyntaxKind psy::C::SyntaxToken::kind ( ) const
inline

The SyntaxKind of this SyntaxToken.

◆ location()

Location SyntaxToken::location ( ) const

The Location of this SyntaxToken.

◆ rawKind()

unsigned int psy::C::SyntaxToken::rawKind ( ) const
inline

The raw kind of this SyntaxToken.

◆ span()

TextSpan SyntaxToken::span ( ) const

The text span of this SyntaxToken.

◆ valueLexeme()

SyntaxLexeme * SyntaxToken::valueLexeme ( ) const

The value of this SyntaxToken represented by a lexeme, from which the actual value (e.g., an integer such as 42) may be obtained.

See also
SyntaxLexeme::value

◆ valueText()

std::string SyntaxToken::valueText ( ) const

The value of this SyntaxToken represented as text, by an std::string.

See also
valueText_c_str

◆ valueText_c_str()

const char * SyntaxToken::valueText_c_str ( ) const

The value of this SyntaxToken represented as text, by C-style string.

See also
valueText

The documentation for this class was generated from the following files: