@herb-tools/node 0.5.0 → 0.6.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.
Files changed (35) hide show
  1. package/dist/herb-node.esm.js +1 -1
  2. package/dist/herb-node.esm.js.map +1 -1
  3. package/dist/types/util.d.ts +2 -0
  4. package/extension/error_helpers.cpp +1 -1
  5. package/extension/error_helpers.h +1 -1
  6. package/extension/herb.cpp +29 -4
  7. package/extension/libherb/ast_nodes.c +79 -36
  8. package/extension/libherb/ast_nodes.h +23 -15
  9. package/extension/libherb/ast_pretty_print.c +21 -13
  10. package/extension/libherb/ast_pretty_print.h +1 -1
  11. package/extension/libherb/errors.c +1 -1
  12. package/extension/libherb/errors.h +1 -1
  13. package/extension/libherb/herb.c +2 -2
  14. package/extension/libherb/herb.h +2 -1
  15. package/extension/libherb/include/ast_nodes.h +23 -15
  16. package/extension/libherb/include/ast_pretty_print.h +1 -1
  17. package/extension/libherb/include/errors.h +1 -1
  18. package/extension/libherb/include/herb.h +2 -1
  19. package/extension/libherb/include/lexer_peek_helpers.h +21 -0
  20. package/extension/libherb/include/parser.h +6 -1
  21. package/extension/libherb/include/token_struct.h +6 -1
  22. package/extension/libherb/include/version.h +1 -1
  23. package/extension/libherb/lexer.c +20 -1
  24. package/extension/libherb/lexer_peek_helpers.c +77 -0
  25. package/extension/libherb/lexer_peek_helpers.h +21 -0
  26. package/extension/libherb/main.c +2 -2
  27. package/extension/libherb/parser.c +435 -122
  28. package/extension/libherb/parser.h +6 -1
  29. package/extension/libherb/token.c +5 -0
  30. package/extension/libherb/token_struct.h +6 -1
  31. package/extension/libherb/version.h +1 -1
  32. package/extension/libherb/visitor.c +39 -6
  33. package/extension/nodes.cpp +74 -44
  34. package/extension/nodes.h +3 -2
  35. package/package.json +2 -2
