mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:07:36 +00:00
LibJS: Use the new is_ascii_foo() helpers from AK
These constexpr helpers generate nicer code than the LibC ctype.h variants, so let's make use of them. :^)
This commit is contained in:
parent
d476144565
commit
39ad705c13
5 changed files with 30 additions and 31 deletions
|
@ -6,9 +6,9 @@
|
|||
*/
|
||||
|
||||
#include "Lexer.h"
|
||||
#include <AK/CharacterTypes.h>
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace JS {
|
||||
|
@ -199,10 +199,10 @@ bool Lexer::consume_exponent()
|
|||
if (m_current_char == '-' || m_current_char == '+')
|
||||
consume();
|
||||
|
||||
if (!isdigit(m_current_char))
|
||||
if (!is_ascii_digit(m_current_char))
|
||||
return false;
|
||||
|
||||
while (isdigit(m_current_char)) {
|
||||
while (is_ascii_digit(m_current_char)) {
|
||||
consume();
|
||||
}
|
||||
return true;
|
||||
|
@ -224,10 +224,10 @@ bool Lexer::consume_octal_number()
|
|||
bool Lexer::consume_hexadecimal_number()
|
||||
{
|
||||
consume();
|
||||
if (!isxdigit(m_current_char))
|
||||
if (!is_ascii_hex_digit(m_current_char))
|
||||
return false;
|
||||
|
||||
while (isxdigit(m_current_char))
|
||||
while (is_ascii_hex_digit(m_current_char))
|
||||
consume();
|
||||
|
||||
return true;
|
||||
|
@ -293,12 +293,12 @@ bool Lexer::is_line_terminator() const
|
|||
|
||||
bool Lexer::is_identifier_start() const
|
||||
{
|
||||
return isalpha(m_current_char) || m_current_char == '_' || m_current_char == '$';
|
||||
return is_ascii_alpha(m_current_char) || m_current_char == '_' || m_current_char == '$';
|
||||
}
|
||||
|
||||
bool Lexer::is_identifier_middle() const
|
||||
{
|
||||
return is_identifier_start() || isdigit(m_current_char);
|
||||
return is_identifier_start() || is_ascii_digit(m_current_char);
|
||||
}
|
||||
|
||||
bool Lexer::is_line_comment_start(bool line_has_token_yet) const
|
||||
|
@ -323,7 +323,7 @@ bool Lexer::is_block_comment_end() const
|
|||
|
||||
bool Lexer::is_numeric_literal_start() const
|
||||
{
|
||||
return isdigit(m_current_char) || (m_current_char == '.' && m_position < m_source.length() && isdigit(m_source[m_position]));
|
||||
return is_ascii_digit(m_current_char) || (m_current_char == '.' && m_position < m_source.length() && is_ascii_digit(m_source[m_position]));
|
||||
}
|
||||
|
||||
bool Lexer::slash_means_division() const
|
||||
|
@ -358,10 +358,10 @@ Token Lexer::next()
|
|||
do {
|
||||
consume();
|
||||
} while (is_line_terminator());
|
||||
} else if (isspace(m_current_char)) {
|
||||
} else if (is_ascii_space(m_current_char)) {
|
||||
do {
|
||||
consume();
|
||||
} while (isspace(m_current_char));
|
||||
} while (is_ascii_space(m_current_char));
|
||||
} else if (is_line_comment_start(line_has_token_yet)) {
|
||||
consume();
|
||||
do {
|
||||
|
@ -393,9 +393,9 @@ Token Lexer::next()
|
|||
// bunch of Invalid* tokens (bad numeric literals, unterminated comments etc.)
|
||||
String token_message;
|
||||
|
||||
if (m_current_token.type() == TokenType::RegexLiteral && !is_eof() && isalpha(m_current_char)) {
|
||||
if (m_current_token.type() == TokenType::RegexLiteral && !is_eof() && is_ascii_alpha(m_current_char)) {
|
||||
token_type = TokenType::RegexFlags;
|
||||
while (!is_eof() && isalpha(m_current_char))
|
||||
while (!is_eof() && is_ascii_alpha(m_current_char))
|
||||
consume();
|
||||
} else if (m_current_char == '`') {
|
||||
consume();
|
||||
|
@ -457,7 +457,7 @@ Token Lexer::next()
|
|||
if (m_current_char == '.') {
|
||||
// decimal
|
||||
consume();
|
||||
while (isdigit(m_current_char))
|
||||
while (is_ascii_digit(m_current_char))
|
||||
consume();
|
||||
if (m_current_char == 'e' || m_current_char == 'E')
|
||||
is_invalid_numeric_literal = !consume_exponent();
|
||||
|
@ -475,15 +475,15 @@ Token Lexer::next()
|
|||
} else if (m_current_char == 'n') {
|
||||
consume();
|
||||
token_type = TokenType::BigIntLiteral;
|
||||
} else if (isdigit(m_current_char)) {
|
||||
} else if (is_ascii_digit(m_current_char)) {
|
||||
// octal without '0o' prefix. Forbidden in 'strict mode'
|
||||
do {
|
||||
consume();
|
||||
} while (isdigit(m_current_char));
|
||||
} while (is_ascii_digit(m_current_char));
|
||||
}
|
||||
} else {
|
||||
// 1...9 or period
|
||||
while (isdigit(m_current_char))
|
||||
while (is_ascii_digit(m_current_char))
|
||||
consume();
|
||||
if (m_current_char == 'n') {
|
||||
consume();
|
||||
|
@ -491,7 +491,7 @@ Token Lexer::next()
|
|||
} else {
|
||||
if (m_current_char == '.') {
|
||||
consume();
|
||||
while (isdigit(m_current_char))
|
||||
while (is_ascii_digit(m_current_char))
|
||||
consume();
|
||||
}
|
||||
if (m_current_char == 'e' || m_current_char == 'E')
|
||||
|
@ -579,7 +579,7 @@ Token Lexer::next()
|
|||
auto it = s_two_char_tokens.find(two_chars_view.hash(), [&](auto& entry) { return entry.key == two_chars_view; });
|
||||
if (it != s_two_char_tokens.end()) {
|
||||
// OptionalChainingPunctuator :: ?. [lookahead ∉ DecimalDigit]
|
||||
if (!(it->value == TokenType::QuestionMarkPeriod && m_position + 1 < m_source.length() && isdigit(m_source[m_position + 1]))) {
|
||||
if (!(it->value == TokenType::QuestionMarkPeriod && m_position + 1 < m_source.length() && is_ascii_digit(m_source[m_position + 1]))) {
|
||||
found_two_char_token = true;
|
||||
consume();
|
||||
consume();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue