tree-sitter-vhdl 1.4.0

VHDL grammar for tree-sitter
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
// #define DEBUG
//------------------------------------------------------------------------------

#include <stddef.h>
#include <stdio.h>
#include <string.h>
//------------------------------------------------------------------------------

#include "tree_sitter/parser.h"
#include "debug_macros.h"
//------------------------------------------------------------------------------

#include "TokenType.h"
#include "TokenTree.h"
//------------------------------------------------------------------------------

typedef struct ScannerTag{
    bool      is_in_directive;
    bool      is_block_comment; // else line comment
    TokenType bit_string_base;
    int       base;
} Scanner;
//------------------------------------------------------------------------------

#include "TokenType.inc"
#include "TokenTree.inc"
//------------------------------------------------------------------------------

void* tree_sitter_vhdl_external_scanner_create()
{
    Scanner* scanner = ts_calloc(1, sizeof(Scanner));
    return scanner;
}
//------------------------------------------------------------------------------

void tree_sitter_vhdl_external_scanner_destroy(Scanner* scanner)
{
    if(scanner) ts_free(scanner);
}
//------------------------------------------------------------------------------

unsigned tree_sitter_vhdl_external_scanner_serialize(Scanner* scanner, char* buffer)
{
    memcpy(buffer, scanner, sizeof(Scanner));
    return sizeof(Scanner);
}
//------------------------------------------------------------------------------

void tree_sitter_vhdl_external_scanner_deserialize(Scanner* scanner, const char* buffer, unsigned length)
{
    if(length > 0 && length <= sizeof(Scanner) && buffer)
        memcpy(scanner, buffer, length);
}
//------------------------------------------------------------------------------

static bool is_whitespace(int32_t character)
{
    return character == ' '  || character == '\t' ||
           character == '\n' || character == '\r';
}
//------------------------------------------------------------------------------

static void skip_whitespace(TSLexer* lexer, bool skip_newline, bool discard)
{
    if(skip_newline){
        while(is_whitespace(lexer->lookahead)){
            debug("Skipping whitespace and newlines");
            lexer->advance(lexer, discard);
        }
    }else{
        while(lexer->lookahead == ' ' || lexer->lookahead == '\t'){
            debug("Skipping whitespace");
            lexer->advance(lexer, discard);
        }
    }
}
//------------------------------------------------------------------------------

static bool bounded_token(TSLexer* lexer, int32_t bound)
{
    while(!lexer->eof(lexer)){
        if(lexer->lookahead == bound){
            lexer->advance(lexer, false);
            lexer->mark_end(lexer);
            if(lexer->lookahead != bound) return true;
        }
        if(lexer->lookahead == '\r') return false;
        if(lexer->lookahead == '\n') return false;
        lexer->advance(lexer, false);
    }
    return false;
}
//------------------------------------------------------------------------------

static bool is_letter_or_digit(int32_t lookahead)
{
    return (lookahead >= 'a' && lookahead <= 'z') ||
           (lookahead >= '0' && lookahead <= '9');
}
//------------------------------------------------------------------------------

static bool finish_identifier(TSLexer* lexer, bool expect_letter)
{
    int32_t lookahead = lowercase(lexer->lookahead);
    bool    result = false;

    if(expect_letter){
        if(!is_letter_or_digit(lookahead)) return false;
    }

    while(!lexer->eof(lexer)){
        lexer->mark_end(lexer);
        if(lookahead == '_') lookahead = advance(lexer);
        if(!is_letter_or_digit(lookahead)) return result;
        lookahead = advance(lexer);
        result = true;
    }
    return result;
}
//------------------------------------------------------------------------------

static bool is_special_value(int32_t value)
{
    switch(value){
        case 'u':
        case 'x':
        case 'z':
        case 'w':
        case 'l':
        case 'h':
        case '-':
            return true;
        default:
            return false;
    }
}
//------------------------------------------------------------------------------

