@@ -33,34 +33,34 @@ static bool consume_if(TSLexer *lexer, const int32_t character)
3333const char SQ_STRING_DELIMITER = '\'' ;
3434const char DQ_STRING_DELIMITER = '"' ;
3535
36- struct ScannerState {
37- unsigned short started ;
36+ enum StartedToken
37+ {
38+ SHORT_COMMENT = 1 ,
39+ SHORT_SQ_STRING ,
40+ SHORT_DQ_STRING ,
41+ LONG_COMMENT ,
42+ LONG_STRING ,
43+ };
44+
45+ struct ScannerState
46+ {
47+ enum StartedToken started ;
3848 unsigned int depth ;
3949};
4050
4151void * tree_sitter_lua_external_scanner_create ()
4252{
43- struct ScannerState * state = malloc (sizeof (struct ScannerState ));
44- return state ;
53+ return malloc (sizeof (struct ScannerState ));
4554}
4655
4756void tree_sitter_lua_external_scanner_destroy (void * payload )
4857{
4958 free (payload );
5059}
5160
52- enum StartedToken
53- {
54- SHORT_COMMENT = 1 ,
55- SHORT_SQ_STRING ,
56- SHORT_DQ_STRING ,
57- LONG_COMMENT ,
58- LONG_STRING ,
59- };
60-
6161unsigned int tree_sitter_lua_external_scanner_serialize (void * payload , char * buffer )
6262{
63- struct ScannerState * state = ( struct ScannerState * ) payload ;
63+ struct ScannerState * state = payload ;
6464 buffer [0 ] = state -> started ;
6565 buffer [1 ] = state -> depth ;
6666 return 2 ;
@@ -70,7 +70,7 @@ void tree_sitter_lua_external_scanner_deserialize(void *payload, const char *buf
7070{
7171 if (length == 2 )
7272 {
73- struct ScannerState * state = ( struct ScannerState * ) payload ;
73+ struct ScannerState * state = payload ;
7474 state -> started = buffer [0 ];
7575 state -> depth = buffer [1 ];
7676 }
@@ -87,9 +87,8 @@ static unsigned int get_depth(TSLexer *lexer)
8787 return current_depth ;
8888}
8989
90- static bool scan_depth (TSLexer * lexer , struct ScannerState * state )
90+ static bool scan_depth (TSLexer * lexer , unsigned int remaining_depth )
9191{
92- unsigned int remaining_depth = state -> depth ;
9392 while (remaining_depth > 0 && consume_if (lexer , '=' ))
9493 {
9594 remaining_depth -= 1 ;
@@ -100,7 +99,7 @@ static bool scan_depth(TSLexer *lexer, struct ScannerState * state)
10099
101100bool tree_sitter_lua_external_scanner_scan (void * payload , TSLexer * lexer , const bool * valid_symbols )
102101{
103- struct ScannerState * state = ( struct ScannerState * ) payload ;
102+ struct ScannerState * state = payload ;
104103 switch (state -> started )
105104 {
106105 case SHORT_COMMENT :
@@ -178,7 +177,7 @@ bool tree_sitter_lua_external_scanner_scan(void *payload, TSLexer *lexer, const
178177 // try to match the long comment's/string's end (]=*])
179178 if (consume_if (lexer , ']' ))
180179 {
181- if (scan_depth (lexer , state ) && consume_if (lexer , ']' ))
180+ if (scan_depth (lexer , state -> depth ) && consume_if (lexer , ']' ))
182181 {
183182 state -> started = 0 ;
184183 state -> depth = 0 ;
@@ -210,7 +209,7 @@ bool tree_sitter_lua_external_scanner_scan(void *payload, TSLexer *lexer, const
210209 lexer -> mark_end (lexer );
211210 if (consume_if (lexer , ']' ))
212211 {
213- if (scan_depth (lexer , state ))
212+ if (scan_depth (lexer , state -> depth ))
214213 {
215214 if (consume_if (lexer , ']' ))
216215 {
0 commit comments