mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-25 11:02:38 +00:00
Factor out character set handling into a separate file. (#352)
This commit is contained in:
1 parent
67ee1fcaa7
commit
97bb6f4e80
5 files changed
+108
-38
No files matched your search
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <bitset>
|
||||
|
||||
#include "lexer/character_set.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
|
||||
@@ -79,13 +80,11 @@ struct WrongRealLiteralExponent {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static bool isLower(char c) { return 'a' <= c && c <= 'z'; }
|
||||
|
||||
auto NumericLiteralToken::Lex(llvm::StringRef source_text)
|
||||
-> llvm::Optional<NumericLiteralToken> {
|
||||
NumericLiteralToken result;
|
||||
|
||||
if (source_text.empty() || !llvm::isDigit(source_text.front())) {
|
||||
if (source_text.empty() || !IsDecimalDigit(source_text.front())) {
|
||||
return llvm::None;
|
||||
}
|
||||
|
||||
@@ -101,8 +100,8 @@ auto NumericLiteralToken::Lex(llvm::StringRef source_text)
|
||||
int i = 1, n = source_text.size();
|
||||
for (; i != n; ++i) {
|
||||
char c = source_text[i];
|
||||
if (llvm::isAlnum(c) || c == '_') {
|
||||
if (isLower(c) && seen_radix_point && !seen_plus_minus) {
|
||||
if (IsAlnum(c) || c == '_') {
|
||||
if (IsLower(c) && seen_radix_point && !seen_plus_minus) {
|
||||
result.exponent = i;
|
||||
seen_potential_exponent = true;
|
||||
}
|
||||
@@ -111,7 +110,7 @@ auto NumericLiteralToken::Lex(llvm::StringRef source_text)
|
||||
|
||||
// Exactly one `.` can be part of the literal, but only if it's followed by
|
||||
// an alphanumeric character.
|
||||
if (c == '.' && i + 1 != n && llvm::isAlnum(source_text[i + 1]) &&
|
||||
if (c == '.' && i + 1 != n && IsAlnum(source_text[i + 1]) &&
|
||||
!seen_radix_point) {
|
||||
result.radix_point = i;
|
||||
seen_radix_point = true;
|
||||
@@ -123,8 +122,7 @@ auto NumericLiteralToken::Lex(llvm::StringRef source_text)
|
||||
// followed by an alphanumeric character. This '+' or '-' cannot be an
|
||||
// operator because a literal cannot end in a lowercase letter.
|
||||
if ((c == '+' || c == '-') && seen_potential_exponent &&
|
||||
result.exponent == i - 1 && i + 1 != n &&
|
||||
llvm::isAlnum(source_text[i + 1])) {
|
||||
result.exponent == i - 1 && i + 1 != n && IsAlnum(source_text[i + 1])) {
|
||||
// This is not possible because we don't update result.exponent after we
|
||||
// see a '+' or '-'.
|
||||
assert(!seen_plus_minus && "should only consume one + or -");
|
||||
|
||||
Reference in new issue
Block a user