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.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/Dockerfile +26 -0
  3. data/Gemfile +15 -0
  4. data/Gemfile.lock +91 -0
  5. data/LICENSE +21 -0
  6. data/README.md +28 -0
  7. data/ast/genheader +3 -0
  8. data/ast/include/hashmap.c +1151 -0
  9. data/ast/include/hashmap.c.license +20 -0
  10. data/ast/include/hashmap.h +54 -0
  11. data/ast/src/core/ast.c +448 -0
  12. data/ast/src/core/ast.h +259 -0
  13. data/ast/src/core/common.h +24 -0
  14. data/ast/src/core/component.c +85 -0
  15. data/ast/src/core/component.h +35 -0
  16. data/ast/src/core/hml.c +665 -0
  17. data/ast/src/core/hml.h +11 -0
  18. data/ast/src/core/input.c +458 -0
  19. data/ast/src/core/input.h +118 -0
  20. data/ast/src/core/style.c +101 -0
  21. data/ast/src/core/style.h +41 -0
  22. data/ast/src/core/text.c +784 -0
  23. data/ast/src/core/text.h +93 -0
  24. data/ast/src/core/util.c +140 -0
  25. data/ast/src/core/util.h +48 -0
  26. data/ast/src/hokusai.c +6 -0
  27. data/ast/src/hokusai.h +6 -0
  28. data/ast/test/fixtures/test.ui +13 -0
  29. data/ast/test/greatest.h +1266 -0
  30. data/ast/test/hokusai.c +14 -0
  31. data/ast/test/parser.c +234 -0
  32. data/ast/test/text.c +116 -0
  33. data/ext/extconf.rb +27 -0
  34. data/grammar/Cargo.lock +80 -0
  35. data/grammar/Cargo.toml +26 -0
  36. data/grammar/binding.gyp +20 -0
  37. data/grammar/bindings/node/binding.cc +28 -0
  38. data/grammar/bindings/node/index.js +19 -0
  39. data/grammar/bindings/rust/build.rs +40 -0
  40. data/grammar/bindings/rust/lib.rs +52 -0
  41. data/grammar/corpus/1_document.txt +131 -0
  42. data/grammar/corpus/2_selectors.txt +58 -0
  43. data/grammar/corpus/3_spaces.txt +69 -0
  44. data/grammar/corpus/4_errors.txt +10 -0
  45. data/grammar/corpus/5_macros.txt +175 -0
  46. data/grammar/corpus/6_styles.txt +81 -0
  47. data/grammar/grammar.js +275 -0
  48. data/grammar/package-lock.json +34 -0
  49. data/grammar/package.json +33 -0
  50. data/grammar/src/grammar.json +1269 -0
  51. data/grammar/src/node-types.json +474 -0
  52. data/grammar/src/parser.c +5772 -0
  53. data/grammar/src/scanner.c +258 -0
  54. data/grammar/src/tree_sitter/parser.h +230 -0
  55. data/grammar/src/tree_sitter/scanner.h +12 -0
  56. data/grammar/test.nml +10 -0
  57. data/hokusai.gemspec +19 -0
  58. data/ui/examples/assets/DigitalDisplay.ttf +0 -0
  59. data/ui/examples/assets/OpenSans-Regular.ttf +0 -0
  60. data/ui/examples/assets/addy.png +0 -0
  61. data/ui/examples/assets/baby_sean.png +0 -0
  62. data/ui/examples/assets/football-troll.png +0 -0
  63. data/ui/examples/assets/gear.png +0 -0
  64. data/ui/examples/assets/icecold.ttf +0 -0
  65. data/ui/examples/assets/science-troll.png +0 -0
  66. data/ui/examples/buddy.rb +31 -0
  67. data/ui/examples/clock.rb +58 -0
  68. data/ui/examples/counter.rb +123 -0
  69. data/ui/examples/dynamic.rb +147 -0
  70. data/ui/examples/foobar.rb +236 -0
  71. data/ui/examples/stock.rb +115 -0
  72. data/ui/examples/stock_decider/option.rb +74 -0
  73. data/ui/examples/tic_tac_toe.rb +246 -0
  74. data/ui/lib/lib_hokusai.rb +425 -0
  75. data/ui/spec/hokusai/ast_spec.rb +88 -0
  76. data/ui/spec/hokusai/automation/keys_transcoder_spec.rb +50 -0
  77. data/ui/spec/hokusai/automation/selector_spec.rb +68 -0
  78. data/ui/spec/hokusai/block_spec.rb +126 -0
  79. data/ui/spec/hokusai/directives_spec.rb +327 -0
  80. data/ui/spec/hokusai/e2e/client_spec.rb +58 -0
  81. data/ui/spec/hokusai/e2e/meta_spec.rb +42 -0
  82. data/ui/spec/hokusai/publisher_spec.rb +38 -0
  83. data/ui/spec/hokusai/slots_spec.rb +150 -0
  84. data/ui/spec/hokusai/util/piece_table_spec.rb +90 -0
  85. data/ui/spec/hokusai_spec.rb +0 -0
  86. data/ui/spec/spec_helper.rb +30 -0
  87. data/ui/src/hokusai/ast.rb +446 -0
  88. data/ui/src/hokusai/automation/client.rb +167 -0
  89. data/ui/src/hokusai/automation/constants.rb +98 -0
  90. data/ui/src/hokusai/automation/converters/selector_converter.rb +61 -0
  91. data/ui/src/hokusai/automation/driver.rb +54 -0
  92. data/ui/src/hokusai/automation/driver_command_queue.rb +50 -0
  93. data/ui/src/hokusai/automation/driver_commands/base.rb +79 -0
  94. data/ui/src/hokusai/automation/driver_commands/get_attribute.rb +41 -0
  95. data/ui/src/hokusai/automation/driver_commands/invoke.rb +33 -0
  96. data/ui/src/hokusai/automation/driver_commands/locate.rb +48 -0
  97. data/ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb +94 -0
  98. data/ui/src/hokusai/automation/driver_commands/trigger_mouse.rb +213 -0
  99. data/ui/src/hokusai/automation/keys_transcoder.rb +128 -0
  100. data/ui/src/hokusai/automation/selector.rb +39 -0
  101. data/ui/src/hokusai/automation/server.rb +114 -0
  102. data/ui/src/hokusai/automation.rb +3 -0
  103. data/ui/src/hokusai/backends/raylib/config.rb +47 -0
  104. data/ui/src/hokusai/backends/raylib/font.rb +113 -0
  105. data/ui/src/hokusai/backends/raylib/keys.rb +124 -0
  106. data/ui/src/hokusai/backends/raylib.rb +449 -0
  107. data/ui/src/hokusai/backends/sdl2/Monaco.ttf +0 -0
  108. data/ui/src/hokusai/backends/sdl2/color.rb +12 -0
  109. data/ui/src/hokusai/backends/sdl2/config.rb +31 -0
  110. data/ui/src/hokusai/backends/sdl2/font.rb +127 -0
  111. data/ui/src/hokusai/backends/sdl2/keys.rb +119 -0
  112. data/ui/src/hokusai/backends/sdl2.rb +529 -0
  113. data/ui/src/hokusai/block.rb +237 -0
  114. data/ui/src/hokusai/blocks/button.rb +100 -0
  115. data/ui/src/hokusai/blocks/checkbox.rb +51 -0
  116. data/ui/src/hokusai/blocks/circle.rb +28 -0
  117. data/ui/src/hokusai/blocks/clipped.rb +23 -0
  118. data/ui/src/hokusai/blocks/cursor.rb +49 -0
  119. data/ui/src/hokusai/blocks/dynamic.rb +37 -0
  120. data/ui/src/hokusai/blocks/empty.rb +10 -0
  121. data/ui/src/hokusai/blocks/hblock.rb +35 -0
  122. data/ui/src/hokusai/blocks/image.rb +18 -0
  123. data/ui/src/hokusai/blocks/input.rb +200 -0
  124. data/ui/src/hokusai/blocks/label.rb +39 -0
  125. data/ui/src/hokusai/blocks/panel.rb +126 -0
  126. data/ui/src/hokusai/blocks/rect.rb +24 -0
  127. data/ui/src/hokusai/blocks/scissor_begin.rb +18 -0
  128. data/ui/src/hokusai/blocks/scissor_end.rb +12 -0
  129. data/ui/src/hokusai/blocks/scrollbar.rb +103 -0
  130. data/ui/src/hokusai/blocks/selectable.rb +77 -0
  131. data/ui/src/hokusai/blocks/svg.rb +20 -0
  132. data/ui/src/hokusai/blocks/text.rb +214 -0
  133. data/ui/src/hokusai/blocks/titlebar/osx.rb +145 -0
  134. data/ui/src/hokusai/blocks/toggle.rb +55 -0
  135. data/ui/src/hokusai/blocks/vblock.rb +35 -0
  136. data/ui/src/hokusai/commands/base.rb +22 -0
  137. data/ui/src/hokusai/commands/circle.rb +47 -0
  138. data/ui/src/hokusai/commands/image.rb +45 -0
  139. data/ui/src/hokusai/commands/rect.rb +158 -0
  140. data/ui/src/hokusai/commands/scissor.rb +22 -0
  141. data/ui/src/hokusai/commands/text.rb +92 -0
  142. data/ui/src/hokusai/commands.rb +87 -0
  143. data/ui/src/hokusai/diff.rb +124 -0
  144. data/ui/src/hokusai/error.rb +3 -0
  145. data/ui/src/hokusai/event.rb +54 -0
  146. data/ui/src/hokusai/events/keyboard.rb +84 -0
  147. data/ui/src/hokusai/events/mouse.rb +172 -0
  148. data/ui/src/hokusai/font.rb +280 -0
  149. data/ui/src/hokusai/meta.rb +152 -0
  150. data/ui/src/hokusai/mounting/loop_entry.rb +230 -0
  151. data/ui/src/hokusai/mounting/mount_entry.rb +74 -0
  152. data/ui/src/hokusai/mounting/update_entry.rb +101 -0
  153. data/ui/src/hokusai/node.rb +98 -0
  154. data/ui/src/hokusai/node_mounter.rb +102 -0
  155. data/ui/src/hokusai/painter.rb +214 -0
  156. data/ui/src/hokusai/publisher.rb +32 -0
  157. data/ui/src/hokusai/style.rb +72 -0
  158. data/ui/src/hokusai/types.rb +266 -0
  159. data/ui/src/hokusai/util/clamping_iterator.rb +202 -0
  160. data/ui/src/hokusai/util/piece_table.rb +111 -0
  161. data/ui/src/hokusai/util/selection.rb +145 -0
  162. data/ui/src/hokusai.rb +120 -0
  163. data/ui/vendor/.gitkeep +0 -0
  164. data/vendor/.gitkeep +0 -0
  165. data/xmake.lua +192 -0
  166. metadata +222 -0
