/* =====================================
 * Generated by Mod-c 0.26.5
 * MODULE Lexer
 * ===================================== */

#include "Lexer.h"

void Lexer(TLexer* lexer, const char* source);

/**
 * Mod-c
 * By M. Scott Reynolds
 * Date 27 July 2026
 *
 * lexer.mc - Lexer/tokenizer for Mod-c source code
 * 27 July 2026 - Conversion to .mc started.
 */
#include "stdio.h"
#include "string.h"
#include "stddef.h"
#include "stdbool.h"
#include "ctype.h"
/**
 * Token kinds recognized by the TMod-c lexer.
 * Ordered roughly by category for readability.
 * Updated 28 March 2026 for grammar 0.6.2
 */
/**
 * Single token produced by the lexer.
 * Points into the original source buffer (no copying of text).
 * For TOK_ERROR, error_msg points to a static or pre-allocated error string.
 */
/**
 * Lexer state.
 * Non-owning pointer to source buffer; does not copy or modify it.
 */
typedef struct TKeywordTable TKeywordTable;
typedef struct TKeywordTable {
    const char* keyword;
    TokenKind kind;
} TKeywordTable;
static TKeywordTable keyword_table[] = {{"AND", TOK_KEYWORD_AND}, {"ARRAY", TOK_KEYWORD_ARRAY}, {"AS", TOK_KEYWORD_AS}, {"ASSERT", TOK_KEYWORD_ASSERT}, {"BEGIN", TOK_KEYWORD_BEGIN}, {"BREAK", TOK_KEYWORD_BREAK}, {"BY", TOK_KEYWORD_BY}, {"CASE", TOK_KEYWORD_CASE}, {"CAST", TOK_KEYWORD_CAST}, {"CONST", TOK_KEYWORD_CONST}, {"CONTINUE", TOK_KEYWORD_CONTINUE}, {"DEC", TOK_KEYWORD_DEC}, {"DEFAULT", TOK_KEYWORD_DEFAULT}, {"DEFER", TOK_KEYWORD_DEFER}, {"DEBUG", TOK_KEYWORD_DEBUG}, {"DIV", TOK_KEYWORD_DIV}, {"DO", TOK_KEYWORD_DO}, {"DOWNTO", TOK_KEYWORD_DOWNTO}, {"ELSE", TOK_KEYWORD_ELSE}, {"ELSIF", TOK_KEYWORD_ELSIF}, {"END", TOK_KEYWORD_END}, {"ENSURE", TOK_KEYWORD_ENSURE}, {"ENUM", TOK_KEYWORD_ENUM}, {"EXPORT", TOK_KEYWORD_EXPORT}, {"EXTENDS", TOK_KEYWORD_EXTENDS}, {"EXTERN", TOK_KEYWORD_EXTERN}, {"FOR", TOK_KEYWORD_FOR}, {"FORWARD", TOK_KEYWORD_FORWARD}, {"FROM", TOK_KEYWORD_FROM}, {"FUNCTION", TOK_KEYWORD_FUNCTION}, {"IF", TOK_KEYWORD_IF}, {"IMPORT", TOK_KEYWORD_IMPORT}, {"IN", TOK_KEYWORD_IN}, {"INC", TOK_KEYWORD_INC}, {"INVARIANT", TOK_KEYWORD_INVARIANT}, {"IS", TOK_KEYWORD_IS}, {"LEN", TOK_KEYWORD_LEN}, {"LET", TOK_KEYWORD_LET}, {"LOOP", TOK_KEYWORD_LOOP}, {"MOD", TOK_KEYWORD_MOD}, {"MODULE", TOK_KEYWORD_MODULE}, {"NOT", TOK_KEYWORD_NOT}, {"OF", TOK_KEYWORD_OF}, {"OPAQUE", TOK_KEYWORD_OPAQUE}, {"OR", TOK_KEYWORD_OR}, {"PACKED", TOK_KEYWORD_PACKED}, {"POINTER", TOK_KEYWORD_POINTER}, {"PROCEDURE", TOK_KEYWORD_PROCEDURE}, {"PROGRAM", TOK_KEYWORD_PROGRAM}, {"RECURSIVE", TOK_KEYWORD_RECURSIVE}, {"REF", TOK_KEYWORD_REF}, {"REPEAT", TOK_KEYWORD_REPEAT}, {"REQUIRE", TOK_KEYWORD_REQUIRE}, {"RETURN", TOK_KEYWORD_RETURN}, {"SIZEOF", TOK_KEYWORD_SIZEOF}, {"STATIC", TOK_KEYWORD_STATIC}, {"STRUCT", TOK_KEYWORD_STRUCT}, {"SWITCH", TOK_KEYWORD_SWITCH}, {"THEN", TOK_KEYWORD_THEN}, {"TO", TOK_KEYWORD_TO}, {"TYPE", TOK_KEYWORD_TYPE}, {"UNION", TOK_KEYWORD_UNION}, {"UNTIL", TOK_KEYWORD_UNTIL}, {"VAR", TOK_KEYWORD_VAR}, {"WHILE", TOK_KEYWORD_WHILE}, {"XOR", TOK_KEYWORD_XOR}};
/**
 * Initialize lexer state with source buffer.
 * Source must remain valid for the lifetime of the lexer.
 *
 * @param lexer 			Lexer state to initialize
 * @param source 			Null-terminated source code buffer.
 */
void TLexer__init(TLexer* lexer, const char* source);
/**
 * Get the next token from the source.
 * Advance internal position; returns TOK_EOF when exhausted.
 * Sets error_msg on TOK_ERROR.
 */
TToken TLexer__next(TLexer* lexer);
/**
 * Debug: return human-readable string for a TokenKind.
 */
const char* TokenKind__string(TokenKind k);
/**
 * Debug print a token (kind, location, text snippet).
 * For debugging and error reporting.
 */
void TToken__print(TToken* tok);
static int NUM_KEYWORDS(void)
{
    /* return value captured before defers */
    int __ret_l309 = (((integer)sizeof(keyword_table)) / ((integer)sizeof(keyword_table[0])));
    return __ret_l309;
}

static const size_t KEYWORD_MAX_LEN = 255;
static const size_t IDENT_MAX_LEN = 255;
typedef unsigned char uchar;
typedef const char* pcchar;
/**
 * Lookup keyword by case-insensitive comparison.
 * Keywords in table are UPPERCASE.
 * Returns TOK_IDENT if no match (preserves original case for identifiers).
 */
