ELAM
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Member Functions | Friends | List of all members
ELAM::Token Class Reference

Represents a single token in a parsed expression. More...

#include <elamexpression.h>

Public Types

enum  Type {
  Invalid =0, Function = 1, Constant = 2, Variable = 4,
  Name =0xff, NameMask =Name, UnaryOp = 0x100, BinaryOp = 0x200,
  AssignmentOp = 0x400, PipeOp = 0x800, Operator =0xff00, OperatorMask =Operator,
  SpecialCharMask =0xff0000, ParenthesesMask =0xf0000, Parentheses =0x10000, ParOpen =0x20000,
  ParClose =0x40000, Comma =0x100000, Literal =0x1000000, LiteralMask =Literal,
  FunctionalMask =NameMask|OperatorMask|SpecialCharMask, Whitespace =0x10000000, IgnoredTokenMask =0xf0000000
}
 The type of token. More...
 

Public Member Functions

 Token (Position pos=Position(-1,-1))
 creates an empty/invalid token More...
 
 Token (QString, Type, Position pos=Position(-1,-1))
 creates a token from a parsed piece of string, only generic types can be used More...
 
 Token (QString, QVariant, Position pos=Position(-1,-1))
 creates a literal token More...
 
QString content () const
 returns the string content of the token More...
 
Type type () const
 returns the type of token this is More...
 
QVariant literalValue () const
 for literals: returns the value More...
 
Position position () const
 returns the original position of the token More...
 
QList< TokensubTokens () const
 when the token is hierarchised (Parentheses, Function) this returns the subordinate tokens More...
 
bool isFunctional () const
 true if the token is functional (not ignored) More...
 
bool isOperator () const
 true if the token represents an operator More...
 
bool isIgnored () const
 true if the token can be ignored More...
 
bool isName () const
 true if the token represents a name More...
 
bool isLiteral () const
 true if the token is a literal More...
 

Protected Member Functions

void setSubType (Type)
 makes the tokens type more specialized More...
 
void changeNameToOperator (Type)
 transmutes a name token to an operator token More...
 
void addSubToken (const Token &)
 adds a token to the sub-token list More...
 
void setSubTokens (const QList< Token > &)
 overrides the list of sub-tokens More...
 

Friends

class Expression
 

Detailed Description

Represents a single token in a parsed expression.

Tokens are pretty stupid themselves - they just know their type, position, their original piece of text and an optional value (literals). They are used by the engine and expressions to transform text into executable expressions.

Member Enumeration Documentation

The type of token.

Enumerator
Invalid 

invalid token

Function 

the token represents a function call

Constant 

the token represents a constant

Variable 

the token represents a variable

Name 

a name: function, variable, or constant

NameMask 

mask for name tokens

UnaryOp 

the token represents an unary operator

BinaryOp 

the token represents a binary operator

AssignmentOp 

the token represents an assignment (with optional implicit binary op)

PipeOp 

the token represents a pipe operator

Operator 

an operator (unary or binary)

OperatorMask 

mask for operator tokens

SpecialCharMask 

mask for special class tokens that have a syntactic function (parentheses, comma, ...)

ParenthesesMask 

mask for parentheses

Parentheses 

meta-type used for parsed sub-tokens

ParOpen 

opening parenthese

ParClose 

closing parenthese

Comma 

a comma - separating expressions in function calls

Literal 

a literal value

LiteralMask 

mask for literal values

FunctionalMask 

mask for tokens that are functional (non-ignored)

Whitespace 

white space chars, this is actually not used for tokens, but for parsing

IgnoredTokenMask 

mask for ignored tokens

Constructor & Destructor Documentation

ELAM::Token::Token ( Position  pos = Position(-1,-1))
explicit

creates an empty/invalid token

ELAM::Token::Token ( QString  ,
Type  ,
Position  pos = Position(-1,-1) 
)

creates a token from a parsed piece of string, only generic types can be used

ELAM::Token::Token ( QString  ,
QVariant  ,
Position  pos = Position(-1,-1) 
)

creates a literal token

Member Function Documentation

void ELAM::Token::addSubToken ( const Token )
protected

adds a token to the sub-token list

void ELAM::Token::changeNameToOperator ( Type  )
protected

transmutes a name token to an operator token

QString ELAM::Token::content ( ) const

returns the string content of the token

bool ELAM::Token::isFunctional ( ) const
inline

true if the token is functional (not ignored)

bool ELAM::Token::isIgnored ( ) const
inline

true if the token can be ignored

bool ELAM::Token::isLiteral ( ) const
inline

true if the token is a literal

bool ELAM::Token::isName ( ) const
inline

true if the token represents a name

bool ELAM::Token::isOperator ( ) const
inline

true if the token represents an operator

QVariant ELAM::Token::literalValue ( ) const

for literals: returns the value

Position ELAM::Token::position ( ) const

returns the original position of the token

void ELAM::Token::setSubTokens ( const QList< Token > &  )
protected

overrides the list of sub-tokens

void ELAM::Token::setSubType ( Type  )
protected

makes the tokens type more specialized

QList<Token> ELAM::Token::subTokens ( ) const

when the token is hierarchised (Parentheses, Function) this returns the subordinate tokens

Type ELAM::Token::type ( ) const

returns the type of token this is

Friends And Related Function Documentation

friend class Expression
friend

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