OpenTTD
Public Member Functions | Private Member Functions | Private Attributes
Lexer Class Reference

Lexer of a file. More...

Public Member Functions

 Lexer (const File *file)
 Create the lexer and fill the keywords table.
 ~Lexer ()
 Free everything.
void Next ()
 Read the next character into 'current_char'.
Token GetToken () const
 Get the current token.
const char * GetString () const
 Read the currenty processed string.
void Lex ()
 Perform the lexing/tokenizing of the file till we can return something that must be parsed.

Private Member Functions

Token FindKeyword (const char *name) const
 The token based on keyword with a given name.
void ReadIdentifier ()
 Read an identifier.
void ReadString (char end, Token token)
 Read a string up to a given character, then set the given token.

Private Attributes

const Filefile
 The file to read from.
char current_char
 The current character to process.
char * string
 Currently processed string.
Token token
 The current token to process.
char * buf
 Temporary buffer.
size_t buf_len
 Length of the temporary buffer.
KeywordList keywords
 All keywords we know of.

Detailed Description

Lexer of a file.

Definition at line 244 of file depend.cpp.

Constructor & Destructor Documentation

Lexer::Lexer ( const File file)
inline

Create the lexer and fill the keywords table.

Parameters
filethe file to read from.

Definition at line 250 of file depend.cpp.

References buf, buf_len, keywords, Next(), TOKEN_DEFINE, TOKEN_DEFINED, TOKEN_ELIF, TOKEN_ELSE, TOKEN_ENDIF, TOKEN_IF, TOKEN_IFDEF, TOKEN_IFNDEF, TOKEN_INCLUDE, and TOKEN_UNDEF.

Member Function Documentation

Token Lexer::FindKeyword ( const char *  name) const
inlineprivate

The token based on keyword with a given name.

Parameters
namethe actual keyword.
Returns
the token of the keyword.

Definition at line 432 of file depend.cpp.

References keywords, and TOKEN_IDENTIFIER.

Referenced by ReadIdentifier().

const char* Lexer::GetString ( ) const
inline

Read the currenty processed string.

Returns
the string, can be NULL.

Definition at line 298 of file depend.cpp.

References string.

Referenced by ExpressionDefined(), and ScanFile().

Token Lexer::GetToken ( ) const
inline

Get the current token.

Returns
the token.

Definition at line 289 of file depend.cpp.

References token.

Referenced by ExpressionAnd(), ExpressionDefined(), ExpressionNot(), ExpressionOr(), and ScanFile().

void Lexer::ReadString ( char  end,
Token  token 
)
inlineprivate

Read a string up to a given character, then set the given token.

Parameters
endthe 'marker' for the end of the string.
tokenthe token to set after returning.

Definition at line 469 of file depend.cpp.

References buf, buf_len, current_char, free(), Next(), and token.

Referenced by Lex().


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