Splits cluster definition file into tokens. More...
#include <Tokenizer.h>
Public Member Functions | |
Tokenizer (const string &fname) | |
Constructor. More... | |
Tokenizer (const string &fname, const string &content) | |
Constructor. More... | |
string | dirname () |
Returns the directory path containing the cluster definition file. More... | |
bool | next (Token &token) |
Returns the next token from the cluster definition file. More... | |
Private Member Functions | |
int | identify_line_type (const char *base, const char *end) |
Identifies token type of line starting at base . More... | |
bool | accumulate (const char **basep, const char *end, int type, Token &token) |
Accumulates the next token. More... | |
Private Attributes | |
string | m_fname |
Pathname of cluster definition file. More... | |
string | m_content |
Content of cluster definition file. More... | |
const char * | m_next |
Pointer to beginning of next token to read. More... | |
size_t | m_line {} |
Line number of end of last token read. More... | |
Splits cluster definition file into tokens.
Definition at line 43 of file Tokenizer.h.
Tokenizer::Tokenizer | ( | const string & | fname | ) |
Tokenizer::Tokenizer | ( | const string & | fname, |
const string & | content | ||
) |
Constructor.
Initializes m_fname with fname
, sets m_content to content
, and then sets m_next pointing to the beginning of the content.
fname | Pathname of cluster definition file |
content | Content of cluster definition file |
Definition at line 61 of file Tokenizer.cc.
|
private |
Accumulates the next token.
This function populates token
with the next token to be returned. If token
is already populated, it first check to see if the following token (identified by basep
, end
, and type
) should be merged with the existing token and if so, it merges the token text with the existing token and advances *basep
to end+1
, otherwise it leaves *basep
unmodified and returns. Tokens that get merged are Token::COMMENT followed by Token::TASK, Token::ROLE followed by Token::CODE, and any a adjacent code tokens (e.g. Token::CODE, Token::FUNCTION, Token::BLANKLINE, Token::CONTROLFLOW). If token
is populated with the token text starting at *basep
because it was merged with an existing token or the existing token was empty, then it sets m_next to end
.
basep | Address of pointer to next token |
end | Pointer to end of next token (either newline or EOF) |
type | Type of next token (see Token::Type) |
token | Reference to token object to hold next token |
token
is ready to be returned Definition at line 251 of file Tokenizer.cc.
string Tokenizer::dirname | ( | ) |
Returns the directory path containing the cluster definition file.
Returns the path of m_fname up to the last '/' character, or "." if m_fname does not contain any '/' character.
Definition at line 66 of file Tokenizer.cc.
|
private |
Identifies token type of line starting at base
.
This function determines the token type (Token::Type) of the line starting at base
and ending at end
.
base | Pointer to beginning of next line |
end | Pointer to end of line or end of content |
base
Definition at line 190 of file Tokenizer.cc.
bool Tokenizer::next | ( | Token & | token | ) |
Returns the next token from the cluster definition file.
This reads the next token from the cluster definition file starting at m_next. It populates token
with the token text, type identifier, line number of the start of the token, and creates a translator for it with a call to Token::create_translator(). The m_next and m_line are advanced to the beginning of the next token (or EOF) and the last line of the returned token, respectively.
token | Next token filled in by this function |
Definition at line 73 of file Tokenizer.cc.
|
private |
Content of cluster definition file.
Definition at line 115 of file Tokenizer.h.
|
private |
Pathname of cluster definition file.
Definition at line 113 of file Tokenizer.h.
|
private |
Line number of end of last token read.
Definition at line 119 of file Tokenizer.h.
|
private |
Pointer to beginning of next token to read.
Definition at line 117 of file Tokenizer.h.