ROSE 0.11.145.237
|
An ordered list of tokens scanned from input.
A token stream is an ordered list of tokens scanned from an unchanging input stream and consumed in the order they're produced.
#include <Sawyer/Lexer.h>
Public Types | |
typedef T | Token |
Public Member Functions | |
TokenStream (const boost::filesystem::path &fileName) | |
Create a token stream from the contents of a file. | |
TokenStream (const std::string &inputString) | |
Create a token stream from a string. | |
TokenStream (const Container::Buffer< size_t, char >::Ptr &buffer) | |
Create a token stream from a buffer. | |
const std::string & | name () const |
Property: Name of stream. | |
const Token & | current () |
Return the current token. | |
bool | atEof () |
Returns true if the stream is at the end. | |
const Token & | operator[] (size_t lookahead) |
Return the current or future token. | |
void | consume (size_t n=1) |
Consume some tokens. | |
std::pair< size_t, size_t > | location (size_t position) |
Return the line number and offset for an input position. | |
std::pair< size_t, size_t > | locationEof () |
Returns the last line index and character offset. | |
std::string | lineString (size_t lineIdx) |
Return the entire string for some line index. | |
virtual Token | scanNextToken (const Container::LineVector &content, size_t &at)=0 |
Function that obtains the next token. | |
std::string | lexeme (const Token &t) |
Return the lexeme for a token. | |
std::string | lexeme () |
Return the lexeme for a token. | |
bool | isa (const Token &t, typename Token::TokenEnum type) |
Determine whether token is a specific type. | |
bool | isa (typename Token::TokenEnum type) |
Determine whether token is a specific type. | |
bool | match (const Token &t, const char *s) |
Determine whether a token matches a string. | |
bool | match (const char *s) |
Determine whether a token matches a string. | |
typedef T Sawyer::Lexer::TokenStream< T >::Token |
|
inlinevirtual |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Return the lexeme for a token.
Consults the input stream to obtain the lexeme for the specified token and converts that part of the stream to a string which is returned. The lexeme for an EOF token is an empty string, although other tokens might also have empty lexemes. One may query the lexeme for any token regardless of whether it's been consumed; in fact, one can even query lexemes for tokens that have never even been seen by the token stream.
The no-argument version returns the lexeme of the current token.
If you're trying to build a fast lexical analyzer, don't call this function to compare a lexeme against some known string. Instead, use match, which doesn't require copying.
Definition at line 182 of file Lexer.h.
References Sawyer::Container::LineVector::characters().
|
inline |
Return the lexeme for a token.
Consults the input stream to obtain the lexeme for the specified token and converts that part of the stream to a string which is returned. The lexeme for an EOF token is an empty string, although other tokens might also have empty lexemes. One may query the lexeme for any token regardless of whether it's been consumed; in fact, one can even query lexemes for tokens that have never even been seen by the token stream.
The no-argument version returns the lexeme of the current token.
If you're trying to build a fast lexical analyzer, don't call this function to compare a lexeme against some known string. Instead, use match, which doesn't require copying.
|
inline |
|
inline |
|
inline |
Determine whether a token matches a string.
Compares the specified string to a token's lexeme and returns true if they are the same. This is faster than obtaining the lexeme from a token and comparing to a string since there's no string copying involved with this function.
The no-argument version compares the string with the current tokens' lexeme.
Definition at line 217 of file Lexer.h.
References Sawyer::Container::LineVector::characters().
|
inline |
Determine whether a token matches a string.
Compares the specified string to a token's lexeme and returns true if they are the same. This is faster than obtaining the lexeme from a token and comparing to a string since there's no string copying involved with this function.
The no-argument version compares the string with the current tokens' lexeme.
|
inline |
Return the line number and offset for an input position.
Returns the zero-origin line number (a.k.a., line index) for the line containing the specified character position, and the offset of that character with respect to the beginning of the line.
Definition at line 235 of file Lexer.h.
References Sawyer::Container::LineVector::location().
|
inline |
Returns the last line index and character offset.
Definition at line 240 of file Lexer.h.
References Sawyer::Container::LineVector::location(), and Sawyer::Container::LineVector::nCharacters().
|
inline |
Return the entire string for some line index.
Definition at line 246 of file Lexer.h.
References Sawyer::Container::LineVector::lineString().
|
pure virtual |
Function that obtains the next token.
Subclasses implement this function to obtain the next token that starts at or after the specified input position. Upon return, the function should adjust at
to point to the next position for scanning a token, which is usually the first character after the returned token's lexeme. If the scanner reaches the end of input or any condition that it deems to be the end then it should return the EOF token (a default-constructed token), after which this function will not be called again.
Implemented in Sawyer::Document::Markup::TokenStream.