33from ..error import GraphQLSyntaxError
44from .ast import Token
55from .block_string import dedent_block_string_value
6+ from .character_classes import is_digit , is_name_start , is_name_continue
67from .source import Source
78from .token_kind import TokenKind
89
@@ -129,10 +130,10 @@ def read_next_token(self, start: int) -> Token:
129130 if kind :
130131 return self .create_token (kind , position , position + 1 )
131132
132- if "0" <= char <= "9" or char == "-" :
133+ if is_digit ( char ) or char == "-" :
133134 return self .read_number (position , char )
134135
135- if "A" <= char <= "Z" or "a" <= char <= "z" or char == "_" :
136+ if is_name_start ( char ) :
136137 return self .read_name (position )
137138
138139 if char == "." :
@@ -196,7 +197,7 @@ def read_number(self, start: int, first_char: str) -> Token:
196197 if char == "0" :
197198 position += 1
198199 char = body [position : position + 1 ]
199- if "0" <= char <= "9" :
200+ if is_digit ( char ) :
200201 raise GraphQLSyntaxError (
201202 self .source ,
202203 position ,
@@ -240,7 +241,7 @@ def read_number(self, start: int, first_char: str) -> Token:
240241
241242 def read_digits (self , start : int , first_char : str ) -> int :
242243 """Return the new position in the source after reading one or more digits."""
243- if not "0" <= first_char <= "9" :
244+ if not is_digit ( first_char ) :
244245 raise GraphQLSyntaxError (
245246 self .source ,
246247 start ,
@@ -251,7 +252,7 @@ def read_digits(self, start: int, first_char: str) -> int:
251252 body = self .source .body
252253 body_length = len (body )
253254 position = start + 1
254- while position < body_length and "0" <= body [position ] <= "9" :
255+ while position < body_length and is_digit ( body [position ]) :
255256 position += 1
256257 return position
257258
@@ -427,12 +428,7 @@ def read_name(self, start: int) -> Token:
427428
428429 while position < body_length :
429430 char = body [position ]
430- if not (
431- "A" <= char <= "Z"
432- or "a" <= char <= "z"
433- or "0" <= char <= "9"
434- or char == "_"
435- ):
431+ if not is_name_continue (char ):
436432 break
437433 position += 1
438434
@@ -558,8 +554,3 @@ def is_supplementary_code_point(body: str, location: int) -> bool:
558554
559555def decode_surrogate_pair (leading : int , trailing : int ) -> int :
560556 return 0x10000 + (((leading & 0x03FF ) << 10 ) | (trailing & 0x03FF ))
561-
562-
563- def is_name_start (char : str ) -> bool :
564- """Check whether char is an underscore or a plain ASCII letter"""
565- return char == "_" or "A" <= char <= "Z" or "a" <= char <= "z"
0 commit comments