static TokenKind lookup_keyword(const char* start, size_t length)
{
    char upper_token[256] = {0};
    size_t i = {0};
    if (length == 0 || length > KEYWORD_MAX_LEN)
    {
        /* return value captured before defers */
        TokenKind __ret_l334 = TOK_IDENT;
        return __ret_l334;
    }
    {
        const long long __for_end_l337 = (long long)(length);
        for (i = 1; (long long)(i) <= __for_end_l337; i++)
        {
            {
                upper_token[i - 1] = (char)toupper((uchar)start[i - 1]);
            }
        }
    }
    upper_token[length] = '\0';
    {
        const long long __for_end_l342 = (long long)(NUM_KEYWORDS());
        for (i = 1; (long long)(i) <= __for_end_l342; i++)
        {
            {
                pcchar kw = (keyword_table[i - 1]).keyword;
                size_t kw_len = strlen(kw);
                if (length == kw_len && memcmp(upper_token, kw, length) == 0)
                {
                    /* return value captured before defers */
                    TokenKind __ret_l347 = (keyword_table[i - 1]).kind;
                    return __ret_l347;
                }
            }
        }
    }
    /* return value captured before defers */
    TokenKind __ret_l351 = TOK_IDENT;
    return __ret_l351;
}

/**
 * Advance offsets to the next character, updating line/column.
 */
static void advance(TLexer* l)
{
    if ((*((*l)).current) != '\0')
    {
        if ((*((*l)).current) == '\n')
        {
            ((*l)).line++;
            ((*l)).column = 1;
        }
        else
        {
            ((*l)).column++;
        }
        ((*l)).current++;
    }
}

/**
 * Peek at the current character (safe).
 */
static char peek(TLexer* l)
{
    /* return value captured before defers */
    char __ret_l377 = (*((*l)).current);
    return __ret_l377;
}

/**
 * Peek at the next character (safe at EOF).
 */
static char peek2(TLexer* l)
{
    if ((*((*l)).current) == '\0')
    {
        /* return value captured before defers */
        char __ret_l387 = '\0';
        return __ret_l387;
    }
    /* return value captured before defers */
    char __ret_l389 = ((*l)).current[1];
    return __ret_l389;
}

/**
 * Is character valid start of identifier?
 */
static bool is_ident_start(char c)
{
    /* return value captured before defers */
    bool __ret_l398 = isalpha((uchar)c) || c == '_';
    return __ret_l398;
}

/**
 * Is character valid inside identifier?
 */
static bool is_ident_char(char c)
{
    /* return value captured before defers */
    bool __ret_l407 = isalnum((uchar)c) || c == '_';
    return __ret_l407;
}

/**
 * Check for line continuation: \ followed by newline.
 */
static bool is_line_continuation(TLexer* l)
{
    /* return value captured before defers */
    bool __ret_l416 = peek(&(*l)) == '\\' && (peek2(&(*l)) == '\n' || peek2(&(*l)) == '\r');
    return __ret_l416;
}

/**
 * Match expected character and advance if it matches.
 */
static bool match(TLexer* l, char expected)
{
    if ((*((*l)).current) != expected)
    {
        /* return value captured before defers */
        bool __ret_l426 = false;
        return __ret_l426;
    }
    advance(&(*l));
    /* return value captured before defers */
    bool __ret_l430 = true;
    return __ret_l430;
}

/**
 * Create a zero-length token (used for single-char tokens).
 */
static TToken make_token(TLexer* l, TokenKind kind, pcchar start)
{
    TToken t = {0};
    (t).kind = kind;
    (t).start = start;
    (t).length = 0;
    (t).line = ((*l)).line;
    (t).column = ((*l)).column;
    /* return value captured before defers */
    TToken __ret_l445 = t;
    return __ret_l445;
}

/**
 * Create token with explicit length.
 */
static TToken make_token_len(TLexer* l, TokenKind kind, pcchar start, size_t length)
{
    TToken t = make_token(&(*l), kind, start);
    (t).length = length;
    /* return value captured before defers */
    TToken __ret_l456 = t;
    return __ret_l456;
}

/**
 * Create error token.
 */
static TToken error_token(TLexer* l, pcchar msg)
{
    TToken t = make_token(&(*l), TOK_ERROR, ((*l)).current);
    (t).error_msg = msg;
    /* return value captured before defers */
    TToken __ret_l467 = t;
    return __ret_l467;
}

/**
 * Initialize lexer state.
 */
void TLexer__init(TLexer* l, const char* source)
{
    assert(source != nil); /* precondition */
    ((*l)).start = source;
    ((*l)).current = source;
    ((*l)).line = 1;
    ((*l)).column = 1;
}

static const char SINGLE_QUOTE = "\'"[0];
static const char DOUBLE_QUOTE = "\""[0];
/**
 * Return the next token from source
 */
