@herb-tools/node 0.7.4 → 0.7.5
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 +0 -1
- package/dist/herb-node.esm.js +1 -1
- package/extension/error_helpers.cpp +1 -1
- package/extension/error_helpers.h +1 -1
- package/extension/extension_helpers.cpp +9 -27
- package/extension/extension_helpers.h +3 -3
- package/extension/libherb/analyze.c +43 -80
- package/extension/libherb/ast_node.c +10 -13
- package/extension/libherb/ast_node.h +3 -3
- package/extension/libherb/ast_nodes.c +32 -34
- package/extension/libherb/ast_nodes.h +33 -33
- package/extension/libherb/ast_pretty_print.c +1 -1
- package/extension/libherb/ast_pretty_print.h +1 -1
- package/extension/libherb/buffer.c +10 -1
- package/extension/libherb/errors.c +36 -36
- package/extension/libherb/errors.h +22 -22
- package/extension/libherb/include/ast_node.h +3 -3
- package/extension/libherb/include/ast_nodes.h +33 -33
- package/extension/libherb/include/ast_pretty_print.h +1 -1
- package/extension/libherb/include/errors.h +22 -22
- package/extension/libherb/include/lexer_peek_helpers.h +8 -6
- package/extension/libherb/include/lexer_struct.h +10 -9
- package/extension/libherb/include/location.h +10 -13
- package/extension/libherb/include/parser_helpers.h +1 -1
- package/extension/libherb/include/position.h +3 -14
- package/extension/libherb/include/pretty_print.h +1 -1
- package/extension/libherb/include/prism_helpers.h +1 -1
- package/extension/libherb/include/range.h +4 -13
- package/extension/libherb/include/token.h +0 -3
- package/extension/libherb/include/token_struct.h +2 -2
- package/extension/libherb/include/version.h +1 -1
- package/extension/libherb/lexer.c +3 -2
- package/extension/libherb/lexer_peek_helpers.c +10 -4
- package/extension/libherb/lexer_peek_helpers.h +8 -6
- package/extension/libherb/lexer_struct.h +10 -9
- package/extension/libherb/location.c +9 -37
- package/extension/libherb/location.h +10 -13
- package/extension/libherb/parser.c +98 -119
- package/extension/libherb/parser_helpers.c +15 -15
- package/extension/libherb/parser_helpers.h +1 -1
- package/extension/libherb/position.h +3 -14
- package/extension/libherb/pretty_print.c +7 -12
- package/extension/libherb/pretty_print.h +1 -1
- package/extension/libherb/prism_helpers.c +7 -7
- package/extension/libherb/prism_helpers.h +1 -1
- package/extension/libherb/range.c +2 -35
- package/extension/libherb/range.h +4 -13
- package/extension/libherb/token.c +25 -29
- package/extension/libherb/token.h +0 -3
- package/extension/libherb/token_struct.h +2 -2
- package/extension/libherb/version.h +1 -1
- package/extension/libherb/visitor.c +1 -1
- package/extension/nodes.cpp +1 -1
- package/extension/nodes.h +1 -1
- package/package.json +2 -2
- package/extension/libherb/position.c +0 -33
package/binding.gyp
CHANGED
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"./extension/libherb/memory.c",
|
|
32
32
|
"./extension/libherb/parser_helpers.c",
|
|
33
33
|
"./extension/libherb/parser.c",
|
|
34
|
-
"./extension/libherb/position.c",
|
|
35
34
|
"./extension/libherb/pretty_print.c",
|
|
36
35
|
"./extension/libherb/prism_helpers.c",
|
|
37
36
|
"./extension/libherb/range.c",
|
package/dist/herb-node.esm.js
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.7.
|
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.7.5/templates/javascript/packages/node/extension/error_helpers.cpp.erb
|
|
3
3
|
|
|
4
4
|
#include <node_api.h>
|
|
5
5
|
#include "error_helpers.h"
|
|
@@ -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.7.
|
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.7.5/templates/javascript/packages/node/extension/error_helpers.h.erb
|
|
3
3
|
|
|
4
4
|
#ifndef HERB_EXTENSION_ERRORS_H
|
|
5
5
|
#define HERB_EXTENSION_ERRORS_H
|
|
@@ -46,19 +46,13 @@ napi_value CreateString(napi_env env, const char* str) {
|
|
|
46
46
|
return result;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
napi_value CreatePosition(napi_env env, position_T
|
|
50
|
-
if (!position) {
|
|
51
|
-
napi_value null_value;
|
|
52
|
-
napi_get_null(env, &null_value);
|
|
53
|
-
return null_value;
|
|
54
|
-
}
|
|
55
|
-
|
|
49
|
+
napi_value CreatePosition(napi_env env, position_T position) {
|
|
56
50
|
napi_value result;
|
|
57
51
|
napi_create_object(env, &result);
|
|
58
52
|
|
|
59
53
|
napi_value line, column;
|
|
60
|
-
napi_create_uint32(env, (uint32_t)position
|
|
61
|
-
napi_create_uint32(env, (uint32_t)position
|
|
54
|
+
napi_create_uint32(env, (uint32_t)position.line, &line);
|
|
55
|
+
napi_create_uint32(env, (uint32_t)position.column, &column);
|
|
62
56
|
|
|
63
57
|
napi_set_named_property(env, result, "line", line);
|
|
64
58
|
napi_set_named_property(env, result, "column", column);
|
|
@@ -66,18 +60,12 @@ napi_value CreatePosition(napi_env env, position_T* position) {
|
|
|
66
60
|
return result;
|
|
67
61
|
}
|
|
68
62
|
|
|
69
|
-
napi_value CreateLocation(napi_env env, location_T
|
|
70
|
-
if (!location) {
|
|
71
|
-
napi_value null_value;
|
|
72
|
-
napi_get_null(env, &null_value);
|
|
73
|
-
return null_value;
|
|
74
|
-
}
|
|
75
|
-
|
|
63
|
+
napi_value CreateLocation(napi_env env, location_T location) {
|
|
76
64
|
napi_value result;
|
|
77
65
|
napi_create_object(env, &result);
|
|
78
66
|
|
|
79
|
-
napi_value start = CreatePosition(env, location
|
|
80
|
-
napi_value end = CreatePosition(env, location
|
|
67
|
+
napi_value start = CreatePosition(env, location.start);
|
|
68
|
+
napi_value end = CreatePosition(env, location.end);
|
|
81
69
|
|
|
82
70
|
napi_set_named_property(env, result, "start", start);
|
|
83
71
|
napi_set_named_property(env, result, "end", end);
|
|
@@ -85,19 +73,13 @@ napi_value CreateLocation(napi_env env, location_T* location) {
|
|
|
85
73
|
return result;
|
|
86
74
|
}
|
|
87
75
|
|
|
88
|
-
napi_value CreateRange(napi_env env, range_T
|
|
89
|
-
if (!range) {
|
|
90
|
-
napi_value null_value;
|
|
91
|
-
napi_get_null(env, &null_value);
|
|
92
|
-
return null_value;
|
|
93
|
-
}
|
|
94
|
-
|
|
76
|
+
napi_value CreateRange(napi_env env, range_T range) {
|
|
95
77
|
napi_value result;
|
|
96
78
|
napi_create_array(env, &result);
|
|
97
79
|
|
|
98
80
|
napi_value from, to;
|
|
99
|
-
napi_create_uint32(env, (uint32_t)range
|
|
100
|
-
napi_create_uint32(env, (uint32_t)range
|
|
81
|
+
napi_create_uint32(env, (uint32_t)range.from, &from);
|
|
82
|
+
napi_create_uint32(env, (uint32_t)range.to, &to);
|
|
101
83
|
|
|
102
84
|
napi_set_element(env, result, 0, from);
|
|
103
85
|
napi_set_element(env, result, 1, to);
|
|
@@ -14,9 +14,9 @@ napi_value ReadFileToString(napi_env env, const char* file_path);
|
|
|
14
14
|
napi_value CreateLexResult(napi_env env, array_T* tokens, napi_value source);
|
|
15
15
|
napi_value CreateParseResult(napi_env env, AST_DOCUMENT_NODE_T* root, napi_value source);
|
|
16
16
|
|
|
17
|
-
napi_value CreateLocation(napi_env env, location_T
|
|
17
|
+
napi_value CreateLocation(napi_env env, location_T location);
|
|
18
18
|
napi_value CreateToken(napi_env env, token_T* token);
|
|
19
|
-
napi_value CreatePosition(napi_env env, position_T
|
|
20
|
-
napi_value CreateRange(napi_env env, range_T
|
|
19
|
+
napi_value CreatePosition(napi_env env, position_T position);
|
|
20
|
+
napi_value CreateRange(napi_env env, range_T range);
|
|
21
21
|
|
|
22
22
|
#endif
|
|
@@ -96,12 +96,8 @@ static control_type_t detect_control_type(AST_ERB_CONTENT_NODE_T* erb_node) {
|
|
|
96
96
|
|
|
97
97
|
if (!ruby) { return CONTROL_TYPE_UNKNOWN; }
|
|
98
98
|
|
|
99
|
-
if (ruby->valid) {
|
|
100
|
-
if (has_yield_node(ruby)) { return CONTROL_TYPE_YIELD; }
|
|
101
|
-
return CONTROL_TYPE_UNKNOWN;
|
|
102
|
-
}
|
|
99
|
+
if (ruby->valid) { return CONTROL_TYPE_UNKNOWN; }
|
|
103
100
|
|
|
104
|
-
if (has_yield_node(ruby)) { return CONTROL_TYPE_YIELD; }
|
|
105
101
|
if (has_block_node(ruby)) { return CONTROL_TYPE_BLOCK; }
|
|
106
102
|
if (has_if_node(ruby)) { return CONTROL_TYPE_IF; }
|
|
107
103
|
if (has_elsif_node(ruby)) { return CONTROL_TYPE_ELSIF; }
|
|
@@ -119,6 +115,7 @@ static control_type_t detect_control_type(AST_ERB_CONTENT_NODE_T* erb_node) {
|
|
|
119
115
|
if (has_until_node(ruby)) { return CONTROL_TYPE_UNTIL; }
|
|
120
116
|
if (has_for_node(ruby)) { return CONTROL_TYPE_FOR; }
|
|
121
117
|
if (has_block_closing(ruby)) { return CONTROL_TYPE_BLOCK_CLOSE; }
|
|
118
|
+
if (has_yield_node(ruby)) { return CONTROL_TYPE_YIELD; }
|
|
122
119
|
|
|
123
120
|
return CONTROL_TYPE_UNKNOWN;
|
|
124
121
|
}
|
|
@@ -158,16 +155,16 @@ static AST_NODE_T* create_control_node(
|
|
|
158
155
|
control_type_t control_type
|
|
159
156
|
) {
|
|
160
157
|
array_T* errors = array_init(8);
|
|
161
|
-
position_T
|
|
162
|
-
position_T
|
|
158
|
+
position_T start_position = erb_node->tag_opening->location.start;
|
|
159
|
+
position_T end_position = erb_node->tag_closing->location.end;
|
|
163
160
|
|
|
164
161
|
if (end_node) {
|
|
165
|
-
end_position = end_node->base.location
|
|
162
|
+
end_position = end_node->base.location.end;
|
|
166
163
|
} else if (children && array_size(children) > 0) {
|
|
167
164
|
AST_NODE_T* last_child = array_get(children, array_size(children) - 1);
|
|
168
|
-
end_position = last_child->location
|
|
165
|
+
end_position = last_child->location.end;
|
|
169
166
|
} else if (subsequent) {
|
|
170
|
-
end_position = subsequent->location
|
|
167
|
+
end_position = subsequent->location.end;
|
|
171
168
|
}
|
|
172
169
|
|
|
173
170
|
token_T* tag_opening = erb_node->tag_opening;
|
|
@@ -435,32 +432,15 @@ static size_t process_control_structure(
|
|
|
435
432
|
array_T* when_statements = array_init(8);
|
|
436
433
|
index++;
|
|
437
434
|
|
|
438
|
-
|
|
439
|
-
AST_NODE_T* child = array_get(array, index);
|
|
440
|
-
|
|
441
|
-
if (!child) { break; }
|
|
442
|
-
|
|
443
|
-
if (child->type == AST_ERB_CONTENT_NODE) {
|
|
444
|
-
AST_ERB_CONTENT_NODE_T* child_erb = (AST_ERB_CONTENT_NODE_T*) child;
|
|
445
|
-
control_type_t child_type = detect_control_type(child_erb);
|
|
446
|
-
|
|
447
|
-
if (child_type == CONTROL_TYPE_WHEN || child_type == CONTROL_TYPE_IN || child_type == CONTROL_TYPE_ELSE
|
|
448
|
-
|| child_type == CONTROL_TYPE_END) {
|
|
449
|
-
break;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
array_append(when_statements, child);
|
|
454
|
-
index++;
|
|
455
|
-
}
|
|
435
|
+
index = process_block_children(node, array, index, when_statements, context, CONTROL_TYPE_WHEN);
|
|
456
436
|
|
|
457
437
|
AST_ERB_WHEN_NODE_T* when_node = ast_erb_when_node_init(
|
|
458
438
|
erb_content->tag_opening,
|
|
459
439
|
erb_content->content,
|
|
460
440
|
erb_content->tag_closing,
|
|
461
441
|
when_statements,
|
|
462
|
-
erb_content->tag_opening->location
|
|
463
|
-
erb_content->tag_closing->location
|
|
442
|
+
erb_content->tag_opening->location.start,
|
|
443
|
+
erb_content->tag_closing->location.end,
|
|
464
444
|
array_init(8)
|
|
465
445
|
);
|
|
466
446
|
|
|
@@ -471,32 +451,15 @@ static size_t process_control_structure(
|
|
|
471
451
|
array_T* in_statements = array_init(8);
|
|
472
452
|
index++;
|
|
473
453
|
|
|
474
|
-
|
|
475
|
-
AST_NODE_T* child = array_get(array, index);
|
|
476
|
-
|
|
477
|
-
if (!child) { break; }
|
|
478
|
-
|
|
479
|
-
if (child->type == AST_ERB_CONTENT_NODE) {
|
|
480
|
-
AST_ERB_CONTENT_NODE_T* child_erb = (AST_ERB_CONTENT_NODE_T*) child;
|
|
481
|
-
control_type_t child_type = detect_control_type(child_erb);
|
|
482
|
-
|
|
483
|
-
if (child_type == CONTROL_TYPE_IN || child_type == CONTROL_TYPE_WHEN || child_type == CONTROL_TYPE_ELSE
|
|
484
|
-
|| child_type == CONTROL_TYPE_END) {
|
|
485
|
-
break;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
array_append(in_statements, child);
|
|
490
|
-
index++;
|
|
491
|
-
}
|
|
454
|
+
index = process_block_children(node, array, index, in_statements, context, CONTROL_TYPE_IN);
|
|
492
455
|
|
|
493
456
|
AST_ERB_IN_NODE_T* in_node = ast_erb_in_node_init(
|
|
494
457
|
erb_content->tag_opening,
|
|
495
458
|
erb_content->content,
|
|
496
459
|
erb_content->tag_closing,
|
|
497
460
|
in_statements,
|
|
498
|
-
erb_content->tag_opening->location
|
|
499
|
-
erb_content->tag_closing->location
|
|
461
|
+
erb_content->tag_opening->location.start,
|
|
462
|
+
erb_content->tag_closing->location.end,
|
|
500
463
|
array_init(8)
|
|
501
464
|
);
|
|
502
465
|
|
|
@@ -546,8 +509,8 @@ static size_t process_control_structure(
|
|
|
546
509
|
next_erb->content,
|
|
547
510
|
next_erb->tag_closing,
|
|
548
511
|
else_children,
|
|
549
|
-
next_erb->tag_opening->location
|
|
550
|
-
next_erb->tag_closing->location
|
|
512
|
+
next_erb->tag_opening->location.start,
|
|
513
|
+
next_erb->tag_closing->location.end,
|
|
551
514
|
array_init(8)
|
|
552
515
|
);
|
|
553
516
|
}
|
|
@@ -567,8 +530,8 @@ static size_t process_control_structure(
|
|
|
567
530
|
end_erb->tag_opening,
|
|
568
531
|
end_erb->content,
|
|
569
532
|
end_erb->tag_closing,
|
|
570
|
-
end_erb->tag_opening->location
|
|
571
|
-
end_erb->tag_closing->location
|
|
533
|
+
end_erb->tag_opening->location.start,
|
|
534
|
+
end_erb->tag_closing->location.end,
|
|
572
535
|
end_erb->base.errors
|
|
573
536
|
);
|
|
574
537
|
|
|
@@ -577,19 +540,19 @@ static size_t process_control_structure(
|
|
|
577
540
|
}
|
|
578
541
|
}
|
|
579
542
|
|
|
580
|
-
position_T
|
|
581
|
-
position_T
|
|
543
|
+
position_T start_position = erb_node->tag_opening->location.start;
|
|
544
|
+
position_T end_position = erb_node->tag_closing->location.end;
|
|
582
545
|
|
|
583
546
|
if (end_node) {
|
|
584
|
-
end_position = end_node->base.location
|
|
547
|
+
end_position = end_node->base.location.end;
|
|
585
548
|
} else if (else_clause) {
|
|
586
|
-
end_position = else_clause->base.location
|
|
549
|
+
end_position = else_clause->base.location.end;
|
|
587
550
|
} else if (array_size(when_conditions) > 0) {
|
|
588
551
|
AST_NODE_T* last_when = array_get(when_conditions, array_size(when_conditions) - 1);
|
|
589
|
-
end_position = last_when->location
|
|
552
|
+
end_position = last_when->location.end;
|
|
590
553
|
} else if (array_size(in_conditions) > 0) {
|
|
591
554
|
AST_NODE_T* last_in = array_get(in_conditions, array_size(in_conditions) - 1);
|
|
592
|
-
end_position = last_in->location
|
|
555
|
+
end_position = last_in->location.end;
|
|
593
556
|
}
|
|
594
557
|
|
|
595
558
|
if (array_size(in_conditions) > 0) {
|
|
@@ -682,8 +645,8 @@ static size_t process_control_structure(
|
|
|
682
645
|
next_erb->content,
|
|
683
646
|
next_erb->tag_closing,
|
|
684
647
|
else_children,
|
|
685
|
-
next_erb->tag_opening->location
|
|
686
|
-
next_erb->tag_closing->location
|
|
648
|
+
next_erb->tag_opening->location.start,
|
|
649
|
+
next_erb->tag_closing->location.end,
|
|
687
650
|
array_init(8)
|
|
688
651
|
);
|
|
689
652
|
}
|
|
@@ -723,8 +686,8 @@ static size_t process_control_structure(
|
|
|
723
686
|
next_erb->content,
|
|
724
687
|
next_erb->tag_closing,
|
|
725
688
|
ensure_children,
|
|
726
|
-
next_erb->tag_opening->location
|
|
727
|
-
next_erb->tag_closing->location
|
|
689
|
+
next_erb->tag_opening->location.start,
|
|
690
|
+
next_erb->tag_closing->location.end,
|
|
728
691
|
array_init(8)
|
|
729
692
|
);
|
|
730
693
|
}
|
|
@@ -744,8 +707,8 @@ static size_t process_control_structure(
|
|
|
744
707
|
end_erb->tag_opening,
|
|
745
708
|
end_erb->content,
|
|
746
709
|
end_erb->tag_closing,
|
|
747
|
-
end_erb->tag_opening->location
|
|
748
|
-
end_erb->tag_closing->location
|
|
710
|
+
end_erb->tag_opening->location.start,
|
|
711
|
+
end_erb->tag_closing->location.end,
|
|
749
712
|
end_erb->base.errors
|
|
750
713
|
);
|
|
751
714
|
|
|
@@ -754,17 +717,17 @@ static size_t process_control_structure(
|
|
|
754
717
|
}
|
|
755
718
|
}
|
|
756
719
|
|
|
757
|
-
position_T
|
|
758
|
-
position_T
|
|
720
|
+
position_T start_position = erb_node->tag_opening->location.start;
|
|
721
|
+
position_T end_position = erb_node->tag_closing->location.end;
|
|
759
722
|
|
|
760
723
|
if (end_node) {
|
|
761
|
-
end_position = end_node->base.location
|
|
724
|
+
end_position = end_node->base.location.end;
|
|
762
725
|
} else if (ensure_clause) {
|
|
763
|
-
end_position = ensure_clause->base.location
|
|
726
|
+
end_position = ensure_clause->base.location.end;
|
|
764
727
|
} else if (else_clause) {
|
|
765
|
-
end_position = else_clause->base.location
|
|
728
|
+
end_position = else_clause->base.location.end;
|
|
766
729
|
} else if (rescue_clause) {
|
|
767
|
-
end_position = rescue_clause->base.location
|
|
730
|
+
end_position = rescue_clause->base.location.end;
|
|
768
731
|
}
|
|
769
732
|
|
|
770
733
|
AST_ERB_BEGIN_NODE_T* begin_node = ast_erb_begin_node_init(
|
|
@@ -802,8 +765,8 @@ static size_t process_control_structure(
|
|
|
802
765
|
close_erb->tag_opening,
|
|
803
766
|
close_erb->content,
|
|
804
767
|
close_erb->tag_closing,
|
|
805
|
-
close_erb->tag_opening->location
|
|
806
|
-
close_erb->tag_closing->location
|
|
768
|
+
close_erb->tag_opening->location.start,
|
|
769
|
+
close_erb->tag_closing->location.end,
|
|
807
770
|
close_erb->base.errors
|
|
808
771
|
);
|
|
809
772
|
|
|
@@ -812,14 +775,14 @@ static size_t process_control_structure(
|
|
|
812
775
|
}
|
|
813
776
|
}
|
|
814
777
|
|
|
815
|
-
position_T
|
|
816
|
-
position_T
|
|
778
|
+
position_T start_position = erb_node->tag_opening->location.start;
|
|
779
|
+
position_T end_position = erb_node->tag_closing->location.end;
|
|
817
780
|
|
|
818
781
|
if (end_node) {
|
|
819
|
-
end_position = end_node->base.location
|
|
782
|
+
end_position = end_node->base.location.end;
|
|
820
783
|
} else if (children && array_size(children) > 0) {
|
|
821
784
|
AST_NODE_T* last_child = array_get(children, array_size(children) - 1);
|
|
822
|
-
end_position = last_child->location
|
|
785
|
+
end_position = last_child->location.end;
|
|
823
786
|
}
|
|
824
787
|
|
|
825
788
|
AST_ERB_BLOCK_NODE_T* block_node = ast_erb_block_node_init(
|
|
@@ -866,8 +829,8 @@ static size_t process_control_structure(
|
|
|
866
829
|
end_erb->tag_opening,
|
|
867
830
|
end_erb->content,
|
|
868
831
|
end_erb->tag_closing,
|
|
869
|
-
end_erb->tag_opening->location
|
|
870
|
-
end_erb->tag_closing->location
|
|
832
|
+
end_erb->tag_opening->location.start,
|
|
833
|
+
end_erb->tag_closing->location.end,
|
|
871
834
|
end_erb->base.errors
|
|
872
835
|
);
|
|
873
836
|
|
|
@@ -12,11 +12,12 @@ size_t ast_node_sizeof(void) {
|
|
|
12
12
|
return sizeof(struct AST_NODE_STRUCT);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T
|
|
15
|
+
void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T start, position_T end, array_T* errors) {
|
|
16
16
|
if (!node) { return; }
|
|
17
17
|
|
|
18
18
|
node->type = type;
|
|
19
|
-
node->location =
|
|
19
|
+
node->location.start = start;
|
|
20
|
+
node->location.end = end;
|
|
20
21
|
|
|
21
22
|
if (errors == NULL) {
|
|
22
23
|
node->errors = array_init(8);
|
|
@@ -28,7 +29,7 @@ void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T* sta
|
|
|
28
29
|
AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token) {
|
|
29
30
|
AST_LITERAL_NODE_T* literal = malloc(sizeof(AST_LITERAL_NODE_T));
|
|
30
31
|
|
|
31
|
-
ast_node_init(&literal->base, AST_LITERAL_NODE, token->location
|
|
32
|
+
ast_node_init(&literal->base, AST_LITERAL_NODE, token->location.start, token->location.end, NULL);
|
|
32
33
|
|
|
33
34
|
literal->content = herb_strdup(token->value);
|
|
34
35
|
|
|
@@ -51,24 +52,20 @@ void ast_node_append_error(const AST_NODE_T* node, ERROR_T* error) {
|
|
|
51
52
|
array_append(node->errors, error);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
void ast_node_set_start(AST_NODE_T* node, position_T
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
node->location->start = position_copy(position);
|
|
55
|
+
void ast_node_set_start(AST_NODE_T* node, position_T position) {
|
|
56
|
+
node->location.start = position;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
void ast_node_set_end(AST_NODE_T* node, position_T
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
node->location->end = position_copy(position);
|
|
59
|
+
void ast_node_set_end(AST_NODE_T* node, position_T position) {
|
|
60
|
+
node->location.end = position;
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
void ast_node_set_start_from_token(AST_NODE_T* node, const token_T* token) {
|
|
67
|
-
ast_node_set_start(node, token->location
|
|
64
|
+
ast_node_set_start(node, token->location.start);
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
void ast_node_set_end_from_token(AST_NODE_T* node, const token_T* token) {
|
|
71
|
-
ast_node_set_end(node, token->location
|
|
68
|
+
ast_node_set_end(node, token->location.end);
|
|
72
69
|
}
|
|
73
70
|
|
|
74
71
|
void ast_node_set_positions_from_token(AST_NODE_T* node, const token_T* token) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#include "position.h"
|
|
7
7
|
#include "token_struct.h"
|
|
8
8
|
|
|
9
|
-
void ast_node_init(AST_NODE_T* node, ast_node_type_T type, position_T
|
|
9
|
+
void ast_node_init(AST_NODE_T* node, ast_node_type_T type, position_T start, position_T end, array_T* errors);
|
|
10
10
|
void ast_node_free(AST_NODE_T* node);
|
|
11
11
|
|
|
12
12
|
AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token);
|
|
@@ -18,8 +18,8 @@ ast_node_type_T ast_node_type(const AST_NODE_T* node);
|
|
|
18
18
|
|
|
19
19
|
char* ast_node_name(AST_NODE_T* node);
|
|
20
20
|
|
|
21
|
-
void ast_node_set_start(AST_NODE_T* node, position_T
|
|
22
|
-
void ast_node_set_end(AST_NODE_T* node, position_T
|
|
21
|
+
void ast_node_set_start(AST_NODE_T* node, position_T position);
|
|
22
|
+
void ast_node_set_end(AST_NODE_T* node, position_T position);
|
|
23
23
|
|
|
24
24
|
size_t ast_node_errors_count(const AST_NODE_T* node);
|
|
25
25
|
array_T* ast_node_errors(const AST_NODE_T* node);
|