37 *err += message +
"\n";
40 const int kTruncateColumn = 72;
41 if (col > 0 && col < kTruncateColumn) {
43 bool truncated =
true;
44 for (len = 0; len < kTruncateColumn; ++len) {
45 if (context[len] == 0 || context[len] ==
'\n') {
50 *err += string(context, len);
54 *err += string(col,
' ');
55 *err +=
"^ near here";
62 Start(
"input", input);
74 case ERROR:
return "lexing error";
75 case BUILD:
return "'build'";
76 case COLON:
return "':'";
77 case DEFAULT:
return "'default'";
79 case IDENT:
return "identifier";
80 case INCLUDE:
return "'include'";
81 case INDENT:
return "indent";
83 case PIPE2:
return "'||'";
84 case PIPE:
return "'|'";
85 case POOL:
return "'pool'";
86 case RULE:
return "'rule'";
88 case TEOF:
return "eof";
96 return " ($ also escapes ':')";
106 return "carriage returns are not allowed, use newlines";
108 return "tabs are not allowed, use spaces";
111 return "lexing error";
119 const char* p =
ofs_;
170 const char* p =
ofs_;
183 const char* p =
ofs_;
185 const char* start = p;
200 const char* p =
ofs_;
void UnreadToken()
Rewind to the last read Token.
StringPiece represents a slice of a string whose memory is managed externally.
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.).
string AsString() const
Convert the slice into a full-fledged std::string, copying the data into a new string.
bool PeekToken(Token token)
If the next token is token, read it and return true.
bool Error(const string &message, string *err)
Construct an error message with context.
Token ReadToken()
Read a Token from the Token enum.
string DescribeLastError()
If the last token read was an ERROR token, provide more info or the empty string. ...
bool ReadIdent(string *out)
Read a simple identifier (a rule or variable name).
bool ReadEvalString(EvalString *eval, bool path, string *err)
Read a $-escaped string.
static const char * TokenName(Token t)
Return a human-readable form of a token, used in error messages.
A tokenized string that contains variable references.
void Start(StringPiece filename, StringPiece input)
Start parsing some input.