TToken TLexer__next(TLexer* l)
{
    while ((*((*l)).current) != '\0')
    {
        {
            if (is_line_continuation(&(*l)))
            {
                advance(&(*l));
                if (peek(&(*l)) == '\r')
                {
                    advance(&(*l));
                }
                advance(&(*l));
                                /* INVARIANT (on loop exit) */
                continue;
            }
            if (isspace((uchar)(*((*l)).current)) && (*((*l)).current) != '\n')
            {
                advance(&(*l));
                                /* INVARIANT (on loop exit) */
                continue;
            }
                        /* INVARIANT (on loop exit) */
            break;
        }
    }
    const char* start_l512_c11 = ((*l)).current;
    const char c_l513_c7 = (*((*l)).current);
    if (c_l513_c7 == '\0')
    {
        /* return value captured before defers */
        TToken __ret_l516 = make_token(&(*l), TOK_EOF, start_l512_c11);
        return __ret_l516;
    }
    if (c_l513_c7 == '\n')
    {
        advance(&(*l));
        /* return value captured before defers */
        TToken __ret_l522 = make_token(&(*l), TOK_NEWLINE, start_l512_c11);
        return __ret_l522;
    }
    if (c_l513_c7 == '#' && ((*l)).column == 1)
    {
        while ((*((*l)).current) != '\0' && (*((*l)).current) != '\n')
        {
            {
                if (is_line_continuation(&(*l)))
                {
                    advance(&(*l));
                                        /* INVARIANT (on loop exit) */
                    continue;
                }
                advance(&(*l));
            }
        }
        /* return value captured before defers */
        TToken __ret_l534 = make_token_len(&(*l), TOK_PREPROCESSOR, start_l512_c11, (size_t)(((*l)).current - start_l512_c11));
        return __ret_l534;
    }
    if (is_ident_start(c_l513_c7))
    {
        while (is_ident_char((*((*l)).current)))
        {
            {
                advance(&(*l));
            }
        }
        const size_t length_l543_c13 = (size_t)(((*l)).current - start_l512_c11);
        if (length_l543_c13 > IDENT_MAX_LEN)
        {
            TToken t = make_token_len(&(*l), TOK_ERROR, start_l512_c11, length_l543_c13);
            (t).error_msg = "identifier longer than 255 characters";
            /* return value captured before defers */
            TToken __ret_l547 = t;
            return __ret_l547;
        }
        /* return value captured before defers */
        TToken __ret_l549 = make_token_len(&(*l), lookup_keyword(start_l512_c11, length_l543_c13), start_l512_c11, length_l543_c13);
        return __ret_l549;
    }
    if (isdigit((uchar)c_l513_c7) || (c_l513_c7 == '0' && (peek2(&(*l)) == 'x' || peek2(&(*l)) == 'X' || peek2(&(*l)) == 'o' || peek2(&(*l)) == 'O' || peek2(&(*l)) == 'b' || peek2(&(*l)) == 'B')))
    {
        if (c_l513_c7 == '0' && (peek2(&(*l)) == 'x' || peek2(&(*l)) == 'X' || peek2(&(*l)) == 'o' || peek2(&(*l)) == 'O' || peek2(&(*l)) == 'b' || peek2(&(*l)) == 'B'))
        {
                        advance(&(*l));
            advance(&(*l));
        }
        while (isdigit((uchar)(*((*l)).current)) || (*((*l)).current) == '_' || (*((*l)).current) == '.' || (*((*l)).current) == 'u' || (*((*l)).current) == 'U' || (*((*l)).current) == 'l' || (*((*l)).current) == 'L' || ((*((*l)).current) >= 'a' && (*((*l)).current) <= 'f') || ((*((*l)).current) >= 'A' && (*((*l)).current) <= 'F'))
        {
            {
                advance(&(*l));
            }
        }
        /* return value captured before defers */
        TToken __ret_l574 = make_token_len(&(*l), TOK_NUMBER, start_l512_c11, (size_t)(((*l)).current - start_l512_c11));
        return __ret_l574;
    }
    if (c_l513_c7 == SINGLE_QUOTE)
    {
        advance(&(*l));
        if ((*((*l)).current) == '\0' || (*((*l)).current) == '\n')
        {
            /* return value captured before defers */
            TToken __ret_l581 = error_token(&(*l), "TLexer::next: Unterminated character literal.");
            return __ret_l581;
        }
        if ((*((*l)).current) == '\\')
        {
            advance(&(*l));
        }
        advance(&(*l));
        if (!match(&(*l), SINGLE_QUOTE))
        {
            /* return value captured before defers */
            TToken __ret_l586 = error_token(&(*l), "TLexer::next: Unterminated character literal.");
            return __ret_l586;
        }
        /* return value captured before defers */
        TToken __ret_l588 = make_token_len(&(*l), TOK_CHAR, start_l512_c11, (size_t)(((*l)).current - start_l512_c11));
        return __ret_l588;
    }
    if (c_l513_c7 == DOUBLE_QUOTE)
    {
        advance(&(*l));
        while ((*((*l)).current) != '\0' && (*((*l)).current) != DOUBLE_QUOTE)
        {
            {
                if ((*((*l)).current) == '\\' && peek2(&(*l)) == DOUBLE_QUOTE)
                {
                    advance(&(*l));
                }
                else if ((*((*l)).current) == '\\' && peek2(&(*l)) == '\\')
                {
                    advance(&(*l));
                }
                else if ((*((*l)).current) == '\n')
                {
                    /* return value captured before defers */
                    TToken __ret_l600 = error_token(&(*l), "TLexer::next: Unterminated string literal.");
                    return __ret_l600;
                }
                advance(&(*l));
            }
        }
        if ((*((*l)).current) != DOUBLE_QUOTE)
        {
            /* return value captured before defers */
            TToken __ret_l605 = error_token(&(*l), "TLexer::next: Unterminated string literal,");
            return __ret_l605;
        }
        advance(&(*l));
        /* return value captured before defers */
        TToken __ret_l608 = make_token_len(&(*l), TOK_STRING, start_l512_c11, (size_t)(((*l)).current - start_l512_c11));
        return __ret_l608;
    }
    if (c_l513_c7 == '/' && peek2(&(*l)) == '/')
    {
        advance(&(*l));
        advance(&(*l));
        while ((*((*l)).current) && (*((*l)).current) != '\n')
        {
            {
                advance(&(*l));
            }
        }
        /* return value captured before defers */
        TToken __ret_l618 = make_token_len(&(*l), TOK_COMMENT_SINGLE, start_l512_c11, (size_t)(((*l)).current - start_l512_c11));
        return __ret_l618;
    }
    if (c_l513_c7 == '/' && peek2(&(*l)) == '*')
    {
        advance(&(*l));
        advance(&(*l));
        const bool is_doc_l626_c13 = peek(&(*l)) == '*';
        while ((*((*l)).current) != '\0')
        {
            {
                if ((*((*l)).current) == '*' && peek2(&(*l)) == '/')
                {
                    advance(&(*l));
                    advance(&(*l));
                                        /* INVARIANT (on loop exit) */
                    break;
                }
                advance(&(*l));
            }
        }
        if ((*((*l)).current) == '\0')
        {
            /* return value captured before defers */
            TToken __ret_l637 = error_token(&(*l), "TLexer::next: Unterminated multi-line comment. /* */");
            return __ret_l637;
        }
        /* return value captured before defers */
        TToken __ret_l640 = make_token_len(&(*l), ((is_doc_l626_c13 ? TOK_DOC_COMMENT : TOK_COMMENT_MULTI)), start_l512_c11, (size_t)(((*l)).current - start_l512_c11));
        return __ret_l640;
    }
    if (c_l513_c7 == '(' && peek2(&(*l)) == '*')
    {
        integer nesting = {0};
        advance(&(*l));
        advance(&(*l));
        const bool is_doc_l650_c13 = peek(&(*l)) == '*';
        nesting = 1;
        while ((*((*l)).current) != '\0' && nesting > 0)
        {
            {
                if ((*((*l)).current) == '(' && peek2(&(*l)) == '*')
                {
                    nesting++;
                    advance(&(*l));
                    advance(&(*l));
                                        /* INVARIANT (on loop exit) */
                    continue;
                }
                if ((*((*l)).current) == '*' && peek2(&(*l)) == ')')
                {
                    nesting--;
                    advance(&(*l));
                    advance(&(*l));
                                        /* INVARIANT (on loop exit) */
                    continue;
                }
                advance(&(*l));
            }
        }
        if (nesting > 0)
        {
            /* return value captured before defers */
            TToken __ret_l669 = error_token(&(*l), "TLexer::next: Unterminated Pascal-style comment (* *)");
            return __ret_l669;
        }
        /* return value captured before defers */
        TToken __ret_l671 = make_token_len(&(*l), ((is_doc_l650_c13 ? TOK_DOC_COMMENT : TOK_COMMENT_PASCAL)), start_l512_c11, (size_t)(((*l)).current - start_l512_c11));
        return __ret_l671;
    }
    switch (c_l513_c7)
    {
        case '(':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l677 = make_token_len(&(*l), TOK_LPAREN, start_l512_c11, 1);
            return __ret_l677;
        }
        break;
        case ')':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l678 = make_token_len(&(*l), TOK_RPAREN, start_l512_c11, 1);
            return __ret_l678;
        }
        break;
        case '{':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l679 = make_token_len(&(*l), TOK_LBRACE, start_l512_c11, 1);
            return __ret_l679;
        }
        break;
        case '}':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l680 = make_token_len(&(*l), TOK_RBRACE, start_l512_c11, 1);
            return __ret_l680;
        }
        break;
        case '[':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l681 = make_token_len(&(*l), TOK_LBRACKET, start_l512_c11, 1);
            return __ret_l681;
        }
        break;
        case ']':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l682 = make_token_len(&(*l), TOK_RBRACKET, start_l512_c11, 1);
            return __ret_l682;
        }
        break;
        case ';':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l683 = make_token_len(&(*l), TOK_SEMICOLON, start_l512_c11, 1);
            return __ret_l683;
        }
        break;
        case ',':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l684 = make_token_len(&(*l), TOK_COMMA, start_l512_c11, 1);
            return __ret_l684;
        }
        break;
        case '+':
        {
            advance(&(*l));
            if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l688 = make_token_len(&(*l), TOK_ADD_EQ, start_l512_c11, 2);
                return __ret_l688;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l690 = make_token_len(&(*l), TOK_ADD, start_l512_c11, 1);
                return __ret_l690;
            }
        }
        break;
        case '-':
        {
            advance(&(*l));
            if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l695 = make_token_len(&(*l), TOK_SUB_EQ, start_l512_c11, 2);
                return __ret_l695;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l697 = make_token_len(&(*l), TOK_SUB, start_l512_c11, 1);
                return __ret_l697;
            }
        }
        break;
        case '*':
        {
            advance(&(*l));
            if (match(&(*l), '*'))
            {
                /* return value captured before defers */
                TToken __ret_l701 = make_token_len(&(*l), TOK_POWER, start_l512_c11, 2);
                return __ret_l701;
            }
            if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l702 = make_token_len(&(*l), TOK_MUL_EQ, start_l512_c11, 2);
                return __ret_l702;
            }
            /* return value captured before defers */
            TToken __ret_l703 = make_token_len(&(*l), TOK_MUL, start_l512_c11, 1);
            return __ret_l703;
        }
        break;
        case '/':
        {
            advance(&(*l));
            if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l707 = make_token_len(&(*l), TOK_DIV_EQ, start_l512_c11, 2);
                return __ret_l707;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l709 = make_token_len(&(*l), TOK_DIV, start_l512_c11, 1);
                return __ret_l709;
            }
        }
        break;
        case '%':
        {
            advance(&(*l));
            if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l714 = make_token_len(&(*l), TOK_MOD_EQ, start_l512_c11, 2);
                return __ret_l714;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l716 = make_token_len(&(*l), TOK_MOD, start_l512_c11, 1);
                return __ret_l716;
            }
        }
        break;
        case '=':
        {
            advance(&(*l));
            if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l721 = make_token_len(&(*l), TOK_EQ_EQ, start_l512_c11, 2);
                return __ret_l721;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l723 = make_token_len(&(*l), TOK_EQ, start_l512_c11, 1);
                return __ret_l723;
            }
        }
        break;
        case '!':
        {
            advance(&(*l));
            if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l728 = make_token_len(&(*l), TOK_NOT_EQ, start_l512_c11, 2);
                return __ret_l728;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l730 = make_token_len(&(*l), TOK_NOT, start_l512_c11, 1);
                return __ret_l730;
            }
        }
        break;
        case '<':
        {
            advance(&(*l));
            if (match(&(*l), '<'))
            {
                if (match(&(*l), '='))
                {
                    /* return value captured before defers */
                    TToken __ret_l736 = make_token_len(&(*l), TOK_LSHIFT_EQ, start_l512_c11, 3);
                    return __ret_l736;
                }
                else
                {
                    /* return value captured before defers */
                    TToken __ret_l738 = make_token_len(&(*l), TOK_BITWISE_LSHIFT, start_l512_c11, 2);
                    return __ret_l738;
                }
            }
            else if (match(&(*l), '>'))
            {
                /* return value captured before defers */
                TToken __ret_l741 = make_token_len(&(*l), TOK_NOT_EQ, start_l512_c11, 2);
                return __ret_l741;
            }
            else if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l743 = make_token_len(&(*l), TOK_LESS_EQ, start_l512_c11, 2);
                return __ret_l743;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l745 = make_token_len(&(*l), TOK_LESS, start_l512_c11, 1);
                return __ret_l745;
            }
        }
        break;
        case '>':
        {
            advance(&(*l));
            if (match(&(*l), '>'))
            {
                if (match(&(*l), '='))
                {
                    /* return value captured before defers */
                    TToken __ret_l751 = make_token_len(&(*l), TOK_RSHIFT_EQ, start_l512_c11, 3);
                    return __ret_l751;
                }
                else
                {
                    /* return value captured before defers */
                    TToken __ret_l753 = make_token_len(&(*l), TOK_BITWISE_RSHIFT, start_l512_c11, 2);
                    return __ret_l753;
                }
            }
            else if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l756 = make_token_len(&(*l), TOK_GREATER_EQ, start_l512_c11, 2);
                return __ret_l756;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l758 = make_token_len(&(*l), TOK_GREATER, start_l512_c11, 1);
                return __ret_l758;
            }
        }
        break;
        case ':':
        {
            advance(&(*l));
            if (match(&(*l), ':'))
            {
                /* return value captured before defers */
                TToken __ret_l763 = make_token_len(&(*l), TOK_COLON_COLON, start_l512_c11, 2);
                return __ret_l763;
            }
            else if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l765 = make_token_len(&(*l), TOK_COLON_EQ, start_l512_c11, 2);
                return __ret_l765;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l767 = make_token_len(&(*l), TOK_COLON, start_l512_c11, 1);
                return __ret_l767;
            }
        }
        break;
        case '.':
        {
            advance(&(*l));
            if (match(&(*l), '.'))
            {
                if (match(&(*l), '.'))
                {
                    /* return value captured before defers */
                    TToken __ret_l773 = make_token_len(&(*l), TOK_DOT_DOT_DOT, start_l512_c11, 3);
                    return __ret_l773;
                }
                else
                {
                    /* return value captured before defers */
                    TToken __ret_l775 = make_token_len(&(*l), TOK_DOT_DOT, start_l512_c11, 2);
                    return __ret_l775;
                }
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l778 = make_token_len(&(*l), TOK_DOT, start_l512_c11, 1);
                return __ret_l778;
            }
        }
        break;
        case '&':
        {
            advance(&(*l));
            if (match(&(*l), '&'))
            {
                /* return value captured before defers */
                TToken __ret_l783 = make_token_len(&(*l), TOK_KEYWORD_AND, start_l512_c11, 2);
                return __ret_l783;
            }
            else if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l785 = make_token_len(&(*l), TOK_AND_EQ, start_l512_c11, 2);
                return __ret_l785;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l787 = make_token_len(&(*l), TOK_BITWISE_AND, start_l512_c11, 1);
                return __ret_l787;
            }
        }
        break;
        case '|':
        {
            advance(&(*l));
            if (match(&(*l), '|'))
            {
                /* return value captured before defers */
                TToken __ret_l792 = make_token_len(&(*l), TOK_KEYWORD_OR, start_l512_c11, 2);
                return __ret_l792;
            }
            else if (match(&(*l), '='))
            {
                /* return value captured before defers */
                TToken __ret_l794 = make_token_len(&(*l), TOK_OR_EQ, start_l512_c11, 2);
                return __ret_l794;
            }
            else
            {
                /* return value captured before defers */
                TToken __ret_l796 = make_token_len(&(*l), TOK_BITWISE_OR, start_l512_c11, 1);
                return __ret_l796;
            }
        }
        break;
        case '^':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l798 = make_token_len(&(*l), TOK_CARET, start_l512_c11, 1);
            return __ret_l798;
        }
        break;
        case '~':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l799 = make_token_len(&(*l), TOK_BITWISE_NOT, start_l512_c11, 1);
            return __ret_l799;
        }
        break;
        case '?':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l800 = make_token_len(&(*l), TOK_QUESTION, start_l512_c11, 1);
            return __ret_l800;
        }
        break;
        case '@':
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l801 = make_token_len(&(*l), TOK_AT, start_l512_c11, 1);
            return __ret_l801;
        }
        break;
        default:
        {
            advance(&(*l));
            /* return value captured before defers */
            TToken __ret_l805 = error_token(&(*l), "TLexer::next: Unexpected character");
            return __ret_l805;
        }
        break;
    }
}