static bool binary_string_literal(TSLexer* lexer)
{
    while(!lexer->eof(lexer)){
        if(lexer->lookahead == '_') lexer->advance(lexer, false);
        if((lexer->lookahead < '0' || lexer->lookahead > '1') &&
           !is_special_value(lowercase(lexer->lookahead))) break;
        lexer->advance(lexer, false);
    }
    if(lexer->lookahead != '"') return false;
    lexer->advance(lexer, false);
    lexer->mark_end(lexer);
    return true;
}
//------------------------------------------------------------------------------

static bool octal_string_literal(TSLexer* lexer)
{
    while(!lexer->eof(lexer)){
        if(lexer->lookahead == '_') lexer->advance(lexer, false);
        if((lexer->lookahead < '0' || lexer->lookahead > '7') &&
           !is_special_value(lowercase(lexer->lookahead))) break;
        lexer->advance(lexer, false);
    }
    if(lexer->lookahead != '"') return false;
    lexer->advance(lexer, false);
    lexer->mark_end(lexer);
    return true;
}
//------------------------------------------------------------------------------

static bool decimal_string_literal(TSLexer* lexer)
{
    while(!lexer->eof(lexer)){
        if(lexer->lookahead == '_') lexer->advance(lexer, false);
        if((lexer->lookahead < '0' || lexer->lookahead > '9') &&
           !is_special_value(lowercase(lexer->lookahead))) break;
        lexer->advance(lexer, false);
    }
    if(lexer->lookahead != '"') return false;
    lexer->advance(lexer, false);
    lexer->mark_end(lexer);
    return true;
}
//------------------------------------------------------------------------------

static bool is_hex_digit(int32_t character)
{
    return (character >= '0' && character <= '9') ||
           (character >= 'a' && character <= 'f') ||
           (character >= 'A' && character <= 'F');
}
//------------------------------------------------------------------------------

static bool hex_string_literal(TSLexer* lexer)
{
    while(!lexer->eof(lexer)){
        if(lexer->lookahead == '_') lexer->advance(lexer, false);
        if(!is_hex_digit(lexer->lookahead) &&
           !is_special_value(lowercase(lexer->lookahead))) break;
        lexer->advance(lexer, false);
    }
    if(lexer->lookahead != '"') return false;
    lexer->advance(lexer, false);
    lexer->mark_end(lexer);
    return true;
}
//------------------------------------------------------------------------------

static bool finish_string_literal(TSLexer* lexer, TokenType type)
{
    switch(type){
        case BASE_SPECIFIER_BINARY:  return binary_string_literal (lexer);
        case BASE_SPECIFIER_OCTAL:   return octal_string_literal  (lexer);
        case BASE_SPECIFIER_DECIMAL: return decimal_string_literal(lexer);
        case BASE_SPECIFIER_HEX:     return hex_string_literal    (lexer);
        default:
            error("Unrecognised type %s", token_type_to_string(type));
            return false;
    }
}
//------------------------------------------------------------------------------

static void finish_line_comment(TSLexer* lexer)
{
    while(!lexer->eof(lexer)){
        if(lexer->lookahead == '\r' || lexer->lookahead == '\n'){
            lexer->advance(lexer, false);
            lexer->mark_end(lexer);
            return;
        }
        lexer->advance(lexer, false);
    }
    lexer->mark_end(lexer);
}
//------------------------------------------------------------------------------

static void finish_block_comment(TSLexer* lexer)
{
    while(!lexer->eof(lexer)){
        if(lexer->lookahead == '*'){
            lexer->advance(lexer, false);
            if(lexer->lookahead == '/') return;
            lexer->mark_end(lexer);

        }else if(is_whitespace(lexer->lookahead)){
            lexer->advance(lexer, false);

        }else{
            lexer->advance(lexer, false);
            lexer->mark_end(lexer);
        }
    }
}
//------------------------------------------------------------------------------