@@ -15,15 +15,20 @@ typedef enum {
15
15
 
16
16
  typedef enum { PARSER_STATE_DATA, PARSER_STATE_FOREIGN_CONTENT } parser_state_T;
17
17
 
18
+ typedef struct PARSER_OPTIONS_STRUCT {
19
+ bool track_whitespace;
20
+ } parser_options_T;
21
+
18
22
  typedef struct PARSER_STRUCT {
19
23
  lexer_T* lexer;
20
24
  token_T* current_token;
21
25
  array_T* open_tags_stack;
22
26
  parser_state_T state;
23
27
  foreign_content_type_T foreign_content_type;
28
+ parser_options_T* options;
24
29
  } parser_T;
25
30
 
26
- parser_T* parser_init(lexer_T* lexer);
31
+ parser_T* parser_init(lexer_T* lexer, parser_options_T* options);
27
32
 
28
33
  AST_DOCUMENT_NODE_T* parser_parse(parser_T* parser);
29
34
 
@@ -47,6 +47,10 @@ const char* token_type_to_string(const token_type_T type) {
47
47
  case TOKEN_NEWLINE: return "TOKEN_NEWLINE";
48
48
  case TOKEN_IDENTIFIER: return "TOKEN_IDENTIFIER";
49
49
  case TOKEN_HTML_DOCTYPE: return "TOKEN_HTML_DOCTYPE";
50
+ case TOKEN_XML_DECLARATION: return "TOKEN_XML_DECLARATION";
51
+ case TOKEN_XML_DECLARATION_END: return "TOKEN_XML_DECLARATION_END";
52
+ case TOKEN_CDATA_START: return "TOKEN_CDATA_START";
53
+ case TOKEN_CDATA_END: return "TOKEN_CDATA_END";
50
54
  case TOKEN_HTML_TAG_START: return "TOKEN_HTML_TAG_START";
51
55
  case TOKEN_HTML_TAG_END: return "TOKEN_HTML_TAG_END";
52
56
  case TOKEN_HTML_TAG_START_CLOSE: return "TOKEN_HTML_TAG_START_CLOSE";
@@ -56,6 +60,7 @@ const char* token_type_to_string(const token_type_T type) {
56
60
  case TOKEN_EQUALS: return "TOKEN_EQUALS";
57
61
  case TOKEN_QUOTE: return "TOKEN_QUOTE";
58
62
  case TOKEN_BACKTICK: return "TOKEN_BACKTICK";
63
+ case TOKEN_BACKSLASH: return "TOKEN_BACKSLASH";
59
64
  case TOKEN_DASH: return "TOKEN_DASH";
60
65
  case TOKEN_UNDERSCORE: return "TOKEN_UNDERSCORE";
61
66
  case TOKEN_EXCLAMATION: return "TOKEN_EXCLAMATION";
@@ -10,7 +10,11 @@ typedef enum {
10
10
  TOKEN_NEWLINE, // \n
11
11
  TOKEN_IDENTIFIER,
12
12
 
13
- TOKEN_HTML_DOCTYPE, // <!DOCTYPE, <!doctype, <!DoCtYpE, <!dOcTyPe
13
+ TOKEN_HTML_DOCTYPE, // <!DOCTYPE, <!doctype, <!DoCtYpE, <!dOcTyPe
14
+ TOKEN_XML_DECLARATION, // <?xml
15
+ TOKEN_XML_DECLARATION_END, // ?>
16
+ TOKEN_CDATA_START, // <![CDATA[
17
+ TOKEN_CDATA_END, // ]]>
14
18
 
15
19
  TOKEN_HTML_TAG_START, // <
16
20
  TOKEN_HTML_TAG_START_CLOSE, // </
@@ -29,6 +33,7 @@ typedef enum {
29
33
  TOKEN_EQUALS, // =
30
34
  TOKEN_QUOTE, // ", '
31
35
  TOKEN_BACKTICK, // `
36
+ TOKEN_BACKSLASH, // backslash
32
37
  TOKEN_DASH, // -
33
38
  TOKEN_UNDERSCORE, // _
34
39
  TOKEN_EXCLAMATION, // !
@@ -1,6 +1,6 @@
1
1
  #ifndef HERB_VERSION_H
2
2
  #define HERB_VERSION_H
3
3
 
4
- #define HERB_VERSION "0.5.0"
4
+ #define HERB_VERSION "0.6.0"
5
5
 
6
6
  #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.5.0/templates/src/visitor.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/src/visitor.c.erb
3
3
 
4
4
  #include <stdio.h>
5
5
 
@@ -42,12 +42,12 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
42
42
 
43
43
  } break;
44
44
 
45
- case AST_HTML_SELF_CLOSE_TAG_NODE: {
46
- const AST_HTML_SELF_CLOSE_TAG_NODE_T* html_self_close_tag_node = ((const AST_HTML_SELF_CLOSE_TAG_NODE_T *) node);
45
+ case AST_HTML_CLOSE_TAG_NODE: {
46
+ const AST_HTML_CLOSE_TAG_NODE_T* html_close_tag_node = ((const AST_HTML_CLOSE_TAG_NODE_T *) node);
47
47
 
48
- if (html_self_close_tag_node->attributes != NULL) {
49
- for (size_t index = 0; index < array_size(html_self_close_tag_node->attributes); index++) {
50
- herb_visit_node(array_get(html_self_close_tag_node->attributes, index), visitor, data);
48
+ if (html_close_tag_node->children != NULL) {
49
+ for (size_t index = 0; index < array_size(html_close_tag_node->children); index++) {
50
+ herb_visit_node(array_get(html_close_tag_node->children, index), visitor, data);
51
51
  }
52
52
  }
53
53
 
@@ -83,6 +83,17 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
83
83
 
84
84
  } break;
85
85
 
86
+ case AST_HTML_ATTRIBUTE_NAME_NODE: {
87
+ const AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node = ((const AST_HTML_ATTRIBUTE_NAME_NODE_T *) node);
88
+
89
+ if (html_attribute_name_node->children != NULL) {
90
+ for (size_t index = 0; index < array_size(html_attribute_name_node->children); index++) {
91
+ herb_visit_node(array_get(html_attribute_name_node->children, index), visitor, data);
92
+ }
93
+ }
94
+
95
+ } break;
96
+
86
97
  case AST_HTML_ATTRIBUTE_NODE: {
87
98
  const AST_HTML_ATTRIBUTE_NODE_T* html_attribute_node = ((const AST_HTML_ATTRIBUTE_NODE_T *) node);
88
99
 
@@ -118,6 +129,28 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
118
129
 
119
130
  } break;
120
131
 
132
+ case AST_XML_DECLARATION_NODE: {
133
+ const AST_XML_DECLARATION_NODE_T* xml_declaration_node = ((const AST_XML_DECLARATION_NODE_T *) node);
134
+
135
+ if (xml_declaration_node->children != NULL) {
136
+ for (size_t index = 0; index < array_size(xml_declaration_node->children); index++) {
137
+ herb_visit_node(array_get(xml_declaration_node->children, index), visitor, data);
138
+ }
139
+ }
140
+
141
+ } break;
142
+
143
+ case AST_CDATA_NODE: {
144
+ const AST_CDATA_NODE_T* cdata_node = ((const AST_CDATA_NODE_T *) node);
145
+
146
+ if (cdata_node->children != NULL) {
147
+ for (size_t index = 0; index < array_size(cdata_node->children); index++) {
148
+ herb_visit_node(array_get(cdata_node->children, index), visitor, data);
149
+ }
150
+ }
151
+
152
+ } break;
153
+
121
154
  case AST_ERB_ELSE_NODE: {
122
155
  const AST_ERB_ELSE_NODE_T* erb_else_node = ((const AST_ERB_ELSE_NODE_T *) node);
123
156
 
@@ -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.5.0/templates/javascript/packages/node/extension/nodes.cpp.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/javascript/packages/node/extension/nodes.cpp.erb
3
3
 
4
4
  #include <node_api.h>
5
5
  #include "error_helpers.h"
@@ -130,47 +130,12 @@ napi_value html_close_tag_nodeNodeFromCStruct(napi_env env, AST_HTML_CLOSE_TAG_N
130
130
  napi_value tag_name = CreateToken(env, html_close_tag_node->tag_name);
131
131
  napi_set_named_property(env, result, "tag_name", tag_name);
132
132
 
133
- napi_value tag_closing = CreateToken(env, html_close_tag_node->tag_closing);
134
- napi_set_named_property(env, result, "tag_closing", tag_closing);
135
-
136
-
137
- return result;
138
- }
139
- napi_value html_self_close_tag_nodeNodeFromCStruct(napi_env env, AST_HTML_SELF_CLOSE_TAG_NODE_T* html_self_close_tag_node) {
140
- if (!html_self_close_tag_node) {
141
- napi_value null_value;
142
- napi_get_null(env, &null_value);
143
- return null_value;
144
- }
145
-
146
- napi_value result;
147
- napi_create_object(env, &result);
148
-
149
- napi_value type = CreateString(env, ast_node_type_to_string(&html_self_close_tag_node->base));
150
- napi_set_named_property(env, result, "type", type);
151
-
152
- napi_value location = CreateLocation(env, html_self_close_tag_node->base.location);
153
- napi_set_named_property(env, result, "location", location);
154
-
155
- napi_value errors = ErrorsArrayFromCArray(env, html_self_close_tag_node->base.errors);
156
- napi_set_named_property(env, result, "errors", errors);
157
-
158
- napi_value tag_opening = CreateToken(env, html_self_close_tag_node->tag_opening);
159
- napi_set_named_property(env, result, "tag_opening", tag_opening);
160
-
161
- napi_value tag_name = CreateToken(env, html_self_close_tag_node->tag_name);
162
- napi_set_named_property(env, result, "tag_name", tag_name);
163
-
164
- napi_value attributes = NodesArrayFromCArray(env, html_self_close_tag_node->attributes);
165
- napi_set_named_property(env, result, "attributes", attributes);
133
+ napi_value children = NodesArrayFromCArray(env, html_close_tag_node->children);
134
+ napi_set_named_property(env, result, "children", children);
166
135
 
167
- napi_value tag_closing = CreateToken(env, html_self_close_tag_node->tag_closing);
136
+ napi_value tag_closing = CreateToken(env, html_close_tag_node->tag_closing);
168
137
  napi_set_named_property(env, result, "tag_closing", tag_closing);
169
138
 
170
- napi_value is_void;
171
- napi_get_boolean(env, html_self_close_tag_node->is_void, &is_void);
172
- napi_set_named_property(env, result, "is_void", is_void);
173
-
174
139
 
175
140
  return result;
176
141
  }
@@ -266,8 +231,8 @@ napi_value html_attribute_name_nodeNodeFromCStruct(napi_env env, AST_HTML_ATTRIB
266
231
  napi_value errors = ErrorsArrayFromCArray(env, html_attribute_name_node->base.errors);
267
232
  napi_set_named_property(env, result, "errors", errors);
268
233
 
269
- napi_value name = CreateToken(env, html_attribute_name_node->name);
270
- napi_set_named_property(env, result, "name", name);
234
+ napi_value children = NodesArrayFromCArray(env, html_attribute_name_node->children);
235
+ napi_set_named_property(env, result, "children", children);
271
236
 
272
237
 
273
238
  return result;
@@ -388,6 +353,68 @@ napi_value html_doctype_nodeNodeFromCStruct(napi_env env, AST_HTML_DOCTYPE_NODE_
388
353
  napi_set_named_property(env, result, "tag_closing", tag_closing);
389
354
 
390
355
 
356
+ return result;
357
+ }
358
+ napi_value xml_declaration_nodeNodeFromCStruct(napi_env env, AST_XML_DECLARATION_NODE_T* xml_declaration_node) {
359
+ if (!xml_declaration_node) {
360
+ napi_value null_value;
361
+ napi_get_null(env, &null_value);
362
+ return null_value;
363
+ }
364
+
365
+ napi_value result;
366
+ napi_create_object(env, &result);
367
+
368
+ napi_value type = CreateString(env, ast_node_type_to_string(&xml_declaration_node->base));
369
+ napi_set_named_property(env, result, "type", type);
370
+
371
+ napi_value location = CreateLocation(env, xml_declaration_node->base.location);
372
+ napi_set_named_property(env, result, "location", location);
373
+
374
+ napi_value errors = ErrorsArrayFromCArray(env, xml_declaration_node->base.errors);
375
+ napi_set_named_property(env, result, "errors", errors);
376
+
377
+ napi_value tag_opening = CreateToken(env, xml_declaration_node->tag_opening);
378
+ napi_set_named_property(env, result, "tag_opening", tag_opening);
379
+
380
+ napi_value children = NodesArrayFromCArray(env, xml_declaration_node->children);
381
+ napi_set_named_property(env, result, "children", children);
382
+
383
+ napi_value tag_closing = CreateToken(env, xml_declaration_node->tag_closing);
384
+ napi_set_named_property(env, result, "tag_closing", tag_closing);
385
+
386
+
387
+ return result;
388
+ }
389
+ napi_value cdata_nodeNodeFromCStruct(napi_env env, AST_CDATA_NODE_T* cdata_node) {
390
+ if (!cdata_node) {
391
+ napi_value null_value;
392
+ napi_get_null(env, &null_value);
393
+ return null_value;
394
+ }
395
+
396
+ napi_value result;
397
+ napi_create_object(env, &result);
398
+
399
+ napi_value type = CreateString(env, ast_node_type_to_string(&cdata_node->base));
400
+ napi_set_named_property(env, result, "type", type);
401
+
402
+ napi_value location = CreateLocation(env, cdata_node->base.location);
403
+ napi_set_named_property(env, result, "location", location);
404
+
405
+ napi_value errors = ErrorsArrayFromCArray(env, cdata_node->base.errors);
406
+ napi_set_named_property(env, result, "errors", errors);
407
+
408
+ napi_value tag_opening = CreateToken(env, cdata_node->tag_opening);
409
+ napi_set_named_property(env, result, "tag_opening", tag_opening);
410
+
411
+ napi_value children = NodesArrayFromCArray(env, cdata_node->children);
412
+ napi_set_named_property(env, result, "children", children);
413
+
414
+ napi_value tag_closing = CreateToken(env, cdata_node->tag_closing);
415
+ napi_set_named_property(env, result, "tag_closing", tag_closing);
416
+
417
+
391
418
  return result;
392
419
  }
393
420
  napi_value whitespace_nodeNodeFromCStruct(napi_env env, AST_WHITESPACE_NODE_T* whitespace_node) {
@@ -1091,9 +1118,6 @@ napi_value NodeFromCStruct(napi_env env, AST_NODE_T* node) {
1091
1118
  case AST_HTML_CLOSE_TAG_NODE:
1092
1119
  return html_close_tag_nodeNodeFromCStruct(env, (AST_HTML_CLOSE_TAG_NODE_T*) node);
1093
1120
  break;
1094
- case AST_HTML_SELF_CLOSE_TAG_NODE:
1095
- return html_self_close_tag_nodeNodeFromCStruct(env, (AST_HTML_SELF_CLOSE_TAG_NODE_T*) node);
1096
- break;
1097
1121
  case AST_HTML_ELEMENT_NODE:
1098
1122
  return html_element_nodeNodeFromCStruct(env, (AST_HTML_ELEMENT_NODE_T*) node);
1099
1123
  break;
@@ -1115,6 +1139,12 @@ napi_value NodeFromCStruct(napi_env env, AST_NODE_T* node) {
1115
1139
  case AST_HTML_DOCTYPE_NODE:
1116
1140
  return html_doctype_nodeNodeFromCStruct(env, (AST_HTML_DOCTYPE_NODE_T*) node);
1117
1141
  break;
1142
+ case AST_XML_DECLARATION_NODE:
1143
+ return xml_declaration_nodeNodeFromCStruct(env, (AST_XML_DECLARATION_NODE_T*) node);
1144
+ break;
1145
+ case AST_CDATA_NODE:
1146
+ return cdata_nodeNodeFromCStruct(env, (AST_CDATA_NODE_T*) node);
1147
+ break;
1118
1148
  case AST_WHITESPACE_NODE:
1119
1149
  return whitespace_nodeNodeFromCStruct(env, (AST_WHITESPACE_NODE_T*) node);
1120
1150
  break;
package/extension/nodes.h CHANGED
@@ -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.5.0/templates/javascript/packages/node/extension/nodes.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/javascript/packages/node/extension/nodes.h.erb
3
3
 
4
4
  #ifndef HERB_EXTENSION_NODES_H
5
5
  #define HERB_EXTENSION_NODES_H
@@ -17,7 +17,6 @@ napi_value document_nodeNodeFromCStruct(napi_env env, AST_DOCUMENT_NODE_T* docum
17
17
  napi_value literal_nodeNodeFromCStruct(napi_env env, AST_LITERAL_NODE_T* literal_node);
18
18
  napi_value html_open_tag_nodeNodeFromCStruct(napi_env env, AST_HTML_OPEN_TAG_NODE_T* html_open_tag_node);
19
19
  napi_value html_close_tag_nodeNodeFromCStruct(napi_env env, AST_HTML_CLOSE_TAG_NODE_T* html_close_tag_node);
20
- napi_value html_self_close_tag_nodeNodeFromCStruct(napi_env env, AST_HTML_SELF_CLOSE_TAG_NODE_T* html_self_close_tag_node);
21
20
  napi_value html_element_nodeNodeFromCStruct(napi_env env, AST_HTML_ELEMENT_NODE_T* html_element_node);
22
21
  napi_value html_attribute_value_nodeNodeFromCStruct(napi_env env, AST_HTML_ATTRIBUTE_VALUE_NODE_T* html_attribute_value_node);
23
22
  napi_value html_attribute_name_nodeNodeFromCStruct(napi_env env, AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node);
@@ -25,6 +24,8 @@ napi_value html_attribute_nodeNodeFromCStruct(napi_env env, AST_HTML_ATTRIBUTE_N
25
24
  napi_value html_text_nodeNodeFromCStruct(napi_env env, AST_HTML_TEXT_NODE_T* html_text_node);
26
25
  napi_value html_comment_nodeNodeFromCStruct(napi_env env, AST_HTML_COMMENT_NODE_T* html_comment_node);
27
26
  napi_value html_doctype_nodeNodeFromCStruct(napi_env env, AST_HTML_DOCTYPE_NODE_T* html_doctype_node);
27
+ napi_value xml_declaration_nodeNodeFromCStruct(napi_env env, AST_XML_DECLARATION_NODE_T* xml_declaration_node);
28
+ napi_value cdata_nodeNodeFromCStruct(napi_env env, AST_CDATA_NODE_T* cdata_node);
28
29
  napi_value whitespace_nodeNodeFromCStruct(napi_env env, AST_WHITESPACE_NODE_T* whitespace_node);
29
30
  napi_value erb_content_nodeNodeFromCStruct(napi_env env, AST_ERB_CONTENT_NODE_T* erb_content_node);
30
31
  napi_value erb_end_nodeNodeFromCStruct(napi_env env, AST_ERB_END_NODE_T* erb_end_node);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herb-tools/node",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Native Node.js addon for HTML-aware ERB parsing using Herb.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,7 +48,7 @@
48
48
  "host": "https://github.com/marcoroth/herb/releases/download/"
49
49
  },
50
50
  "dependencies": {
51
- "@herb-tools/core": "0.5.0",
51
+ "@herb-tools/core": "0.6.0",
52
52
  "@mapbox/node-pre-gyp": "^2.0.0",
53
53
  "node-addon-api": "^5.1.0",
54
54
  "node-pre-gyp-github": "^2.0.0"