Skip to content

Commit b497890

Browse files
committed
Convert Token to be a normal class
Actually it was already a normal class, just added a docstring and types and comments for the attributes. Replicates graphql/graphql-js@8960d0d
1 parent a003731 commit b497890

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/graphql/language/ast.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,25 @@
6767

6868

6969
class Token:
70+
"""AST Token
71+
72+
Represents a range of characters represented by a lexical token within a Source.
73+
"""
74+
7075
__slots__ = ("kind", "start", "end", "line", "column", "prev", "next", "value")
7176

77+
kind: TokenKind # the kind of token
78+
start: int # the character offset at which this Node begins
79+
end: int # the character offset at which this Node ends
80+
line: int # the 1-indexed line number on which this Token appears
81+
column: int # the 1-indexed column number at which this Token begins
82+
# for non-punctuation tokens, represents the interpreted value of the token:
83+
value: Optional[str]
84+
# Tokens exist as nodes in a double-linked-list amongst all tokens including
85+
# ignored tokens. <SOF> is always the first node and <EOF> the last.
86+
prev: Optional["Token"]
87+
next: Optional["Token"]
88+
7289
def __init__(
7390
self,
7491
kind: TokenKind,
@@ -82,9 +99,9 @@ def __init__(
8299
self.kind = kind
83100
self.start, self.end = start, end
84101
self.line, self.column = line, column
85-
self.prev: Optional[Token] = prev
86-
self.next: Optional[Token] = None
87-
self.value: Optional[str] = value
102+
self.value = value
103+
self.prev = prev
104+
self.next = None
88105

89106
def __str__(self):
90107
return self.desc

0 commit comments

Comments
 (0)