@herb-tools/node 0.7.5 → 0.8.0
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 +8 -4
- package/dist/herb-node.esm.js +6 -6
- package/dist/herb-node.esm.js.map +1 -1
- package/extension/error_helpers.cpp +67 -9
- package/extension/error_helpers.h +4 -2
- package/extension/extension_helpers.cpp +12 -5
- package/extension/extension_helpers.h +4 -2
- package/extension/herb.cpp +10 -42
- package/extension/libherb/analyze.c +420 -171
- package/extension/libherb/analyze.h +10 -2
- package/extension/libherb/analyze_helpers.c +5 -0
- package/extension/libherb/analyze_helpers.h +3 -0
- package/extension/libherb/analyze_missing_end.c +147 -0
- package/extension/libherb/analyze_transform.c +196 -0
- package/extension/libherb/analyzed_ruby.c +23 -2
- package/extension/libherb/analyzed_ruby.h +4 -2
- package/extension/libherb/ast_node.c +5 -5
- package/extension/libherb/ast_node.h +2 -2
- package/extension/libherb/ast_nodes.c +180 -180
- package/extension/libherb/ast_nodes.h +68 -67
- package/extension/libherb/ast_pretty_print.c +233 -233
- package/extension/libherb/ast_pretty_print.h +3 -3
- package/extension/libherb/element_source.c +7 -6
- package/extension/libherb/element_source.h +3 -1
- package/extension/libherb/errors.c +247 -127
- package/extension/libherb/errors.h +31 -15
- package/extension/libherb/extract.c +92 -34
- package/extension/libherb/extract.h +4 -4
- package/extension/libherb/herb.c +37 -49
- package/extension/libherb/herb.h +6 -7
- package/extension/libherb/html_util.c +34 -96
- package/extension/libherb/html_util.h +4 -5
- package/extension/libherb/include/analyze.h +10 -2
- package/extension/libherb/include/analyze_helpers.h +3 -0
- package/extension/libherb/include/analyzed_ruby.h +4 -2
- package/extension/libherb/include/ast_node.h +2 -2
- package/extension/libherb/include/ast_nodes.h +68 -67
- package/extension/libherb/include/ast_pretty_print.h +3 -3
- package/extension/libherb/include/element_source.h +3 -1
- package/extension/libherb/include/errors.h +31 -15
- package/extension/libherb/include/extract.h +4 -4
- package/extension/libherb/include/herb.h +6 -7
- package/extension/libherb/include/html_util.h +4 -5
- package/extension/libherb/include/lexer.h +1 -3
- package/extension/libherb/include/lexer_peek_helpers.h +14 -14
- package/extension/libherb/include/lexer_struct.h +3 -2
- package/extension/libherb/include/macros.h +4 -0
- package/extension/libherb/include/parser.h +12 -6
- package/extension/libherb/include/parser_helpers.h +25 -15
- package/extension/libherb/include/pretty_print.h +38 -28
- package/extension/libherb/include/token.h +5 -8
- package/extension/libherb/include/utf8.h +3 -2
- package/extension/libherb/include/util/hb_arena.h +31 -0
- package/extension/libherb/include/util/hb_arena_debug.h +8 -0
- package/extension/libherb/include/util/hb_array.h +33 -0
- package/extension/libherb/include/util/hb_buffer.h +34 -0
- package/extension/libherb/include/util/hb_string.h +29 -0
- package/extension/libherb/include/util/hb_system.h +9 -0
- package/extension/libherb/include/util.h +3 -14
- package/extension/libherb/include/version.h +1 -1
- package/extension/libherb/include/visitor.h +1 -1
- package/extension/libherb/io.c +7 -4
- package/extension/libherb/lexer.c +61 -88
- package/extension/libherb/lexer.h +1 -3
- package/extension/libherb/lexer_peek_helpers.c +35 -37
- package/extension/libherb/lexer_peek_helpers.h +14 -14
- package/extension/libherb/lexer_struct.h +3 -2
- package/extension/libherb/macros.h +4 -0
- package/extension/libherb/main.c +19 -23
- package/extension/libherb/parser.c +282 -201
- package/extension/libherb/parser.h +12 -6
- package/extension/libherb/parser_helpers.c +46 -40
- package/extension/libherb/parser_helpers.h +25 -15
- package/extension/libherb/parser_match_tags.c +316 -0
- package/extension/libherb/pretty_print.c +82 -106
- package/extension/libherb/pretty_print.h +38 -28
- package/extension/libherb/token.c +18 -65
- package/extension/libherb/token.h +5 -8
- package/extension/libherb/utf8.c +4 -4
- package/extension/libherb/utf8.h +3 -2
- package/extension/libherb/util/hb_arena.c +179 -0
- package/extension/libherb/util/hb_arena.h +31 -0
- package/extension/libherb/util/hb_arena_debug.c +237 -0
- package/extension/libherb/util/hb_arena_debug.h +8 -0
- package/extension/libherb/{array.c → util/hb_array.c} +26 -27
- package/extension/libherb/util/hb_array.h +33 -0
- package/extension/libherb/util/hb_buffer.c +203 -0
- package/extension/libherb/util/hb_buffer.h +34 -0
- package/extension/libherb/util/hb_string.c +85 -0
- package/extension/libherb/util/hb_string.h +29 -0
- package/extension/libherb/util/hb_system.c +30 -0
- package/extension/libherb/util/hb_system.h +9 -0
- package/extension/libherb/util.c +29 -99
- package/extension/libherb/util.h +3 -14
- package/extension/libherb/version.h +1 -1
- package/extension/libherb/visitor.c +55 -55
- package/extension/libherb/visitor.h +1 -1
- package/extension/nodes.cpp +40 -40
- package/extension/nodes.h +2 -2
- package/extension/prism/include/prism/ast.h +31 -1
- package/extension/prism/include/prism/diagnostic.h +1 -0
- package/extension/prism/include/prism/version.h +3 -3
- package/extension/prism/src/diagnostic.c +3 -1
- package/extension/prism/src/prism.c +130 -71
- package/extension/prism/src/util/pm_string.c +6 -8
- package/package.json +3 -3
- package/extension/libherb/array.h +0 -33
- package/extension/libherb/buffer.c +0 -241
- package/extension/libherb/buffer.h +0 -39
- package/extension/libherb/include/array.h +0 -33
- package/extension/libherb/include/buffer.h +0 -39
- package/extension/libherb/include/json.h +0 -28
- package/extension/libherb/include/memory.h +0 -12
- package/extension/libherb/json.c +0 -205
- package/extension/libherb/json.h +0 -28
- package/extension/libherb/memory.c +0 -53
- package/extension/libherb/memory.h +0 -12
|
@@ -1,15 +1,15 @@
|
|
|
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.8.0/templates/src/include/errors.h.erb
|
|
3
3
|
|
|
4
4
|
#ifndef HERB_ERRORS_H
|
|
5
5
|
#define HERB_ERRORS_H
|
|
6
6
|
|
|
7
|
-
#include "array.h"
|
|
8
|
-
#include "buffer.h"
|
|
9
7
|
#include "errors.h"
|
|
10
8
|
#include "location.h"
|
|
11
9
|
#include "position.h"
|
|
12
10
|
#include "token.h"
|
|
11
|
+
#include "util/hb_array.h"
|
|
12
|
+
#include "util/hb_buffer.h"
|
|
13
13
|
|
|
14
14
|
typedef enum {
|
|
15
15
|
UNEXPECTED_ERROR,
|
|
@@ -21,6 +21,8 @@ typedef enum {
|
|
|
21
21
|
VOID_ELEMENT_CLOSING_TAG_ERROR,
|
|
22
22
|
UNCLOSED_ELEMENT_ERROR,
|
|
23
23
|
RUBY_PARSE_ERROR,
|
|
24
|
+
ERB_CONTROL_FLOW_SCOPE_ERROR,
|
|
25
|
+
MISSINGERB_END_TAG_ERROR,
|
|
24
26
|
} error_type_T;
|
|
25
27
|
|
|
26
28
|
typedef struct ERROR_STRUCT {
|
|
@@ -84,24 +86,38 @@ typedef struct {
|
|
|
84
86
|
const char* level;
|
|
85
87
|
} RUBY_PARSE_ERROR_T;
|
|
86
88
|
|
|
89
|
+
typedef struct {
|
|
90
|
+
ERROR_T base;
|
|
91
|
+
const char* keyword;
|
|
92
|
+
} ERB_CONTROL_FLOW_SCOPE_ERROR_T;
|
|
93
|
+
|
|
94
|
+
typedef struct {
|
|
95
|
+
ERROR_T base;
|
|
96
|
+
const char* keyword;
|
|
97
|
+
} MISSINGERB_END_TAG_ERROR_T;
|
|
98
|
+
|
|
87
99
|
UNEXPECTED_ERROR_T* unexpected_error_init(const char* description, const char* expected, const char* found, position_T start, position_T end);
|
|
88
|
-
void append_unexpected_error(const char* description, const char* expected, const char* found, position_T start, position_T end,
|
|
100
|
+
void append_unexpected_error(const char* description, const char* expected, const char* found, position_T start, position_T end, hb_array_T* errors);
|
|
89
101
|
UNEXPECTED_TOKEN_ERROR_T* unexpected_token_error_init(token_type_T expected_type, token_T* found, position_T start, position_T end);
|
|
90
|
-
void append_unexpected_token_error(token_type_T expected_type, token_T* found, position_T start, position_T end,
|
|
102
|
+
void append_unexpected_token_error(token_type_T expected_type, token_T* found, position_T start, position_T end, hb_array_T* errors);
|
|
91
103
|
MISSING_OPENING_TAG_ERROR_T* missing_opening_tag_error_init(token_T* closing_tag, position_T start, position_T end);
|
|
92
|
-
void append_missing_opening_tag_error(token_T* closing_tag, position_T start, position_T end,
|
|
104
|
+
void append_missing_opening_tag_error(token_T* closing_tag, position_T start, position_T end, hb_array_T* errors);
|
|
93
105
|
MISSING_CLOSING_TAG_ERROR_T* missing_closing_tag_error_init(token_T* opening_tag, position_T start, position_T end);
|
|
94
|
-
void append_missing_closing_tag_error(token_T* opening_tag, position_T start, position_T end,
|
|
106
|
+
void append_missing_closing_tag_error(token_T* opening_tag, position_T start, position_T end, hb_array_T* errors);
|
|
95
107
|
TAG_NAMES_MISMATCH_ERROR_T* tag_names_mismatch_error_init(token_T* opening_tag, token_T* closing_tag, position_T start, position_T end);
|
|
96
|
-
void append_tag_names_mismatch_error(token_T* opening_tag, token_T* closing_tag, position_T start, position_T end,
|
|
108
|
+
void append_tag_names_mismatch_error(token_T* opening_tag, token_T* closing_tag, position_T start, position_T end, hb_array_T* errors);
|
|
97
109
|
QUOTES_MISMATCH_ERROR_T* quotes_mismatch_error_init(token_T* opening_quote, token_T* closing_quote, position_T start, position_T end);
|
|
98
|
-
void append_quotes_mismatch_error(token_T* opening_quote, token_T* closing_quote, position_T start, position_T end,
|
|
110
|
+
void append_quotes_mismatch_error(token_T* opening_quote, token_T* closing_quote, position_T start, position_T end, hb_array_T* errors);
|
|
99
111
|
VOID_ELEMENT_CLOSING_TAG_ERROR_T* void_element_closing_tag_error_init(token_T* tag_name, const char* expected, const char* found, position_T start, position_T end);
|
|
100
|
-
void append_void_element_closing_tag_error(token_T* tag_name, const char* expected, const char* found, position_T start, position_T end,
|
|
112
|
+
void append_void_element_closing_tag_error(token_T* tag_name, const char* expected, const char* found, position_T start, position_T end, hb_array_T* errors);
|
|
101
113
|
UNCLOSED_ELEMENT_ERROR_T* unclosed_element_error_init(token_T* opening_tag, position_T start, position_T end);
|
|
102
|
-
void append_unclosed_element_error(token_T* opening_tag, position_T start, position_T end,
|
|
114
|
+
void append_unclosed_element_error(token_T* opening_tag, position_T start, position_T end, hb_array_T* errors);
|
|
103
115
|
RUBY_PARSE_ERROR_T* ruby_parse_error_init(const char* error_message, const char* diagnostic_id, const char* level, position_T start, position_T end);
|
|
104
|
-
void append_ruby_parse_error(const char* error_message, const char* diagnostic_id, const char* level, position_T start, position_T end,
|
|
116
|
+
void append_ruby_parse_error(const char* error_message, const char* diagnostic_id, const char* level, position_T start, position_T end, hb_array_T* errors);
|
|
117
|
+
ERB_CONTROL_FLOW_SCOPE_ERROR_T* erb_control_flow_scope_error_init(const char* keyword, position_T start, position_T end);
|
|
118
|
+
void append_erb_control_flow_scope_error(const char* keyword, position_T start, position_T end, hb_array_T* errors);
|
|
119
|
+
MISSINGERB_END_TAG_ERROR_T* missingerb_end_tag_error_init(const char* keyword, position_T start, position_T end);
|
|
120
|
+
void append_missingerb_end_tag_error(const char* keyword, position_T start, position_T end, hb_array_T* errors);
|
|
105
121
|
|
|
106
122
|
void error_init(ERROR_T* error, error_type_T type, position_T start, position_T end);
|
|
107
123
|
|
|
@@ -115,11 +131,11 @@ const char* error_human_type(ERROR_T* error);
|
|
|
115
131
|
|
|
116
132
|
void error_free(ERROR_T* error);
|
|
117
133
|
|
|
118
|
-
void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent,
|
|
134
|
+
void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent, hb_buffer_T* buffer);
|
|
119
135
|
|
|
120
136
|
void error_pretty_print_array(
|
|
121
|
-
const char* name,
|
|
122
|
-
|
|
137
|
+
const char* name, hb_array_T* array, size_t indent, size_t relative_indent, bool last_property,
|
|
138
|
+
hb_buffer_T* buffer
|
|
123
139
|
);
|
|
124
140
|
|
|
125
141
|
#endif
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#ifndef HERB_EXTRACT_H
|
|
2
2
|
#define HERB_EXTRACT_H
|
|
3
3
|
|
|
4
|
-
#include "
|
|
4
|
+
#include "util/hb_buffer.h"
|
|
5
5
|
|
|
6
6
|
typedef enum {
|
|
7
7
|
HERB_EXTRACT_LANGUAGE_RUBY,
|
|
8
8
|
HERB_EXTRACT_LANGUAGE_HTML,
|
|
9
9
|
} herb_extract_language_T;
|
|
10
10
|
|
|
11
|
-
void herb_extract_ruby_to_buffer(const char* source,
|
|
12
|
-
void herb_extract_html_to_buffer(const char* source,
|
|
11
|
+
void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output);
|
|
12
|
+
void herb_extract_html_to_buffer(const char* source, hb_buffer_T* output);
|
|
13
13
|
|
|
14
14
|
char* herb_extract_ruby_with_semicolons(const char* source);
|
|
15
|
-
void herb_extract_ruby_to_buffer_with_semicolons(const char* source,
|
|
15
|
+
void herb_extract_ruby_to_buffer_with_semicolons(const char* source, hb_buffer_T* output);
|
|
16
16
|
|
|
17
17
|
char* herb_extract(const char* source, herb_extract_language_T language);
|
|
18
18
|
char* herb_extract_from_file(const char* path, herb_extract_language_T language);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#ifndef HERB_H
|
|
2
2
|
#define HERB_H
|
|
3
3
|
|
|
4
|
-
#include "array.h"
|
|
5
4
|
#include "ast_node.h"
|
|
6
|
-
#include "buffer.h"
|
|
7
5
|
#include "extract.h"
|
|
8
6
|
#include "parser.h"
|
|
7
|
+
#include "util/hb_array.h"
|
|
8
|
+
#include "util/hb_buffer.h"
|
|
9
9
|
|
|
10
10
|
#include <stdint.h>
|
|
11
11
|
|
|
@@ -13,18 +13,17 @@
|
|
|
13
13
|
extern "C" {
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
|
-
void herb_lex_to_buffer(const char* source,
|
|
17
|
-
void herb_lex_json_to_buffer(const char* source, buffer_T* output);
|
|
16
|
+
void herb_lex_to_buffer(const char* source, hb_buffer_T* output);
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
hb_array_T* herb_lex(const char* source);
|
|
19
|
+
hb_array_T* herb_lex_file(const char* path);
|
|
21
20
|
|
|
22
21
|
AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options);
|
|
23
22
|
|
|
24
23
|
const char* herb_version(void);
|
|
25
24
|
const char* herb_prism_version(void);
|
|
26
25
|
|
|
27
|
-
void herb_free_tokens(
|
|
26
|
+
void herb_free_tokens(hb_array_T** tokens);
|
|
28
27
|
|
|
29
28
|
#ifdef __cplusplus
|
|
30
29
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#ifndef HERB_HTML_UTIL_H
|
|
2
2
|
#define HERB_HTML_UTIL_H
|
|
3
3
|
|
|
4
|
+
#include "util/hb_string.h"
|
|
4
5
|
#include <stdbool.h>
|
|
5
6
|
|
|
6
|
-
bool is_void_element(
|
|
7
|
-
bool is_html4_void_element(const char* tag_name);
|
|
7
|
+
bool is_void_element(hb_string_T tag_name);
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
char* html_self_closing_tag_string(const char* tag_name);
|
|
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);
|
|
12
11
|
|
|
13
12
|
#endif
|
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
#include "lexer_struct.h"
|
|
5
5
|
#include "token_struct.h"
|
|
6
6
|
|
|
7
|
-
lexer_T*
|
|
7
|
+
void lexer_init(lexer_T* lexer, const char* source);
|
|
8
8
|
token_T* lexer_next_token(lexer_T* lexer);
|
|
9
9
|
token_T* lexer_error(lexer_T* lexer, const char* message);
|
|
10
10
|
|
|
11
|
-
void lexer_free(lexer_T* lexer);
|
|
12
|
-
|
|
13
11
|
#endif
|
|
@@ -20,25 +20,25 @@ typedef struct {
|
|
|
20
20
|
lexer_state_T state;
|
|
21
21
|
} lexer_state_snapshot_T;
|
|
22
22
|
|
|
23
|
-
char lexer_peek(const lexer_T* lexer,
|
|
24
|
-
bool lexer_peek_for_doctype(const lexer_T* lexer,
|
|
25
|
-
bool lexer_peek_for_xml_declaration(const lexer_T* lexer,
|
|
26
|
-
bool lexer_peek_for_cdata_start(const lexer_T* lexer,
|
|
27
|
-
bool lexer_peek_for_cdata_end(const lexer_T* lexer,
|
|
23
|
+
char lexer_peek(const lexer_T* lexer, uint32_t offset);
|
|
24
|
+
bool lexer_peek_for_doctype(const lexer_T* lexer, uint32_t offset);
|
|
25
|
+
bool lexer_peek_for_xml_declaration(const lexer_T* lexer, uint32_t offset);
|
|
26
|
+
bool lexer_peek_for_cdata_start(const lexer_T* lexer, uint32_t offset);
|
|
27
|
+
bool lexer_peek_for_cdata_end(const lexer_T* lexer, uint32_t offset);
|
|
28
28
|
|
|
29
|
-
bool lexer_peek_for_html_comment_start(const lexer_T* lexer,
|
|
30
|
-
bool lexer_peek_for_html_comment_end(const lexer_T* lexer,
|
|
29
|
+
bool lexer_peek_for_html_comment_start(const lexer_T* lexer, uint32_t offset);
|
|
30
|
+
bool lexer_peek_for_html_comment_end(const lexer_T* lexer, uint32_t offset);
|
|
31
31
|
|
|
32
|
-
bool lexer_peek_erb_close_tag(const lexer_T* lexer,
|
|
33
|
-
bool lexer_peek_erb_dash_close_tag(const lexer_T* lexer,
|
|
34
|
-
bool lexer_peek_erb_percent_close_tag(const lexer_T* lexer,
|
|
35
|
-
bool lexer_peek_erb_equals_close_tag(const lexer_T* lexer,
|
|
36
|
-
bool lexer_peek_erb_end(const lexer_T* lexer,
|
|
32
|
+
bool lexer_peek_erb_close_tag(const lexer_T* lexer, uint32_t offset);
|
|
33
|
+
bool lexer_peek_erb_dash_close_tag(const lexer_T* lexer, uint32_t offset);
|
|
34
|
+
bool lexer_peek_erb_percent_close_tag(const lexer_T* lexer, uint32_t offset);
|
|
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);
|
|
37
37
|
|
|
38
|
-
char lexer_backtrack(const lexer_T* lexer,
|
|
38
|
+
char lexer_backtrack(const lexer_T* lexer, uint32_t offset);
|
|
39
39
|
|
|
40
40
|
bool lexer_peek_for_token_type_after_whitespace(lexer_T* lexer, token_type_T token_type);
|
|
41
|
-
bool lexer_peek_for_close_tag_start(const lexer_T* lexer,
|
|
41
|
+
bool lexer_peek_for_close_tag_start(const lexer_T* lexer, uint32_t offset);
|
|
42
42
|
|
|
43
43
|
lexer_state_snapshot_T lexer_save_state(lexer_T* lexer);
|
|
44
44
|
void lexer_restore_state(lexer_T* lexer, lexer_state_snapshot_T snapshot);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#ifndef HERB_LEXER_STRUCT_H
|
|
2
2
|
#define HERB_LEXER_STRUCT_H
|
|
3
3
|
|
|
4
|
+
#include "util/hb_string.h"
|
|
5
|
+
|
|
4
6
|
#include <stdbool.h>
|
|
5
7
|
#include <stdint.h>
|
|
6
8
|
#include <stdlib.h>
|
|
@@ -12,8 +14,7 @@ typedef enum {
|
|
|
12
14
|
} lexer_state_T;
|
|
13
15
|
|
|
14
16
|
typedef struct LEXER_STRUCT {
|
|
15
|
-
|
|
16
|
-
uint32_t source_length;
|
|
17
|
+
hb_string_T source;
|
|
17
18
|
|
|
18
19
|
uint32_t current_line;
|
|
19
20
|
uint32_t current_column;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#ifndef HERB_PARSER_H
|
|
2
2
|
#define HERB_PARSER_H
|
|
3
3
|
|
|
4
|
-
#include "array.h"
|
|
5
4
|
#include "ast_node.h"
|
|
6
5
|
#include "lexer.h"
|
|
6
|
+
#include "util/hb_array.h"
|
|
7
7
|
|
|
8
8
|
typedef enum {
|
|
9
9
|
FOREIGN_CONTENT_UNKNOWN = 0,
|
|
@@ -19,21 +19,27 @@ typedef struct PARSER_OPTIONS_STRUCT {
|
|
|
19
19
|
bool track_whitespace;
|
|
20
20
|
} parser_options_T;
|
|
21
21
|
|
|
22
|
+
extern const parser_options_T HERB_DEFAULT_PARSER_OPTIONS;
|
|
23
|
+
|
|
22
24
|
typedef struct PARSER_STRUCT {
|
|
23
25
|
lexer_T* lexer;
|
|
24
26
|
token_T* current_token;
|
|
25
|
-
|
|
27
|
+
hb_array_T* open_tags_stack;
|
|
26
28
|
parser_state_T state;
|
|
27
29
|
foreign_content_type_T foreign_content_type;
|
|
28
|
-
parser_options_T
|
|
30
|
+
parser_options_T options;
|
|
29
31
|
} parser_T;
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
size_t parser_sizeof(void);
|
|
34
|
+
|
|
35
|
+
void herb_parser_init(parser_T* parser, lexer_T* lexer, parser_options_T options);
|
|
32
36
|
|
|
33
37
|
AST_DOCUMENT_NODE_T* herb_parser_parse(parser_T* parser);
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
void herb_parser_match_html_tags_post_analyze(AST_DOCUMENT_NODE_T* document);
|
|
40
|
+
void herb_parser_deinit(parser_T* parser);
|
|
36
41
|
|
|
37
|
-
void
|
|
42
|
+
void match_tags_in_node_array(hb_array_T* nodes, hb_array_T* errors);
|
|
43
|
+
bool match_tags_visitor(const AST_NODE_T* node, void* data);
|
|
38
44
|
|
|
39
45
|
#endif
|
|
@@ -1,47 +1,57 @@
|
|
|
1
1
|
#ifndef HERB_PARSER_HELPERS_H
|
|
2
2
|
#define HERB_PARSER_HELPERS_H
|
|
3
3
|
|
|
4
|
-
#include "array.h"
|
|
5
4
|
#include "ast_nodes.h"
|
|
6
|
-
#include "buffer.h"
|
|
7
5
|
#include "errors.h"
|
|
8
6
|
#include "parser.h"
|
|
9
7
|
#include "token.h"
|
|
8
|
+
#include "util/hb_array.h"
|
|
9
|
+
#include "util/hb_buffer.h"
|
|
10
|
+
#include "util/hb_string.h"
|
|
10
11
|
|
|
11
12
|
void parser_push_open_tag(const parser_T* parser, token_T* tag_name);
|
|
12
|
-
bool parser_check_matching_tag(const parser_T* parser,
|
|
13
|
+
bool parser_check_matching_tag(const parser_T* parser, hb_string_T tag_name);
|
|
13
14
|
token_T* parser_pop_open_tag(const parser_T* parser);
|
|
14
15
|
|
|
15
|
-
void parser_append_unexpected_error(
|
|
16
|
-
|
|
16
|
+
void parser_append_unexpected_error(
|
|
17
|
+
parser_T* parser,
|
|
18
|
+
const char* description,
|
|
19
|
+
const char* expected,
|
|
20
|
+
hb_array_T* errors
|
|
21
|
+
);
|
|
22
|
+
void parser_append_unexpected_token_error(parser_T* parser, token_type_T expected_type, hb_array_T* errors);
|
|
17
23
|
|
|
18
24
|
void parser_append_literal_node_from_buffer(
|
|
19
25
|
const parser_T* parser,
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
hb_buffer_T* buffer,
|
|
27
|
+
hb_array_T* children,
|
|
22
28
|
position_T start
|
|
23
29
|
);
|
|
24
30
|
|
|
25
31
|
bool parser_in_svg_context(const parser_T* parser);
|
|
26
32
|
|
|
27
|
-
foreign_content_type_T parser_get_foreign_content_type(
|
|
28
|
-
bool parser_is_foreign_content_tag(
|
|
29
|
-
|
|
33
|
+
foreign_content_type_T parser_get_foreign_content_type(hb_string_T tag_name);
|
|
34
|
+
bool parser_is_foreign_content_tag(hb_string_T tag_name);
|
|
35
|
+
hb_string_T parser_get_foreign_content_closing_tag(foreign_content_type_T type);
|
|
30
36
|
|
|
31
37
|
void parser_enter_foreign_content(parser_T* parser, foreign_content_type_T type);
|
|
32
38
|
void parser_exit_foreign_content(parser_T* parser);
|
|
33
39
|
|
|
34
|
-
bool parser_is_expected_closing_tag_name(
|
|
40
|
+
bool parser_is_expected_closing_tag_name(hb_string_T tag_name, foreign_content_type_T expected_type);
|
|
35
41
|
|
|
36
42
|
token_T* parser_advance(parser_T* parser);
|
|
37
43
|
token_T* parser_consume_if_present(parser_T* parser, token_type_T type);
|
|
38
|
-
token_T* parser_consume_expected(parser_T* parser, token_type_T type,
|
|
44
|
+
token_T* parser_consume_expected(parser_T* parser, token_type_T type, hb_array_T* array);
|
|
39
45
|
|
|
40
46
|
AST_HTML_ELEMENT_NODE_T* parser_handle_missing_close_tag(
|
|
41
47
|
AST_HTML_OPEN_TAG_NODE_T* open_tag,
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
hb_array_T* body,
|
|
49
|
+
hb_array_T* errors
|
|
50
|
+
);
|
|
51
|
+
void parser_handle_mismatched_tags(
|
|
52
|
+
const parser_T* parser,
|
|
53
|
+
const AST_HTML_CLOSE_TAG_NODE_T* close_tag,
|
|
54
|
+
hb_array_T* errors
|
|
44
55
|
);
|
|
45
|
-
void parser_handle_mismatched_tags(const parser_T* parser, const AST_HTML_CLOSE_TAG_NODE_T* close_tag, array_T* errors);
|
|
46
56
|
|
|
47
57
|
#endif
|
|
@@ -3,91 +3,101 @@
|
|
|
3
3
|
|
|
4
4
|
#include "analyzed_ruby.h"
|
|
5
5
|
#include "ast_nodes.h"
|
|
6
|
-
#include "buffer.h"
|
|
7
6
|
#include "location.h"
|
|
7
|
+
#include "util/hb_buffer.h"
|
|
8
8
|
|
|
9
9
|
#include <stdbool.h>
|
|
10
10
|
|
|
11
|
-
void pretty_print_indent(
|
|
12
|
-
void pretty_print_newline(size_t indent, size_t relative_indent,
|
|
13
|
-
void pretty_print_label(
|
|
11
|
+
void pretty_print_indent(hb_buffer_T* buffer, size_t indent);
|
|
12
|
+
void pretty_print_newline(size_t indent, size_t relative_indent, hb_buffer_T* buffer);
|
|
13
|
+
void pretty_print_label(
|
|
14
|
+
hb_string_T name,
|
|
15
|
+
size_t indent,
|
|
16
|
+
size_t relative_indent,
|
|
17
|
+
bool last_property,
|
|
18
|
+
hb_buffer_T* buffer
|
|
19
|
+
);
|
|
14
20
|
|
|
15
21
|
void pretty_print_position_property(
|
|
16
22
|
position_T* position,
|
|
17
|
-
|
|
23
|
+
hb_string_T name,
|
|
18
24
|
size_t indent,
|
|
19
25
|
size_t relative_indent,
|
|
20
26
|
bool last_property,
|
|
21
|
-
|
|
27
|
+
hb_buffer_T* buffer
|
|
22
28
|
);
|
|
23
29
|
|
|
24
|
-
void pretty_print_location(location_T location,
|
|
30
|
+
void pretty_print_location(location_T location, hb_buffer_T* buffer);
|
|
25
31
|
|
|
26
32
|
void pretty_print_property(
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
hb_string_T name,
|
|
34
|
+
hb_string_T value,
|
|
29
35
|
size_t indent,
|
|
30
36
|
size_t relative_indent,
|
|
31
37
|
bool last_property,
|
|
32
|
-
|
|
38
|
+
hb_buffer_T* buffer
|
|
33
39
|
);
|
|
34
40
|
|
|
35
41
|
void pretty_print_size_t_property(
|
|
36
42
|
size_t value,
|
|
37
|
-
|
|
43
|
+
hb_string_T name,
|
|
38
44
|
size_t indent,
|
|
39
45
|
size_t relative_indent,
|
|
40
46
|
bool last_property,
|
|
41
|
-
|
|
47
|
+
hb_buffer_T* buffer
|
|
42
48
|
);
|
|
43
49
|
|
|
44
50
|
void pretty_print_string_property(
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
hb_string_T string,
|
|
52
|
+
hb_string_T name,
|
|
47
53
|
size_t indent,
|
|
48
54
|
size_t relative_indent,
|
|
49
55
|
bool last_property,
|
|
50
|
-
|
|
56
|
+
hb_buffer_T* buffer
|
|
51
57
|
);
|
|
52
58
|
|
|
53
59
|
void pretty_print_quoted_property(
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
hb_string_T name,
|
|
61
|
+
hb_string_T value,
|
|
56
62
|
size_t indent,
|
|
57
63
|
size_t relative_indent,
|
|
58
64
|
bool last_property,
|
|
59
|
-
|
|
65
|
+
hb_buffer_T* buffer
|
|
60
66
|
);
|
|
61
67
|
|
|
62
68
|
void pretty_print_boolean_property(
|
|
63
|
-
|
|
69
|
+
hb_string_T name,
|
|
64
70
|
bool value,
|
|
65
71
|
size_t indent,
|
|
66
72
|
size_t relative_indent,
|
|
67
73
|
bool last_property,
|
|
68
|
-
|
|
74
|
+
hb_buffer_T* buffer
|
|
69
75
|
);
|
|
70
76
|
|
|
71
77
|
void pretty_print_token_property(
|
|
72
78
|
token_T* token,
|
|
73
|
-
|
|
79
|
+
hb_string_T name,
|
|
74
80
|
size_t indent,
|
|
75
81
|
size_t relative_indent,
|
|
76
82
|
bool last_property,
|
|
77
|
-
|
|
83
|
+
hb_buffer_T* buffer
|
|
78
84
|
);
|
|
79
85
|
|
|
80
86
|
void pretty_print_array(
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
hb_string_T name,
|
|
88
|
+
hb_array_T* array,
|
|
83
89
|
size_t indent,
|
|
84
90
|
size_t relative_indent,
|
|
85
91
|
bool last_property,
|
|
86
|
-
|
|
92
|
+
hb_buffer_T* buffer
|
|
87
93
|
);
|
|
88
94
|
|
|
89
|
-
void pretty_print_errors(
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
void pretty_print_errors(
|
|
96
|
+
AST_NODE_T* node,
|
|
97
|
+
size_t indent,
|
|
98
|
+
size_t relative_indent,
|
|
99
|
+
bool last_property,
|
|
100
|
+
hb_buffer_T* buffer
|
|
101
|
+
);
|
|
92
102
|
|
|
93
103
|
#endif
|
|
@@ -4,19 +4,16 @@
|
|
|
4
4
|
#include "lexer_struct.h"
|
|
5
5
|
#include "position.h"
|
|
6
6
|
#include "token_struct.h"
|
|
7
|
+
#include "util/hb_string.h"
|
|
7
8
|
|
|
8
|
-
token_T* token_init(
|
|
9
|
-
|
|
10
|
-
char* token_to_json(const token_T* token);
|
|
9
|
+
token_T* token_init(hb_string_T value, token_type_T type, lexer_T* lexer);
|
|
10
|
+
hb_string_T token_to_string(const token_T* token);
|
|
11
11
|
const char* token_type_to_string(token_type_T type);
|
|
12
12
|
|
|
13
|
-
char* token_value(const token_T* token);
|
|
14
|
-
int token_type(const token_T* token);
|
|
15
|
-
|
|
16
|
-
size_t token_sizeof(void);
|
|
17
|
-
|
|
18
13
|
token_T* token_copy(token_T* token);
|
|
19
14
|
|
|
20
15
|
void token_free(token_T* token);
|
|
21
16
|
|
|
17
|
+
bool token_value_empty(const token_T* token);
|
|
18
|
+
|
|
22
19
|
#endif
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
#define HERB_UTF8_H
|
|
3
3
|
|
|
4
4
|
#include <stdbool.h>
|
|
5
|
+
#include <stdint.h>
|
|
5
6
|
#include <stdlib.h>
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
uint32_t utf8_char_byte_length(unsigned char first_byte);
|
|
9
|
+
uint32_t utf8_sequence_length(const char* str, size_t position, size_t max_length);
|
|
9
10
|
bool utf8_is_valid_continuation_byte(unsigned char byte);
|
|
10
11
|
|
|
11
12
|
#endif
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#ifndef HERB_ARENA_H
|
|
2
|
+
#define HERB_ARENA_H
|
|
3
|
+
|
|
4
|
+
#include <stdbool.h>
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
|
|
7
|
+
typedef struct HB_ARENA_PAGE_STRUCT hb_arena_page_T;
|
|
8
|
+
|
|
9
|
+
struct HB_ARENA_PAGE_STRUCT {
|
|
10
|
+
hb_arena_page_T* next;
|
|
11
|
+
size_t capacity;
|
|
12
|
+
size_t position;
|
|
13
|
+
char memory[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
typedef struct HB_ARENA_STRUCT {
|
|
17
|
+
hb_arena_page_T* head;
|
|
18
|
+
hb_arena_page_T* tail;
|
|
19
|
+
size_t default_page_size;
|
|
20
|
+
size_t allocation_count;
|
|
21
|
+
} hb_arena_T;
|
|
22
|
+
|
|
23
|
+
bool hb_arena_init(hb_arena_T* allocator, size_t initial_size);
|
|
24
|
+
void* hb_arena_alloc(hb_arena_T* allocator, size_t size);
|
|
25
|
+
size_t hb_arena_position(hb_arena_T* allocator);
|
|
26
|
+
size_t hb_arena_capacity(hb_arena_T* allocator);
|
|
27
|
+
void hb_arena_reset(hb_arena_T* allocator);
|
|
28
|
+
void hb_arena_reset_to(hb_arena_T* allocator, size_t new_position);
|
|
29
|
+
void hb_arena_free(hb_arena_T* allocator);
|
|
30
|
+
|
|
31
|
+
#endif
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#ifndef HERB_ARRAY_H
|
|
2
|
+
#define HERB_ARRAY_H
|
|
3
|
+
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
typedef struct HB_ARRAY_STRUCT {
|
|
7
|
+
void** items;
|
|
8
|
+
size_t size;
|
|
9
|
+
size_t capacity;
|
|
10
|
+
} hb_array_T;
|
|
11
|
+
|
|
12
|
+
hb_array_T* hb_array_init(size_t capacity);
|
|
13
|
+
|
|
14
|
+
void* hb_array_get(const hb_array_T* array, size_t index);
|
|
15
|
+
void* hb_array_first(hb_array_T* array);
|
|
16
|
+
void* hb_array_last(hb_array_T* array);
|
|
17
|
+
|
|
18
|
+
void hb_array_append(hb_array_T* array, void* item);
|
|
19
|
+
void hb_array_set(const hb_array_T* array, size_t index, void* item);
|
|
20
|
+
void hb_array_free(hb_array_T** array);
|
|
21
|
+
void hb_array_remove(hb_array_T* array, size_t index);
|
|
22
|
+
|
|
23
|
+
size_t hb_array_index_of(hb_array_T* array, void* item);
|
|
24
|
+
void hb_array_remove_item(hb_array_T* array, void* item);
|
|
25
|
+
|
|
26
|
+
void hb_array_push(hb_array_T* array, void* item);
|
|
27
|
+
void* hb_array_pop(hb_array_T* array);
|
|
28
|
+
|
|
29
|
+
size_t hb_array_capacity(const hb_array_T* array);
|
|
30
|
+
size_t hb_array_size(const hb_array_T* array);
|
|
31
|
+
size_t hb_array_sizeof(void);
|
|
32
|
+
|
|
33
|
+
#endif
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#ifndef HERB_BUFFER_H
|
|
2
|
+
#define HERB_BUFFER_H
|
|
3
|
+
|
|
4
|
+
#include "hb_string.h"
|
|
5
|
+
|
|
6
|
+
#include <stdbool.h>
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
|
|
9
|
+
typedef struct HB_BUFFER_STRUCT {
|
|
10
|
+
char* value;
|
|
11
|
+
size_t length;
|
|
12
|
+
size_t capacity;
|
|
13
|
+
} hb_buffer_T;
|
|
14
|
+
|
|
15
|
+
bool hb_buffer_init(hb_buffer_T* buffer, size_t capacity);
|
|
16
|
+
|
|
17
|
+
void hb_buffer_append(hb_buffer_T* buffer, const char* text);
|
|
18
|
+
void hb_buffer_append_with_length(hb_buffer_T* buffer, const char* text, size_t length);
|
|
19
|
+
void hb_buffer_append_string(hb_buffer_T* buffer, hb_string_T string);
|
|
20
|
+
void hb_buffer_append_char(hb_buffer_T* buffer, char character);
|
|
21
|
+
void hb_buffer_append_whitespace(hb_buffer_T* buffer, size_t length);
|
|
22
|
+
void hb_buffer_prepend(hb_buffer_T* buffer, const char* text);
|
|
23
|
+
void hb_buffer_concat(hb_buffer_T* destination, hb_buffer_T* source);
|
|
24
|
+
|
|
25
|
+
char* hb_buffer_value(const hb_buffer_T* buffer);
|
|
26
|
+
|
|
27
|
+
size_t hb_buffer_length(const hb_buffer_T* buffer);
|
|
28
|
+
size_t hb_buffer_capacity(const hb_buffer_T* buffer);
|
|
29
|
+
size_t hb_buffer_sizeof(void);
|
|
30
|
+
|
|
31
|
+
void hb_buffer_clear(hb_buffer_T* buffer);
|
|
32
|
+
void hb_buffer_free(hb_buffer_T** buffer);
|
|
33
|
+
|
|
34
|
+
#endif
|