strusBase  0.17
Public Types | Public Member Functions | List of all members
strus::ProgramLexer Class Reference

Class for a lexer used for implementing domain specific languages of strus. More...

#include <programLexer.hpp>

Public Types

enum  Option { KeepStringEscaping =1 }
 

Public Member Functions

 ProgramLexer (const char *src, const char *eolncomment_, const char **tokens, const char **errtokens, ErrorBufferInterface *errhnd_)
 Constructor. More...
 
 ~ProgramLexer ()
 
const ProgramLexemnext ()
 Get the next lexem. More...
 
const ProgramLexemcurrent ()
 Get the current lexem. More...
 
const ProgramLexemrescanCurrent ()
 Rescan the current lexem (with different options) More...
 
bool consumeToken (int tokid)
 Skip to next and return true if the current lexem is a token with a defined id. More...
 
bool setOption (Option opt_, bool value)
 Switch lexer option on/off. More...
 
int lineno () const
 Get the current line number. More...
 
const char * pos () const
 Get the current source pointer. More...
 
std::size_t len () const
 Get the rest length to parse. More...
 
bool skipto (char const *pos)
 Skip to a defined position is the parsed source and scan the next token. More...
 
const char * nextpos ()
 Get the start of the next token. More...
 
const char * currentpos ()
 Get the start of the current token. More...
 
std::string currentLocationString (int posincr, int size, const char *marker) const
 Get an excerpt of the current source location starting from a position with a marker inserted. More...
 

Detailed Description

Class for a lexer used for implementing domain specific languages of strus.

Member Enumeration Documentation

Enumerator
KeepStringEscaping 

Constructor & Destructor Documentation

strus::ProgramLexer::ProgramLexer ( const char *  src,
const char *  eolncomment_,
const char **  tokens,
const char **  errtokens,
ErrorBufferInterface errhnd_ 
)

Constructor.

Parameters
[in]srcpointer to source to parse
[in]eolncomment_operator used for comments (end of line comments)
[in]errtokensillegal lexems defined as regular expressions (leading to a syntax error)
[in]tokenslexems defined as regular expressions with the position in the array as associated id
[in]errhnd_error buffer interface to use for reporting errors
strus::ProgramLexer::~ProgramLexer ( )

Member Function Documentation

bool strus::ProgramLexer::consumeToken ( int  tokid)
inline

Skip to next and return true if the current lexem is a token with a defined id.

const ProgramLexem& strus::ProgramLexer::current ( )
inline

Get the current lexem.

std::string strus::ProgramLexer::currentLocationString ( int  posincr,
int  size,
const char *  marker 
) const

Get an excerpt of the current source location starting from a position with a marker inserted.

Parameters
[in]posincrincrement of the current position to show
[in]markermarker to insert in the result at the current position
[in]sizesize of excerpt to show
const char* strus::ProgramLexer::currentpos ( )

Get the start of the current token.

Returns
the position of the current token or NULL, if an error occurred or if we got to the end of source
std::size_t strus::ProgramLexer::len ( ) const
inline

Get the rest length to parse.

int strus::ProgramLexer::lineno ( ) const

Get the current line number.

Remarks
expensive operation, if scans the source every time it is called, because it is thought to be used only for error messages
const ProgramLexem& strus::ProgramLexer::next ( )

Get the next lexem.

const char* strus::ProgramLexer::nextpos ( )

Get the start of the next token.

Returns
the position of the next token or NULL, if an error occurred or if we got to the end of source
const char* strus::ProgramLexer::pos ( ) const
inline

Get the current source pointer.

const ProgramLexem& strus::ProgramLexer::rescanCurrent ( )

Rescan the current lexem (with different options)

bool strus::ProgramLexer::setOption ( Option  opt_,
bool  value 
)

Switch lexer option on/off.

Parameters
[in]optoption identifier
[in]valuetrue=on, false=off
Returns
previous option value
bool strus::ProgramLexer::skipto ( char const *  pos)

Skip to a defined position is the parsed source and scan the next token.

Parameters
[in]pospointer to position to set scanner to for restart scanning
Remarks
pos must be inside of the parsed source

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