| 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 #include "tools/gn/tokenizer.h" | 5 #include "tools/gn/tokenizer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "tools/gn/input_file.h" | 9 #include "tools/gn/input_file.h" |
| 10 | 10 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 return static_cast<size_t>(-1); | 173 return static_cast<size_t>(-1); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // static | 176 // static |
| 177 bool Tokenizer::IsNewline(const base::StringPiece& buffer, size_t offset) { | 177 bool Tokenizer::IsNewline(const base::StringPiece& buffer, size_t offset) { |
| 178 DCHECK(offset < buffer.size()); | 178 DCHECK(offset < buffer.size()); |
| 179 // We may need more logic here to handle different line ending styles. | 179 // We may need more logic here to handle different line ending styles. |
| 180 return buffer[offset] == '\n'; | 180 return buffer[offset] == '\n'; |
| 181 } | 181 } |
| 182 | 182 |
| 183 // static |
| 184 bool Tokenizer::IsIdentifierFirstChar(char c) { |
| 185 return base::IsAsciiAlpha(c) || c == '_'; |
| 186 } |
| 187 |
| 188 // static |
| 189 bool Tokenizer::IsIdentifierContinuingChar(char c) { |
| 190 // Also allow digits after the first char. |
| 191 return IsIdentifierFirstChar(c) || base::IsAsciiDigit(c); |
| 192 } |
| 183 | 193 |
| 184 void Tokenizer::AdvanceToNextToken() { | 194 void Tokenizer::AdvanceToNextToken() { |
| 185 while (!at_end() && IsCurrentWhitespace()) | 195 while (!at_end() && IsCurrentWhitespace()) |
| 186 Advance(); | 196 Advance(); |
| 187 } | 197 } |
| 188 | 198 |
| 189 Token::Type Tokenizer::ClassifyCurrent() const { | 199 Token::Type Tokenizer::ClassifyCurrent() const { |
| 190 DCHECK(!at_end()); | 200 DCHECK(!at_end()); |
| 191 char next_char = cur_char(); | 201 char next_char = cur_char(); |
| 192 if (base::IsAsciiDigit(next_char)) | 202 if (base::IsAsciiDigit(next_char)) |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 // Different types of comments. | 400 // Different types of comments. |
| 391 help = "Comments should start with # instead"; | 401 help = "Comments should start with # instead"; |
| 392 } else if (cur_char() == '\'') { | 402 } else if (cur_char() == '\'') { |
| 393 help = "Strings are delimited by \" characters, not apostrophes."; | 403 help = "Strings are delimited by \" characters, not apostrophes."; |
| 394 } else { | 404 } else { |
| 395 help = "I have no idea what this is."; | 405 help = "I have no idea what this is."; |
| 396 } | 406 } |
| 397 | 407 |
| 398 return Err(location, "Invalid token.", help); | 408 return Err(location, "Invalid token.", help); |
| 399 } | 409 } |
| OLD | NEW |