@herb-tools/node 0.8.10 → 0.9.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.
- package/binding.gyp +27 -8
- package/dist/herb-node.cjs +41 -12
- package/dist/herb-node.cjs.map +1 -1
- package/dist/herb-node.esm.js +8 -1
- package/dist/herb-node.esm.js.map +1 -1
- package/dist/types/node-backend.d.ts +3 -1
- package/extension/error_helpers.cpp +598 -73
- package/extension/error_helpers.h +20 -3
- package/extension/extension_helpers.cpp +40 -35
- package/extension/extension_helpers.h +2 -2
- package/extension/herb.cpp +194 -64
- package/extension/libherb/analyze/action_view/attribute_extraction_helpers.c +303 -0
- package/extension/libherb/analyze/action_view/attribute_extraction_helpers.h +36 -0
- package/extension/libherb/analyze/action_view/content_tag.c +78 -0
- package/extension/libherb/analyze/action_view/link_to.c +167 -0
- package/extension/libherb/analyze/action_view/registry.c +83 -0
- package/extension/libherb/analyze/action_view/tag.c +70 -0
- package/extension/libherb/analyze/action_view/tag_helper_handler.h +43 -0
- package/extension/libherb/analyze/action_view/tag_helper_node_builders.c +305 -0
- package/extension/libherb/analyze/action_view/tag_helper_node_builders.h +70 -0
- package/extension/libherb/analyze/action_view/tag_helpers.c +815 -0
- package/extension/libherb/analyze/action_view/tag_helpers.h +38 -0
- package/extension/libherb/analyze/action_view/turbo_frame_tag.c +88 -0
- package/extension/libherb/analyze/analyze.c +885 -0
- package/extension/libherb/{include → analyze}/analyze.h +14 -4
- package/extension/libherb/{analyzed_ruby.c → analyze/analyzed_ruby.c} +13 -11
- package/extension/libherb/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
- package/extension/libherb/analyze/builders.c +343 -0
- package/extension/libherb/analyze/builders.h +27 -0
- package/extension/libherb/analyze/conditional_elements.c +594 -0
- package/extension/libherb/analyze/conditional_elements.h +9 -0
- package/extension/libherb/analyze/conditional_open_tags.c +640 -0
- package/extension/libherb/analyze/conditional_open_tags.h +9 -0
- package/extension/libherb/analyze/control_type.c +250 -0
- package/extension/libherb/analyze/control_type.h +14 -0
- package/extension/libherb/{analyze_helpers.c → analyze/helpers.c} +48 -23
- package/extension/libherb/{analyze_helpers.h → analyze/helpers.h} +4 -2
- package/extension/libherb/analyze/invalid_structures.c +193 -0
- package/extension/libherb/analyze/invalid_structures.h +11 -0
- package/extension/libherb/{analyze_missing_end.c → analyze/missing_end.c} +33 -22
- package/extension/libherb/analyze/parse_errors.c +84 -0
- package/extension/libherb/analyze/prism_annotate.c +399 -0
- package/extension/libherb/analyze/prism_annotate.h +16 -0
- package/extension/libherb/analyze/render_nodes.c +761 -0
- package/extension/libherb/analyze/render_nodes.h +11 -0
- package/extension/libherb/{analyze_transform.c → analyze/transform.c} +24 -3
- package/extension/libherb/ast_node.c +17 -7
- package/extension/libherb/ast_node.h +11 -5
- package/extension/libherb/ast_nodes.c +760 -388
- package/extension/libherb/ast_nodes.h +155 -39
- package/extension/libherb/ast_pretty_print.c +265 -7
- package/extension/libherb/ast_pretty_print.h +6 -1
- package/extension/libherb/element_source.h +3 -8
- package/extension/libherb/errors.c +1455 -520
- package/extension/libherb/errors.h +207 -56
- package/extension/libherb/extract.c +145 -49
- package/extension/libherb/extract.h +21 -5
- package/extension/libherb/herb.c +52 -34
- package/extension/libherb/herb.h +18 -6
- package/extension/libherb/herb_prism_node.h +13 -0
- package/extension/libherb/html_util.c +241 -12
- package/extension/libherb/html_util.h +7 -2
- package/extension/libherb/include/analyze/action_view/attribute_extraction_helpers.h +36 -0
- package/extension/libherb/include/analyze/action_view/tag_helper_handler.h +43 -0
- package/extension/libherb/include/analyze/action_view/tag_helper_node_builders.h +70 -0
- package/extension/libherb/include/analyze/action_view/tag_helpers.h +38 -0
- package/extension/libherb/{analyze.h → include/analyze/analyze.h} +14 -4
- package/extension/libherb/include/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
- package/extension/libherb/include/analyze/builders.h +27 -0
- package/extension/libherb/include/analyze/conditional_elements.h +9 -0
- package/extension/libherb/include/analyze/conditional_open_tags.h +9 -0
- package/extension/libherb/include/analyze/control_type.h +14 -0
- package/extension/libherb/include/{analyze_helpers.h → analyze/helpers.h} +4 -2
- package/extension/libherb/include/analyze/invalid_structures.h +11 -0
- package/extension/libherb/include/analyze/prism_annotate.h +16 -0
- package/extension/libherb/include/analyze/render_nodes.h +11 -0
- package/extension/libherb/include/ast_node.h +11 -5
- package/extension/libherb/include/ast_nodes.h +155 -39
- package/extension/libherb/include/ast_pretty_print.h +6 -1
- package/extension/libherb/include/element_source.h +3 -8
- package/extension/libherb/include/errors.h +207 -56
- package/extension/libherb/include/extract.h +21 -5
- package/extension/libherb/include/herb.h +18 -6
- package/extension/libherb/include/herb_prism_node.h +13 -0
- package/extension/libherb/include/html_util.h +7 -2
- package/extension/libherb/include/io.h +3 -1
- package/extension/libherb/include/lex_helpers.h +29 -0
- package/extension/libherb/include/lexer.h +1 -1
- package/extension/libherb/include/lexer_peek_helpers.h +87 -13
- package/extension/libherb/include/lexer_struct.h +2 -0
- package/extension/libherb/include/location.h +2 -1
- package/extension/libherb/include/parser.h +28 -2
- package/extension/libherb/include/parser_helpers.h +19 -3
- package/extension/libherb/include/pretty_print.h +10 -5
- package/extension/libherb/include/prism_context.h +45 -0
- package/extension/libherb/include/prism_helpers.h +10 -7
- package/extension/libherb/include/prism_serialized.h +12 -0
- package/extension/libherb/include/token.h +16 -4
- package/extension/libherb/include/token_struct.h +10 -3
- package/extension/libherb/include/utf8.h +2 -1
- package/extension/libherb/include/util/hb_allocator.h +78 -0
- package/extension/libherb/include/util/hb_arena.h +6 -1
- package/extension/libherb/include/util/hb_arena_debug.h +12 -1
- package/extension/libherb/include/util/hb_array.h +7 -3
- package/extension/libherb/include/util/hb_buffer.h +6 -4
- package/extension/libherb/include/util/hb_foreach.h +79 -0
- package/extension/libherb/include/util/hb_narray.h +8 -4
- package/extension/libherb/include/util/hb_string.h +56 -9
- package/extension/libherb/include/util.h +6 -3
- package/extension/libherb/include/version.h +1 -1
- package/extension/libherb/io.c +3 -2
- package/extension/libherb/io.h +3 -1
- package/extension/libherb/lex_helpers.h +29 -0
- package/extension/libherb/lexer.c +42 -30
- package/extension/libherb/lexer.h +1 -1
- package/extension/libherb/lexer_peek_helpers.c +12 -74
- package/extension/libherb/lexer_peek_helpers.h +87 -13
- package/extension/libherb/lexer_struct.h +2 -0
- package/extension/libherb/location.c +2 -2
- package/extension/libherb/location.h +2 -1
- package/extension/libherb/main.c +53 -28
- package/extension/libherb/parser.c +784 -247
- package/extension/libherb/parser.h +28 -2
- package/extension/libherb/parser_helpers.c +110 -23
- package/extension/libherb/parser_helpers.h +19 -3
- package/extension/libherb/parser_match_tags.c +130 -49
- package/extension/libherb/pretty_print.c +29 -24
- package/extension/libherb/pretty_print.h +10 -5
- package/extension/libherb/prism_context.h +45 -0
- package/extension/libherb/prism_helpers.c +30 -27
- package/extension/libherb/prism_helpers.h +10 -7
- package/extension/libherb/prism_serialized.h +12 -0
- package/extension/libherb/ruby_parser.c +2 -0
- package/extension/libherb/token.c +151 -66
- package/extension/libherb/token.h +16 -4
- package/extension/libherb/token_matchers.c +0 -1
- package/extension/libherb/token_struct.h +10 -3
- package/extension/libherb/utf8.c +7 -6
- package/extension/libherb/utf8.h +2 -1
- package/extension/libherb/util/hb_allocator.c +341 -0
- package/extension/libherb/util/hb_allocator.h +78 -0
- package/extension/libherb/util/hb_arena.c +81 -56
- package/extension/libherb/util/hb_arena.h +6 -1
- package/extension/libherb/util/hb_arena_debug.c +32 -17
- package/extension/libherb/util/hb_arena_debug.h +12 -1
- package/extension/libherb/util/hb_array.c +30 -15
- package/extension/libherb/util/hb_array.h +7 -3
- package/extension/libherb/util/hb_buffer.c +17 -21
- package/extension/libherb/util/hb_buffer.h +6 -4
- package/extension/libherb/util/hb_foreach.h +79 -0
- package/extension/libherb/util/hb_narray.c +22 -7
- package/extension/libherb/util/hb_narray.h +8 -4
- package/extension/libherb/util/hb_string.c +49 -35
- package/extension/libherb/util/hb_string.h +56 -9
- package/extension/libherb/util.c +21 -11
- package/extension/libherb/util.h +6 -3
- package/extension/libherb/version.h +1 -1
- package/extension/libherb/visitor.c +68 -1
- package/extension/nodes.cpp +593 -6
- package/extension/nodes.h +10 -1
- package/package.json +12 -8
- package/src/node-backend.ts +11 -1
- package/dist/types/index-cjs.d.cts +0 -1
- package/extension/libherb/analyze.c +0 -1608
- package/extension/libherb/element_source.c +0 -12
- package/extension/libherb/include/util/hb_system.h +0 -9
- package/extension/libherb/util/hb_system.c +0 -30
- package/extension/libherb/util/hb_system.h +0 -9
- package/src/index-cjs.cts +0 -22
- /package/dist/types/{index-esm.d.mts → index.d.ts} +0 -0
- /package/src/{index-esm.mts → index.ts} +0 -0
|
@@ -3,13 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
#include "util/hb_string.h"
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
ELEMENT_SOURCE_HAML,
|
|
10
|
-
ELEMENT_SOURCE_SLIM
|
|
11
|
-
} element_source_t;
|
|
12
|
-
|
|
13
|
-
hb_string_T element_source_to_string(element_source_t source);
|
|
6
|
+
#define ELEMENT_SOURCE_HTML hb_string("HTML")
|
|
7
|
+
#define ELEMENT_SOURCE_HAML hb_string("Haml")
|
|
8
|
+
#define ELEMENT_SOURCE_SLIM hb_string("Slim")
|
|
14
9
|
|
|
15
10
|
#endif
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
2
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.
|
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.1/templates/src/include/errors.h.erb
|
|
3
3
|
|
|
4
4
|
#ifndef HERB_ERRORS_H
|
|
5
5
|
#define HERB_ERRORS_H
|
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
#include "location.h"
|
|
9
9
|
#include "position.h"
|
|
10
10
|
#include "token.h"
|
|
11
|
+
#include "util/hb_allocator.h"
|
|
11
12
|
#include "util/hb_array.h"
|
|
12
13
|
#include "util/hb_buffer.h"
|
|
14
|
+
#include "util/hb_string.h"
|
|
13
15
|
|
|
14
16
|
typedef enum {
|
|
15
17
|
UNEXPECTED_ERROR,
|
|
@@ -17,28 +19,45 @@ typedef enum {
|
|
|
17
19
|
MISSING_OPENING_TAG_ERROR,
|
|
18
20
|
MISSING_CLOSING_TAG_ERROR,
|
|
19
21
|
TAG_NAMES_MISMATCH_ERROR,
|
|
20
|
-
QUOTES_MISMATCH_ERROR,
|
|
21
22
|
VOID_ELEMENT_CLOSING_TAG_ERROR,
|
|
22
23
|
UNCLOSED_ELEMENT_ERROR,
|
|
23
24
|
RUBY_PARSE_ERROR,
|
|
24
25
|
ERB_CONTROL_FLOW_SCOPE_ERROR,
|
|
25
|
-
|
|
26
|
+
MISSING_ERB_END_TAG_ERROR,
|
|
26
27
|
ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR,
|
|
27
28
|
ERB_CASE_WITH_CONDITIONS_ERROR,
|
|
29
|
+
CONDITIONAL_ELEMENT_MULTIPLE_TAGS_ERROR,
|
|
30
|
+
CONDITIONAL_ELEMENT_CONDITION_MISMATCH_ERROR,
|
|
31
|
+
INVALID_COMMENT_CLOSING_TAG_ERROR,
|
|
32
|
+
OMITTED_CLOSING_TAG_ERROR,
|
|
33
|
+
UNCLOSED_OPEN_TAG_ERROR,
|
|
34
|
+
UNCLOSED_CLOSE_TAG_ERROR,
|
|
35
|
+
UNCLOSED_QUOTE_ERROR,
|
|
36
|
+
MISSING_ATTRIBUTE_VALUE_ERROR,
|
|
37
|
+
UNCLOSED_ERB_TAG_ERROR,
|
|
38
|
+
STRAY_ERB_CLOSING_TAG_ERROR,
|
|
39
|
+
NESTED_ERB_TAG_ERROR,
|
|
40
|
+
RENDER_AMBIGUOUS_LOCALS_ERROR,
|
|
41
|
+
RENDER_MISSING_LOCALS_ERROR,
|
|
42
|
+
RENDER_NO_ARGUMENTS_ERROR,
|
|
43
|
+
RENDER_CONFLICTING_PARTIAL_ERROR,
|
|
44
|
+
RENDER_INVALID_AS_OPTION_ERROR,
|
|
45
|
+
RENDER_OBJECT_AND_COLLECTION_ERROR,
|
|
46
|
+
RENDER_LAYOUT_WITHOUT_BLOCK_ERROR,
|
|
28
47
|
} error_type_T;
|
|
29
48
|
|
|
30
49
|
typedef struct ERROR_STRUCT {
|
|
31
50
|
error_type_T type;
|
|
32
51
|
location_T location;
|
|
33
|
-
|
|
52
|
+
hb_string_T message;
|
|
34
53
|
} ERROR_T;
|
|
35
54
|
|
|
36
55
|
|
|
37
56
|
typedef struct {
|
|
38
57
|
ERROR_T base;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
hb_string_T description;
|
|
59
|
+
hb_string_T expected;
|
|
60
|
+
hb_string_T found;
|
|
42
61
|
} UNEXPECTED_ERROR_T;
|
|
43
62
|
|
|
44
63
|
typedef struct {
|
|
@@ -63,17 +82,11 @@ typedef struct {
|
|
|
63
82
|
token_T* closing_tag;
|
|
64
83
|
} TAG_NAMES_MISMATCH_ERROR_T;
|
|
65
84
|
|
|
66
|
-
typedef struct {
|
|
67
|
-
ERROR_T base;
|
|
68
|
-
token_T* opening_quote;
|
|
69
|
-
token_T* closing_quote;
|
|
70
|
-
} QUOTES_MISMATCH_ERROR_T;
|
|
71
|
-
|
|
72
85
|
typedef struct {
|
|
73
86
|
ERROR_T base;
|
|
74
87
|
token_T* tag_name;
|
|
75
|
-
|
|
76
|
-
|
|
88
|
+
hb_string_T expected;
|
|
89
|
+
hb_string_T found;
|
|
77
90
|
} VOID_ELEMENT_CLOSING_TAG_ERROR_T;
|
|
78
91
|
|
|
79
92
|
typedef struct {
|
|
@@ -83,20 +96,20 @@ typedef struct {
|
|
|
83
96
|
|
|
84
97
|
typedef struct {
|
|
85
98
|
ERROR_T base;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
hb_string_T error_message;
|
|
100
|
+
hb_string_T diagnostic_id;
|
|
101
|
+
hb_string_T level;
|
|
89
102
|
} RUBY_PARSE_ERROR_T;
|
|
90
103
|
|
|
91
104
|
typedef struct {
|
|
92
105
|
ERROR_T base;
|
|
93
|
-
|
|
106
|
+
hb_string_T keyword;
|
|
94
107
|
} ERB_CONTROL_FLOW_SCOPE_ERROR_T;
|
|
95
108
|
|
|
96
109
|
typedef struct {
|
|
97
110
|
ERROR_T base;
|
|
98
|
-
|
|
99
|
-
}
|
|
111
|
+
hb_string_T keyword;
|
|
112
|
+
} MISSING_ERB_END_TAG_ERROR_T;
|
|
100
113
|
|
|
101
114
|
typedef struct {
|
|
102
115
|
ERROR_T base;
|
|
@@ -108,50 +121,188 @@ typedef struct {
|
|
|
108
121
|
/* no additional fields */
|
|
109
122
|
} ERB_CASE_WITH_CONDITIONS_ERROR_T;
|
|
110
123
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
124
|
+
typedef struct {
|
|
125
|
+
ERROR_T base;
|
|
126
|
+
size_t line;
|
|
127
|
+
size_t column;
|
|
128
|
+
} CONDITIONAL_ELEMENT_MULTIPLE_TAGS_ERROR_T;
|
|
129
|
+
|
|
130
|
+
typedef struct {
|
|
131
|
+
ERROR_T base;
|
|
132
|
+
hb_string_T tag_name;
|
|
133
|
+
hb_string_T open_condition;
|
|
134
|
+
size_t open_line;
|
|
135
|
+
size_t open_column;
|
|
136
|
+
hb_string_T close_condition;
|
|
137
|
+
size_t close_line;
|
|
138
|
+
size_t close_column;
|
|
139
|
+
} CONDITIONAL_ELEMENT_CONDITION_MISMATCH_ERROR_T;
|
|
140
|
+
|
|
141
|
+
typedef struct {
|
|
142
|
+
ERROR_T base;
|
|
143
|
+
token_T* closing_tag;
|
|
144
|
+
} INVALID_COMMENT_CLOSING_TAG_ERROR_T;
|
|
145
|
+
|
|
146
|
+
typedef struct {
|
|
147
|
+
ERROR_T base;
|
|
148
|
+
token_T* opening_tag;
|
|
149
|
+
position_T insertion_point;
|
|
150
|
+
} OMITTED_CLOSING_TAG_ERROR_T;
|
|
151
|
+
|
|
152
|
+
typedef struct {
|
|
153
|
+
ERROR_T base;
|
|
154
|
+
token_T* tag_name;
|
|
155
|
+
} UNCLOSED_OPEN_TAG_ERROR_T;
|
|
156
|
+
|
|
157
|
+
typedef struct {
|
|
158
|
+
ERROR_T base;
|
|
159
|
+
token_T* tag_name;
|
|
160
|
+
} UNCLOSED_CLOSE_TAG_ERROR_T;
|
|
161
|
+
|
|
162
|
+
typedef struct {
|
|
163
|
+
ERROR_T base;
|
|
164
|
+
token_T* opening_quote;
|
|
165
|
+
} UNCLOSED_QUOTE_ERROR_T;
|
|
166
|
+
|
|
167
|
+
typedef struct {
|
|
168
|
+
ERROR_T base;
|
|
169
|
+
hb_string_T attribute_name;
|
|
170
|
+
} MISSING_ATTRIBUTE_VALUE_ERROR_T;
|
|
171
|
+
|
|
172
|
+
typedef struct {
|
|
173
|
+
ERROR_T base;
|
|
174
|
+
token_T* opening_tag;
|
|
175
|
+
} UNCLOSED_ERB_TAG_ERROR_T;
|
|
176
|
+
|
|
177
|
+
typedef struct {
|
|
178
|
+
ERROR_T base;
|
|
179
|
+
/* no additional fields */
|
|
180
|
+
} STRAY_ERB_CLOSING_TAG_ERROR_T;
|
|
181
|
+
|
|
182
|
+
typedef struct {
|
|
183
|
+
ERROR_T base;
|
|
184
|
+
token_T* opening_tag;
|
|
185
|
+
size_t nested_tag_line;
|
|
186
|
+
size_t nested_tag_column;
|
|
187
|
+
} NESTED_ERB_TAG_ERROR_T;
|
|
188
|
+
|
|
189
|
+
typedef struct {
|
|
190
|
+
ERROR_T base;
|
|
191
|
+
hb_string_T partial;
|
|
192
|
+
} RENDER_AMBIGUOUS_LOCALS_ERROR_T;
|
|
193
|
+
|
|
194
|
+
typedef struct {
|
|
195
|
+
ERROR_T base;
|
|
196
|
+
hb_string_T partial;
|
|
197
|
+
hb_string_T keywords;
|
|
198
|
+
} RENDER_MISSING_LOCALS_ERROR_T;
|
|
199
|
+
|
|
200
|
+
typedef struct {
|
|
201
|
+
ERROR_T base;
|
|
202
|
+
/* no additional fields */
|
|
203
|
+
} RENDER_NO_ARGUMENTS_ERROR_T;
|
|
204
|
+
|
|
205
|
+
typedef struct {
|
|
206
|
+
ERROR_T base;
|
|
207
|
+
hb_string_T positional_partial;
|
|
208
|
+
hb_string_T keyword_partial;
|
|
209
|
+
} RENDER_CONFLICTING_PARTIAL_ERROR_T;
|
|
210
|
+
|
|
211
|
+
typedef struct {
|
|
212
|
+
ERROR_T base;
|
|
213
|
+
hb_string_T as_value;
|
|
214
|
+
} RENDER_INVALID_AS_OPTION_ERROR_T;
|
|
215
|
+
|
|
216
|
+
typedef struct {
|
|
217
|
+
ERROR_T base;
|
|
218
|
+
/* no additional fields */
|
|
219
|
+
} RENDER_OBJECT_AND_COLLECTION_ERROR_T;
|
|
220
|
+
|
|
221
|
+
typedef struct {
|
|
222
|
+
ERROR_T base;
|
|
223
|
+
hb_string_T layout;
|
|
224
|
+
} RENDER_LAYOUT_WITHOUT_BLOCK_ERROR_T;
|
|
225
|
+
|
|
226
|
+
UNEXPECTED_ERROR_T* unexpected_error_init(hb_string_T description, hb_string_T expected, hb_string_T found, position_T start, position_T end, hb_allocator_T* allocator);
|
|
227
|
+
void append_unexpected_error(hb_string_T description, hb_string_T expected, hb_string_T found, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
228
|
+
UNEXPECTED_TOKEN_ERROR_T* unexpected_token_error_init(token_type_T expected_type, token_T* found, position_T start, position_T end, hb_allocator_T* allocator);
|
|
229
|
+
void append_unexpected_token_error(token_type_T expected_type, token_T* found, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
230
|
+
MISSING_OPENING_TAG_ERROR_T* missing_opening_tag_error_init(token_T* closing_tag, position_T start, position_T end, hb_allocator_T* allocator);
|
|
231
|
+
void append_missing_opening_tag_error(token_T* closing_tag, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
232
|
+
MISSING_CLOSING_TAG_ERROR_T* missing_closing_tag_error_init(token_T* opening_tag, position_T start, position_T end, hb_allocator_T* allocator);
|
|
233
|
+
void append_missing_closing_tag_error(token_T* opening_tag, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
234
|
+
TAG_NAMES_MISMATCH_ERROR_T* tag_names_mismatch_error_init(token_T* opening_tag, token_T* closing_tag, position_T start, position_T end, hb_allocator_T* allocator);
|
|
235
|
+
void append_tag_names_mismatch_error(token_T* opening_tag, token_T* closing_tag, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
236
|
+
VOID_ELEMENT_CLOSING_TAG_ERROR_T* void_element_closing_tag_error_init(token_T* tag_name, hb_string_T expected, hb_string_T found, position_T start, position_T end, hb_allocator_T* allocator);
|
|
237
|
+
void append_void_element_closing_tag_error(token_T* tag_name, hb_string_T expected, hb_string_T found, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
238
|
+
UNCLOSED_ELEMENT_ERROR_T* unclosed_element_error_init(token_T* opening_tag, position_T start, position_T end, hb_allocator_T* allocator);
|
|
239
|
+
void append_unclosed_element_error(token_T* opening_tag, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
240
|
+
RUBY_PARSE_ERROR_T* ruby_parse_error_init(hb_string_T error_message, hb_string_T diagnostic_id, hb_string_T level, position_T start, position_T end, hb_allocator_T* allocator);
|
|
241
|
+
void append_ruby_parse_error(hb_string_T error_message, hb_string_T diagnostic_id, hb_string_T level, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
242
|
+
ERB_CONTROL_FLOW_SCOPE_ERROR_T* erb_control_flow_scope_error_init(hb_string_T keyword, position_T start, position_T end, hb_allocator_T* allocator);
|
|
243
|
+
void append_erb_control_flow_scope_error(hb_string_T keyword, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
244
|
+
MISSING_ERB_END_TAG_ERROR_T* missing_erb_end_tag_error_init(hb_string_T keyword, position_T start, position_T end, hb_allocator_T* allocator);
|
|
245
|
+
void append_missing_erb_end_tag_error(hb_string_T keyword, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
246
|
+
ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T* erb_multiple_blocks_in_tag_error_init(position_T start, position_T end, hb_allocator_T* allocator);
|
|
247
|
+
void append_erb_multiple_blocks_in_tag_error(position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
248
|
+
ERB_CASE_WITH_CONDITIONS_ERROR_T* erb_case_with_conditions_error_init(position_T start, position_T end, hb_allocator_T* allocator);
|
|
249
|
+
void append_erb_case_with_conditions_error(position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
250
|
+
CONDITIONAL_ELEMENT_MULTIPLE_TAGS_ERROR_T* conditional_element_multiple_tags_error_init(size_t line, size_t column, position_T start, position_T end, hb_allocator_T* allocator);
|
|
251
|
+
void append_conditional_element_multiple_tags_error(size_t line, size_t column, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
252
|
+
CONDITIONAL_ELEMENT_CONDITION_MISMATCH_ERROR_T* conditional_element_condition_mismatch_error_init(hb_string_T tag_name, hb_string_T open_condition, size_t open_line, size_t open_column, hb_string_T close_condition, size_t close_line, size_t close_column, position_T start, position_T end, hb_allocator_T* allocator);
|
|
253
|
+
void append_conditional_element_condition_mismatch_error(hb_string_T tag_name, hb_string_T open_condition, size_t open_line, size_t open_column, hb_string_T close_condition, size_t close_line, size_t close_column, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
254
|
+
INVALID_COMMENT_CLOSING_TAG_ERROR_T* invalid_comment_closing_tag_error_init(token_T* closing_tag, position_T start, position_T end, hb_allocator_T* allocator);
|
|
255
|
+
void append_invalid_comment_closing_tag_error(token_T* closing_tag, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
256
|
+
OMITTED_CLOSING_TAG_ERROR_T* omitted_closing_tag_error_init(token_T* opening_tag, position_T insertion_point, position_T start, position_T end, hb_allocator_T* allocator);
|
|
257
|
+
void append_omitted_closing_tag_error(token_T* opening_tag, position_T insertion_point, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
258
|
+
UNCLOSED_OPEN_TAG_ERROR_T* unclosed_open_tag_error_init(token_T* tag_name, position_T start, position_T end, hb_allocator_T* allocator);
|
|
259
|
+
void append_unclosed_open_tag_error(token_T* tag_name, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
260
|
+
UNCLOSED_CLOSE_TAG_ERROR_T* unclosed_close_tag_error_init(token_T* tag_name, position_T start, position_T end, hb_allocator_T* allocator);
|
|
261
|
+
void append_unclosed_close_tag_error(token_T* tag_name, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
262
|
+
UNCLOSED_QUOTE_ERROR_T* unclosed_quote_error_init(token_T* opening_quote, position_T start, position_T end, hb_allocator_T* allocator);
|
|
263
|
+
void append_unclosed_quote_error(token_T* opening_quote, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
264
|
+
MISSING_ATTRIBUTE_VALUE_ERROR_T* missing_attribute_value_error_init(hb_string_T attribute_name, position_T start, position_T end, hb_allocator_T* allocator);
|
|
265
|
+
void append_missing_attribute_value_error(hb_string_T attribute_name, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
266
|
+
UNCLOSED_ERB_TAG_ERROR_T* unclosed_erb_tag_error_init(token_T* opening_tag, position_T start, position_T end, hb_allocator_T* allocator);
|
|
267
|
+
void append_unclosed_erb_tag_error(token_T* opening_tag, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
268
|
+
STRAY_ERB_CLOSING_TAG_ERROR_T* stray_erb_closing_tag_error_init(position_T start, position_T end, hb_allocator_T* allocator);
|
|
269
|
+
void append_stray_erb_closing_tag_error(position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
270
|
+
NESTED_ERB_TAG_ERROR_T* nested_erb_tag_error_init(token_T* opening_tag, size_t nested_tag_line, size_t nested_tag_column, position_T start, position_T end, hb_allocator_T* allocator);
|
|
271
|
+
void append_nested_erb_tag_error(token_T* opening_tag, size_t nested_tag_line, size_t nested_tag_column, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
272
|
+
RENDER_AMBIGUOUS_LOCALS_ERROR_T* render_ambiguous_locals_error_init(hb_string_T partial, position_T start, position_T end, hb_allocator_T* allocator);
|
|
273
|
+
void append_render_ambiguous_locals_error(hb_string_T partial, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
274
|
+
RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error_init(hb_string_T partial, hb_string_T keywords, position_T start, position_T end, hb_allocator_T* allocator);
|
|
275
|
+
void append_render_missing_locals_error(hb_string_T partial, hb_string_T keywords, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
276
|
+
RENDER_NO_ARGUMENTS_ERROR_T* render_no_arguments_error_init(position_T start, position_T end, hb_allocator_T* allocator);
|
|
277
|
+
void append_render_no_arguments_error(position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
278
|
+
RENDER_CONFLICTING_PARTIAL_ERROR_T* render_conflicting_partial_error_init(hb_string_T positional_partial, hb_string_T keyword_partial, position_T start, position_T end, hb_allocator_T* allocator);
|
|
279
|
+
void append_render_conflicting_partial_error(hb_string_T positional_partial, hb_string_T keyword_partial, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
280
|
+
RENDER_INVALID_AS_OPTION_ERROR_T* render_invalid_as_option_error_init(hb_string_T as_value, position_T start, position_T end, hb_allocator_T* allocator);
|
|
281
|
+
void append_render_invalid_as_option_error(hb_string_T as_value, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
282
|
+
RENDER_OBJECT_AND_COLLECTION_ERROR_T* render_object_and_collection_error_init(position_T start, position_T end, hb_allocator_T* allocator);
|
|
283
|
+
void append_render_object_and_collection_error(position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
284
|
+
RENDER_LAYOUT_WITHOUT_BLOCK_ERROR_T* render_layout_without_block_error_init(hb_string_T layout, position_T start, position_T end, hb_allocator_T* allocator);
|
|
285
|
+
void append_render_layout_without_block_error(hb_string_T layout, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T* errors);
|
|
137
286
|
|
|
138
287
|
void error_init(ERROR_T* error, error_type_T type, position_T start, position_T end);
|
|
139
288
|
|
|
140
289
|
size_t error_sizeof(void);
|
|
141
290
|
error_type_T error_type(ERROR_T* error);
|
|
142
291
|
|
|
143
|
-
|
|
292
|
+
hb_string_T error_message(ERROR_T* error);
|
|
144
293
|
|
|
145
|
-
|
|
146
|
-
|
|
294
|
+
hb_string_T error_type_to_string(ERROR_T* error);
|
|
295
|
+
hb_string_T error_human_type(ERROR_T* error);
|
|
147
296
|
|
|
148
|
-
void error_free(ERROR_T* error);
|
|
297
|
+
void error_free(ERROR_T* error, hb_allocator_T* allocator);
|
|
149
298
|
|
|
150
|
-
|
|
299
|
+
#ifndef HERB_EXCLUDE_PRETTYPRINT
|
|
300
|
+
void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent, hb_buffer_T* buffer);
|
|
151
301
|
|
|
152
|
-
void error_pretty_print_array(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
);
|
|
302
|
+
void error_pretty_print_array(
|
|
303
|
+
const char* name, hb_array_T* array, size_t indent, size_t relative_indent, bool last_property,
|
|
304
|
+
hb_buffer_T* buffer
|
|
305
|
+
);
|
|
306
|
+
#endif
|
|
156
307
|
|
|
157
308
|
#endif
|
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
#ifndef HERB_EXTRACT_H
|
|
2
2
|
#define HERB_EXTRACT_H
|
|
3
3
|
|
|
4
|
+
#include "util/hb_allocator.h"
|
|
4
5
|
#include "util/hb_buffer.h"
|
|
5
6
|
|
|
7
|
+
#include <stdbool.h>
|
|
8
|
+
|
|
6
9
|
typedef enum {
|
|
7
10
|
HERB_EXTRACT_LANGUAGE_RUBY,
|
|
8
11
|
HERB_EXTRACT_LANGUAGE_HTML,
|
|
9
12
|
} herb_extract_language_T;
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
typedef struct {
|
|
15
|
+
bool semicolons;
|
|
16
|
+
bool comments;
|
|
17
|
+
bool preserve_positions;
|
|
18
|
+
} herb_extract_ruby_options_T;
|
|
19
|
+
|
|
20
|
+
extern const herb_extract_ruby_options_T HERB_EXTRACT_RUBY_DEFAULT_OPTIONS;
|
|
21
|
+
|
|
22
|
+
void herb_extract_ruby_to_buffer_with_options(
|
|
23
|
+
const char* source,
|
|
24
|
+
hb_buffer_T* output,
|
|
25
|
+
const herb_extract_ruby_options_T* options,
|
|
26
|
+
hb_allocator_T* allocator
|
|
27
|
+
);
|
|
28
|
+
void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output, hb_allocator_T* allocator);
|
|
29
|
+
void herb_extract_html_to_buffer(const char* source, hb_buffer_T* output, hb_allocator_T* allocator);
|
|
13
30
|
|
|
14
|
-
char* herb_extract_ruby_with_semicolons(const char* source);
|
|
31
|
+
char* herb_extract_ruby_with_semicolons(const char* source, hb_allocator_T* allocator);
|
|
15
32
|
|
|
16
|
-
char* herb_extract(const char* source, herb_extract_language_T language);
|
|
17
|
-
char* herb_extract_from_file(const char* path, herb_extract_language_T language);
|
|
33
|
+
char* herb_extract(const char* source, herb_extract_language_T language, hb_allocator_T* allocator);
|
|
18
34
|
|
|
19
35
|
#endif
|
|
@@ -5,26 +5,38 @@
|
|
|
5
5
|
#include "extract.h"
|
|
6
6
|
#include "macros.h"
|
|
7
7
|
#include "parser.h"
|
|
8
|
+
#include "util/hb_allocator.h"
|
|
8
9
|
#include "util/hb_array.h"
|
|
9
10
|
#include "util/hb_buffer.h"
|
|
10
11
|
|
|
12
|
+
#include <prism.h>
|
|
13
|
+
#include <stdbool.h>
|
|
11
14
|
#include <stdint.h>
|
|
12
15
|
|
|
13
16
|
#ifdef __cplusplus
|
|
14
17
|
extern "C" {
|
|
15
18
|
#endif
|
|
16
19
|
|
|
17
|
-
HERB_EXPORTED_FUNCTION
|
|
20
|
+
HERB_EXPORTED_FUNCTION hb_array_T* herb_lex(const char* source, hb_allocator_T* allocator);
|
|
18
21
|
|
|
19
|
-
HERB_EXPORTED_FUNCTION
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
HERB_EXPORTED_FUNCTION AST_DOCUMENT_NODE_T* herb_parse(
|
|
23
|
+
const char* source,
|
|
24
|
+
const parser_options_T* options,
|
|
25
|
+
hb_allocator_T* allocator
|
|
26
|
+
);
|
|
23
27
|
|
|
24
28
|
HERB_EXPORTED_FUNCTION const char* herb_version(void);
|
|
25
29
|
HERB_EXPORTED_FUNCTION const char* herb_prism_version(void);
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
typedef struct {
|
|
32
|
+
pm_parser_t parser;
|
|
33
|
+
pm_node_t* root;
|
|
34
|
+
pm_options_t options;
|
|
35
|
+
} herb_ruby_parse_result_T;
|
|
36
|
+
|
|
37
|
+
HERB_EXPORTED_FUNCTION herb_ruby_parse_result_T* herb_parse_ruby(const char* source, size_t length);
|
|
38
|
+
HERB_EXPORTED_FUNCTION void herb_free_ruby_parse_result(herb_ruby_parse_result_T* result);
|
|
39
|
+
HERB_EXPORTED_FUNCTION void herb_free_tokens(hb_array_T** tokens, hb_allocator_T* allocator);
|
|
28
40
|
|
|
29
41
|
#ifdef __cplusplus
|
|
30
42
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#ifndef HERB_PRISM_NODE_H
|
|
2
|
+
#define HERB_PRISM_NODE_H
|
|
3
|
+
|
|
4
|
+
#include <prism.h>
|
|
5
|
+
|
|
6
|
+
typedef struct {
|
|
7
|
+
pm_node_t* node;
|
|
8
|
+
pm_parser_t* parser;
|
|
9
|
+
} herb_prism_node_T;
|
|
10
|
+
|
|
11
|
+
#define HERB_PRISM_NODE_EMPTY ((herb_prism_node_T) { .node = NULL, .parser = NULL })
|
|
12
|
+
|
|
13
|
+
#endif
|
|
@@ -4,9 +4,14 @@
|
|
|
4
4
|
#include "util/hb_string.h"
|
|
5
5
|
#include <stdbool.h>
|
|
6
6
|
|
|
7
|
+
struct hb_allocator;
|
|
8
|
+
|
|
7
9
|
bool is_void_element(hb_string_T tag_name);
|
|
10
|
+
bool has_optional_end_tag(hb_string_T tag_name);
|
|
11
|
+
bool should_implicitly_close(hb_string_T open_tag_name, hb_string_T next_tag_name);
|
|
12
|
+
bool parent_closes_element(hb_string_T open_tag_name, hb_string_T parent_close_tag_name);
|
|
8
13
|
|
|
9
|
-
hb_string_T html_closing_tag_string(hb_string_T tag_name);
|
|
10
|
-
hb_string_T html_self_closing_tag_string(hb_string_T tag_name);
|
|
14
|
+
hb_string_T html_closing_tag_string(hb_string_T tag_name, struct hb_allocator* allocator);
|
|
15
|
+
hb_string_T html_self_closing_tag_string(hb_string_T tag_name, struct hb_allocator* allocator);
|
|
11
16
|
|
|
12
17
|
#endif
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#ifndef HERB_LEX_HELPERS_H
|
|
2
|
+
#define HERB_LEX_HELPERS_H
|
|
3
|
+
|
|
4
|
+
#include "herb.h"
|
|
5
|
+
#include "token.h"
|
|
6
|
+
#include "util/hb_allocator.h"
|
|
7
|
+
#include "util/hb_array.h"
|
|
8
|
+
#include "util/hb_buffer.h"
|
|
9
|
+
#include "util/hb_string.h"
|
|
10
|
+
|
|
11
|
+
#include <stdlib.h>
|
|
12
|
+
|
|
13
|
+
static inline void herb_lex_to_buffer(const char* source, hb_buffer_T* output, hb_allocator_T* allocator) {
|
|
14
|
+
hb_array_T* tokens = herb_lex(source, allocator);
|
|
15
|
+
|
|
16
|
+
for (size_t i = 0; i < hb_array_size(tokens); i++) {
|
|
17
|
+
token_T* token = hb_array_get(tokens, i);
|
|
18
|
+
|
|
19
|
+
hb_string_T type = token_to_string(allocator, token);
|
|
20
|
+
hb_buffer_append_string(output, type);
|
|
21
|
+
hb_allocator_dealloc(allocator, type.data);
|
|
22
|
+
|
|
23
|
+
hb_buffer_append(output, "\n");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
herb_free_tokens(&tokens, allocator);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#endif
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
#include "lexer_struct.h"
|
|
5
5
|
#include "token_struct.h"
|
|
6
6
|
|
|
7
|
-
void lexer_init(lexer_T* lexer, const char* source);
|
|
7
|
+
void lexer_init(lexer_T* lexer, const char* source, hb_allocator_T* allocator);
|
|
8
8
|
token_T* lexer_next_token(lexer_T* lexer);
|
|
9
9
|
token_T* lexer_error(lexer_T* lexer, const char* message);
|
|
10
10
|
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
#define HERB_LEXER_PEEK_HELPERS_H
|
|
3
3
|
|
|
4
4
|
#include "lexer_struct.h"
|
|
5
|
+
#include "macros.h"
|
|
5
6
|
#include "token_struct.h"
|
|
7
|
+
#include "util/hb_string.h"
|
|
6
8
|
|
|
9
|
+
#include <ctype.h>
|
|
7
10
|
#include <stdbool.h>
|
|
8
11
|
#include <stdint.h>
|
|
9
12
|
#include <stdio.h>
|
|
@@ -20,27 +23,98 @@ typedef struct {
|
|
|
20
23
|
lexer_state_T state;
|
|
21
24
|
} lexer_state_snapshot_T;
|
|
22
25
|
|
|
23
|
-
char lexer_peek(const lexer_T* lexer, uint32_t offset);
|
|
24
26
|
bool lexer_peek_for_doctype(const lexer_T* lexer, uint32_t offset);
|
|
25
27
|
bool lexer_peek_for_xml_declaration(const lexer_T* lexer, uint32_t offset);
|
|
26
28
|
bool lexer_peek_for_cdata_start(const lexer_T* lexer, uint32_t offset);
|
|
27
29
|
bool lexer_peek_for_cdata_end(const lexer_T* lexer, uint32_t offset);
|
|
28
|
-
|
|
29
30
|
bool lexer_peek_for_html_comment_start(const lexer_T* lexer, uint32_t offset);
|
|
30
|
-
bool
|
|
31
|
+
bool lexer_peek_for_token_type_after_whitespace(lexer_T* lexer, token_type_T token_type);
|
|
32
|
+
bool lexer_peek_for_close_tag_start(const lexer_T* lexer, uint32_t offset);
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
bool lexer_peek_erb_equals_close_tag(const lexer_T* lexer, uint32_t offset);
|
|
36
|
-
bool lexer_peek_erb_end(const lexer_T* lexer, uint32_t offset);
|
|
34
|
+
static inline char lexer_peek(const lexer_T* lexer, uint32_t offset) {
|
|
35
|
+
return lexer->source.data[MIN(lexer->current_position + offset, lexer->source.length)];
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
char lexer_backtrack(const lexer_T* lexer, uint32_t offset)
|
|
38
|
+
static inline char lexer_backtrack(const lexer_T* lexer, uint32_t offset) {
|
|
39
|
+
return lexer->source.data[MAX(lexer->current_position - offset, 0)];
|
|
40
|
+
}
|
|
39
41
|
|
|
40
|
-
bool
|
|
41
|
-
|
|
42
|
+
static inline bool lexer_peek_for_html_comment_end(const lexer_T* lexer, uint32_t offset) {
|
|
43
|
+
uint32_t position = lexer->current_position + offset;
|
|
44
|
+
|
|
45
|
+
return position + 2 < lexer->source.length && lexer->source.data[position] == '-'
|
|
46
|
+
&& lexer->source.data[position + 1] == '-' && lexer->source.data[position + 2] == '>';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static inline bool lexer_peek_for_html_comment_invalid_end(const lexer_T* lexer, uint32_t offset) {
|
|
50
|
+
uint32_t position = lexer->current_position + offset;
|
|
51
|
+
|
|
52
|
+
return position + 3 < lexer->source.length && lexer->source.data[position] == '-'
|
|
53
|
+
&& lexer->source.data[position + 1] == '-' && lexer->source.data[position + 2] == '!'
|
|
54
|
+
&& lexer->source.data[position + 3] == '>';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static inline bool lexer_peek_erb_start(const lexer_T* lexer, uint32_t offset) {
|
|
58
|
+
uint32_t position = lexer->current_position + offset;
|
|
59
|
+
|
|
60
|
+
return position + 1 < lexer->source.length && lexer->source.data[position] == '<'
|
|
61
|
+
&& lexer->source.data[position + 1] == '%';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static inline bool lexer_peek_erb_close_tag(const lexer_T* lexer, uint32_t offset) {
|
|
65
|
+
uint32_t position = lexer->current_position + offset;
|
|
66
|
+
|
|
67
|
+
return position + 1 < lexer->source.length && lexer->source.data[position] == '%'
|
|
68
|
+
&& lexer->source.data[position + 1] == '>';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static inline bool lexer_peek_erb_dash_close_tag(const lexer_T* lexer, uint32_t offset) {
|
|
72
|
+
uint32_t position = lexer->current_position + offset;
|
|
73
|
+
|
|
74
|
+
return position + 2 < lexer->source.length && lexer->source.data[position] == '-'
|
|
75
|
+
&& lexer->source.data[position + 1] == '%' && lexer->source.data[position + 2] == '>';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static inline bool lexer_peek_erb_percent_close_tag(const lexer_T* lexer, uint32_t offset) {
|
|
79
|
+
uint32_t position = lexer->current_position + offset;
|
|
80
|
+
|
|
81
|
+
return position + 2 < lexer->source.length && lexer->source.data[position] == '%'
|
|
82
|
+
&& lexer->source.data[position + 1] == '%' && lexer->source.data[position + 2] == '>';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static inline bool lexer_peek_erb_equals_close_tag(const lexer_T* lexer, uint32_t offset) {
|
|
86
|
+
uint32_t position = lexer->current_position + offset;
|
|
87
|
+
|
|
88
|
+
return position + 2 < lexer->source.length && lexer->source.data[position] == '='
|
|
89
|
+
&& lexer->source.data[position + 1] == '%' && lexer->source.data[position + 2] == '>';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static inline bool lexer_peek_erb_end(const lexer_T* lexer, uint32_t offset) {
|
|
93
|
+
return lexer_peek_erb_close_tag(lexer, offset) || lexer_peek_erb_dash_close_tag(lexer, offset)
|
|
94
|
+
|| lexer_peek_erb_percent_close_tag(lexer, offset) || lexer_peek_erb_equals_close_tag(lexer, offset);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static inline lexer_state_snapshot_T lexer_save_state(lexer_T* lexer) {
|
|
98
|
+
lexer_state_snapshot_T snapshot = { .position = lexer->current_position,
|
|
99
|
+
.line = lexer->current_line,
|
|
100
|
+
.column = lexer->current_column,
|
|
101
|
+
.previous_position = lexer->previous_position,
|
|
102
|
+
.previous_line = lexer->previous_line,
|
|
103
|
+
.previous_column = lexer->previous_column,
|
|
104
|
+
.current_character = lexer->current_character,
|
|
105
|
+
.state = lexer->state };
|
|
106
|
+
return snapshot;
|
|
107
|
+
}
|
|
42
108
|
|
|
43
|
-
|
|
44
|
-
|
|
109
|
+
static inline void lexer_restore_state(lexer_T* lexer, lexer_state_snapshot_T snapshot) {
|
|
110
|
+
lexer->current_position = snapshot.position;
|
|
111
|
+
lexer->current_line = snapshot.line;
|
|
112
|
+
lexer->current_column = snapshot.column;
|
|
113
|
+
lexer->previous_position = snapshot.previous_position;
|
|
114
|
+
lexer->previous_line = snapshot.previous_line;
|
|
115
|
+
lexer->previous_column = snapshot.previous_column;
|
|
116
|
+
lexer->current_character = snapshot.current_character;
|
|
117
|
+
lexer->state = snapshot.state;
|
|
118
|
+
}
|
|
45
119
|
|
|
46
120
|
#endif
|