Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/graphql/language/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

from __future__ import annotations

import re
from typing import TYPE_CHECKING, NamedTuple

from ..error import GraphQLSyntaxError
from .ast import Token
from .block_string import dedent_block_string_lines
from .character_classes import is_digit, is_name_continue, is_name_start
from .character_classes import is_digit, is_name_start
from .token_kind import TokenKind

if TYPE_CHECKING:
from .source import Source

__all__ = ["Lexer", "is_punctuator_token_kind"]

# NameContinue is ASCII letters, digits and underscore only
_re_name_continue = re.compile("[0-9A-Z_a-z]*")


class EscapeSequence(NamedTuple):
"""The string value and lexed size of an escape sequence."""
Expand Down Expand Up @@ -663,14 +667,8 @@ def read_name(self, start: int) -> Token:
:meta private:
"""
body = self.source.body
body_length = len(body)
position = start + 1

while position < body_length:
char = body[position]
if not is_name_continue(char):
break
position += 1
# NameContinue* can match the empty string, so the match is never None
position = _re_name_continue.match(body, start + 1).end() # type: ignore[union-attr]

return self.create_token(TokenKind.NAME, start, position, body[start:position])

Expand Down
Loading