/**
 * Return human-readable string for TokenKind.
 */
const char* TokenKind__string(const TokenKind k)
{
    switch (k)
    {
        case TOK_EOF:
        {
            /* return value captured before defers */
            const char* __ret_l816 = "EOF";
            return __ret_l816;
        }
        break;
        case TOK_IDENT:
        {
            /* return value captured before defers */
            const char* __ret_l817 = "IDENT";
            return __ret_l817;
        }
        break;
        case TOK_NUMBER:
        {
            /* return value captured before defers */
            const char* __ret_l818 = "NUMBER";
            return __ret_l818;
        }
        break;
        case TOK_REAL:
        {
            /* return value captured before defers */
            const char* __ret_l819 = "REAL";
            return __ret_l819;
        }
        break;
        case TOK_CHAR:
        {
            /* return value captured before defers */
            const char* __ret_l820 = "CHAR";
            return __ret_l820;
        }
        break;
        case TOK_STRING:
        {
            /* return value captured before defers */
            const char* __ret_l821 = "STRING";
            return __ret_l821;
        }
        break;
        case TOK_PREPROCESSOR:
        {
            /* return value captured before defers */
            const char* __ret_l822 = "PREPROC";
            return __ret_l822;
        }
        break;
        case TOK_COMMENT:
        {
            /* return value captured before defers */
            const char* __ret_l823 = "COMMENT";
            return __ret_l823;
        }
        break;
        case TOK_COMMENT_SINGLE:
        {
            /* return value captured before defers */
            const char* __ret_l824 = "// COMMENT";
            return __ret_l824;
        }
        break;
        case TOK_COMMENT_MULTI:
        {
            /* return value captured before defers */
            const char* __ret_l825 = "/* COMMENT */";
            return __ret_l825;
        }
        break;
        case TOK_COMMENT_PASCAL:
        {
            /* return value captured before defers */
            const char* __ret_l826 = "(* COMMENT *)";
            return __ret_l826;
        }
        break;
        case TOK_DOC_COMMENT:
        {
            /* return value captured before defers */
            const char* __ret_l827 = "/** DOC COMMENT */";
            return __ret_l827;
        }
        break;
        case TOK_NEWLINE:
        {
            /* return value captured before defers */
            const char* __ret_l828 = "NEWLINE";
            return __ret_l828;
        }
        break;
        case TOK_SEMICOLON:
        {
            /* return value captured before defers */
            const char* __ret_l829 = ";";
            return __ret_l829;
        }
        break;
        case TOK_COLON:
        {
            /* return value captured before defers */
            const char* __ret_l830 = ":";
            return __ret_l830;
        }
        break;
        case TOK_COLON_COLON:
        {
            /* return value captured before defers */
            const char* __ret_l831 = "::";
            return __ret_l831;
        }
        break;
        case TOK_COLON_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l832 = ":=";
            return __ret_l832;
        }
        break;
        case TOK_COMMA:
        {
            /* return value captured before defers */
            const char* __ret_l833 = ",";
            return __ret_l833;
        }
        break;
        case TOK_LPAREN:
        {
            /* return value captured before defers */
            const char* __ret_l834 = "(";
            return __ret_l834;
        }
        break;
        case TOK_RPAREN:
        {
            /* return value captured before defers */
            const char* __ret_l835 = ")";
            return __ret_l835;
        }
        break;
        case TOK_LBRACKET:
        {
            /* return value captured before defers */
            const char* __ret_l836 = "[";
            return __ret_l836;
        }
        break;
        case TOK_RBRACKET:
        {
            /* return value captured before defers */
            const char* __ret_l837 = "]";
            return __ret_l837;
        }
        break;
        case TOK_LBRACE:
        {
            /* return value captured before defers */
            const char* __ret_l838 = "{";
            return __ret_l838;
        }
        break;
        case TOK_RBRACE:
        {
            /* return value captured before defers */
            const char* __ret_l839 = "}";
            return __ret_l839;
        }
        break;
        case TOK_QUESTION:
        {
            /* return value captured before defers */
            const char* __ret_l840 = "?";
            return __ret_l840;
        }
        break;
        case TOK_ADD:
        {
            /* return value captured before defers */
            const char* __ret_l841 = "+";
            return __ret_l841;
        }
        break;
        case TOK_SUB:
        {
            /* return value captured before defers */
            const char* __ret_l842 = "-";
            return __ret_l842;
        }
        break;
        case TOK_MUL:
        {
            /* return value captured before defers */
            const char* __ret_l843 = "*";
            return __ret_l843;
        }
        break;
        case TOK_DIV:
        {
            /* return value captured before defers */
            const char* __ret_l844 = "/";
            return __ret_l844;
        }
        break;
        case TOK_MOD:
        {
            /* return value captured before defers */
            const char* __ret_l845 = "%";
            return __ret_l845;
        }
        break;
        case TOK_CARET:
        {
            /* return value captured before defers */
            const char* __ret_l846 = "^";
            return __ret_l846;
        }
        break;
        case TOK_AT:
        {
            /* return value captured before defers */
            const char* __ret_l847 = "@";
            return __ret_l847;
        }
        break;
        case TOK_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l848 = "=";
            return __ret_l848;
        }
        break;
        case TOK_EQ_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l849 = "==";
            return __ret_l849;
        }
        break;
        case TOK_LESS_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l850 = "<=";
            return __ret_l850;
        }
        break;
        case TOK_LESS:
        {
            /* return value captured before defers */
            const char* __ret_l851 = "<";
            return __ret_l851;
        }
        break;
        case TOK_GREATER_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l852 = ">=";
            return __ret_l852;
        }
        break;
        case TOK_GREATER:
        {
            /* return value captured before defers */
            const char* __ret_l853 = ">";
            return __ret_l853;
        }
        break;
        case TOK_NOT_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l854 = "!=";
            return __ret_l854;
        }
        break;
        case TOK_DOT:
        {
            /* return value captured before defers */
            const char* __ret_l855 = ".";
            return __ret_l855;
        }
        break;
        case TOK_DOT_DOT:
        {
            /* return value captured before defers */
            const char* __ret_l856 = "..";
            return __ret_l856;
        }
        break;
        case TOK_DOT_DOT_DOT:
        {
            /* return value captured before defers */
            const char* __ret_l857 = "...";
            return __ret_l857;
        }
        break;
        case TOK_NOT:
        {
            /* return value captured before defers */
            const char* __ret_l858 = "!";
            return __ret_l858;
        }
        break;
        case TOK_POWER:
        {
            /* return value captured before defers */
            const char* __ret_l859 = "**";
            return __ret_l859;
        }
        break;
        case TOK_MUL_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l860 = "*=";
            return __ret_l860;
        }
        break;
        case TOK_DIV_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l861 = "/=";
            return __ret_l861;
        }
        break;
        case TOK_MOD_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l862 = "%=";
            return __ret_l862;
        }
        break;
        case TOK_ADD_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l863 = "+=";
            return __ret_l863;
        }
        break;
        case TOK_SUB_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l864 = "-=";
            return __ret_l864;
        }
        break;
        case TOK_LSHIFT_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l865 = "<<=";
            return __ret_l865;
        }
        break;
        case TOK_RSHIFT_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l866 = ">>=";
            return __ret_l866;
        }
        break;
        case TOK_AND_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l867 = "&=";
            return __ret_l867;
        }
        break;
        case TOK_OR_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l868 = "|=";
            return __ret_l868;
        }
        break;
        case TOK_BITWISE_NOT_EQ:
        {
            /* return value captured before defers */
            const char* __ret_l869 = "~|";
            return __ret_l869;
        }
        break;
        case TOK_KEYWORD_BEGIN:
        {
            /* return value captured before defers */
            const char* __ret_l870 = "BEGIN";
            return __ret_l870;
        }
        break;
        case TOK_KEYWORD_END:
        {
            /* return value captured before defers */
            const char* __ret_l871 = "END";
            return __ret_l871;
        }
        break;
        case TOK_KEYWORD_IF:
        {
            /* return value captured before defers */
            const char* __ret_l872 = "IF";
            return __ret_l872;
        }
        break;
        case TOK_KEYWORD_THEN:
        {
            /* return value captured before defers */
            const char* __ret_l873 = "THEN";
            return __ret_l873;
        }
        break;
        case TOK_KEYWORD_ELSE:
        {
            /* return value captured before defers */
            const char* __ret_l874 = "ELSE";
            return __ret_l874;
        }
        break;
        case TOK_KEYWORD_ELSIF:
        {
            /* return value captured before defers */
            const char* __ret_l875 = "ELSIF";
            return __ret_l875;
        }
        break;
        case TOK_KEYWORD_FOR:
        {
            /* return value captured before defers */
            const char* __ret_l876 = "FOR";
            return __ret_l876;
        }
        break;
        case TOK_KEYWORD_TO:
        {
            /* return value captured before defers */
            const char* __ret_l877 = "TO";
            return __ret_l877;
        }
        break;
        case TOK_KEYWORD_BY:
        {
            /* return value captured before defers */
            const char* __ret_l878 = "BY";
            return __ret_l878;
        }
        break;
        case TOK_KEYWORD_DO:
        {
            /* return value captured before defers */
            const char* __ret_l879 = "DO";
            return __ret_l879;
        }
        break;
        case TOK_KEYWORD_DOWNTO:
        {
            /* return value captured before defers */
            const char* __ret_l880 = "DOWNTO";
            return __ret_l880;
        }
        break;
        case TOK_KEYWORD_PROGRAM:
        {
            /* return value captured before defers */
            const char* __ret_l881 = "PROGRAM";
            return __ret_l881;
        }
        break;
        case TOK_KEYWORD_MODULE:
        {
            /* return value captured before defers */
            const char* __ret_l882 = "MODULE";
            return __ret_l882;
        }
        break;
        case TOK_KEYWORD_HEADER:
        {
            /* return value captured before defers */
            const char* __ret_l883 = "HEADER";
            return __ret_l883;
        }
        break;
        case TOK_KEYWORD_IMPORT:
        {
            /* return value captured before defers */
            const char* __ret_l884 = "IMPORT";
            return __ret_l884;
        }
        break;
        case TOK_KEYWORD_FROM:
        {
            /* return value captured before defers */
            const char* __ret_l885 = "FROM";
            return __ret_l885;
        }
        break;
        case TOK_KEYWORD_PROCEDURE:
        {
            /* return value captured before defers */
            const char* __ret_l886 = "PROCEDURE";
            return __ret_l886;
        }
        break;
        case TOK_KEYWORD_FUNCTION:
        {
            /* return value captured before defers */
            const char* __ret_l887 = "FUNCTION";
            return __ret_l887;
        }
        break;
        case TOK_KEYWORD_FORWARD:
        {
            /* return value captured before defers */
            const char* __ret_l888 = "FORWARD";
            return __ret_l888;
        }
        break;
        case TOK_KEYWORD_EXPORT:
        {
            /* return value captured before defers */
            const char* __ret_l889 = "EXPORT";
            return __ret_l889;
        }
        break;
        case TOK_KEYWORD_VAR:
        {
            /* return value captured before defers */
            const char* __ret_l890 = "VAR";
            return __ret_l890;
        }
        break;
        case TOK_KEYWORD_LEN:
        {
            /* return value captured before defers */
            const char* __ret_l891 = "LEN";
            return __ret_l891;
        }
        break;
        case TOK_KEYWORD_LET:
        {
            /* return value captured before defers */
            const char* __ret_l892 = "LET";
            return __ret_l892;
        }
        break;
        case TOK_KEYWORD_CONST:
        {
            /* return value captured before defers */
            const char* __ret_l893 = "CONST";
            return __ret_l893;
        }
        break;
        case TOK_KEYWORD_WHILE:
        {
            /* return value captured before defers */
            const char* __ret_l894 = "WHILE";
            return __ret_l894;
        }
        break;
        case TOK_KEYWORD_LOOP:
        {
            /* return value captured before defers */
            const char* __ret_l895 = "LOOP";
            return __ret_l895;
        }
        break;
        case TOK_KEYWORD_REPEAT:
        {
            /* return value captured before defers */
            const char* __ret_l896 = "REPEAT";
            return __ret_l896;
        }
        break;
        case TOK_KEYWORD_UNTIL:
        {
            /* return value captured before defers */
            const char* __ret_l897 = "UNTIL";
            return __ret_l897;
        }
        break;
        case TOK_KEYWORD_INC:
        {
            /* return value captured before defers */
            const char* __ret_l898 = "INC";
            return __ret_l898;
        }
        break;
        case TOK_KEYWORD_DEC:
        {
            /* return value captured before defers */
            const char* __ret_l899 = "DEC";
            return __ret_l899;
        }
        break;
        case TOK_KEYWORD_TYPE:
        {
            /* return value captured before defers */
            const char* __ret_l900 = "TYPE";
            return __ret_l900;
        }
        break;
        case TOK_KEYWORD_AS:
        {
            /* return value captured before defers */
            const char* __ret_l901 = "AS";
            return __ret_l901;
        }
        break;
        case TOK_KEYWORD_CAST:
        {
            /* return value captured before defers */
            const char* __ret_l902 = "CAST";
            return __ret_l902;
        }
        break;
        case TOK_KEYWORD_DIV:
        {
            /* return value captured before defers */
            const char* __ret_l903 = "DIV";
            return __ret_l903;
        }
        break;
        case TOK_KEYWORD_MOD:
        {
            /* return value captured before defers */
            const char* __ret_l904 = "MOD";
            return __ret_l904;
        }
        break;
        case TOK_KEYWORD_XOR:
        {
            /* return value captured before defers */
            const char* __ret_l905 = "XOR";
            return __ret_l905;
        }
        break;
        case TOK_KEYWORD_AND:
        {
            /* return value captured before defers */
            const char* __ret_l906 = "AND";
            return __ret_l906;
        }
        break;
        case TOK_KEYWORD_OF:
        {
            /* return value captured before defers */
            const char* __ret_l907 = "OF";
            return __ret_l907;
        }
        break;
        case TOK_KEYWORD_OR:
        {
            /* return value captured before defers */
            const char* __ret_l908 = "OR";
            return __ret_l908;
        }
        break;
        case TOK_KEYWORD_NOT:
        {
            /* return value captured before defers */
            const char* __ret_l909 = "NOT";
            return __ret_l909;
        }
        break;
        case TOK_KEYWORD_REQUIRE:
        {
            /* return value captured before defers */
            const char* __ret_l910 = "REQUIRE";
            return __ret_l910;
        }
        break;
        case TOK_KEYWORD_ENSURE:
        {
            /* return value captured before defers */
            const char* __ret_l911 = "ENSURE";
            return __ret_l911;
        }
        break;
        case TOK_KEYWORD_INVARIANT:
        {
            /* return value captured before defers */
            const char* __ret_l912 = "INVARIANT";
            return __ret_l912;
        }
        break;
        case TOK_KEYWORD_SWITCH:
        {
            /* return value captured before defers */
            const char* __ret_l913 = "SWITCH";
            return __ret_l913;
        }
        break;
        case TOK_KEYWORD_CASE:
        {
            /* return value captured before defers */
            const char* __ret_l914 = "CASE";
            return __ret_l914;
        }
        break;
        case TOK_KEYWORD_DEFAULT:
        {
            /* return value captured before defers */
            const char* __ret_l915 = "DEFAULT";
            return __ret_l915;
        }
        break;
        case TOK_KEYWORD_BREAK:
        {
            /* return value captured before defers */
            const char* __ret_l916 = "BREAK";
            return __ret_l916;
        }
        break;
        case TOK_KEYWORD_CONTINUE:
        {
            /* return value captured before defers */
            const char* __ret_l917 = "CONTINUE";
            return __ret_l917;
        }
        break;
        case TOK_KEYWORD_RETURN:
        {
            /* return value captured before defers */
            const char* __ret_l918 = "RETURN";
            return __ret_l918;
        }
        break;
        case TOK_KEYWORD_DEFER:
        {
            /* return value captured before defers */
            const char* __ret_l919 = "DEFER";
            return __ret_l919;
        }
        break;
        case TOK_KEYWORD_DEBUG:
        {
            /* return value captured before defers */
            const char* __ret_l920 = "DEBUG";
            return __ret_l920;
        }
        break;
        case TOK_KEYWORD_RECURSIVE:
        {
            /* return value captured before defers */
            const char* __ret_l921 = "RECURSIVE";
            return __ret_l921;
        }
        break;
        case TOK_KEYWORD_STRUCT:
        {
            /* return value captured before defers */
            const char* __ret_l922 = "STRUCT";
            return __ret_l922;
        }
        break;
        case TOK_KEYWORD_EXTENDS:
        {
            /* return value captured before defers */
            const char* __ret_l923 = "EXTENDS";
            return __ret_l923;
        }
        break;
        case TOK_KEYWORD_ARRAY:
        {
            /* return value captured before defers */
            const char* __ret_l926 = "ARRAY";
            return __ret_l926;
        }
        break;
        case TOK_KEYWORD_POINTER:
        {
            /* return value captured before defers */
            const char* __ret_l927 = "POINTER";
            return __ret_l927;
        }
        break;
        case TOK_KEYWORD_OPAQUE:
        {
            /* return value captured before defers */
            const char* __ret_l928 = "OPAQUE";
            return __ret_l928;
        }
        break;
        case TOK_KEYWORD_REF:
        {
            /* return value captured before defers */
            const char* __ret_l929 = "REF";
            return __ret_l929;
        }
        break;
        case TOK_KEYWORD_IN:
        {
            /* return value captured before defers */
            const char* __ret_l930 = "IN";
            return __ret_l930;
        }
        break;
        case TOK_KEYWORD_IS:
        {
            /* return value captured before defers */
            const char* __ret_l931 = "IS";
            return __ret_l931;
        }
        break;
        case TOK_KEYWORD_ENUM:
        {
            /* return value captured before defers */
            const char* __ret_l932 = "ENUM";
            return __ret_l932;
        }
        break;
        case TOK_KEYWORD_ASSERT:
        {
            /* return value captured before defers */
            const char* __ret_l933 = "ASSERT";
            return __ret_l933;
        }
        break;
        case TOK_KEYWORD_SIZEOF:
        {
            /* return value captured before defers */
            const char* __ret_l934 = "SIZEOF";
            return __ret_l934;
        }
        break;
        case TOK_KEYWORD_EXTERN:
        {
            /* return value captured before defers */
            const char* __ret_l935 = "EXTERN";
            return __ret_l935;
        }
        break;
        case TOK_KEYWORD_STATIC:
        {
            /* return value captured before defers */
            const char* __ret_l936 = "STATIC";
            return __ret_l936;
        }
        break;
        case TOK_KEYWORD_PACKED:
        {
            /* return value captured before defers */
            const char* __ret_l937 = "PACKED";
            return __ret_l937;
        }
        break;
        case TOK_BITWISE_AND:
        {
            /* return value captured before defers */
            const char* __ret_l938 = "&";
            return __ret_l938;
        }
        break;
        case TOK_BITWISE_OR:
        {
            /* return value captured before defers */
            const char* __ret_l939 = "|";
            return __ret_l939;
        }
        break;
        case TOK_BITWISE_NOT:
        {
            /* return value captured before defers */
            const char* __ret_l940 = "~";
            return __ret_l940;
        }
        break;
        case TOK_BITWISE_LSHIFT:
        {
            /* return value captured before defers */
            const char* __ret_l941 = "<<";
            return __ret_l941;
        }
        break;
        case TOK_BITWISE_RSHIFT:
        {
            /* return value captured before defers */
            const char* __ret_l942 = ">>";
            return __ret_l942;
        }
        break;
        case TOK_ERROR:
        {
            /* return value captured before defers */
            const char* __ret_l943 = "ERROR";
            return __ret_l943;
        }
        break;
        default:
        {
            /* return value captured before defers */
            const char* __ret_l944 = "UNKNOWN";
            return __ret_l944;
        }
        break;
    }
}

/**
 * Print token info.
 */
void TToken__print(TToken* t)
{
    const char* kind_name_l959_c15 = TokenKind__string(((*t)).kind);
    printf("Token { kind: '%-12s', line: %3d, column: %3d, ", kind_name_l959_c15, ((*t)).line, ((*t)).column);
    if (((*t)).length > 0 && ((*t)).start != nil)
    {
        printf("text: '%.*s', ", (int)((*t)).length, ((*t)).start);
    }
    else
    {
        printf("text: %s, ", "''");
    }
    if (((*t)).kind == TOK_ERROR && ((*t)).error_msg != nil)
    {
        printf("\terror_msg: '%s', ", ((*t)).error_msg);
    }
    else
    {
        printf("\terror_msg: '', ");
    }
    printf(" }, \n");
}


void Lexer(TLexer* lexer, const char* source)
{
    TLexer__init(&(*lexer), source);
}
