52 Token(): type_(TOK_EOF), prior_(0), begin_(0), end_(0) {}
54 Token(TokenType type,
size_t prior,
size_t begin,
size_t end)
55 : type_(type), prior_(prior), begin_(begin), end_(end) {
56 ASSERT_require(prior <= begin_);
57 ASSERT_require(begin <= end);
60 TokenType type()
const {
64 size_t prior()
const {
68 size_t begin()
const {
80 Indices where()
const {
81 return end_ > begin_ ?
Indices::hull(begin_, end_-1) : Indices();
84 explicit operator bool()
const {
85 return type_ != TOK_EOF;
88 bool operator!()
const {
89 return type_ == TOK_EOF;
95 std::string fileName_;
100 std::vector<Token> tokens_;
101 bool skipPreprocessorTokens_;
102 bool skipCommentTokens_;
107 : fileName_(fileName), content_(fileName), parseRegion_(
Indices::whole()), prior_(0), at_(0),
108 skipPreprocessorTokens_(
true), skipCommentTokens_(
true) {}
112 : fileName_(fileName), content_(buffer), parseRegion_(
Indices::whole()), prior_(0), at_(0),
113 skipPreprocessorTokens_(
true), skipCommentTokens_(
true) {}
117 : fileName_(super.fileName_), content_(super.content_), parseRegion_(region), prior_(region.
least()), at_(region.
least()),
118 skipPreprocessorTokens_(
true), skipCommentTokens_(
true) {
119 ASSERT_require(region);
122 const std::string fileName()
const {
return fileName_; }
124 bool skipPreprocessorTokens()
const {
return skipPreprocessorTokens_; }
125 void skipPreprocessorTokens(
bool b) { skipPreprocessorTokens_ = b; }
127 bool skipCommentTokens()
const {
return skipCommentTokens_; }
128 void skipCommentTokens(
bool b) { skipCommentTokens_ = b; }
130 int getChar(
size_t position);
132 const Token& operator[](
size_t lookahead);
134 void consume(
size_t n = 1);
136 std::string lexeme(
const Token &t)
const;
138 std::string toString(
const Token &t)
const;
141 std::string line(
const Token &t)
const;
143 bool matches(
const Token &token,
const char *s2)
const;
144 bool startsWith(
const Token &token,
const char *prefix)
const;
146 void emit(std::ostream &out,
const std::string &fileName,
const Token &token,
const std::string &message)
const;
148 void emit(std::ostream &out,
const std::string &fileName,
const Token &begin,
const Token &locus,
const Token &end,
149 const std::string &message)
const;
151 std::pair<size_t, size_t> location(
const Token &token)
const;
159 void makeNextToken();