3
3
from ..error import GraphQLSyntaxError
4
4
from .ast import Token
5
5
from .block_string import dedent_block_string_value
6
+ from .character_classes import is_digit , is_name_start , is_name_continue
6
7
from .source import Source
7
8
from .token_kind import TokenKind
8
9
@@ -129,10 +130,10 @@ def read_next_token(self, start: int) -> Token:
129
130
if kind :
130
131
return self .create_token (kind , position , position + 1 )
131
132
132
- if "0" <= char <= "9" or char == "-" :
133
+ if is_digit ( char ) or char == "-" :
133
134
return self .read_number (position , char )
134
135
135
- if "A" <= char <= "Z" or "a" <= char <= "z" or char == "_" :
136
+ if is_name_start ( char ) :
136
137
return self .read_name (position )
137
138
138
139
if char == "." :
@@ -196,7 +197,7 @@ def read_number(self, start: int, first_char: str) -> Token:
196
197
if char == "0" :
197
198
position += 1
198
199
char = body [position : position + 1 ]
199
- if "0" <= char <= "9" :
200
+ if is_digit ( char ) :
200
201
raise GraphQLSyntaxError (
201
202
self .source ,
202
203
position ,
@@ -240,7 +241,7 @@ def read_number(self, start: int, first_char: str) -> Token:
240
241
241
242
def read_digits (self , start : int , first_char : str ) -> int :
242
243
"""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 ) :
244
245
raise GraphQLSyntaxError (
245
246
self .source ,
246
247
start ,
@@ -251,7 +252,7 @@ def read_digits(self, start: int, first_char: str) -> int:
251
252
body = self .source .body
252
253
body_length = len (body )
253
254
position = start + 1
254
- while position < body_length and "0" <= body [position ] <= "9" :
255
+ while position < body_length and is_digit ( body [position ]) :
255
256
position += 1
256
257
return position
257
258
@@ -427,12 +428,7 @@ def read_name(self, start: int) -> Token:
427
428
428
429
while position < body_length :
429
430
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 ):
436
432
break
437
433
position += 1
438
434
@@ -558,8 +554,3 @@ def is_supplementary_code_point(body: str, location: int) -> bool:
558
554
559
555
def decode_surrogate_pair (leading : int , trailing : int ) -> int :
560
556
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