static bool finish_block_comment_end(TSLexer* lexer)
{
    while(!lexer->eof(lexer)){
        if(lexer->lookahead == '*'){
            lexer->advance(lexer, false);
            if(lexer->lookahead == '/'){
                lexer->advance(lexer, false);
                lexer->mark_end(lexer);
                return true;
            }
        }else{
            lexer->advance(lexer, false);
        }
    }
    return false;
}
//------------------------------------------------------------------------------

static void finish_comment_content(TSLexer* lexer, bool is_block_comment)
{
    lexer->mark_end(lexer);
    if(is_block_comment) finish_block_comment(lexer);
    else                 finish_line_comment(lexer);
}
//------------------------------------------------------------------------------

static bool may_start_with_digit(const bool* valid_symbols)
{
    return valid_symbols[TOKEN_DECIMAL_INTEGER] ||
           valid_symbols[TOKEN_DECIMAL_FLOAT]   ||
           valid_symbols[TOKEN_BASED_BASE]      ||
           valid_symbols[TOKEN_BIT_STRING_LENGTH];
}
//------------------------------------------------------------------------------

static int parse_integer(TSLexer* lexer)
{
    int result = 0;
    while(!lexer->eof(lexer)){
        lexer->mark_end(lexer);
        if(lexer->lookahead == '_') lexer->advance(lexer, false);
        if(lexer->lookahead < '0' || lexer->lookahead > '9') return result;

        result *= 10;
        result += lexer->lookahead - '0';
        lexer->advance(lexer, false);
    }
    return result;
}
//------------------------------------------------------------------------------

static bool parse_decimal_exponent(TSLexer* lexer)
{
    lexer->advance(lexer, false);
    if(lexer->lookahead == '+' || lexer->lookahead == '-') lexer->advance(lexer, false);
    if(lexer->lookahead < '0' || lexer->lookahead > '9') return false;

    parse_integer(lexer);

    return true;
}
//------------------------------------------------------------------------------

static bool parse_decimal_fraction(TSLexer* lexer)
{
    lexer->advance(lexer, false);
    if(lexer->lookahead < '0' || lexer->lookahead > '9') return false;

    parse_integer(lexer);

    if(lexer->lookahead == 'e' || lexer->lookahead == 'E'){
        return parse_decimal_exponent(lexer);
    }
    return true;
}
//------------------------------------------------------------------------------

static int to_digit(int32_t character)
{
    if(character >= '0' && character <= '9') return character - '0';
    if(character >= 'a' && character <= 'z') return character - 'a' + 10;
    if(character >= 'A' && character <= 'Z') return character - 'A' + 10;
    return -1;
}
//------------------------------------------------------------------------------

static bool based_integer(TSLexer* lexer, int base)
{
    while(!lexer->eof(lexer)){
        lexer->mark_end(lexer);
        if(lexer->lookahead == '_') lexer->advance(lexer, false);
        int digit = to_digit(lexer->lookahead);
        if(digit < 0) return true;
        if(digit >= base) return false;
        lexer->advance(lexer, false);
    }
    return true;
}
//------------------------------------------------------------------------------

static bool parse_base_literal(TSLexer* lexer, int base)
{
    lexer->advance(lexer, false);
    lexer->result_symbol = TOKEN_BASED_INTEGER;

    if(!based_integer(lexer, base)) return false;
    if(lexer->lookahead == '.'){
        lexer->advance(lexer, false);
        lexer->result_symbol = TOKEN_BASED_FLOAT;
        if(!based_integer(lexer, base)) return false;
    }
    if(lexer->lookahead != '#') return false;
    lexer->advance(lexer, false);
    lexer->mark_end(lexer);
    if(lexer->lookahead == 'e' || lexer->lookahead == 'E'){
        return parse_decimal_exponent(lexer);
    }
    return true;
}
//------------------------------------------------------------------------------

