scratchblocks: rótulos com ( ) e vírgula ("nova imagem(96 x 72)", "em (x,y)")
Rótulos de library com pontuação literal não casavam: o "(" do rótulo
virava campo da notação. Agora, nos rótulos do editor e das libraries,
"( )" e "," são texto, e na importação um grupo ( ) com vários tokens
dentro é aberto quando nada casa. Aceita o que o exportador escreve
("nova imagem((96) x (72))") e a forma sem parênteses extras; a linha
"pinte a imagem ... em ((px),(py))" sumia sem aviso.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
63c8fb0c1c
commit
feb20a2127
2 files changed
+77
-6
No files matched your search
@@ -15,11 +15,14 @@ static int fails = 0;
|
||||
static const TbSbLabel s_labels[] = {
|
||||
{"Stage.Circle", "desenhe círculo em x %1 y %2 raio %3"},
|
||||
{"FS.IsDir", "%1 é pasta?"},
|
||||
{"Image.New", "nova imagem(%1 x %2) cor r %3 g %4 b %5"}, /* ( ) e , no rotulo */
|
||||
{"Image.SetPixel", "pinte a imagem %1 em (%2,%3) com r %4 g %5 b %6"},
|
||||
};
|
||||
|
||||
static int shape(const char* type, void* ud) {
|
||||
(void)ud;
|
||||
if (!strcmp(type, "FS.IsDir")) return TB_SB_BOOLEAN;
|
||||
if (!strcmp(type, "Image.New")) return TB_SB_REPORTER;
|
||||
return -1; /* o resto: tabela interna */
|
||||
}
|
||||
static int slot_kind(const char* type, int slot, void* ud) {
|
||||
@@ -31,7 +34,7 @@ static const char* category(const char* type, void* ud) {
|
||||
return !strncmp(type, "Stage.", 6) ? "pen" : "extension";
|
||||
}
|
||||
|
||||
static const TbSbContext CX = { s_labels, 2, shape, slot_kind, category, NULL };
|
||||
static const TbSbContext CX = { s_labels, (int)(sizeof(s_labels) / sizeof(s_labels[0])), shape, slot_kind, category, NULL };
|
||||
|
||||
static TbBpTab* fresh(void) { return calloc(1, sizeof(TbBpTab)); }
|
||||
|
||||
@@ -159,6 +162,31 @@ int main(void) {
|
||||
CHECK(txt && !strcmp(txt, "say [a \\] b]\n"), "exporta escapando o ]");
|
||||
free(txt); drop(t);
|
||||
|
||||
/* -- rotulos com ( ) e , : com os parenteses do exportador e sem eles --- */
|
||||
t = fresh();
|
||||
warn[0] = 0;
|
||||
n = tb_scratchblocks_import("set [tela v] to (nova imagem((96) x (72)) cor r (135) g (200) b (255))\n"
|
||||
"pinte a imagem (tela) em ((px),(py)) com r (1) g (2) b (3)\n"
|
||||
"pinte a imagem (tela) em (4) , (5) com r (1) g (2) b (3)\n", t, &CX, warn, sizeof(warn));
|
||||
{
|
||||
int set = t->top_n ? t->top[0] : -1, img = child(t, set, 1);
|
||||
int p1 = set >= 0 ? t->blocks[set].next : -1, p2 = p1 >= 0 ? t->blocks[p1].next : -1;
|
||||
CHECK(!warn[0] && !strcmp(ty(t, img), "Image.New") && !strcmp(t->blocks[img].in_text[0], "96") &&
|
||||
!strcmp(t->blocks[img].in_text[4], "255"), "rótulo com ( ) no meio: nova imagem((96) x (72))");
|
||||
CHECK(!strcmp(ty(t, p1), "Image.SetPixel") && !strcmp(ty(t, child(t, p1, 1)), "Variables.Get"),
|
||||
"rótulo com (x,y): pinte ... em ((px),(py))");
|
||||
CHECK(!strcmp(ty(t, p2), "Image.SetPixel") && !strcmp(t->blocks[p2].in_text[2], "5"),
|
||||
"e sem os parênteses: em (4) , (5)");
|
||||
txt = tb_scratchblocks_export(t, &CX);
|
||||
TbBpTab* t3 = fresh();
|
||||
int n3 = txt ? tb_scratchblocks_import(txt, t3, &CX, warn, sizeof(warn)) : 0;
|
||||
char* txt3 = n3 > 0 ? tb_scratchblocks_export(t3, &CX) : NULL;
|
||||
CHECK(txt && txt3 && !strcmp(txt, txt3), "rótulos com pontuação: exporta e importa de novo igual");
|
||||
if (txt && txt3 && strcmp(txt, txt3)) printf("---- 1:\n%s---- 2:\n%s", txt, txt3);
|
||||
free(txt); free(txt3); drop(t3);
|
||||
}
|
||||
drop(t);
|
||||
|
||||
if (fails) printf("\n%d FALHA(S)\n", fails);
|
||||
else printf("\nTUDO OK\n");
|
||||
return fails != 0;
|
||||
|
||||
Reference in new issue
Block a user