Skip to content

Commit c81913c

Browse files
authored
Print token value for illegal tokens (#591)
* print token value for illegal tokens * Revert "print token value for illegal tokens" This reverts commit c47748f. * make illegal tokens explicit * feedback
1 parent f57e51f commit c81913c

File tree

1 file changed

+57
-17
lines changed

1 file changed

+57
-17
lines changed

syntax/scan.go

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,26 @@ const (
9898
RETURN
9999
WHILE
100100

101+
// Reserved words (following Python); unused in Starlark
102+
103+
AS
104+
// ASSERT // heavily used in our tests
105+
ASYNC
106+
AWAIT
107+
CLASS
108+
DEL
109+
EXCEPT
110+
FINALLY
111+
FROM
112+
GLOBAL
113+
IMPORT
114+
IS
115+
NONLOCAL
116+
RAISE
117+
TRY
118+
WITH
119+
YIELD
120+
101121
maxToken
102122
)
103123

@@ -180,6 +200,26 @@ var tokenNames = [...]string{
180200
PASS: "pass",
181201
RETURN: "return",
182202
WHILE: "while",
203+
204+
// Reserved words (following Python); unused in Starlark
205+
206+
AS: "as",
207+
// ASSERT: "assert", // heavily used in our tests
208+
ASYNC: "async",
209+
AWAIT: "await",
210+
CLASS: "class",
211+
DEL: "del",
212+
EXCEPT: "except",
213+
FINALLY: "finally",
214+
FROM: "from",
215+
GLOBAL: "global",
216+
IMPORT: "import",
217+
IS: "is",
218+
NONLOCAL: "nonlocal",
219+
RAISE: "raise",
220+
TRY: "try",
221+
WITH: "with",
222+
YIELD: "yield",
183223
}
184224

185225
// A FilePortion describes the content of a portion of a file.
@@ -1104,21 +1144,21 @@ var keywordToken = map[string]Token{
11041144
"while": WHILE,
11051145

11061146
// reserved words:
1107-
"as": ILLEGAL,
1108-
// "assert": ILLEGAL, // heavily used by our tests
1109-
"async": ILLEGAL,
1110-
"await": ILLEGAL,
1111-
"class": ILLEGAL,
1112-
"del": ILLEGAL,
1113-
"except": ILLEGAL,
1114-
"finally": ILLEGAL,
1115-
"from": ILLEGAL,
1116-
"global": ILLEGAL,
1117-
"import": ILLEGAL,
1118-
"is": ILLEGAL,
1119-
"nonlocal": ILLEGAL,
1120-
"raise": ILLEGAL,
1121-
"try": ILLEGAL,
1122-
"with": ILLEGAL,
1123-
"yield": ILLEGAL,
1147+
"as": AS,
1148+
// "assert": ASSERT, // heavily used by our tests
1149+
"async": ASYNC,
1150+
"await": AWAIT,
1151+
"class": CLASS,
1152+
"del": DEL,
1153+
"except": EXCEPT,
1154+
"finally": FINALLY,
1155+
"from": FROM,
1156+
"global": GLOBAL,
1157+
"import": IMPORT,
1158+
"is": IS,
1159+
"nonlocal": NONLOCAL,
1160+
"raise": RAISE,
1161+
"try": TRY,
1162+
"with": WITH,
1163+
"yield": YIELD,
11241164
}

0 commit comments

Comments
 (0)