@@ -42,7 +42,7 @@ fn dotted_name_text(toks: read List<Tok>, i: read Int) -> String {
4242 let mut j = i + 1
4343 let mut going = true
4444 while going {
45- let dot = at_symbol(toks: read toks, i: read j, code: read 46 )
45+ let dot = at_symbol(toks: read toks, i: read j, code: read SYM_DOT )
4646 let nextIdent = is_ident_tok(toks: read toks, i: read (j + 1))
4747 if dot && nextIdent {
4848 out = String.concat(left: read out, right: read ".")
@@ -58,10 +58,10 @@ fn dotted_name_text(toks: read List<Tok>, i: read Int) -> String {
5858// Index of the name token for a type decl (after optional pub, opaque, kind kw).
5959fn type_name_start(toks: read List<Tok >, i: read Int) -> Int {
6060 let mut j = i
61- if at_ident(toks: read toks, i: read j, wid: read 13 ) {
61+ if at_ident(toks: read toks, i: read j, wid: read WORD_PUB ) {
6262 j = j + 1
6363 }
64- if at_ident(toks: read toks, i: read j, wid: read 5 ) {
64+ if at_ident(toks: read toks, i: read j, wid: read WORD_OPAQUE ) {
6565 j = j + 1
6666 }
6767 j = j + 1
@@ -71,7 +71,7 @@ fn type_name_start(toks: read List<Tok>, i: read Int) -> Int {
7171// Index of the name token for a sum decl (after optional pub, sum kw).
7272fn sum_name_start(toks: read List<Tok >, i: read Int) -> Int {
7373 let mut j = i
74- if at_ident(toks: read toks, i: read j, wid: read 13 ) {
74+ if at_ident(toks: read toks, i: read j, wid: read WORD_PUB ) {
7575 j = j + 1
7676 }
7777 j = j + 1
@@ -83,15 +83,15 @@ fn fn_name_start(toks: read List<Tok>, i: read Int) -> Int {
8383 let mut j = i
8484 let mut attrs = true
8585 while attrs {
86- if at_symbol(toks: read toks, i: read j, code: read 35 ) {
86+ if at_symbol(toks: read toks, i: read j, code: read SYM_HASH ) {
8787 j = j + 5
8888 } else {
8989 attrs = false
9090 }
9191 }
9292 let mut mods = true
9393 while mods {
94- let isMod = at_ident(toks: read toks, i: read j, wid: read 13 ) || at_ident(toks: read toks, i: read j, wid: read 14 ) || at_ident(toks: read toks, i: read j, wid: read 9 )
94+ let isMod = at_ident(toks: read toks, i: read j, wid: read WORD_PUB ) || at_ident(toks: read toks, i: read j, wid: read WORD_ASYNC ) || at_ident(toks: read toks, i: read j, wid: read WORD_NATIVE )
9595 if isMod {
9696 j = j + 1
9797 } else {
@@ -106,7 +106,7 @@ fn fn_name_start(toks: read List<Tok>, i: read Int) -> Int {
106106fn find_body_open(toks: read List<Tok >, i: read Int, end: read Int) -> Int {
107107 let mut k = i
108108 while k < end {
109- if at_symbol(toks: read toks, i: read k, code: read 123 ) {
109+ if at_symbol(toks: read toks, i: read k, code: read SYM_LBRACE ) {
110110 return k
111111 }
112112 k = k + 1
@@ -126,7 +126,7 @@ fn body_has_duplicate_field(toks: read List<Tok>, ob: read Int, close: read Int)
126126 let mut brace = 0
127127 let mut k = ob + 1
128128 while k < close {
129- let isColon = at_symbol(toks: read toks, i: read k, code: read 58 )
129+ let isColon = at_symbol(toks: read toks, i: read k, code: read SYM_COLON )
130130 let atTop = paren == 0 && br == 0 && ang == 0 && brace == 0
131131 if isColon && atTop && is_ident_tok(toks: read toks, i: read (k - 1)) {
132132 let name = tk_text(toks: read toks, i: read (k - 1))
@@ -135,27 +135,27 @@ fn body_has_duplicate_field(toks: read List<Tok>, ob: read Int, close: read Int)
135135 }
136136 Set.insert<String >(set: mut seen, value: read name)
137137 }
138- if at_symbol(toks: read toks, i: read k, code: read 40 ) {
138+ if at_symbol(toks: read toks, i: read k, code: read SYM_LPAREN ) {
139139 paren = paren + 1
140- } else if at_symbol(toks: read toks, i: read k, code: read 41 ) {
140+ } else if at_symbol(toks: read toks, i: read k, code: read SYM_RPAREN ) {
141141 if paren > 0 {
142142 paren = paren - 1
143143 }
144- } else if at_symbol(toks: read toks, i: read k, code: read 91 ) {
144+ } else if at_symbol(toks: read toks, i: read k, code: read SYM_LBRACKET ) {
145145 br = br + 1
146- } else if at_symbol(toks: read toks, i: read k, code: read 93 ) {
146+ } else if at_symbol(toks: read toks, i: read k, code: read SYM_RBRACKET ) {
147147 if br > 0 {
148148 br = br - 1
149149 }
150- } else if at_symbol(toks: read toks, i: read k, code: read 60 ) {
150+ } else if at_symbol(toks: read toks, i: read k, code: read SYM_LANGLE ) {
151151 ang = ang + 1
152- } else if at_symbol(toks: read toks, i: read k, code: read 62 ) {
152+ } else if at_symbol(toks: read toks, i: read k, code: read SYM_RANGLE ) {
153153 if ang > 0 {
154154 ang = ang - 1
155155 }
156- } else if at_symbol(toks: read toks, i: read k, code: read 123 ) {
156+ } else if at_symbol(toks: read toks, i: read k, code: read SYM_LBRACE ) {
157157 brace = brace + 1
158- } else if at_symbol(toks: read toks, i: read k, code: read 125 ) {
158+ } else if at_symbol(toks: read toks, i: read k, code: read SYM_RBRACE ) {
159159 if brace > 0 {
160160 brace = brace - 1
161161 }
@@ -181,16 +181,17 @@ fn main() -> Unit {
181181 while running {
182182 if i >= ntok {
183183 running = false
184- } else if tk_kind(toks: read toks, i: read i) == 8 {
184+ } else if tk_kind(toks: read toks, i: read i) == TOK_EOF {
185185 running = false
186186 } else {
187- let isPub = at_ident(toks: read toks, i: read i, wid: read 13)
188- let isFeatures = at_ident(toks: read toks, i: read i, wid: read 17) && at_symbol(toks: read toks, i: read (i + 1), code: read 58)
189- let isProfile = at_ident(toks: read toks, i: read i, wid: read 16) && at_symbol(toks: read toks, i: read (i + 1), code: read 58)
190- let isSum = at_ident(toks: read toks, i: read i, wid: read 6) || (isPub && at_ident(toks: read toks, i: read (i + 1), wid: read 6))
191- let isNativeMod = at_ident(toks: read toks, i: read i, wid: read 9) && at_ident(toks: read toks, i: read (i + 1), wid: read 10)
192- let isTypeAlias = at_ident(toks: read toks, i: read i, wid: read 11) || (isPub && at_ident(toks: read toks, i: read (i + 1), wid: read 11))
193- let isConst = at_ident(toks: read toks, i: read i, wid: read 12) || (isPub && at_ident(toks: read toks, i: read (i + 1), wid: read 12))
187+ let cls = classify_top(toks: read toks, i: read i)
188+ let isPub = cls.isPub
189+ let isFeatures = cls.isFeatures
190+ let isProfile = cls.isProfile
191+ let isSum = cls.isSum
192+ let isNativeMod = cls.isNativeMod
193+ let isTypeAlias = cls.isTypeAlias
194+ let isConst = cls.isConst
194195 if isFeatures {
195196 i = declaration_line_end(toks: read toks, start: read i)
196197 } else if isProfile {
@@ -230,14 +231,14 @@ fn main() -> Unit {
230231 Set.insert<String >(set: mut types, value: read name)
231232 i = r
232233 }
233- } else if at_ident(toks: read toks, i: read i, wid: read 7 ) {
234+ } else if at_ident(toks: read toks, i: read i, wid: read WORD_PROTOCOL ) {
234235 let r = parse_protocol_decl(toks: read toks, i: read i)
235236 if r < 0 {
236237 running = false
237238 } else {
238239 i = r
239240 }
240- } else if at_ident(toks: read toks, i: read i, wid: read 8 ) {
241+ } else if at_ident(toks: read toks, i: read i, wid: read WORD_IMPL ) {
241242 let r = parse_impl_decl(toks: read toks, i: read i)
242243 if r < 0 {
243244 running = false
@@ -265,14 +266,14 @@ fn main() -> Unit {
265266 } else {
266267 i = r
267268 }
268- } else if at_ident(toks: read toks, i: read i, wid: read 10 ) {
269+ } else if at_ident(toks: read toks, i: read i, wid: read WORD_MODULE ) {
269270 let r = parse_module_decl(toks: read toks, i: read i)
270271 if r < 0 {
271272 i = i + 1
272273 } else {
273274 i = r
274275 }
275- } else if at_ident(toks: read toks, i: read i, wid: read 15 ) {
276+ } else if at_ident(toks: read toks, i: read i, wid: read WORD_USE ) {
276277 let r = parse_use_decl(toks: read toks, i: read i)
277278 if r < 0 {
278279 i = i + 1
0 commit comments