Debian Codegraph @

src/graphql/language/character_classes.py

raw
1 __all__ = ["is_digit", "is_letter", "is_name_start", "is_name_continue"]
2
3 try:
4 "string".isascii()
5 except AttributeError: # Python < 3.7
6
7 def is_digit(char: str) -> bool:
8 """Check whether char is a digit
9
10 For internal use by the lexer only.
11 """
12 return "0" <= char <= "9"
13
14 def is_letter(char: str) -> bool:
15 """Check whether char is a plain ASCII letter
16
17 For internal use by the lexer only.
18 """
19 return "a" <= char <= "z" or "A" <= char <= "Z"
20
21 def is_name_start(char: str) -> bool:
22 """Check whether char is allowed at the beginning of a GraphQL name
23
24 For internal use by the lexer only.
25 """
26 return "a" <= char <= "z" or "A" <= char <= "Z" or char == "_"
27
28 def is_name_continue(char: str) -> bool:
29 """Check whether char is allowed in the continuation of a GraphQL name
30
31 For internal use by the lexer only.
32 """
33 return (
34 "a" <= char <= "z"
35 or "A" <= char <= "Z"
36 or "0" <= char <= "9"
37 or char == "_"
38 )
39
40 else:
41
42 def is_digit(char: str) -> bool:
43 """Check whether char is a digit
44
45 For internal use by the lexer only.
46 """
47 return char.isascii() and char.isdigit()
48
49 def is_letter(char: str) -> bool:
50 """Check whether char is a plain ASCII letter
51
52 For internal use by the lexer only.
53 """
54 return char.isascii() and char.isalpha()
55
56 def is_name_start(char: str) -> bool:
57 """Check whether char is allowed at the beginning of a GraphQL name
58
59 For internal use by the lexer only.
60 """
61 return char.isascii() and (char.isalpha() or char == "_")
62
63 def is_name_continue(char: str) -> bool:
64 """Check whether char is allowed in the continuation of a GraphQL name
65
66 For internal use by the lexer only.
67 """
68 return char.isascii() and (char.isalnum() or char == "_")