27 const char* line_start =
input_.str_;
37 snprintf(buf,
sizeof(buf),
"%s:%d: ",
filename_.AsString().c_str(), line);
39 *err += message +
"\n";
42 const int kTruncateColumn = 72;
43 if (col > 0 && col < kTruncateColumn) {
45 bool truncated =
true;
46 for (len = 0; len < kTruncateColumn; ++len) {
47 if (line_start[len] == 0 || line_start[len] ==
'\n') {
52 *err += string(line_start, len);
56 *err += string(col,
' ');
57 *err +=
"^ near here";
64 Start(
"input", input);
76 case ERROR:
return "lexing error";
77 case BUILD:
return "'build'";
78 case COLON:
return "':'";
79 case DEFAULT:
return "'default'";
81 case IDENT:
return "identifier";
82 case INCLUDE:
return "'include'";
83 case INDENT:
return "indent";
85 case PIPE2:
return "'||'";
86 case PIPE:
return "'|'";
87 case PIPEAT:
return "'|@'";
88 case POOL:
return "'pool'";
89 case RULE:
return "'rule'";
91 case TEOF:
return "eof";
99 return " ($ also escapes ':')";
109 return "tabs are not allowed, use spaces";
112 return "lexing error";
120 const char* p =
ofs_;
173 const char* p =
ofs_;
188 const char* p =
ofs_;
210 const char* p =
ofs_;
A tokenized string that contains variable references.
static const char * TokenName(Token t)
Return a human-readable form of a token, used in error messages.
bool PeekToken(Token token)
If the next token is token, read it and return true.
std::string DescribeLastError()
If the last token read was an ERROR token, provide more info or the empty string.
void UnreadToken()
Rewind to the last read Token.
bool ReadEvalString(EvalString *eval, bool path, std::string *err)
Read a $-escaped string.
void Start(StringPiece filename, StringPiece input)
Start parsing some input.
Token ReadToken()
Read a Token from the Token enum.
static const char * TokenErrorHint(Token expected)
Return a human-readable token hint, used in error messages.
void EatWhitespace()
Skip past whitespace (called after each read token/ident/etc.).
bool ReadIdent(std::string *out)
Read a simple identifier (a rule or variable name).
bool Error(const std::string &message, std::string *err)
Construct an error message with context.
StringPiece represents a slice of a string whose memory is managed externally.