/* * TinyBlocks - tinyblocks-json / include/lexeme.h * Lexer de JSON: transforma o texto em uma lista de lexemas. */ #ifndef TB_JSON_LEXEME_H #define TB_JSON_LEXEME_H #include #include typedef enum { JL_EOF, JL_ERROR, JL_LBRACE, JL_RBRACE, JL_LBRACKET, JL_RBRACKET, JL_COLON, JL_COMMA, JL_STRING, JL_NUMBER, JL_TRUE, JL_FALSE, JL_NULL } JsonLexKind; typedef struct { JsonLexKind kind; const char* start; /* inicio no texto original */ size_t len; int line, col; char* text; /* string decodificada (JL_STRING) */ bool is_int; long long ival; double num; } JsonLexeme; typedef struct { JsonLexeme* items; size_t count, cap; } JsonLexemeList; typedef struct { bool ok; char msg[128]; int line, col; } JsonLexError; /* Tokeniza 'src'; em sucesso devolve true e preenche 'out'. */ bool json_lex(const char* src, JsonLexemeList* out, JsonLexError* err); void json_lexemes_free(JsonLexemeList* l); const char* json_lexeme_name(JsonLexKind k); #endif /* TB_JSON_LEXEME_H */