@@ -0,0 +1,258 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include "tree_sitter/parser.h"
4
+ #include <unistd.h>
5
+ #include <string.h>
6
+ enum TokenType
7
+ {
8
+ INDENT,
9
+ DEDENT,
10
+ NEWLINE,
11
+ ERROR_SENTINEL,
12
+ };
13
+
14
+ struct HmlScanList
15
+ {
16
+ long int col;
17
+ struct HmlScanList* next;
18
+ };
19
+
20
+ struct HmlScanner
21
+ {
22
+ struct HmlScanList* list;
23
+ };
24
+
25
+ /**
26
+ prepends an item to the stack
27
+ */
28
+ static void scanner_push(struct HmlScanList** scanner, long int col)
29
+ {
30
+ struct HmlScanList* first = malloc(sizeof(struct HmlScanList));
31
+ first->col = col;
32
+ first->next = *scanner;
33
+ *scanner = first;
34
+ }
35
+
36
+ /**
37
+ removes a item from the stack
38
+ */
39
+ static bool scanner_pop(struct HmlScanList** scanner)
40
+ {
41
+ if ((*scanner)->next == NULL)
42
+ {
43
+ return false;
44
+ }
45
+ else
46
+ {
47
+ struct HmlScanList* head = *scanner;
48
+ struct HmlScanList* next = head->next;
49
+ free(head);
50
+ *scanner = next;
51
+ return true;
52
+
53
+ }
54
+ }
55
+
56
+ /**
57
+ serialize the stack
58
+ 8 -> 6 -> 4 -> 2 -> 0
59
+
60
+ "0:2:4:6:8"
61
+ */
62
+ static void scanner_serialize(struct HmlScanList** scanner, char* buffer)
63
+ {
64
+ int i = 0;
65
+ struct HmlScanList* head = *scanner;
66
+ i = sprintf(buffer, "%ld", head->col);
67
+ head = head->next;
68
+ while (head != NULL && head->col != 0)
69
+ {
70
+ char tmp[200];
71
+ sprintf(tmp, "%ld:%s", head->col, buffer);
72
+ strcpy(buffer, tmp);
73
+ head = head->next;
74
+ }
75
+ // printf("buffer is %s (%d) it(%d)\n", buffer, strlen(buffer), i);
76
+ }
77
+
78
+ /**
79
+ deserialize the stack
80
+ */
81
+ static void scanner_deserialize(struct HmlScanner* scanner, const char* buffer, unsigned len)
82
+ {
83
+ // printf("stack serial: %s, len: %u\n", buffer,len);
84
+ if (len <= 0)
85
+ {
86
+ return;
87
+ }
88
+ while (scanner_pop(&scanner->list));
89
+
90
+ char* scan_ep;
91
+ char scan_buffer[32];
92
+ bool scanned_indent = false;
93
+ int track = 0;
94
+ int done = 0;
95
+
96
+ for (int i = 0; i < len; i++)
97
+ {
98
+ char letter = buffer[i];
99
+ if (buffer[i] == ':')
100
+ {
101
+ // parse indents and clear buffer
102
+ scan_buffer[i] = '\0';
103
+ long int col = strtol(scan_buffer, &scan_ep, 0);
104
+ scanner_push(&scanner->list, col);
105
+
106
+ for (int ii=0;ii<i;ii++)
107
+ {
108
+ scan_buffer[ii] = '\0';
109
+ }
110
+
111
+ track = i;
112
+ }
113
+ else
114
+ {
115
+ scan_buffer[done] = letter;
116
+ }
117
+ done = i - track;
118
+ }
119
+
120
+ scan_buffer[done + 1] = '\0';
121
+ long int col = strtol(scan_buffer, &scan_ep, 0);
122
+ scanner_push(&scanner->list, col);
123
+ }
124
+
125
+ void* tree_sitter_hml_external_scanner_create()
126
+ {
127
+ // printf("create scanner\n");
128
+ struct HmlScanner* scanner = malloc(sizeof(struct HmlScanner));
129
+ scanner->list = malloc(sizeof(struct HmlScanList));
130
+ scanner->list->col = 0;
131
+ scanner->list->next = NULL;
132
+ return scanner;
133
+ }
134
+
135
+ void tree_sitter_hml_external_scanner_destroy(void* payload)
136
+ {
137
+ // printf("destroy scanner\n");
138
+ struct HmlScanner* scanner = (struct HmlScanner*) payload;
139
+ while(scanner_pop(&scanner->list));
140
+ free(scanner->list);
141
+ free(scanner);
142
+ }
143
+
144
+ unsigned tree_sitter_hml_external_scanner_serialize(void* payload, char* buffer)
145
+ {
146
+ struct HmlScanner* scanner = (struct HmlScanner*) payload;
147
+ // printf("serizliae %ld\n", scanner->list->col);
148
+ scanner_serialize(&scanner->list, buffer);
149
+ return (unsigned) strlen(buffer);
150
+ }
151
+
152
+ void tree_sitter_hml_external_scanner_deserialize(void* payload, const char* buffer, unsigned len)
153
+ {
154
+ struct HmlScanner* scanner = (struct HmlScanner*) payload;
155
+ scanner_deserialize(scanner, buffer, len);
156
+ // printf("deserialized, %ld\n", scanner->list->col);
157
+ }
158
+
159
+ bool tree_sitter_hml_external_scanner_scan(void* payload, TSLexer* lexer, const bool* valid_symbols)
160
+ {
161
+ struct HmlScanner* scanner = (struct HmlScanner*) payload;
162
+
163
+ if (valid_symbols[ERROR_SENTINEL]) {
164
+ return false;
165
+ }
166
+
167
+ uint32_t current_column;
168
+
169
+ if (lexer->eof(lexer) || (lexer->lookahead == '[' && lexer->get_column(lexer) == 0))
170
+ {
171
+ // printf("COLUMN: %ld\n", scanner->list->col);
172
+ if (scanner->list->col != 0)
173
+ {
174
+ scanner_pop(&scanner->list);
175
+ lexer->result_symbol = DEDENT;
176
+ return true;
177
+ }
178
+ }
179
+
180
+ // find column position of next non whitespace char.
181
+ if (valid_symbols[INDENT] || valid_symbols[NEWLINE] || valid_symbols[DEDENT])
182
+ {
183
+ // {
184
+
185
+ // return false;
186
+ // }
187
+
188
+ while (true)
189
+ {
190
+ if (lexer->lookahead != ' ' && lexer->lookahead != '\f' && lexer->lookahead != '\n' && lexer->lookahead != '\t' && lexer->lookahead != '\0')
191
+ {
192
+ if (lexer->lookahead == '#' || lexer->lookahead == '{' || lexer->lookahead == '.') return false;
193
+
194
+ current_column = (long int) lexer->get_column(lexer) + 1;
195
+ long int a = -1;
196
+ if (scanner->list->next) a = scanner->list->next->col;
197
+ // printf("'%c' CURRENT %ld | SCANNED %ld | NEXT %ld\n", lexer->lookahead, current_column, scanner->list->col, a);
198
+
199
+ if (current_column == scanner->list->col)
200
+ {
201
+ lexer->result_symbol = NEWLINE;
202
+ return true;
203
+ }
204
+ else if (valid_symbols[INDENT] && current_column > scanner->list->col)
205
+ {
206
+ scanner_push(&scanner->list, current_column);
207
+ lexer->result_symbol = INDENT;
208
+ return true;
209
+ }
210
+ else if (scanner->list->next && scanner->list->next->col >= current_column)
211
+ {
212
+ // printf("Scanner pop\n");
213
+ scanner_pop(&scanner->list);
214
+ lexer->result_symbol = DEDENT;
215
+ return true;
216
+ }
217
+ else if (scanner->list->next && current_column < scanner->list->next->col)
218
+ {
219
+ // unreachable
220
+ // printf("POPPING '%c' CURRENT %ld | SCANNED %ld | NEXT %ld\n", lexer->lookahead, current_column, scanner->list->col, a);
221
+
222
+ while (scanner_pop(&scanner->list))
223
+ {
224
+ if (current_column > scanner->list->next->col)
225
+ {
226
+ return false;
227
+ }
228
+
229
+ if (current_column == scanner->list->next->col)
230
+ {
231
+ break;
232
+ }
233
+ }
234
+ lexer->result_symbol = DEDENT;
235
+ return true;
236
+ }
237
+ else
238
+ {
239
+ // printf("ERROR '%c' CURRENT %ld | SCANNED %ld | NEXT %ld\n", lexer->lookahead, current_column, scanner->list->col, a);
240
+ return false;
241
+ }
242
+ }
243
+ else if (lexer->lookahead == '\0')
244
+ {
245
+ if (scanner->list->col != 0)
246
+ {
247
+ return false;
248
+ }
249
+ return true;
250
+ }
251
+ else {
252
+ lexer->advance(lexer, false);
253
+ }
254
+ }
255
+ }
256
+
257
+ return false;
258
+ }
@@ -0,0 +1,230 @@
1
+ #ifndef TREE_SITTER_PARSER_H_
2
+ #define TREE_SITTER_PARSER_H_
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include <stdbool.h>
9
+ #include <stdint.h>
10
+ #include <stdlib.h>
11
+
12
+ #define ts_builtin_sym_error ((TSSymbol)-1)
13
+ #define ts_builtin_sym_end 0
14
+ #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
15
+
16
+ #ifndef TREE_SITTER_API_H_
17
+ typedef uint16_t TSStateId;
18
+ typedef uint16_t TSSymbol;
19
+ typedef uint16_t TSFieldId;
20
+ typedef struct TSLanguage TSLanguage;
21
+ #endif
22
+
23
+ typedef struct {
24
+ TSFieldId field_id;
25
+ uint8_t child_index;
26
+ bool inherited;
27
+ } TSFieldMapEntry;
28
+
29
+ typedef struct {
30
+ uint16_t index;
31
+ uint16_t length;
32
+ } TSFieldMapSlice;
33
+
34
+ typedef struct {
35
+ bool visible;
36
+ bool named;
37
+ bool supertype;
38
+ } TSSymbolMetadata;
39
+
40
+ typedef struct TSLexer TSLexer;
41
+
42
+ struct TSLexer {
43
+ int32_t lookahead;
44
+ TSSymbol result_symbol;
45
+ void (*advance)(TSLexer *, bool);
46
+ void (*mark_end)(TSLexer *);
47
+ uint32_t (*get_column)(TSLexer *);
48
+ bool (*is_at_included_range_start)(const TSLexer *);
49
+ bool (*eof)(const TSLexer *);
50
+ };
51
+
52
+ typedef enum {
53
+ TSParseActionTypeShift,
54
+ TSParseActionTypeReduce,
55
+ TSParseActionTypeAccept,
56
+ TSParseActionTypeRecover,
57
+ } TSParseActionType;
58
+
59
+ typedef union {
60
+ struct {
61
+ uint8_t type;
62
+ TSStateId state;
63
+ bool extra;
64
+ bool repetition;
65
+ } shift;
66
+ struct {
67
+ uint8_t type;
68
+ uint8_t child_count;
69
+ TSSymbol symbol;
70
+ int16_t dynamic_precedence;
71
+ uint16_t production_id;
72
+ } reduce;
73
+ uint8_t type;
74
+ } TSParseAction;
75
+
76
+ typedef struct {
77
+ uint16_t lex_state;
78
+ uint16_t external_lex_state;
79
+ } TSLexMode;
80
+
81
+ typedef union {
82
+ TSParseAction action;
83
+ struct {
84
+ uint8_t count;
85
+ bool reusable;
86
+ } entry;
87
+ } TSParseActionEntry;
88
+
89
+ struct TSLanguage {
90
+ uint32_t version;
91
+ uint32_t symbol_count;
92
+ uint32_t alias_count;
93
+ uint32_t token_count;
94
+ uint32_t external_token_count;
95
+ uint32_t state_count;
96
+ uint32_t large_state_count;
97
+ uint32_t production_id_count;
98
+ uint32_t field_count;
99
+ uint16_t max_alias_sequence_length;
100
+ const uint16_t *parse_table;
101
+ const uint16_t *small_parse_table;
102
+ const uint32_t *small_parse_table_map;
103
+ const TSParseActionEntry *parse_actions;
104
+ const char * const *symbol_names;
105
+ const char * const *field_names;
106
+ const TSFieldMapSlice *field_map_slices;
107
+ const TSFieldMapEntry *field_map_entries;
108
+ const TSSymbolMetadata *symbol_metadata;
109
+ const TSSymbol *public_symbol_map;
110
+ const uint16_t *alias_map;
111
+ const TSSymbol *alias_sequences;
112
+ const TSLexMode *lex_modes;
113
+ bool (*lex_fn)(TSLexer *, TSStateId);
114
+ bool (*keyword_lex_fn)(TSLexer *, TSStateId);
115
+ TSSymbol keyword_capture_token;
116
+ struct {
117
+ const bool *states;
118
+ const TSSymbol *symbol_map;
119
+ void *(*create)(void);
120
+ void (*destroy)(void *);
121
+ bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
122
+ unsigned (*serialize)(void *, char *);
123
+ void (*deserialize)(void *, const char *, unsigned);
124
+ } external_scanner;
125
+ const TSStateId *primary_state_ids;
126
+ };
127
+
128
+ /*
129
+ * Lexer Macros
130
+ */
131
+
132
+ #ifdef _MSC_VER
133
+ #define UNUSED __pragma(warning(suppress : 4101))
134
+ #else
135
+ #define UNUSED __attribute__((unused))
136
+ #endif
137
+
138
+ #define START_LEXER() \
139
+ bool result = false; \
140
+ bool skip = false; \
141
+ UNUSED \
142
+ bool eof = false; \
143
+ int32_t lookahead; \
144
+ goto start; \
145
+ next_state: \
146
+ lexer->advance(lexer, skip); \
147
+ start: \
148
+ skip = false; \
149
+ lookahead = lexer->lookahead;
150
+
151
+ #define ADVANCE(state_value) \
152
+ { \
153
+ state = state_value; \
154
+ goto next_state; \
155
+ }
156
+
157
+ #define SKIP(state_value) \
158
+ { \
159
+ skip = true; \
160
+ state = state_value; \
161
+ goto next_state; \
162
+ }
163
+
164
+ #define ACCEPT_TOKEN(symbol_value) \
165
+ result = true; \
166
+ lexer->result_symbol = symbol_value; \
167
+ lexer->mark_end(lexer);
168
+
169
+ #define END_STATE() return result;
170
+
171
+ /*
172
+ * Parse Table Macros
173
+ */
174
+
175
+ #define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
176
+
177
+ #define STATE(id) id
178
+
179
+ #define ACTIONS(id) id
180
+
181
+ #define SHIFT(state_value) \
182
+ {{ \
183
+ .shift = { \
184
+ .type = TSParseActionTypeShift, \
185
+ .state = (state_value) \
186
+ } \
187
+ }}
188
+
189
+ #define SHIFT_REPEAT(state_value) \
190
+ {{ \
191
+ .shift = { \
192
+ .type = TSParseActionTypeShift, \
193
+ .state = (state_value), \
194
+ .repetition = true \
195
+ } \
196
+ }}
197
+
198
+ #define SHIFT_EXTRA() \
199
+ {{ \
200
+ .shift = { \
201
+ .type = TSParseActionTypeShift, \
202
+ .extra = true \
203
+ } \
204
+ }}
205
+
206
+ #define REDUCE(symbol_val, child_count_val, ...) \
207
+ {{ \
208
+ .reduce = { \
209
+ .type = TSParseActionTypeReduce, \
210
+ .symbol = symbol_val, \
211
+ .child_count = child_count_val, \
212
+ __VA_ARGS__ \
213
+ }, \
214
+ }}
215
+
216
+ #define RECOVER() \
217
+ {{ \
218
+ .type = TSParseActionTypeRecover \
219
+ }}
220
+
221
+ #define ACCEPT_INPUT() \
222
+ {{ \
223
+ .type = TSParseActionTypeAccept \
224
+ }}
225
+
226
+ #ifdef __cplusplus
227
+ }
228
+ #endif
229
+
230
+ #endif // TREE_SITTER_PARSER_H_
@@ -0,0 +1,12 @@
1
+ #ifndef TREE_SITTER_SCANNER_H_
2
+ #define TREE_SITTER_SCANNER_H_
3
+ #include "parser.h"
4
+
5
+ extern const TSLanguage *tree_sitter_hml(void);
6
+ void *tree_sitter_hml_external_scanner_create(void);
7
+ void tree_sitter_hml_external_scanner_destroy(void *);
8
+ bool tree_sitter_hml_external_scanner_scan(void *, TSLexer *, const bool *);
9
+ unsigned tree_sitter_hml_external_scanner_serialize(void *, char *);
10
+ void tree_sitter_hml_external_scanner_deserialize(void *, const char *, unsigned);
11
+
12
+ #endif
data/grammar/test.nml ADDED
@@ -0,0 +1,10 @@
1
+ [template]
2
+ vblock {
3
+ ...styleSpread
4
+ }
5
+
6
+ [style]
7
+ styleSpread {
8
+ background: rgb(86, 116, 25);
9
+ outline_color: rgba(191, 112, 112, 0.67);
10
+ }
data/hokusai.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'hokusai-zero'
3
+ s.version = '0.1.1'
4
+ s.licenses = ['MIT']
5
+ s.summary = "A Ruby library for writing GUI applications"
6
+ s.authors = ["skinnyjames"]
7
+ s.email = 'zero@skinnyjames.net'
8
+ s.extensions << "ext/extconf.rb"
9
+ s.require_paths = ['ui/src']
10
+
11
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
12
+ f =~ /^(\.|spec)/
13
+ end
14
+
15
+ s.homepage = 'https://codeberg.org/skinnyjames/hokusai'
16
+ s.metadata = { "source_code_uri" => "https://codeberg.org/skinnyjames/hokusai" }
17
+
18
+ s.add_dependency "ffi", "~> 1.16"
19
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,31 @@
1
+ require_relative "../src/hokusai"
2
+ require_relative "../src/hokusai/backends/sdl2"
3
+ require_relative "../src/hokusai/backends/raylib"
4
+
5
+ module Buddy
6
+ class App < Hokusai::Block
7
+ template <<~EOF
8
+ [template]
9
+ buddy {
10
+ width="400"
11
+ height="400"
12
+ :source="buddy_img"
13
+ }
14
+ EOF
15
+
16
+ uses(buddy: Hokusai::Blocks::Image)
17
+
18
+ def buddy_img
19
+ "#{__dir__}/assets/science-troll.png"
20
+ end
21
+ end
22
+ end
23
+
24
+ Hokusai::Backends::RaylibBackend.run(Buddy::App) do |config|
25
+ config.width = 500
26
+ config.height = 500
27
+ config.title = "Buddy"
28
+ config.config_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_VSYNC_HINT | Raylib::FLAG_WINDOW_TRANSPARENT
29
+ config.window_state_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_WINDOW_UNDECORATED | Raylib::FLAG_WINDOW_TRANSPARENT
30
+ config.background = Raylib::BLANK
31
+ end
@@ -0,0 +1,58 @@
1
+ require_relative "../src/hokusai"
2
+ require_relative "../src/hokusai/backends/sdl2"
3
+ require_relative "../src/hokusai/backends/raylib"
4
+ require_relative "./tic_tac_toe"
5
+ require_relative "./counter"
6
+ require "date"
7
+
8
+ class Clock < Hokusai::Block
9
+ template <<~EOF
10
+ [template]
11
+ vblock { background="22,22,22" height="50"}
12
+ label { :content="time" size="30" color="233,233,233" }
13
+ hblock
14
+ game { @width="set_width"}
15
+ [if="fullscreen"]
16
+ stock
17
+ EOF
18
+
19
+ uses(
20
+ vblock: Hokusai::Blocks::Vblock,
21
+ hblock: Hokusai::Blocks::Hblock,
22
+ empty: Hokusai::Blocks::Empty,
23
+ label: Hokusai::Blocks::Label,
24
+ game: TicTacToe::App,
25
+ stock: Counter
26
+ )
27
+
28
+ attr_accessor :width
29
+
30
+ provide :clock_time, :time
31
+
32
+ def time
33
+ time = DateTime.now
34
+ "#{time.hour}:#{time.minute} #{time.second}"
35
+ end
36
+
37
+ def set_width(width)
38
+ @width = width
39
+ end
40
+
41
+ def fullscreen
42
+ (width || 0) > 500
43
+ end
44
+ end
45
+
46
+ Hokusai::Backends::SDLBackend.run(Clock) do |config|
47
+ config.after_load do
48
+ # Note: how to load a font...
49
+ # Thank you to Vladimir Nikolic - https://www.1001fonts.com/users/vladimirnikolic/
50
+ font = Hokusai::Backends::SDLBackend::Font.from_ext("#{__dir__}/assets/DigitalDisplay.ttf", 132)
51
+ Hokusai.fonts.register "DigitalDisplay", font
52
+ # Hokusai.fonts.activate "DigitalDisplay"
53
+ end
54
+
55
+ config.width = 500
56
+ config.height = 500
57
+ config.title = "Counter application"
58
+ end