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,275 @@
1
+ module.exports = grammar({
2
+ name: 'hml',
3
+ extras: $ => [$.comment, /\s+/],
4
+ externals: $ => [$._indent, $._dedent, $._newline, $.error_sentinel],
5
+
6
+ rules: {
7
+ document: $ => choice(
8
+ seq($.template, $.style_template),
9
+ seq($.style_template, $.template),
10
+ $.template,
11
+ $.style_template
12
+ ),
13
+
14
+ comment: $ => seq(
15
+ '#!',
16
+ /.*/,
17
+ '!#'
18
+ ),
19
+
20
+ template: $ => seq(
21
+ $._template_macro,
22
+ $._element_body,
23
+ ),
24
+
25
+ style_template: $ => seq(
26
+ $._style_macro,
27
+ repeat1(alias($._style_body, $.style))
28
+ ),
29
+
30
+ _body: $ => choice(
31
+ $._element_body,
32
+ // $._macro_body,
33
+ ),
34
+
35
+ element: $ => seq(
36
+ alias($._word, $.name),
37
+ optional($.selectors),
38
+ optional(alias($._element_attributes, $.attributes)),
39
+ optional(alias($._element_body, $.children)),
40
+ ),
41
+
42
+ selectors: $ => choice(
43
+ seq(
44
+ $._element_id_selctor,
45
+ repeat($._element_class_selector),
46
+ ),
47
+ repeat1($._element_class_selector),
48
+ ),
49
+
50
+ _element_body: $ => choice(
51
+ seq(
52
+ $._indent,
53
+ repeat(
54
+ prec.right(2, choice(
55
+ seq(
56
+ $.element,
57
+ $._newline,
58
+ ),
59
+ seq(
60
+ $.for_if_macro,
61
+ optional(seq($._newline, $.else_macro)),
62
+ $._newline,
63
+ ),
64
+ seq(
65
+ $.for_macro,
66
+ $._newline
67
+ ),
68
+ seq(
69
+ $.if_macro,
70
+ optional(seq($._newline, $.else_macro)),
71
+ $._newline
72
+ ),
73
+ ),
74
+ )),
75
+ prec.right(3, choice(
76
+ $.element,
77
+ seq($.if_macro, optional(seq($._newline, $.else_macro))),
78
+ seq($.for_if_macro, optional(seq($._newline, $.else_macro))),
79
+ $.for_macro
80
+ )),
81
+ optional(/ *\n\s*/),
82
+ $._dedent,
83
+ ),
84
+ ),
85
+
86
+ // _macro_body: $ => choice(
87
+ // choice(
88
+ // seq(
89
+ // $._indent,
90
+ // $.for_macro,
91
+ // repeat(seq($._newline, choice($.if_macro, $.for_macro, $.element))),
92
+ // optional(/ *\n\s*/),
93
+ // $._dedent,
94
+ // ),
95
+ // seq(
96
+ // $._indent,
97
+ // $.if_macro,
98
+ // optional(seq($._newline, $.else_macro)),
99
+ // repeat(seq($._newline, choice($.if_macro, $.for_macro, $.element))),
100
+ // optional(/ *\n\s*/),
101
+ // $._dedent,
102
+ // ),
103
+ // )
104
+ // ),
105
+
106
+ _element_attributes: $ => seq(
107
+ $._attributes_start,
108
+ repeat(seq(choice($.prop, $.event, seq($._spread_punctuation, alias($._spread, $.style))), optional($._comma))),
109
+ $._attributes_end,
110
+ ),
111
+
112
+ event: $ => seq(
113
+ $._at,
114
+ alias($._method, $.name),
115
+ $._equal,
116
+ $._quote,
117
+ $.function,
118
+ $._quote
119
+ ),
120
+
121
+ prop: $ => seq(
122
+ optional(alias($._colon, $.computed)),
123
+ alias($._method, $.name),
124
+ $._equal,
125
+ $._quote,
126
+ $.function,
127
+ $._quote
128
+ ),
129
+
130
+ function: $ => seq(
131
+ alias(choice($._float, $._static_string), $.name),
132
+ optional(alias($.function_args, $.args))
133
+ ),
134
+
135
+ function_args: $ => seq(
136
+ $._lparen,
137
+ repeat(seq(alias($._word, $.arg), $._comma, /\s*/)),
138
+ alias($._word, $.arg),
139
+ $._rparen,
140
+ ),
141
+
142
+ _element_id_selctor: $ => seq($._pound, alias($._word, $.id)),
143
+ _element_class_selector: $ => seq($._dot, alias($._word, $.class)),
144
+
145
+ _template_macro: $ => seq(
146
+ $._macro_start,
147
+ $._template_key,
148
+ $._macro_end
149
+ ),
150
+
151
+ _spread: $ => seq(
152
+ alias($._method, $.name)
153
+ ),
154
+
155
+ _style_macro: $ => seq(
156
+ $._macro_start,
157
+ $._style_key,
158
+ $._macro_end
159
+ ),
160
+
161
+ _style_body: $ => seq(
162
+ alias($._word, $.name),
163
+ $._attributes_start,
164
+ alias(repeat(alias($._style_element, $.element)), $.children),
165
+ $._attributes_end
166
+ ),
167
+
168
+ _style_element: $ => seq(
169
+ optional(/\s+/),
170
+ alias($._method, $.name),
171
+ $._colon,
172
+ optional(/\s+/),
173
+ choice(
174
+ seq($._quote, alias($._method, $.style_string), $._quote),
175
+ $.style_float,
176
+ $.style_int,
177
+ $.style_bool,
178
+ $.style_func
179
+ ),
180
+ $._semi,
181
+ optional(/\s*/)
182
+ ),
183
+
184
+ // style_string: $ => seq($._quote, alias($._method, $.value), $._quote),
185
+ style_float: $ => $._float,
186
+ style_int: $ => /[0-9]+/,
187
+ style_bool: $ => /true|false/,
188
+ style_func: $ => seq(
189
+ alias($._method, $.function),
190
+ $._lparen,
191
+ alias($._any, $.value),
192
+ $._rparen
193
+ ),
194
+
195
+ for_macro: $ => seq(
196
+ $._macro_start,
197
+ $._for_key,
198
+ $._equal,
199
+ $._quote,
200
+ alias($._method, $.name),
201
+ "in",
202
+ alias($._method, $.list_name),
203
+ $._quote,
204
+ $._macro_end,
205
+ alias($._element_body, $.children)
206
+ ),
207
+
208
+ for_if_macro: $ => seq(
209
+ $._macro_start,
210
+ $._for_key,
211
+ $._equal,
212
+ $._quote,
213
+ alias($._method, $.name),
214
+ "in",
215
+ alias($._method, $.list_name),
216
+ $._quote,
217
+ $._macro_end,
218
+ $._newline,
219
+ $._macro_start,
220
+ $._if_key,
221
+ $._equal,
222
+ $._quote,
223
+ alias($.function, $.if_function),
224
+ $._quote,
225
+ $._macro_end,
226
+ alias($._element_body, $.children)
227
+ ),
228
+
229
+ if_macro: $ => seq(
230
+ $._macro_start,
231
+ $._if_key,
232
+ $._equal,
233
+ $._quote,
234
+ $.function,
235
+ $._quote,
236
+ $._macro_end,
237
+ alias($._element_body, $.children),
238
+ ),
239
+
240
+ else_macro: $ => seq(
241
+ $._macro_start,
242
+ $._else_key,
243
+ $._macro_end,
244
+ alias($._element_body, $.children),
245
+ ),
246
+
247
+ _spread_punctuation: $ => "...",
248
+ _for_key: $ => "for",
249
+ _if_key: $ => "if",
250
+ _else_key: $ => "else",
251
+ _template_key: $ => "template",
252
+ _style_key: $ => "style",
253
+ _any: $ => /[A-Za-z0-9\,\_\-\=\*\&\^\%\.\$\#\s]*/,
254
+ _method: $ => /[A-Za-z][A-Za-z0-9\_]*/,
255
+ _word: $ => /[A-Za-z][A-Za-z0-9_-]*/,
256
+ _float: $ => /\d+\.\d+/,
257
+ _static_string: $ => /[A-Za-z0-9_\-,]*/,
258
+ _attributes_start: $ => / *\{/,
259
+ _attributes_end: $ => /\} */,
260
+ _macro_start: $ => "[",
261
+ _macro_end: $ => "]",
262
+ _lparen: $ => "(",
263
+ _rparen: $ => ")",
264
+ _lbrack: $ => "[",
265
+ _rbrack: $ => "]",
266
+ _comma: $ => ",",
267
+ _semi: $ => /\;/,
268
+ _colon: $ => /\:/,
269
+ _equal: $ => "=",
270
+ _pound: $ => "#",
271
+ _quote: $ => "\"",
272
+ _dot: $ => ".",
273
+ _at: $ => "@",
274
+ },
275
+ })
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "grammar",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "grammar",
9
+ "version": "1.0.0",
10
+ "license": "MIT",
11
+ "dependencies": {
12
+ "nan": "^2.18.0"
13
+ },
14
+ "devDependencies": {
15
+ "tree-sitter-cli": "^0.21.0-pre-release-1"
16
+ }
17
+ },
18
+ "node_modules/nan": {
19
+ "version": "2.18.0",
20
+ "resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz",
21
+ "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w=="
22
+ },
23
+ "node_modules/tree-sitter-cli": {
24
+ "version": "0.21.0-pre-release-1",
25
+ "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.21.0-pre-release-1.tgz",
26
+ "integrity": "sha512-Vr/9mlcphNSSYKB73UpBlVE9ZiRfLcsYtbsdFEfIq9Kh306W0nGY0QISvnn5vixmx6oAS//pbWcrz0uUPwRvcA==",
27
+ "dev": true,
28
+ "hasInstallScript": true,
29
+ "bin": {
30
+ "tree-sitter": "cli.js"
31
+ }
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "grammar",
3
+ "version": "1.0.0",
4
+ "description": "Grammar for hokusai templates",
5
+ "main": "bindings/node",
6
+ "scripts": {
7
+ "test": "npm run build && tree-sitter test",
8
+ "build": "tree-sitter generate",
9
+ "parse": "npm run build && tree-sitter parse test.nml",
10
+ "debug": "npm run build && tree-sitter parse --debug test.nml",
11
+ "highlight": "tree-sitter highlight test.nml"
12
+ },
13
+ "author": "",
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "nan": "^2.18.0"
17
+ },
18
+ "devDependencies": {
19
+ "tree-sitter-cli": "^0.21.0-pre-release-1"
20
+ },
21
+ "tree-sitter": [
22
+ {
23
+ "scope": "source.hml",
24
+ "file-types": [
25
+ ".hml"
26
+ ],
27
+ "first-line-regex": "^{{ *template *}}",
28
+ "highlights": [
29
+ "queries/highlights.scm"
30
+ ]
31
+ }
32
+ ]
33
+ }