43 #include <sys/types.h>
62 : m_fname(fname), m_content(content) {
67 size_t lastslash =
m_fname.find_last_of(
'/');
68 if (lastslash != string::npos)
69 return m_fname.substr(0, lastslash);
89 while (*end && *end !=
'\n')
99 ptr = strchr(base,
'=');
101 if (*ptr ==
'\'' || *ptr ==
'"' || *ptr ==
'`') {
102 int starting_line = (int)
m_line;
105 "Unterminated string starting on line %d", starting_line);
117 if ((ptr = strchr(base,
'{')) == 0)
119 "Mal-formed task: statement starting on line %d",(
int)
m_line);
121 int starting_line = (int)m_line;
124 "task: statement on line %d of file '%s'",
125 starting_line,
m_fname.c_str());
132 if ((ptr = strchr(base,
'{')) == 0)
134 "Mal-formed function starting on line %d",(
int)m_line);
136 int starting_line = (int)m_line;
139 "function on line %d of file '%s'",
140 starting_line,
m_fname.c_str());
152 "Incomplete control flow statement on line %d of file '%s'",
182 HT_FATALF(
"Unknown token type - %u", (
unsigned int)line_type);
191 const char *ptr = base;
194 while (ptr < end && isspace(*ptr))
206 else if (*ptr ==
':') {
207 if (!strncmp(base,
"include", 7))
209 if (!strncmp(base,
"role", 4))
211 else if (!strncmp(base,
"task", 4))
214 string tag(base, ptr-base);
216 "Unrecognized meta tag '%s:' on line %u",
217 tag.c_str(), (
unsigned int)
m_line);
220 else if (isspace(*ptr)) {
221 if (!strncmp(base,
"if", 2) || !strncmp(base,
"while", 5) ||
222 !strncmp(base,
"for", 3) || !strncmp(base,
"until", 5) ||
223 !strncmp(base,
"case", 4))
225 else if (!strncmp(base,
"function", 8))
227 else if (!strncmp(base,
"role", 4))
229 "Invalid role: statement on line %d",(
int)
m_line);
230 else if (!strncmp(base,
"task", 4))
232 "Invalid task: statement on line %d",(
int)m_line);
233 else if (!strncmp(base,
"include", 4))
235 "Invalid include: statement on line %d",(
int)m_line);
237 while (ptr < end && isspace(*ptr))
244 else if (*ptr ==
'#')
253 int type,
Token &token) {
275 token.
text.append(*basep, end-*basep);
bool next(Token &token)
Returns the next token from the cluster definition file.
static bool read(const String &fname, String &contents)
Reads a whole file into a String.
string fname
Pathname of file from which token was extracted.
bool accumulate(const char **basep, const char *end, int type, Token &token)
Accumulates the next token.
Cluster definition file token.
File system utility functions.
Tokenizer(const string &fname)
Constructor.
void create_translator()
Creates a translator for the token.
size_t line
Starting line number of token.
Logging routines and macros.
Compatibility Macros for C/C++.
void clear()
Clears token state.
const char * m_next
Pointer to beginning of next token to read.
string dirname()
Returns the directory path containing the cluster definition file.
size_t m_line
Line number of end of last token read.
#define HT_FATALF(msg,...)
string m_fname
Pathname of cluster definition file.
#define HT_THROWF(_code_, _fmt_,...)
int identify_line_type(const char *base, const char *end)
Identifies token type of line starting at base.
Declarations for Tokenizer.
Cluster definition file translation definitions.
Error codes, Exception handling, error logging.
string m_content
Content of cluster definition file.