hokusai-zero 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -2
- data/README.md +1 -1
- data/ast/src/core/ast.c +3 -11
- data/ast/src/core/hml.c +214 -40
- data/ast/src/core/hml.h +1 -0
- data/ast/src/core/input.h +0 -1
- data/ast/src/core/log.c +87 -0
- data/ast/src/core/log.h +41 -0
- data/ast/src/core/util.c +23 -23
- data/ast/src/core/util.h +7 -7
- data/ast/test/parser.c +1 -0
- data/ext/extconf.rb +6 -6
- data/hokusai.gemspec +1 -2
- data/ui/examples/drag.rb +154 -0
- data/ui/examples/embedded.rb +58 -0
- data/ui/examples/forum/file.rb +1 -1
- data/ui/examples/forum/post.rb +0 -1
- data/ui/examples/forum.rb +7 -7
- data/ui/examples/game.rb +143 -0
- data/ui/examples/keyboard.rb +47 -0
- data/ui/examples/overlay.rb +233 -0
- data/ui/examples/provider.rb +56 -0
- data/ui/examples/shader/test.rb +155 -0
- data/ui/examples/shader.rb +100 -0
- data/ui/examples/spreadsheet.rb +12 -11
- data/ui/examples/wiki.rb +82 -0
- data/ui/lib/lib_hokusai.rb +43 -24
- data/ui/spec/hokusai/e2e/client_spec.rb +0 -1
- data/ui/spec/hokusai/e2e/keyboard_spec.rb +52 -0
- data/ui/spec/spec_helper.rb +1 -1
- data/ui/src/hokusai/assets/arrow-down-line.png +0 -0
- data/ui/src/hokusai/assets/arrow-down-wide-line.png +0 -0
- data/ui/src/hokusai/assets/icons/outline/arrow-big-up.svg +19 -0
- data/ui/src/hokusai/assets/icons/outline/backspace.svg +20 -0
- data/ui/src/hokusai/automation/driver_commands/base.rb +2 -8
- data/ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb +3 -6
- data/ui/src/hokusai/automation/driver_commands/trigger_mouse.rb +12 -5
- data/ui/src/hokusai/automation/server.rb +2 -3
- data/ui/src/hokusai/backends/raylib/config.rb +2 -1
- data/ui/src/hokusai/backends/raylib/font.rb +55 -4
- data/ui/src/hokusai/backends/raylib.rb +199 -36
- data/ui/src/hokusai/backends/sdl2/config.rb +9 -6
- data/ui/src/hokusai/backends/sdl2/font.rb +3 -1
- data/ui/src/hokusai/backends/sdl2.rb +188 -93
- data/ui/src/hokusai/blocks/color_picker.rb +1080 -0
- data/ui/src/hokusai/blocks/dynamic.rb +2 -0
- data/ui/src/hokusai/blocks/input.rb +2 -2
- data/ui/src/hokusai/blocks/keyboard.rb +249 -0
- data/ui/src/hokusai/blocks/panel.rb +2 -0
- data/ui/src/hokusai/blocks/scrollbar.rb +7 -0
- data/ui/src/hokusai/blocks/selectable.rb +1 -0
- data/ui/src/hokusai/blocks/shader_begin.rb +22 -0
- data/ui/src/hokusai/blocks/shader_end.rb +12 -0
- data/ui/src/hokusai/blocks/slider.rb +139 -0
- data/ui/src/hokusai/blocks/text_stream.rb +130 -0
- data/ui/src/hokusai/blocks/texture.rb +23 -0
- data/ui/src/hokusai/blocks/translation.rb +91 -0
- data/ui/src/hokusai/commands/rect.rb +12 -3
- data/ui/src/hokusai/commands/rotation.rb +21 -0
- data/ui/src/hokusai/commands/scale.rb +20 -0
- data/ui/src/hokusai/commands/shader.rb +33 -0
- data/ui/src/hokusai/commands/texture.rb +26 -0
- data/ui/src/hokusai/commands/translation.rb +20 -0
- data/ui/src/hokusai/commands.rb +49 -3
- data/ui/src/hokusai/event.rb +2 -1
- data/ui/src/hokusai/events/keyboard.rb +11 -18
- data/ui/src/hokusai/events/mouse.rb +10 -8
- data/ui/src/hokusai/events/touch.rb +62 -0
- data/ui/src/hokusai/meta.rb +13 -6
- data/ui/src/hokusai/mounting/loop_entry.rb +4 -4
- data/ui/src/hokusai/mounting/update_entry.rb +5 -6
- data/ui/src/hokusai/painter.rb +31 -8
- data/ui/src/hokusai/types/display.rb +155 -0
- data/ui/src/hokusai/types/keyboard.rb +168 -0
- data/ui/src/hokusai/types/mouse.rb +36 -0
- data/ui/src/hokusai/types/primitives.rb +56 -0
- data/ui/src/hokusai/types/touch.rb +181 -0
- data/ui/src/hokusai/types.rb +20 -244
- data/ui/src/hokusai/util/selection.rb +28 -7
- data/ui/src/hokusai/util/wrap_stream.rb +268 -0
- data/ui/src/hokusai.rb +72 -35
- data/xmake.lua +2 -1
- metadata +39 -22
- data/ui/src/hokusai/assets/chevron-down.svg +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3430bbda86d7deae31c2e789646f7347e378bb8e0349bb7f37545010417b5d1f
|
4
|
+
data.tar.gz: 72457b126d79909ef0989cb67fd278993377b7aa18b9e759b6822e2c05380e8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 407646a8c7bb287f18b1cc864d72150f4f93f12e29dbcb833befb9968ee5bbea48e0447fda35ca9b40513e4a371db499bc3cd4457e66f8f1d70a6b1d6c0692bb
|
7
|
+
data.tar.gz: ea2e824fb8df8fb0c0a28fbf2ffeb6768f6c2a66d900bf0f2146e04da68dad0a9d93e30eb36d654a60deec1fa4d0625321d9d21a47156a3162bd428f10049b8d
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -8,7 +8,6 @@ GIT
|
|
8
8
|
GEM
|
9
9
|
remote: https://www.rubygems.org/
|
10
10
|
specs:
|
11
|
-
concurrent-ruby (1.3.5)
|
12
11
|
daemons (1.4.1)
|
13
12
|
diff-lcs (1.6.1)
|
14
13
|
domain_name (0.6.20240107)
|
@@ -77,7 +76,6 @@ PLATFORMS
|
|
77
76
|
x86_64-linux
|
78
77
|
|
79
78
|
DEPENDENCIES
|
80
|
-
concurrent-ruby
|
81
79
|
ffi!
|
82
80
|
memory_profiler
|
83
81
|
mini_portile2 (~> 2.0.0)
|
data/README.md
CHANGED
data/ast/src/core/ast.c
CHANGED
@@ -194,26 +194,18 @@ int hoku_ast_event_compare(const void* a, const void* b, void* udata)
|
|
194
194
|
|
195
195
|
int hoku_ast_add_prop(hoku_ast* component, hoku_ast_prop* prop)
|
196
196
|
{
|
197
|
-
|
198
|
-
{
|
199
|
-
return -1;
|
200
|
-
}
|
201
|
-
|
197
|
+
hashmap_set(component->props, prop);
|
202
198
|
return 0;
|
203
199
|
}
|
204
200
|
|
205
201
|
hoku_ast_prop* hoku_ast_get_prop(hoku_ast* component, hoku_ast_prop* prop)
|
206
202
|
{
|
207
|
-
return hashmap_get(component->props, prop);
|
203
|
+
return (hoku_ast_prop*)hashmap_get(component->props, prop);
|
208
204
|
}
|
209
205
|
|
210
206
|
int hoku_ast_add_event(hoku_ast* component, hoku_ast_event* event)
|
211
207
|
{
|
212
|
-
|
213
|
-
{
|
214
|
-
return -1;
|
215
|
-
}
|
216
|
-
|
208
|
+
hashmap_set(component->events, event);
|
217
209
|
return 0;
|
218
210
|
}
|
219
211
|
|
data/ast/src/core/hml.c
CHANGED
@@ -88,6 +88,10 @@ void hoku_dump(hoku_ast* c, int level)
|
|
88
88
|
hoku_dump(sibling, level);
|
89
89
|
}
|
90
90
|
|
91
|
+
if (c->else_relations != NULL)
|
92
|
+
{
|
93
|
+
hoku_dump(c->else_relations->next_child, level);
|
94
|
+
}
|
91
95
|
return;
|
92
96
|
}
|
93
97
|
|
@@ -180,15 +184,31 @@ element 1
|
|
180
184
|
hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
|
181
185
|
{
|
182
186
|
char* ntype = ts_node_type(node);
|
187
|
+
if (ntype == NULL)
|
188
|
+
{
|
189
|
+
f_log(F_LOG_ERROR, "Node type is null!\n %s", template);
|
190
|
+
return NULL;
|
191
|
+
}
|
183
192
|
|
184
193
|
if (strcmp(ntype, "name") == 0)
|
185
194
|
{
|
186
195
|
char* name = hoku_get_tag(node, template);
|
196
|
+
if (name == NULL)
|
197
|
+
{
|
198
|
+
f_log(F_LOG_ERROR, "Node name is null!\n%s", template);
|
199
|
+
return NULL;
|
200
|
+
}
|
187
201
|
hoku_ast* init;
|
188
|
-
hoku_ast_init(&init, name)
|
202
|
+
if (hoku_ast_init(&init, name) == -1)
|
203
|
+
{
|
204
|
+
f_log(F_LOG_ERROR, "Could not init ast for %s", name);
|
205
|
+
return NULL;
|
206
|
+
}
|
207
|
+
|
189
208
|
free(name);
|
190
209
|
int i = 0;
|
191
|
-
|
210
|
+
|
211
|
+
TSNode sibling = ts_node_next_named_sibling(node);
|
192
212
|
|
193
213
|
// a lateral walk across siblings
|
194
214
|
// can be "attributes OR children"
|
@@ -196,46 +216,94 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
|
|
196
216
|
{
|
197
217
|
i++;
|
198
218
|
char* stype = ts_node_type(sibling);
|
219
|
+
if (stype == NULL)
|
220
|
+
{
|
221
|
+
f_log(F_LOG_ERROR, "Sibling node type is null");
|
222
|
+
return NULL;
|
223
|
+
}
|
224
|
+
|
199
225
|
if (strcmp(stype, "attributes") == 0)
|
200
226
|
{
|
227
|
+
f_log(F_LOG_FINE, "Processing attributes for %s", init->type);
|
201
228
|
// process attributes
|
202
|
-
TSNode attribute =
|
229
|
+
TSNode attribute = ts_node_named_child(sibling, 0);
|
203
230
|
while (!ts_node_is_null(attribute))
|
204
231
|
{
|
205
232
|
char* atype = ts_node_type(attribute);
|
233
|
+
if (atype == NULL)
|
234
|
+
{
|
235
|
+
f_log(F_LOG_ERROR, "attribute type is null");
|
236
|
+
return NULL;
|
237
|
+
}
|
206
238
|
if (strcmp(atype, "prop") == 0)
|
207
239
|
{
|
240
|
+
f_log(F_LOG_FINE, "Walking props");
|
208
241
|
hoku_ast_prop* prop = hoku_ast_walk_prop(attribute, template, level + 1);
|
209
|
-
|
242
|
+
if (prop == NULL)
|
243
|
+
{
|
244
|
+
f_log(F_LOG_ERROR, "Prop is null for attribute %s", attribute);
|
245
|
+
return NULL;
|
246
|
+
}
|
247
|
+
if (hoku_ast_add_prop(init, prop) == -1)
|
248
|
+
{
|
249
|
+
f_log(F_LOG_ERROR, "Couldn't add prop %s to %s", prop->name, init->type);
|
250
|
+
return NULL;
|
251
|
+
}
|
210
252
|
}
|
211
253
|
else if (strcmp(atype, "event") == 0)
|
212
254
|
{
|
255
|
+
f_log(F_LOG_FINE, "Walking events");
|
213
256
|
hoku_ast_event* event = hoku_ast_walk_event(attribute, template, level + 1);
|
214
|
-
|
257
|
+
if (event == NULL)
|
258
|
+
{
|
259
|
+
f_log(F_LOG_ERROR, "Event is null for attribute %s", attribute);
|
260
|
+
return NULL;
|
261
|
+
}
|
262
|
+
|
263
|
+
f_log(F_LOG_FINE, "Adding event %s to ast", event->name);
|
264
|
+
if (hoku_ast_add_event(init, event) == -1)
|
265
|
+
{
|
266
|
+
f_log(F_LOG_ERROR, "Couldn't add event to %s", init->type);
|
267
|
+
return NULL;
|
268
|
+
}
|
215
269
|
}
|
216
270
|
else if (strcmp(atype, "style") == 0)
|
217
271
|
{
|
218
|
-
|
219
272
|
char* style_name = hoku_get_tag(attribute, template);
|
273
|
+
if (style_name == NULL)
|
274
|
+
{
|
275
|
+
f_log(F_LOG_ERROR, "Style tag name is NULL");
|
276
|
+
return NULL;
|
277
|
+
}
|
278
|
+
f_log(F_LOG_FINE, "prepending style name %s to ast", style_name);
|
220
279
|
if (hoku_ast_style_list_prepend(init, style_name) != 0) return NULL;
|
280
|
+
free(style_name);
|
221
281
|
}
|
222
282
|
else
|
223
283
|
{
|
224
284
|
hoku_ast_set_error(init, "Expecting `event` or `prop`", attribute, hoku_get_tag(attribute, template));
|
225
285
|
}
|
226
|
-
attribute =
|
286
|
+
attribute = ts_node_next_named_sibling(attribute);
|
227
287
|
}
|
228
288
|
}
|
229
289
|
else if (strcmp(stype, "selectors") == 0)
|
230
290
|
{
|
231
|
-
|
291
|
+
f_log(F_LOG_FINE, "Walking selectors");
|
292
|
+
TSNode sel = ts_node_named_child(sibling, 0);
|
232
293
|
while (!ts_node_is_null(sel))
|
233
294
|
{
|
234
295
|
char* seltype = ts_node_type(sel);
|
235
296
|
char* seltag = hoku_get_tag(sel, template);
|
297
|
+
if (seltag == NULL)
|
298
|
+
{
|
299
|
+
f_log(F_LOG_ERROR, "selector tag is null!");
|
300
|
+
return NULL;
|
301
|
+
}
|
302
|
+
|
236
303
|
if (strcmp(seltype, "id") == 0)
|
237
304
|
{
|
238
|
-
init->id = seltag;
|
305
|
+
init->id = strdup(seltag);
|
306
|
+
free(seltag);
|
239
307
|
}
|
240
308
|
else if (strcmp(seltype, "class") == 0)
|
241
309
|
{
|
@@ -243,45 +311,66 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
|
|
243
311
|
free(seltag);
|
244
312
|
}
|
245
313
|
|
246
|
-
|
314
|
+
f_log(F_LOG_FINE, "Getting next selector sibling");
|
315
|
+
sel = ts_node_next_named_sibling(sel);
|
247
316
|
}
|
248
317
|
}
|
249
318
|
else if (strcmp(stype, "children") == 0)
|
250
319
|
{
|
251
320
|
TSNode child;
|
252
|
-
uint32_t child_count =
|
321
|
+
uint32_t child_count = ts_node_named_child_count(sibling);
|
322
|
+
f_log(F_LOG_DEBUG, "Walking %u children", child_count);
|
323
|
+
|
253
324
|
init->child_len = (int) child_count;
|
254
325
|
hoku_ast* sinit = NULL;
|
255
326
|
for (uint32_t i=0; i<child_count; i++)
|
256
327
|
{
|
257
|
-
child =
|
258
|
-
char*
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
}
|
264
|
-
else
|
328
|
+
child = ts_node_named_child(sibling, i);
|
329
|
+
char* ctype = ts_node_type(child);
|
330
|
+
f_log(F_LOG_FINE, "Child: %s %d", ctype, i);
|
331
|
+
f_log(F_LOG_DEBUG, "Walking ast tree for %s (%d)", ctype, level);
|
332
|
+
|
333
|
+
if(strcmp(ctype, "else_macro") != 0)
|
265
334
|
{
|
266
|
-
|
335
|
+
|
336
|
+
hoku_ast* cchild = hoku_ast_walk_tree(child, template, level + 1);
|
337
|
+
if (cchild == NULL)
|
338
|
+
{
|
339
|
+
f_log(F_LOG_ERROR, "Ast child is NULL");
|
340
|
+
return NULL;
|
341
|
+
}
|
342
|
+
|
343
|
+
if (sinit == NULL)
|
344
|
+
{
|
345
|
+
sinit = cchild;
|
346
|
+
}
|
347
|
+
else
|
348
|
+
{
|
349
|
+
f_log(F_LOG_FINE, "Appending sibling %s to %s", cchild->type, sinit->type);
|
350
|
+
hoku_ast_append_sibling(&sinit, cchild);
|
351
|
+
}
|
267
352
|
}
|
268
353
|
}
|
269
354
|
|
355
|
+
f_log(F_LOG_DEBUG, "Appending child %s to %s", sinit->type, init->type);
|
270
356
|
hoku_ast_append_child(&init, sinit);
|
271
357
|
}
|
272
358
|
|
273
359
|
sibling = ts_node_next_sibling(sibling);
|
274
360
|
}
|
275
361
|
|
362
|
+
f_log(F_LOG_DEBUG, "Returning ast %s", init->type);
|
276
363
|
return init;
|
277
364
|
}
|
278
365
|
else if (strcmp(ntype, "element") == 0)
|
279
366
|
{
|
367
|
+
f_log(F_LOG_FINE, "Walking element tree");
|
280
368
|
TSNode child = ts_node_child(node, 0);
|
281
369
|
return hoku_ast_walk_tree(child, template, level + 1);
|
282
370
|
}
|
283
371
|
else if (strcmp(ntype, "children") == 0)
|
284
372
|
{
|
373
|
+
f_log(F_LOG_FINE, "Walking children tree");
|
285
374
|
TSNode child = ts_node_child(node, 0);
|
286
375
|
return hoku_ast_walk_tree(child, template, level + 1);
|
287
376
|
}
|
@@ -289,19 +378,38 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
|
|
289
378
|
{
|
290
379
|
TSNode child = ts_node_named_child(node, 0);
|
291
380
|
char* name = hoku_get_tag(child, template);
|
381
|
+
if (name == NULL)
|
382
|
+
{
|
383
|
+
f_log(F_LOG_ERROR, "for macro name is null!");
|
384
|
+
return NULL;
|
385
|
+
}
|
292
386
|
|
293
387
|
TSNode sibling = ts_node_next_named_sibling(child);
|
294
388
|
char* list_name = hoku_get_tag(sibling, template);
|
389
|
+
if (list_name == NULL)
|
390
|
+
{
|
391
|
+
f_log(F_LOG_ERROR, "for macro list name is null!");
|
392
|
+
return NULL;
|
393
|
+
}
|
394
|
+
|
295
395
|
hoku_ast_loop* loop;
|
296
396
|
if (hoku_ast_loop_init(&loop, name, list_name) == -1)
|
297
397
|
{
|
398
|
+
f_log(F_LOG_ERROR, "Failed to initialize loop %s %s", name, list_name);
|
298
399
|
return NULL;
|
299
400
|
}
|
300
401
|
|
301
402
|
free(name);
|
302
403
|
free(list_name);
|
404
|
+
|
303
405
|
TSNode children = ts_node_next_named_sibling(sibling);
|
406
|
+
f_log(F_LOG_DEBUG, "Walking loop children");
|
304
407
|
hoku_ast* ast = hoku_ast_walk_tree(children, template, level + 1);
|
408
|
+
if (ast == NULL)
|
409
|
+
{
|
410
|
+
f_log(F_LOG_ERROR, "Loop ast is null");
|
411
|
+
return NULL;
|
412
|
+
}
|
305
413
|
|
306
414
|
ast->loop = loop;
|
307
415
|
|
@@ -309,17 +417,32 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
|
|
309
417
|
}
|
310
418
|
else if (strcmp(ntype, "if_macro") == 0)
|
311
419
|
{
|
420
|
+
f_log(F_LOG_DEBUG, "Handling if macro");
|
312
421
|
TSNode child = ts_node_named_child(node, 0);
|
313
422
|
hoku_ast_func_call* call = hoku_ast_walk_func(child, template, level);
|
423
|
+
if (call == NULL)
|
424
|
+
{
|
425
|
+
f_log(F_LOG_ERROR, "Func call for if macro is null");
|
426
|
+
return NULL;
|
427
|
+
}
|
314
428
|
|
315
429
|
hoku_ast_condition* cond;
|
316
430
|
if (hoku_ast_cond_init(&cond, call) == -1)
|
317
431
|
{
|
432
|
+
f_log(F_LOG_ERROR, "Condition for if macro is null");
|
318
433
|
return NULL;
|
319
434
|
}
|
320
435
|
|
321
436
|
TSNode ichildren = ts_node_next_named_sibling(child);
|
437
|
+
|
322
438
|
hoku_ast* iast = hoku_ast_walk_tree(ichildren, template, level + 1);
|
439
|
+
if (iast == NULL)
|
440
|
+
{
|
441
|
+
f_log(F_LOG_ERROR, "If macro children ast is null");
|
442
|
+
return NULL;
|
443
|
+
}
|
444
|
+
|
445
|
+
f_log(F_LOG_FINE, "Walked if macro children");
|
323
446
|
iast->cond = cond;
|
324
447
|
|
325
448
|
TSNode echild = ts_node_next_named_sibling(node);
|
@@ -329,21 +452,35 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
|
|
329
452
|
|
330
453
|
if (strcmp(etype, "else_macro") == 0)
|
331
454
|
{
|
455
|
+
f_log(F_LOG_FINE, "Walking next else child");
|
456
|
+
|
332
457
|
TSNode eechildren = ts_node_named_child(echild, 0);
|
333
|
-
|
458
|
+
if (!ts_node_is_null(eechildren))
|
459
|
+
{
|
460
|
+
hoku_ast* oast = hoku_ast_walk_tree(eechildren, template, level + 1);
|
461
|
+
if (oast == NULL)
|
462
|
+
{
|
463
|
+
f_log(F_LOG_ERROR, "Else cond children ast is null");
|
464
|
+
return NULL;
|
465
|
+
}
|
334
466
|
|
335
|
-
|
336
|
-
|
467
|
+
iast->else_relations = malloc(sizeof(hoku_ast*));
|
468
|
+
if (iast->else_relations == NULL) return NULL;
|
337
469
|
|
338
|
-
|
339
|
-
|
340
|
-
|
470
|
+
iast->else_relations->next_child = oast;
|
471
|
+
iast->else_relations->next_sibling = NULL;
|
472
|
+
}
|
473
|
+
}
|
474
|
+
}
|
475
|
+
else
|
476
|
+
{
|
477
|
+
f_log(F_LOG_WARN, "If macro has no else children");
|
341
478
|
}
|
342
|
-
|
343
479
|
return iast;
|
344
480
|
}
|
345
481
|
else if (strcmp(ntype, "for_if_macro") == 0)
|
346
482
|
{
|
483
|
+
f_log(F_LOG_DEBUG, "Handling for/if macro");
|
347
484
|
TSNode child = ts_node_named_child(node, 0);
|
348
485
|
char* name = hoku_get_tag(child, template);
|
349
486
|
|
@@ -394,6 +531,7 @@ hoku_ast* hoku_ast_walk_tree(TSNode node, char* template, int level)
|
|
394
531
|
}
|
395
532
|
else
|
396
533
|
{
|
534
|
+
f_log(F_LOG_WARN, "Unsupported type %s", ntype);
|
397
535
|
return NULL;
|
398
536
|
}
|
399
537
|
}
|
@@ -412,6 +550,11 @@ hoku_style_attribute* hoku_walk_style_attributes(TSNode node, char* template)
|
|
412
550
|
TSNode value_node = ts_node_next_named_sibling(attribute_name_node);
|
413
551
|
char* value_node_type = ts_node_type(value_node);
|
414
552
|
|
553
|
+
if (value_node_type == NULL || attribute_name == NULL)
|
554
|
+
{
|
555
|
+
return NULL;
|
556
|
+
}
|
557
|
+
|
415
558
|
enum HOKU_STYLE_TYPE type;
|
416
559
|
char* value = NULL;
|
417
560
|
char* function_name = NULL;
|
@@ -564,6 +707,8 @@ int hoku_style_from_template(hoku_style** out, char* template)
|
|
564
707
|
return -1;
|
565
708
|
}
|
566
709
|
|
710
|
+
ts_tree_delete(tree);
|
711
|
+
ts_parser_delete(parser);
|
567
712
|
*out = style;
|
568
713
|
return 0;
|
569
714
|
}
|
@@ -571,26 +716,35 @@ int hoku_style_from_template(hoku_style** out, char* template)
|
|
571
716
|
int hoku_ast_from_template(hoku_ast** out, char* type, char* template)
|
572
717
|
{
|
573
718
|
hoku_ast* init;
|
574
|
-
if (hoku_ast_init(&init, type) == -1)
|
719
|
+
if (hoku_ast_init(&init, type) == -1)
|
720
|
+
{
|
721
|
+
f_log(F_LOG_ERROR, "AST initialization failed.");
|
722
|
+
return -1;
|
723
|
+
}
|
575
724
|
|
576
725
|
hoku_style* style = NULL;
|
577
726
|
|
727
|
+
f_log(F_LOG_FINE, "Initializing parser.");
|
578
728
|
TSParser* parser = ts_parser_new();
|
579
729
|
if (parser == NULL)
|
580
730
|
{
|
731
|
+
f_log(F_LOG_ERROR, "Parser initialization failed.");
|
581
732
|
free(init);
|
582
733
|
return -1;
|
583
734
|
}
|
584
735
|
|
736
|
+
f_log(F_LOG_FINE, "Parsing document.");
|
585
737
|
ts_parser_set_language(parser, tree_sitter_hml());
|
586
738
|
TSTree* tree = ts_parser_parse_string(parser, NULL, template, strlen(template));
|
587
739
|
if (tree == NULL)
|
588
740
|
{
|
741
|
+
f_log(F_LOG_ERROR, "TS Parser tree is NULL.");
|
589
742
|
ts_parser_delete(parser);
|
590
743
|
free(init);
|
591
744
|
return -1;
|
592
745
|
}
|
593
746
|
|
747
|
+
f_log(F_LOG_FINE, "Getting tree root node.");
|
594
748
|
TSNode document = ts_tree_root_node(tree);
|
595
749
|
if (strcmp(ts_node_type(document), "document") != 0)
|
596
750
|
{
|
@@ -599,16 +753,20 @@ int hoku_ast_from_template(hoku_ast** out, char* type, char* template)
|
|
599
753
|
return 0;
|
600
754
|
}
|
601
755
|
|
756
|
+
f_log(F_LOG_FINE, "Getting document template (first child)");
|
602
757
|
TSNode templ = ts_node_named_child(document, 0);
|
603
758
|
if (strcmp(ts_node_type(templ), "template") != 0 && strcmp(ts_node_type(templ), "style_template") != 0)
|
604
759
|
{
|
760
|
+
f_log(F_LOG_DEBUG, "Document not expected.");
|
605
761
|
hoku_ast_set_error(init, "Expecting template", templ, hoku_get_tag(templ, template));
|
606
762
|
*out = init;
|
607
763
|
return 0;
|
608
764
|
}
|
609
765
|
|
766
|
+
f_log(F_LOG_FINE, "Checking style template");
|
610
767
|
if (strcmp(ts_node_type(templ), "style_template") == 0)
|
611
768
|
{
|
769
|
+
f_log(F_LOG_DEBUG, "Walking style template.");
|
612
770
|
style = hoku_walk_style_template(templ, template);
|
613
771
|
templ = ts_node_next_named_sibling(templ);
|
614
772
|
|
@@ -623,39 +781,55 @@ int hoku_ast_from_template(hoku_ast** out, char* type, char* template)
|
|
623
781
|
TSNode child = ts_node_named_child(templ, 0);
|
624
782
|
hoku_ast* roots = NULL;
|
625
783
|
char* ntype = ts_node_type(child);
|
784
|
+
f_log(F_LOG_FINE, "init vars, %p, %p", child, ntype);
|
626
785
|
|
786
|
+
f_log(F_LOG_DEBUG, "Walking template tree for");
|
627
787
|
while (!ts_node_is_null(child))
|
628
788
|
{
|
629
|
-
|
630
|
-
children = hoku_ast_walk_tree(child, template, 0);
|
789
|
+
ntype = ts_node_type(child);
|
631
790
|
|
632
|
-
if (
|
791
|
+
if (strcmp(ntype, "else_macro") != 0)
|
633
792
|
{
|
634
|
-
|
635
|
-
|
793
|
+
hoku_ast* children;
|
794
|
+
children = hoku_ast_walk_tree(child, template, 0);
|
636
795
|
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
796
|
+
f_log(F_LOG_DEBUG, "Walked template children, %p", children);
|
797
|
+
|
798
|
+
if (children == NULL)
|
799
|
+
{
|
800
|
+
f_log(F_LOG_WARN, "Children are NULL");
|
801
|
+
char* ntype = ts_node_type(child);
|
802
|
+
}
|
803
|
+
|
804
|
+
if (roots == NULL)
|
805
|
+
{
|
806
|
+
f_log(F_LOG_DEBUG, "Setting roots to children");
|
807
|
+
roots = children;
|
808
|
+
}
|
809
|
+
else
|
810
|
+
{
|
811
|
+
f_log(F_LOG_FINE, "Appending children as siblings to root ast.");
|
812
|
+
hoku_ast_append_sibling(&roots, children);
|
813
|
+
}
|
644
814
|
}
|
645
815
|
|
816
|
+
f_log(F_LOG_DEBUG, "Assigning next sibling.");
|
646
817
|
child = ts_node_next_named_sibling(child);
|
647
818
|
}
|
648
819
|
|
820
|
+
f_log(F_LOG_DEBUG, "Appending root ast to init ast");
|
649
821
|
hoku_ast_append_child(&init, roots);
|
650
822
|
|
651
823
|
templ = ts_node_next_named_sibling(templ);
|
652
824
|
if (!ts_node_is_null(templ) && strcmp(ts_node_type(templ), "style_template") == 0)
|
653
825
|
{
|
826
|
+
f_log(F_LOG_FINE, "walking style template\n");
|
654
827
|
style = hoku_walk_style_template(templ, template);
|
655
828
|
}
|
656
829
|
|
657
830
|
init->styles = style;
|
658
831
|
|
832
|
+
f_log(F_LOG_FINE, "delete tree and parser");
|
659
833
|
ts_tree_delete(tree);
|
660
834
|
ts_parser_delete(parser);
|
661
835
|
|
data/ast/src/core/hml.h
CHANGED
data/ast/src/core/input.h
CHANGED
data/ast/src/core/log.c
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#ifndef FLASHLIGHT_LOG
|
2
|
+
#define FLASHLIGHT_LOG
|
3
|
+
#include "log.h"
|
4
|
+
|
5
|
+
void f_default_on_log_message(f_log_message msg)
|
6
|
+
{
|
7
|
+
if (msg.level & f_logger_get_level())
|
8
|
+
{
|
9
|
+
switch(msg.level)
|
10
|
+
{
|
11
|
+
case F_LOG_FINE: {
|
12
|
+
fprintf(stderr, ANSI_COLOR_YELLOW " [%s] " ANSI_COLOR_RESET "%s\n", msg.datetime, msg.message);
|
13
|
+
break;
|
14
|
+
}
|
15
|
+
case F_LOG_DEBUG: {
|
16
|
+
fprintf(stderr, ANSI_COLOR_CYAN " [%s] " ANSI_COLOR_RESET "%s\n", msg.datetime, msg.message);
|
17
|
+
break;
|
18
|
+
}
|
19
|
+
case F_LOG_INFO: {
|
20
|
+
fprintf(stderr, ANSI_COLOR_BLUE " [%s] " ANSI_COLOR_RESET "%s\n", msg.datetime, msg.message);
|
21
|
+
break;
|
22
|
+
}
|
23
|
+
case F_LOG_WARN: {
|
24
|
+
fprintf(stderr, ANSI_COLOR_YELLOW " [%s] " ANSI_COLOR_RESET "%s\n", msg.datetime, msg.message);
|
25
|
+
break;
|
26
|
+
}
|
27
|
+
case F_LOG_ERROR: {
|
28
|
+
fprintf(stderr, ANSI_COLOR_MAGENTA " [%s] " ANSI_COLOR_RESET "%s\n", msg.datetime, msg.message);
|
29
|
+
break;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
void f_logger_set_level(enum F_LOG_LEVEL level)
|
36
|
+
{
|
37
|
+
f_log_level = level;
|
38
|
+
}
|
39
|
+
|
40
|
+
void f_logger_set_cb(f_logger_cb cb, volatile void* payload)
|
41
|
+
{
|
42
|
+
f_log_cb = cb;
|
43
|
+
f_log_payload = payload;
|
44
|
+
}
|
45
|
+
|
46
|
+
f_logger_cb f_logger_get_cb()
|
47
|
+
{
|
48
|
+
return f_log_cb;
|
49
|
+
}
|
50
|
+
|
51
|
+
volatile void* f_logger_get_payload()
|
52
|
+
{
|
53
|
+
return f_log_payload;
|
54
|
+
}
|
55
|
+
|
56
|
+
enum F_LOG_LEVEL f_logger_get_level()
|
57
|
+
{
|
58
|
+
return f_log_level;
|
59
|
+
}
|
60
|
+
|
61
|
+
void f_log(enum F_LOG_LEVEL level, char* fmt, ...)
|
62
|
+
{
|
63
|
+
time_t t = time(NULL);
|
64
|
+
struct tm* tm = localtime(&t);
|
65
|
+
char datetime[64];
|
66
|
+
strftime(datetime, sizeof(datetime), "%c", tm);
|
67
|
+
char message[500];
|
68
|
+
volatile void* payload = f_logger_get_payload();
|
69
|
+
|
70
|
+
va_list args;
|
71
|
+
va_start(args, fmt);
|
72
|
+
vsprintf(message, fmt, args);
|
73
|
+
va_end(args);
|
74
|
+
|
75
|
+
f_log_message msg = {datetime, level, message};
|
76
|
+
|
77
|
+
if (f_log_cb == NULL)
|
78
|
+
{
|
79
|
+
f_default_on_log_message(msg);
|
80
|
+
}
|
81
|
+
else
|
82
|
+
{
|
83
|
+
f_log_cb(msg, payload);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
#endif
|