Adiciona tinyblocks-blueprint e libraries json/xml/csv; abrir/salvar/exportar projeto
- tinyblocks-blueprint: dona do estado de edicao (abas, pool de blocos, vinculos parent/prel/next/sub/args, blocos compostos e variaveis) e da serializacao. JSON nativo (to/from) usando a AST JSON do core e export JSON/XML/CSV. Testado com round-trip (test-blueprint). - tinyblocks-json: lexer + parser + emissor JSON independentes. - tinyblocks-xml: lexer + parser de XML -> AST JSON do core + emissor. - tinyblocks-csv: divisor de linhas/campos + parser/emissor sobre a AST JSON. - Editor: botoes Abrir / Salvar / Exportar JSON XML CSV no menu; converte Ed <-> TbBlueprint; barra de caminho com modo; .json pode ser arrastado. - Variaveis: tb_variables_clear e tb_variables_set_text. - Harness: teste de salvar/abrir projeto; tests/blueprint_test.c.
This commit is contained in:
1 parent
dc23b92d15
commit
1199d2d7c7
39 files changed
+3462
-24
No files matched your search
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* TinyBlocks - tinyblocks-json / include/ast.h
|
||||
* Arvore de valores JSON e API de parse/construcao/emissao.
|
||||
*/
|
||||
#ifndef TB_JSON_AST_H
|
||||
#define TB_JSON_AST_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "lexeme.h"
|
||||
|
||||
typedef enum {
|
||||
JSON_NULL, JSON_BOOL, JSON_INT, JSON_REAL, JSON_STR, JSON_ARR, JSON_OBJ
|
||||
} JsonKind;
|
||||
|
||||
typedef struct JsonValue JsonValue;
|
||||
struct JsonValue {
|
||||
JsonKind kind;
|
||||
bool bval;
|
||||
long long ival;
|
||||
double fval;
|
||||
char* str; /* JSON_STR */
|
||||
JsonValue** items; /* JSON_ARR / JSON_OBJ (valores) */
|
||||
char** keys; /* JSON_OBJ (chaves, alinhado a items) */
|
||||
size_t count, cap;
|
||||
};
|
||||
|
||||
/* -- Parse --- */
|
||||
JsonValue* json_parse(const char* text, JsonLexError* err);
|
||||
JsonValue* json_parse_file(const char* path, JsonLexError* err);
|
||||
void json_free(JsonValue* v);
|
||||
|
||||
/* -- Construcao (assumem a posse dos filhos) --- */
|
||||
JsonValue* json_null(void);
|
||||
JsonValue* json_bool(bool b);
|
||||
JsonValue* json_int(long long i);
|
||||
JsonValue* json_real(double d);
|
||||
JsonValue* json_str(const char* s);
|
||||
JsonValue* json_arr(void);
|
||||
JsonValue* json_obj(void);
|
||||
void json_arr_add(JsonValue* arr, JsonValue* v);
|
||||
void json_obj_put(JsonValue* obj, const char* key, JsonValue* v); /* ultimo vence */
|
||||
|
||||
/* -- Navegacao --- */
|
||||
JsonValue* json_obj_get(const JsonValue* obj, const char* key);
|
||||
JsonValue* json_arr_at(const JsonValue* arr, size_t i);
|
||||
size_t json_size(const JsonValue* v);
|
||||
const char* json_as_str (const JsonValue* v, const char* def);
|
||||
long long json_as_int (const JsonValue* v, long long def);
|
||||
double json_as_real(const JsonValue* v, double def);
|
||||
bool json_as_bool(const JsonValue* v, bool def);
|
||||
|
||||
/* -- Emissao (json_to_string devolve malloc; libere com free) --- */
|
||||
char* json_to_string(const JsonValue* v, bool pretty);
|
||||
bool json_write_file(const JsonValue* v, const char* path, bool pretty);
|
||||
|
||||
#endif /* TB_JSON_AST_H */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
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 */
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* TinyBlocks - tb_json.h
|
||||
* Library tinyblocks-json: parser/emissor de JSON e blocos de consulta.
|
||||
*/
|
||||
#ifndef TINYBLOCKS_JSON_H
|
||||
#define TINYBLOCKS_JSON_H
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "ast.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
TB_API const TinyBlocks_LibraryDescriptor* tb_json_get_library(void);
|
||||
|
||||
/* Le um valor escalar de um texto JSON (caminho "a.b[0].c").
|
||||
* Devolve em buffer estatico; util para metadados/UI. */
|
||||
TB_API const char* tb_json_get_path(const char* text, const char* dotted, const char* def);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TINYBLOCKS_JSON_H */
|
||||
Reference in new issue
Block a user