static bool parse_digit_based_literal(Scanner* scanner, TSLexer* lexer)
{
    lexer->result_symbol = TOKEN_DECIMAL_INTEGER;

    scanner->base = parse_integer(lexer);
    debug("base = %d", scanner->base);
    // NOTE: VHDL-2008 limits the base to 16, but I feel it's pointless to
    //       enforce, so I don't.  A future version will most likely relax
    //       that rule.

    switch(lowercase(lexer->lookahead)){
        case '.':
            lexer->result_symbol = TOKEN_DECIMAL_FLOAT;
            return parse_decimal_fraction(lexer);

        case 'e':
            return parse_decimal_exponent(lexer);

        case '#':
            lexer->result_symbol = TOKEN_BASED_BASE;
            return true;

        case 'b': case 'o': case 'd': case 'x':
            lexer->advance(lexer, false);
            if(lexer->lookahead != '"') return true;
            lexer->result_symbol = TOKEN_BIT_STRING_LENGTH;
            return true;

        case 'u': case 's':
            switch(advance(lexer)){
                case 'b': case 'o': case 'x': break;
                default: return true;
            }
            lexer->advance(lexer, false);
            if(lexer->lookahead != '"') return true;
            lexer->result_symbol = TOKEN_BIT_STRING_LENGTH;
            return true;

        default:
            return true;
    }
}
//------------------------------------------------------------------------------

static bool graphic_characters(TSLexer* lexer)
{
    if(lexer->lookahead == '\n' || lexer->lookahead == '\r') return false;

    while(!lexer->eof(lexer)){
        debug("lookahead = %c(0x%x)", (char)lexer->lookahead, lexer->lookahead);
        if(lexer->lookahead == ' '  || lexer->lookahead == '\t' ||
           lexer->lookahead == '\n' || lexer->lookahead == '\r'){
            return true;
        }
        lexer->advance(lexer, false);
    }
    return false;
}
//------------------------------------------------------------------------------

