/* * TinyBlocks - tinyblocks-toml * lexeme.h: tipos de token e lexer de TOML. */ #ifndef TB_TOML_LEXEME_H #define TB_TOML_LEXEME_H #include #include #ifdef __cplusplus extern "C" { #endif typedef enum { TL_EOF = 0, TL_ERROR, TL_NEWLINE, TL_LBRACKET, /* [ */ TL_RBRACKET, /* ] */ TL_LBRACE, /* { */ TL_RBRACE, /* } */ TL_EQUALS, /* = */ TL_COMMA, /* , */ TL_DOT, /* . */ TL_BARE, /* chave simples */ TL_STRING, /* string (basica/literal) */ TL_INTEGER, TL_FLOAT, TL_BOOL, TL_DATETIME } TomlLexKind; typedef struct { TomlLexKind kind; const char* start; /* inicio no fonte (nao NUL-terminado) */ size_t len; /* tamanho no fonte */ int line, col; char* text; /* string decodificada (TL_STRING), malloc */ long long ival; double fval; bool bval; } Lexeme; typedef struct { Lexeme* items; size_t count, cap; } LexemeList; typedef struct { bool ok; char msg[256]; int line, col; } TomlLexError; /* Tokeniza o texto inteiro. Em erro retorna false e preenche *err. */ bool toml_lex(const char* src, LexemeList* out, TomlLexError* err); /* Libera a lista e os textos decodificados */ void toml_lexemes_free(LexemeList* list); const char* toml_lexeme_kind_name(TomlLexKind kind); #ifdef __cplusplus } #endif #endif /* TB_TOML_LEXEME_H */