OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef TOOLS_GN_PARSER_H_ | 5 #ifndef TOOLS_GN_PARSER_H_ |
6 #define TOOLS_GN_PARSER_H_ | 6 #define TOOLS_GN_PARSER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 bool IsStatementBreak(Token::Type token_type) const; | 104 bool IsStatementBreak(Token::Type token_type) const; |
105 | 105 |
106 bool LookAhead(Token::Type type); | 106 bool LookAhead(Token::Type type); |
107 bool Match(Token::Type type); | 107 bool Match(Token::Type type); |
108 Token Consume(Token::Type type, const char* error_message); | 108 Token Consume(Token::Type type, const char* error_message); |
109 Token Consume(Token::Type* types, | 109 Token Consume(Token::Type* types, |
110 size_t num_types, | 110 size_t num_types, |
111 const char* error_message); | 111 const char* error_message); |
112 Token Consume(); | 112 Token Consume(); |
113 | 113 |
| 114 // Call this only if !at_end(). |
114 const Token& cur_token() const { return tokens_[cur_]; } | 115 const Token& cur_token() const { return tokens_[cur_]; } |
115 | 116 |
| 117 const Token& cur_or_last_token() const { |
| 118 return at_end() ? tokens_[tokens_.size() - 1] : cur_token(); |
| 119 } |
| 120 |
116 bool done() const { return at_end() || has_error(); } | 121 bool done() const { return at_end() || has_error(); } |
117 bool at_end() const { return cur_ >= tokens_.size(); } | 122 bool at_end() const { return cur_ >= tokens_.size(); } |
118 bool has_error() const { return err_->has_error(); } | 123 bool has_error() const { return err_->has_error(); } |
119 | 124 |
120 std::vector<Token> tokens_; | 125 std::vector<Token> tokens_; |
121 std::vector<Token> line_comment_tokens_; | 126 std::vector<Token> line_comment_tokens_; |
122 std::vector<Token> suffix_comment_tokens_; | 127 std::vector<Token> suffix_comment_tokens_; |
123 | 128 |
124 static ParserHelper expressions_[Token::NUM_TYPES]; | 129 static ParserHelper expressions_[Token::NUM_TYPES]; |
125 | 130 |
126 Err* err_; | 131 Err* err_; |
127 | 132 |
128 // Current index into the tokens. | 133 // Current index into the tokens. |
129 size_t cur_; | 134 size_t cur_; |
130 | 135 |
131 FRIEND_TEST_ALL_PREFIXES(Parser, BinaryOp); | 136 FRIEND_TEST_ALL_PREFIXES(Parser, BinaryOp); |
132 FRIEND_TEST_ALL_PREFIXES(Parser, Block); | 137 FRIEND_TEST_ALL_PREFIXES(Parser, Block); |
133 FRIEND_TEST_ALL_PREFIXES(Parser, Condition); | 138 FRIEND_TEST_ALL_PREFIXES(Parser, Condition); |
134 FRIEND_TEST_ALL_PREFIXES(Parser, Expression); | 139 FRIEND_TEST_ALL_PREFIXES(Parser, Expression); |
135 FRIEND_TEST_ALL_PREFIXES(Parser, FunctionCall); | 140 FRIEND_TEST_ALL_PREFIXES(Parser, FunctionCall); |
136 FRIEND_TEST_ALL_PREFIXES(Parser, List); | 141 FRIEND_TEST_ALL_PREFIXES(Parser, List); |
137 FRIEND_TEST_ALL_PREFIXES(Parser, ParenExpression); | 142 FRIEND_TEST_ALL_PREFIXES(Parser, ParenExpression); |
138 FRIEND_TEST_ALL_PREFIXES(Parser, UnaryOp); | 143 FRIEND_TEST_ALL_PREFIXES(Parser, UnaryOp); |
139 | 144 |
140 DISALLOW_COPY_AND_ASSIGN(Parser); | 145 DISALLOW_COPY_AND_ASSIGN(Parser); |
141 }; | 146 }; |
142 | 147 |
143 #endif // TOOLS_GN_PARSER_H_ | 148 #endif // TOOLS_GN_PARSER_H_ |
OLD | NEW |