bool tree_sitter_vhdl_external_scanner_scan(Scanner* scanner, TSLexer* lexer, const bool* valid_symbols)
{
    #ifdef DEBUG
        if(valid_symbols[ERROR_SENTINEL]){
            debug("Error correction mode");
        }else{
            debug("Looking for:");
            for(int n = 0; n < ERROR_SENTINEL; n++){
                if(valid_symbols[n]) printf("    %s\n", token_type_to_string(n));
            }
            printf("\n");
        }
    #endif

    if(!valid_symbols[ERROR_SENTINEL] && valid_symbols[TOKEN_COMMENT_CONTENT]){
        finish_comment_content(lexer, scanner->is_block_comment);
        lexer->result_symbol = TOKEN_COMMENT_CONTENT;
        debug("Returning type TOKEN_COMMENT_CONTENT");
        return true;

    }else if(!valid_symbols[ERROR_SENTINEL] && valid_symbols[TOKEN_BLOCK_COMMENT_END]){
        if(finish_block_comment_end(lexer)){
            lexer->result_symbol = TOKEN_BLOCK_COMMENT_END;
            debug("Returning type TOKEN_BLOCK_COMMENT_END");
            return true;
        }
        debug("Returning false");
        return false;
    }

    skip_whitespace(lexer, !scanner->is_in_directive, true);

    if(valid_symbols[END_OF_FILE] && lexer->eof(lexer)){
        lexer->result_symbol = END_OF_FILE;
        debug("Returning type END_OF_FILE");
        return true;

    }else if(valid_symbols[IDENTIFIER] && lexer->lookahead == '\\'){
        lexer->advance(lexer, false);
        if(!bounded_token(lexer, '\\')) return false;
        lexer->result_symbol = IDENTIFIER;
        debug("Returning type IDENTIFIER");
        return true;

    }else if((valid_symbols[TOKEN_CHARACTER_LITERAL] ||
              valid_symbols[LIBRARY_CONSTANT_STD_LOGIC]) && lexer->lookahead == '\''){
        int32_t lookahead = advance(lexer);
        lexer->result_symbol = TOKEN_CHARACTER_LITERAL;
        if(lookahead == '0' || lookahead == '1' || is_special_value(lookahead)){
            if(valid_symbols[LIBRARY_CONSTANT_STD_LOGIC]){
                lexer->result_symbol = LIBRARY_CONSTANT_STD_LOGIC;
            }
        }
        if(lexer->eof(lexer)) return false;
        lexer->advance(lexer, false);
        if(lexer->lookahead != '\'') return false;
        lexer->advance(lexer, false);
        debug("Returning type %s", token_type_to_string(lexer->result_symbol));
        return true;

    }else if(lexer->lookahead >= '0' && lexer->lookahead <= '9'){
        if(!may_start_with_digit(valid_symbols)) return false;
        if(!parse_digit_based_literal(scanner, lexer)) return false;
        debug("returning type %s", token_type_to_string(lexer->result_symbol));
        return true;

    }else if(!valid_symbols[ERROR_SENTINEL] && valid_symbols[TOKEN_BIT_STRING_VALUE]){
        if(lexer->lookahead == '"'){
            lexer->advance(lexer, false);
            lexer->result_symbol = TOKEN_BIT_STRING_VALUE;
            if(finish_string_literal(lexer, scanner->bit_string_base)){
                debug("Returning type TOKEN_BIT_STRING_VALUE");
                return true;
            }
        }
        debug("Returning false");
        return false;

    }else if(!valid_symbols[ERROR_SENTINEL] &&
             (valid_symbols[TOKEN_BASED_INTEGER] || valid_symbols[TOKEN_BASED_FLOAT])){
        if(lexer->lookahead == '#'){
            if(parse_base_literal(lexer, scanner->base)){
                debug("Returning type %s", token_type_to_string(lexer->result_symbol));
                return true;
            }
        }
        debug("Returning false");
        return false;

    }else if(!valid_symbols[ERROR_SENTINEL] && valid_symbols[DIRECTIVE_BODY] && graphic_characters(lexer)){
        lexer->result_symbol = DIRECTIVE_BODY;
        debug("returning type DIRECTIVE_BODY");
        return true;
    }

    bool first_char_is_letter = (lexer->lookahead >= 'a' && lexer->lookahead <= 'z') ||
                                (lexer->lookahead >= 'A' && lexer->lookahead <= 'Z');

    bool first_char_is_double_quote = (lexer->lookahead == '"');

    const TokenType* types = token_tree_match(lexer);

    if(!types && first_char_is_letter){
        /* This works because all registered tokens in the search tree that
         * start with a letter are also valid identifiers.  If the tree search
         * exits early, whatever came before is a valid identifier
         *
         * The underscore corner cases are handled by IDENTIFIER_EXPECTING_LETTER
         */
        lexer->mark_end(lexer);
        finish_identifier(lexer, false);
        lexer->result_symbol = IDENTIFIER;
        debug("Returning type IDENTIFIER");
        return valid_symbols[IDENTIFIER];
    }

    if(!types && first_char_is_double_quote){
        if(!bounded_token(lexer, '"')) return false;
        lexer->result_symbol = TOKEN_STRING_LITERAL;
        debug("Returning type TOKEN_STRING_LITERAL");
        return valid_symbols[TOKEN_STRING_LITERAL];
    }

    bool found_can_be_identifier    = false;
    bool found_cannot_be_identifier = false;

    if(types){
        while(*types){
            if(*types == LINE_COMMENT_START){
                if(valid_symbols[TOKEN_LINE_COMMENT_START]){
                    scanner->is_block_comment = false;
                    skip_whitespace(lexer, false, false);
                    lexer->mark_end(lexer);
                    lexer->result_symbol = TOKEN_LINE_COMMENT_START;
                    debug("Returning type TOKEN_LINE_COMMENT_START");
                    return true;
                }
                debug("Returning false");
                return false;

            }else if(*types == BLOCK_COMMENT_START){
                if(valid_symbols[TOKEN_BLOCK_COMMENT_START]){
                    scanner->is_block_comment = true;
                    skip_whitespace(lexer, true, false);
                    lexer->mark_end(lexer);
                    lexer->result_symbol = TOKEN_BLOCK_COMMENT_START;
                    debug("Returning type TOKEN_BLOCK_COMMENT_START");
                    return true;
                }
                debug("Returning false");
                return false;

            }else if(can_start_identifier(*types) &&
                finish_identifier(lexer, *types == IDENTIFIER_EXPECTING_LETTER)){
                lexer->result_symbol = IDENTIFIER;
                debug("Returning type IDENTIFIER");
                return true;

            }else if(is_base_specifier(*types)){
                if(lexer->lookahead == '"'){
                    scanner->bit_string_base = *types;
                    lexer->result_symbol = TOKEN_BIT_STRING_BASE;
                    debug("Returning type TOKEN_BIT_STRING_BASE");
                    return true;
                }else if(!types[1]){
                    finish_identifier(lexer, false);
                    lexer->result_symbol = IDENTIFIER;
                    debug("Returning type IDENTIFIER");
                    return true;
                }

            }else if(*types == LIBRARY_CONSTANT_CHARACTER && lexer->lookahead == '"'){
                // This could actually be a bit-string base, so let the while continue
                // It is not possible to follow a character constant with a string

            }else if(*types == TOKEN_OPERATOR_SYMBOL ||
                     *types == TOKEN_STRING_LITERAL_STD_LOGIC){
                if(lexer->lookahead == '"'){
                    if(valid_symbols[TOKEN_STRING_LITERAL]){
                        lexer->advance(lexer, false);
                        if(!bounded_token(lexer, '"')) return false;
                        lexer->result_symbol = TOKEN_STRING_LITERAL;
                        debug("Returning type TOKEN_STRING_LITERAL");
                        return true;
                    }else{
                        debug("Returning false");
                        return false;
                    }
                }else if(valid_symbols[*types]){
                    lexer->result_symbol = *types;
                    debug("Returning type %s", token_type_to_string(*types));
                    return true;
                }else if(!types[1] && valid_symbols[TOKEN_STRING_LITERAL]){
                    lexer->result_symbol = TOKEN_STRING_LITERAL;
                    debug("Returning type TOKEN_STRING_LITERAL");
                    return true;
                }

            }else if(*types == STRING_LITERAL_STD_LOGIC_START){
                if(valid_symbols[TOKEN_STRING_LITERAL_STD_LOGIC] && binary_string_literal(lexer)){
                    if(lexer->lookahead != '"'){
                        lexer->result_symbol = TOKEN_STRING_LITERAL_STD_LOGIC;
                        debug("Returning type TOKEN_STRING_LITERAL_STD_LOGIC");
                        return valid_symbols[TOKEN_STRING_LITERAL_STD_LOGIC];
                    }else{
                        lexer->advance(lexer, false);
                        // and drop down to continue the string parsing below
                    }
                }
                if(valid_symbols[TOKEN_STRING_LITERAL] && bounded_token(lexer, '"')){
                    lexer->result_symbol = TOKEN_STRING_LITERAL;
                    debug("Returning type TOKEN_STRING_LITERAL");
                    return valid_symbols[TOKEN_STRING_LITERAL];
                }
                debug("Returning false");
                return false;

            }else if(*types < ERROR_SENTINEL && valid_symbols[*types]){
                lexer->result_symbol = *types;

                if(scanner->is_in_directive){
                   scanner->is_in_directive = (*types != DIRECTIVE_NEWLINE);
                }else{
                   scanner->is_in_directive = (*types == DELIMITER_GRAVE_ACCENT);
                }

                debug("Returning type %s", token_type_to_string(*types));
                return true;

            }else if(can_be_identifier(scanner, *types)){
                found_can_be_identifier = true;
            }else{
                found_cannot_be_identifier = true;
            }
            types++;
        }
    }
    if(valid_symbols[IDENTIFIER] && found_can_be_identifier && !found_cannot_be_identifier){
        lexer->result_symbol = IDENTIFIER;
        debug("Returning type IDENTIFIER");
        return true;
    }

    debug("Returning false...");
    return false;
}
//------------------------------------------------------------------------------