hokusai-zero 0.1.1
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 +7 -0
- data/Dockerfile +26 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +91 -0
- data/LICENSE +21 -0
- data/README.md +28 -0
- data/ast/genheader +3 -0
- data/ast/include/hashmap.c +1151 -0
- data/ast/include/hashmap.c.license +20 -0
- data/ast/include/hashmap.h +54 -0
- data/ast/src/core/ast.c +448 -0
- data/ast/src/core/ast.h +259 -0
- data/ast/src/core/common.h +24 -0
- data/ast/src/core/component.c +85 -0
- data/ast/src/core/component.h +35 -0
- data/ast/src/core/hml.c +665 -0
- data/ast/src/core/hml.h +11 -0
- data/ast/src/core/input.c +458 -0
- data/ast/src/core/input.h +118 -0
- data/ast/src/core/style.c +101 -0
- data/ast/src/core/style.h +41 -0
- data/ast/src/core/text.c +784 -0
- data/ast/src/core/text.h +93 -0
- data/ast/src/core/util.c +140 -0
- data/ast/src/core/util.h +48 -0
- data/ast/src/hokusai.c +6 -0
- data/ast/src/hokusai.h +6 -0
- data/ast/test/fixtures/test.ui +13 -0
- data/ast/test/greatest.h +1266 -0
- data/ast/test/hokusai.c +14 -0
- data/ast/test/parser.c +234 -0
- data/ast/test/text.c +116 -0
- data/ext/extconf.rb +27 -0
- data/grammar/Cargo.lock +80 -0
- data/grammar/Cargo.toml +26 -0
- data/grammar/binding.gyp +20 -0
- data/grammar/bindings/node/binding.cc +28 -0
- data/grammar/bindings/node/index.js +19 -0
- data/grammar/bindings/rust/build.rs +40 -0
- data/grammar/bindings/rust/lib.rs +52 -0
- data/grammar/corpus/1_document.txt +131 -0
- data/grammar/corpus/2_selectors.txt +58 -0
- data/grammar/corpus/3_spaces.txt +69 -0
- data/grammar/corpus/4_errors.txt +10 -0
- data/grammar/corpus/5_macros.txt +175 -0
- data/grammar/corpus/6_styles.txt +81 -0
- data/grammar/grammar.js +275 -0
- data/grammar/package-lock.json +34 -0
- data/grammar/package.json +33 -0
- data/grammar/src/grammar.json +1269 -0
- data/grammar/src/node-types.json +474 -0
- data/grammar/src/parser.c +5772 -0
- data/grammar/src/scanner.c +258 -0
- data/grammar/src/tree_sitter/parser.h +230 -0
- data/grammar/src/tree_sitter/scanner.h +12 -0
- data/grammar/test.nml +10 -0
- data/hokusai.gemspec +19 -0
- data/ui/examples/assets/DigitalDisplay.ttf +0 -0
- data/ui/examples/assets/OpenSans-Regular.ttf +0 -0
- data/ui/examples/assets/addy.png +0 -0
- data/ui/examples/assets/baby_sean.png +0 -0
- data/ui/examples/assets/football-troll.png +0 -0
- data/ui/examples/assets/gear.png +0 -0
- data/ui/examples/assets/icecold.ttf +0 -0
- data/ui/examples/assets/science-troll.png +0 -0
- data/ui/examples/buddy.rb +31 -0
- data/ui/examples/clock.rb +58 -0
- data/ui/examples/counter.rb +123 -0
- data/ui/examples/dynamic.rb +147 -0
- data/ui/examples/foobar.rb +236 -0
- data/ui/examples/stock.rb +115 -0
- data/ui/examples/stock_decider/option.rb +74 -0
- data/ui/examples/tic_tac_toe.rb +246 -0
- data/ui/lib/lib_hokusai.rb +425 -0
- data/ui/spec/hokusai/ast_spec.rb +88 -0
- data/ui/spec/hokusai/automation/keys_transcoder_spec.rb +50 -0
- data/ui/spec/hokusai/automation/selector_spec.rb +68 -0
- data/ui/spec/hokusai/block_spec.rb +126 -0
- data/ui/spec/hokusai/directives_spec.rb +327 -0
- data/ui/spec/hokusai/e2e/client_spec.rb +58 -0
- data/ui/spec/hokusai/e2e/meta_spec.rb +42 -0
- data/ui/spec/hokusai/publisher_spec.rb +38 -0
- data/ui/spec/hokusai/slots_spec.rb +150 -0
- data/ui/spec/hokusai/util/piece_table_spec.rb +90 -0
- data/ui/spec/hokusai_spec.rb +0 -0
- data/ui/spec/spec_helper.rb +30 -0
- data/ui/src/hokusai/ast.rb +446 -0
- data/ui/src/hokusai/automation/client.rb +167 -0
- data/ui/src/hokusai/automation/constants.rb +98 -0
- data/ui/src/hokusai/automation/converters/selector_converter.rb +61 -0
- data/ui/src/hokusai/automation/driver.rb +54 -0
- data/ui/src/hokusai/automation/driver_command_queue.rb +50 -0
- data/ui/src/hokusai/automation/driver_commands/base.rb +79 -0
- data/ui/src/hokusai/automation/driver_commands/get_attribute.rb +41 -0
- data/ui/src/hokusai/automation/driver_commands/invoke.rb +33 -0
- data/ui/src/hokusai/automation/driver_commands/locate.rb +48 -0
- data/ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb +94 -0
- data/ui/src/hokusai/automation/driver_commands/trigger_mouse.rb +213 -0
- data/ui/src/hokusai/automation/keys_transcoder.rb +128 -0
- data/ui/src/hokusai/automation/selector.rb +39 -0
- data/ui/src/hokusai/automation/server.rb +114 -0
- data/ui/src/hokusai/automation.rb +3 -0
- data/ui/src/hokusai/backends/raylib/config.rb +47 -0
- data/ui/src/hokusai/backends/raylib/font.rb +113 -0
- data/ui/src/hokusai/backends/raylib/keys.rb +124 -0
- data/ui/src/hokusai/backends/raylib.rb +449 -0
- data/ui/src/hokusai/backends/sdl2/Monaco.ttf +0 -0
- data/ui/src/hokusai/backends/sdl2/color.rb +12 -0
- data/ui/src/hokusai/backends/sdl2/config.rb +31 -0
- data/ui/src/hokusai/backends/sdl2/font.rb +127 -0
- data/ui/src/hokusai/backends/sdl2/keys.rb +119 -0
- data/ui/src/hokusai/backends/sdl2.rb +529 -0
- data/ui/src/hokusai/block.rb +237 -0
- data/ui/src/hokusai/blocks/button.rb +100 -0
- data/ui/src/hokusai/blocks/checkbox.rb +51 -0
- data/ui/src/hokusai/blocks/circle.rb +28 -0
- data/ui/src/hokusai/blocks/clipped.rb +23 -0
- data/ui/src/hokusai/blocks/cursor.rb +49 -0
- data/ui/src/hokusai/blocks/dynamic.rb +37 -0
- data/ui/src/hokusai/blocks/empty.rb +10 -0
- data/ui/src/hokusai/blocks/hblock.rb +35 -0
- data/ui/src/hokusai/blocks/image.rb +18 -0
- data/ui/src/hokusai/blocks/input.rb +200 -0
- data/ui/src/hokusai/blocks/label.rb +39 -0
- data/ui/src/hokusai/blocks/panel.rb +126 -0
- data/ui/src/hokusai/blocks/rect.rb +24 -0
- data/ui/src/hokusai/blocks/scissor_begin.rb +18 -0
- data/ui/src/hokusai/blocks/scissor_end.rb +12 -0
- data/ui/src/hokusai/blocks/scrollbar.rb +103 -0
- data/ui/src/hokusai/blocks/selectable.rb +77 -0
- data/ui/src/hokusai/blocks/svg.rb +20 -0
- data/ui/src/hokusai/blocks/text.rb +214 -0
- data/ui/src/hokusai/blocks/titlebar/osx.rb +145 -0
- data/ui/src/hokusai/blocks/toggle.rb +55 -0
- data/ui/src/hokusai/blocks/vblock.rb +35 -0
- data/ui/src/hokusai/commands/base.rb +22 -0
- data/ui/src/hokusai/commands/circle.rb +47 -0
- data/ui/src/hokusai/commands/image.rb +45 -0
- data/ui/src/hokusai/commands/rect.rb +158 -0
- data/ui/src/hokusai/commands/scissor.rb +22 -0
- data/ui/src/hokusai/commands/text.rb +92 -0
- data/ui/src/hokusai/commands.rb +87 -0
- data/ui/src/hokusai/diff.rb +124 -0
- data/ui/src/hokusai/error.rb +3 -0
- data/ui/src/hokusai/event.rb +54 -0
- data/ui/src/hokusai/events/keyboard.rb +84 -0
- data/ui/src/hokusai/events/mouse.rb +172 -0
- data/ui/src/hokusai/font.rb +280 -0
- data/ui/src/hokusai/meta.rb +152 -0
- data/ui/src/hokusai/mounting/loop_entry.rb +230 -0
- data/ui/src/hokusai/mounting/mount_entry.rb +74 -0
- data/ui/src/hokusai/mounting/update_entry.rb +101 -0
- data/ui/src/hokusai/node.rb +98 -0
- data/ui/src/hokusai/node_mounter.rb +102 -0
- data/ui/src/hokusai/painter.rb +214 -0
- data/ui/src/hokusai/publisher.rb +32 -0
- data/ui/src/hokusai/style.rb +72 -0
- data/ui/src/hokusai/types.rb +266 -0
- data/ui/src/hokusai/util/clamping_iterator.rb +202 -0
- data/ui/src/hokusai/util/piece_table.rb +111 -0
- data/ui/src/hokusai/util/selection.rb +145 -0
- data/ui/src/hokusai.rb +120 -0
- data/ui/vendor/.gitkeep +0 -0
- data/vendor/.gitkeep +0 -0
- data/xmake.lua +192 -0
- metadata +222 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Joshua J Baker
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,54 @@
|
|
1
|
+
// Copyright 2020 Joshua J Baker. All rights reserved.
|
2
|
+
// Use of this source code is governed by an MIT-style
|
3
|
+
// license that can be found in the LICENSE file.
|
4
|
+
|
5
|
+
#ifndef HASHMAP_H
|
6
|
+
#define HASHMAP_H
|
7
|
+
|
8
|
+
#include <stdbool.h>
|
9
|
+
#include <stddef.h>
|
10
|
+
#include <stdint.h>
|
11
|
+
|
12
|
+
struct hashmap;
|
13
|
+
|
14
|
+
struct hashmap *hashmap_new(size_t elsize, size_t cap, uint64_t seed0,
|
15
|
+
uint64_t seed1,
|
16
|
+
uint64_t (*hash)(const void *item, uint64_t seed0, uint64_t seed1),
|
17
|
+
int (*compare)(const void *a, const void *b, void *udata),
|
18
|
+
void (*elfree)(void *item),
|
19
|
+
void *udata);
|
20
|
+
|
21
|
+
struct hashmap *hashmap_new_with_allocator(void *(*malloc)(size_t),
|
22
|
+
void *(*realloc)(void *, size_t), void (*free)(void*), size_t elsize,
|
23
|
+
size_t cap, uint64_t seed0, uint64_t seed1,
|
24
|
+
uint64_t (*hash)(const void *item, uint64_t seed0, uint64_t seed1),
|
25
|
+
int (*compare)(const void *a, const void *b, void *udata),
|
26
|
+
void (*elfree)(void *item),
|
27
|
+
void *udata);
|
28
|
+
|
29
|
+
void hashmap_free(struct hashmap *map);
|
30
|
+
void hashmap_clear(struct hashmap *map, bool update_cap);
|
31
|
+
size_t hashmap_count(struct hashmap *map);
|
32
|
+
bool hashmap_oom(struct hashmap *map);
|
33
|
+
const void *hashmap_get(struct hashmap *map, const void *item);
|
34
|
+
const void *hashmap_set(struct hashmap *map, const void *item);
|
35
|
+
const void *hashmap_delete(struct hashmap *map, const void *item);
|
36
|
+
const void *hashmap_probe(struct hashmap *map, uint64_t position);
|
37
|
+
bool hashmap_scan(struct hashmap *map, bool (*iter)(const void *item, void *udata), void *udata);
|
38
|
+
bool hashmap_iter(struct hashmap *map, size_t *i, void **item);
|
39
|
+
|
40
|
+
uint64_t hashmap_sip(const void *data, size_t len, uint64_t seed0, uint64_t seed1);
|
41
|
+
uint64_t hashmap_murmur(const void *data, size_t len, uint64_t seed0, uint64_t seed1);
|
42
|
+
uint64_t hashmap_xxhash3(const void *data, size_t len, uint64_t seed0, uint64_t seed1);
|
43
|
+
|
44
|
+
const void *hashmap_get_with_hash(struct hashmap *map, const void *key, uint64_t hash);
|
45
|
+
const void *hashmap_delete_with_hash(struct hashmap *map, const void *key, uint64_t hash);
|
46
|
+
const void *hashmap_set_with_hash(struct hashmap *map, const void *item, uint64_t hash);
|
47
|
+
void hashmap_set_grow_by_power(struct hashmap *map, size_t power);
|
48
|
+
void hashmap_set_load_factor(struct hashmap *map, double load_factor);
|
49
|
+
|
50
|
+
|
51
|
+
// DEPRECATED: use `hashmap_new_with_allocator`
|
52
|
+
void hashmap_set_allocator(void *(*malloc)(size_t), void (*free)(void*));
|
53
|
+
|
54
|
+
#endif
|
data/ast/src/core/ast.c
ADDED
@@ -0,0 +1,448 @@
|
|
1
|
+
#ifndef HOKUSAI_CORE_AST
|
2
|
+
#define HOKUSAI_CORE_AST
|
3
|
+
|
4
|
+
#include "ast.h"
|
5
|
+
|
6
|
+
int hoku_ast_class_list_init(hoku_ast_class_list** out, char* name)
|
7
|
+
{
|
8
|
+
hoku_ast_class_list* init = malloc(sizeof(hoku_ast_class_list));
|
9
|
+
if (init == NULL) return -1;
|
10
|
+
|
11
|
+
init->name = strdup(name);
|
12
|
+
if (init->name == NULL)
|
13
|
+
{
|
14
|
+
free(init);
|
15
|
+
return -1;
|
16
|
+
}
|
17
|
+
|
18
|
+
init->next = NULL;
|
19
|
+
*out = init;
|
20
|
+
return 0;
|
21
|
+
}
|
22
|
+
|
23
|
+
void hoku_ast_class_list_free(hoku_ast_class_list* list)
|
24
|
+
{
|
25
|
+
hoku_ast_class_list* head = list;
|
26
|
+
while (head != NULL)
|
27
|
+
{
|
28
|
+
hoku_ast_class_list* cpy = head->next;
|
29
|
+
free(head->name);
|
30
|
+
free(head);
|
31
|
+
head = cpy;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
int hoku_ast_style_list_prepend(hoku_ast* ast, char* name)
|
36
|
+
{
|
37
|
+
hoku_ast_class_list* init;
|
38
|
+
if (hoku_ast_class_list_init(&init, name) == -1) return -1;
|
39
|
+
|
40
|
+
if (ast->style_list == NULL)
|
41
|
+
{
|
42
|
+
ast->style_list = init;
|
43
|
+
}
|
44
|
+
else
|
45
|
+
{
|
46
|
+
init->next = ast->style_list;
|
47
|
+
ast->style_list = init;
|
48
|
+
}
|
49
|
+
|
50
|
+
return 0;
|
51
|
+
}
|
52
|
+
|
53
|
+
int hoku_ast_class_list_prepend(hoku_ast* ast, char* name)
|
54
|
+
{
|
55
|
+
hoku_ast_class_list* init;
|
56
|
+
if (hoku_ast_class_list_init(&init, name) == -1) return -1;
|
57
|
+
|
58
|
+
if (ast->class_list == NULL)
|
59
|
+
{
|
60
|
+
ast->class_list = init;
|
61
|
+
}
|
62
|
+
else
|
63
|
+
{
|
64
|
+
init->next = ast->class_list;
|
65
|
+
ast->class_list = init;
|
66
|
+
}
|
67
|
+
|
68
|
+
return 0;
|
69
|
+
}
|
70
|
+
|
71
|
+
bool hoku_ast_class_list_includes(hoku_ast* ast, char* name)
|
72
|
+
{
|
73
|
+
hoku_ast_class_list* head = ast->class_list;
|
74
|
+
bool found = false;
|
75
|
+
while (head != NULL)
|
76
|
+
{
|
77
|
+
if (strcmp(head->name, name) == 0)
|
78
|
+
{
|
79
|
+
found = true;
|
80
|
+
break;
|
81
|
+
}
|
82
|
+
head = head->next;
|
83
|
+
}
|
84
|
+
|
85
|
+
return found;
|
86
|
+
}
|
87
|
+
|
88
|
+
int hoku_ast_func_call_init(hoku_ast_func_call** call, char* name)
|
89
|
+
{
|
90
|
+
hoku_ast_func_call* init = malloc(sizeof(hoku_ast_func_call));
|
91
|
+
if (init == NULL) return -1;
|
92
|
+
|
93
|
+
// name should be null terminated.
|
94
|
+
init->function = strdup(name);
|
95
|
+
if (init->function == NULL)
|
96
|
+
{
|
97
|
+
free(init);
|
98
|
+
return -1;
|
99
|
+
}
|
100
|
+
|
101
|
+
init->args_len = 0;
|
102
|
+
init->args = NULL;
|
103
|
+
init->strargs = malloc(sizeof(char*) * 10);
|
104
|
+
// 10 arg buffer.
|
105
|
+
|
106
|
+
*call = init;
|
107
|
+
return 0;
|
108
|
+
}
|
109
|
+
|
110
|
+
void hoku_ast_func_call_free(hoku_ast_func_call* init)
|
111
|
+
{
|
112
|
+
free(init->strargs);
|
113
|
+
free(init->function);
|
114
|
+
free(init);
|
115
|
+
}
|
116
|
+
|
117
|
+
int hoku_ast_event_init(hoku_ast_event** event, char* name)
|
118
|
+
{
|
119
|
+
hoku_ast_event* init = malloc(sizeof(hoku_ast_event));
|
120
|
+
if (init == NULL) return -1;
|
121
|
+
|
122
|
+
init->call = NULL;
|
123
|
+
init->name = strdup(name);
|
124
|
+
if (init->name == NULL)
|
125
|
+
{
|
126
|
+
free(init);
|
127
|
+
return -1;
|
128
|
+
}
|
129
|
+
|
130
|
+
*event = init;
|
131
|
+
return 0;
|
132
|
+
}
|
133
|
+
|
134
|
+
void hoku_ast_event_free(hoku_ast_event* event)
|
135
|
+
{
|
136
|
+
hoku_ast_func_call_free(event->call);
|
137
|
+
free(event->name);
|
138
|
+
free(event);
|
139
|
+
}
|
140
|
+
|
141
|
+
int hoku_ast_prop_init(hoku_ast_prop** prop, char* name)
|
142
|
+
{
|
143
|
+
hoku_ast_prop* init = malloc(sizeof(hoku_ast_prop));
|
144
|
+
if (init == NULL) return -1;
|
145
|
+
|
146
|
+
init->computed = false;
|
147
|
+
init->call = NULL;
|
148
|
+
init->name = strdup(name);
|
149
|
+
if (init->name == NULL)
|
150
|
+
{
|
151
|
+
free(init);
|
152
|
+
return -1;
|
153
|
+
}
|
154
|
+
|
155
|
+
*prop = init;
|
156
|
+
return 0;
|
157
|
+
}
|
158
|
+
|
159
|
+
void hoku_ast_prop_free(hoku_ast_prop* prop)
|
160
|
+
{
|
161
|
+
hoku_ast_func_call_free(prop->call);
|
162
|
+
free(prop->name);
|
163
|
+
free(prop);
|
164
|
+
}
|
165
|
+
|
166
|
+
/** hashmap functions for props and events
|
167
|
+
*/
|
168
|
+
|
169
|
+
uint64_t hoku_ast_prop_hash(const void* item, uint64_t seed0, uint64_t seed1)
|
170
|
+
{
|
171
|
+
hoku_ast_prop* prop = (hoku_ast_prop*) item;
|
172
|
+
return hashmap_sip(prop->name, strlen(prop->name), seed0, seed1);
|
173
|
+
}
|
174
|
+
|
175
|
+
uint64_t hoku_ast_event_hash(const void* item, uint64_t seed0, uint64_t seed1)
|
176
|
+
{
|
177
|
+
hoku_ast_event* event = (hoku_ast_event*) item;
|
178
|
+
return hashmap_sip(event->name, strlen(event->name), seed0, seed1);
|
179
|
+
}
|
180
|
+
|
181
|
+
int hoku_ast_prop_compare(const void* a, const void* b, void* udata)
|
182
|
+
{
|
183
|
+
const hoku_ast_prop* prop_a = (hoku_ast_prop*) a;
|
184
|
+
const hoku_ast_prop* prop_b = (hoku_ast_prop*) b;
|
185
|
+
return strcmp(prop_a->name, prop_b->name);
|
186
|
+
}
|
187
|
+
|
188
|
+
int hoku_ast_event_compare(const void* a, const void* b, void* udata)
|
189
|
+
{
|
190
|
+
const hoku_ast_event* ea = (hoku_ast_event*) a;
|
191
|
+
const hoku_ast_event* eb = (hoku_ast_event*) b;
|
192
|
+
return strcmp(ea->name, eb->name);
|
193
|
+
}
|
194
|
+
|
195
|
+
int hoku_ast_add_prop(hoku_ast* component, hoku_ast_prop* prop)
|
196
|
+
{
|
197
|
+
if (hashmap_set(component->props, prop) == NULL)
|
198
|
+
{
|
199
|
+
return -1;
|
200
|
+
}
|
201
|
+
|
202
|
+
return 0;
|
203
|
+
}
|
204
|
+
|
205
|
+
hoku_ast_prop* hoku_ast_get_prop(hoku_ast* component, hoku_ast_prop* prop)
|
206
|
+
{
|
207
|
+
return hashmap_get(component->props, prop);
|
208
|
+
}
|
209
|
+
|
210
|
+
int hoku_ast_add_event(hoku_ast* component, hoku_ast_event* event)
|
211
|
+
{
|
212
|
+
if (hashmap_set(component->events, event) == NULL)
|
213
|
+
{
|
214
|
+
return -1;
|
215
|
+
}
|
216
|
+
|
217
|
+
return 0;
|
218
|
+
}
|
219
|
+
|
220
|
+
hoku_ast_event* hoku_ast_get_event(hoku_ast* component, hoku_ast_event* event)
|
221
|
+
{
|
222
|
+
return (hoku_ast_event*) hashmap_get(component->events, event);
|
223
|
+
}
|
224
|
+
|
225
|
+
int hoku_ast_props_init(struct hashmap** props)
|
226
|
+
{
|
227
|
+
struct hashmap* init = hashmap_new(sizeof(hoku_ast_prop), 0, 0, 0, hoku_ast_prop_hash, hoku_ast_prop_compare, NULL, hoku_ast_prop_free);
|
228
|
+
if (init == NULL) return -1;
|
229
|
+
|
230
|
+
*props = init;
|
231
|
+
return 0;
|
232
|
+
}
|
233
|
+
|
234
|
+
int hoku_ast_events_init(struct hashmap** events)
|
235
|
+
{
|
236
|
+
struct hashmap* init = hashmap_new(sizeof(hoku_ast_event), 0, 0, 0, hoku_ast_event_hash, hoku_ast_event_compare, NULL, hoku_ast_event_free);
|
237
|
+
if (init == NULL) return -1;
|
238
|
+
|
239
|
+
*events = init;
|
240
|
+
return 0;
|
241
|
+
}
|
242
|
+
|
243
|
+
int hoku_ast_events_count(hoku_ast* component)
|
244
|
+
{
|
245
|
+
return hashmap_count(component->events);
|
246
|
+
}
|
247
|
+
|
248
|
+
int hoku_ast_props_count(hoku_ast* component)
|
249
|
+
{
|
250
|
+
return hashmap_count(component->props);
|
251
|
+
}
|
252
|
+
|
253
|
+
int hoku_ast_prepend_sibling(hoku_ast** first, hoku_ast* second)
|
254
|
+
{
|
255
|
+
if ((*first)->relations->next_sibling == NULL)
|
256
|
+
{
|
257
|
+
(*first)->relations->next_sibling = second;
|
258
|
+
}
|
259
|
+
else
|
260
|
+
{
|
261
|
+
hoku_ast* head = *first;
|
262
|
+
second->relations->next_sibling = head;
|
263
|
+
(*first)->relations->next_sibling = second;
|
264
|
+
}
|
265
|
+
return 0;
|
266
|
+
}
|
267
|
+
int hoku_ast_prepend_child(hoku_ast** parent, hoku_ast* child)
|
268
|
+
{
|
269
|
+
if ((*parent)->relations->next_child == NULL)
|
270
|
+
{
|
271
|
+
child->parent = *parent;
|
272
|
+
(*parent)->relations->next_child = child;
|
273
|
+
}
|
274
|
+
else
|
275
|
+
{
|
276
|
+
hoku_ast* head = (*parent)->relations->next_child;
|
277
|
+
child->parent = *parent;
|
278
|
+
child->relations->next_child = head;
|
279
|
+
(*parent)->relations->next_child = child;
|
280
|
+
}
|
281
|
+
return 0;
|
282
|
+
}
|
283
|
+
|
284
|
+
int hoku_ast_append_sibling(hoku_ast** first, hoku_ast* second)
|
285
|
+
{
|
286
|
+
hoku_ast* head = *first;
|
287
|
+
while (head->relations->next_sibling != NULL)
|
288
|
+
{
|
289
|
+
head = head->relations->next_sibling;
|
290
|
+
}
|
291
|
+
|
292
|
+
head->relations->next_sibling = second;
|
293
|
+
return 0;
|
294
|
+
}
|
295
|
+
|
296
|
+
int hoku_ast_append_child(hoku_ast** parent, hoku_ast* child)
|
297
|
+
{
|
298
|
+
hoku_ast* head = *parent;
|
299
|
+
child->parent = *parent;
|
300
|
+
while (head->relations->next_child != NULL)
|
301
|
+
{
|
302
|
+
head = head->relations->next_child;
|
303
|
+
}
|
304
|
+
head->relations->next_child = child;
|
305
|
+
return 0;
|
306
|
+
}
|
307
|
+
|
308
|
+
int hoku_ast_cond_init(hoku_ast_condition** cond, hoku_ast_func_call* call)
|
309
|
+
{
|
310
|
+
hoku_ast_condition* init = malloc(sizeof(hoku_ast_condition));
|
311
|
+
if (init == NULL) return -1;
|
312
|
+
|
313
|
+
init->not = false;
|
314
|
+
init->call = call;
|
315
|
+
*cond = init;
|
316
|
+
return 0;
|
317
|
+
}
|
318
|
+
|
319
|
+
int hoku_ast_loop_init(hoku_ast_loop** loop, char* name, char* list_name)
|
320
|
+
{
|
321
|
+
hoku_ast_loop* init = malloc(sizeof(hoku_ast_loop));
|
322
|
+
if (init == NULL) return -1;
|
323
|
+
init->name = strdup(name);
|
324
|
+
if (init->name == NULL)
|
325
|
+
{
|
326
|
+
free(init);
|
327
|
+
return -1;
|
328
|
+
}
|
329
|
+
|
330
|
+
init->list_name = strdup(list_name);
|
331
|
+
if (init->list_name == NULL)
|
332
|
+
{
|
333
|
+
free(init);
|
334
|
+
return -1;
|
335
|
+
}
|
336
|
+
|
337
|
+
*loop = init;
|
338
|
+
return 0;
|
339
|
+
}
|
340
|
+
|
341
|
+
int hoku_ast_init(hoku_ast** component, char* type)
|
342
|
+
{
|
343
|
+
hoku_ast* init = malloc(sizeof(hoku_ast));
|
344
|
+
if (init == NULL) return -1;
|
345
|
+
|
346
|
+
init->type = strdup(type);
|
347
|
+
if (init->type == NULL)
|
348
|
+
{
|
349
|
+
free(init);
|
350
|
+
return -1;
|
351
|
+
}
|
352
|
+
|
353
|
+
if (hoku_ast_props_init(&init->props) == -1)
|
354
|
+
{
|
355
|
+
free(init->type);
|
356
|
+
free(init);
|
357
|
+
return -1;
|
358
|
+
}
|
359
|
+
|
360
|
+
if (hoku_ast_events_init(&init->events) == -1)
|
361
|
+
{
|
362
|
+
hashmap_free(init->props);
|
363
|
+
free(init->type);
|
364
|
+
free(init);
|
365
|
+
return -1;
|
366
|
+
}
|
367
|
+
|
368
|
+
init->child_len = 0;
|
369
|
+
init->id = NULL;
|
370
|
+
init->error = NULL;
|
371
|
+
init->styles = NULL;
|
372
|
+
init->style_list = NULL;
|
373
|
+
init->class_list = NULL;
|
374
|
+
init->has_slot = false;
|
375
|
+
init->cond = NULL;
|
376
|
+
init->loop = NULL;
|
377
|
+
init->parent = NULL;
|
378
|
+
init->relations = malloc(sizeof(hoku_ast_list));
|
379
|
+
init->relations->next_child = NULL;
|
380
|
+
init->relations->next_sibling = NULL;
|
381
|
+
init->else_relations = NULL;
|
382
|
+
init->else_active = false;
|
383
|
+
*component = init;
|
384
|
+
|
385
|
+
return 0;
|
386
|
+
}
|
387
|
+
|
388
|
+
int hoku_ast_set_error(hoku_ast* ast, char* error, TSNode node, char* tag)
|
389
|
+
{
|
390
|
+
char copy[600];
|
391
|
+
TSPoint start = ts_node_start_point(node);
|
392
|
+
sprintf(copy, "Error at row: %d col: %d - %s, got: \"%s\"\n", start.row, start.column, error, tag);
|
393
|
+
ast->error = strdup(copy);
|
394
|
+
if (ast->error == NULL) return -1;
|
395
|
+
return 0;
|
396
|
+
}
|
397
|
+
|
398
|
+
hoku_ast* hoku_errored_ast(hoku_ast* ast)
|
399
|
+
{
|
400
|
+
if (ast->error != NULL) return ast;
|
401
|
+
|
402
|
+
hoku_ast* child = ast->relations->next_child;
|
403
|
+
if (child != NULL)
|
404
|
+
{
|
405
|
+
hoku_ast* errored = hoku_errored_ast(child);
|
406
|
+
if (errored != NULL) return errored;
|
407
|
+
}
|
408
|
+
|
409
|
+
hoku_ast* sibling = ast->relations->next_sibling;
|
410
|
+
if (sibling != NULL)
|
411
|
+
{
|
412
|
+
hoku_ast* errored = hoku_errored_ast(sibling);
|
413
|
+
if (errored != NULL) return errored;
|
414
|
+
}
|
415
|
+
|
416
|
+
return NULL;
|
417
|
+
}
|
418
|
+
|
419
|
+
void hoku_ast_list_free(hoku_ast_list* list)
|
420
|
+
{
|
421
|
+
if (list->next_sibling)
|
422
|
+
{
|
423
|
+
hoku_ast_free(list->next_sibling);
|
424
|
+
}
|
425
|
+
|
426
|
+
if (list->next_child)
|
427
|
+
{
|
428
|
+
hoku_ast_free(list->next_child);
|
429
|
+
}
|
430
|
+
|
431
|
+
free(list);
|
432
|
+
}
|
433
|
+
|
434
|
+
void hoku_ast_free(hoku_ast* component)
|
435
|
+
{
|
436
|
+
if (component->styles) hoku_style_free(component->styles);
|
437
|
+
hoku_ast_class_list_free(component->style_list);
|
438
|
+
hoku_ast_class_list_free(component->class_list);
|
439
|
+
hashmap_free(component->props);
|
440
|
+
hashmap_free(component->events);
|
441
|
+
free(component->type);
|
442
|
+
free(component->id);
|
443
|
+
|
444
|
+
hoku_ast_list_free(component->relations);
|
445
|
+
if (component->else_relations) hoku_ast_list_free(component->else_relations);
|
446
|
+
free(component);
|
447
|
+
}
|
448
|
+
#endif
|