prism 0.24.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BSDmakefile +58 -0
- data/CHANGELOG.md +50 -1
- data/Makefile +5 -2
- data/README.md +45 -6
- data/config.yml +499 -4
- data/docs/build_system.md +31 -0
- data/docs/configuration.md +2 -0
- data/docs/cruby_compilation.md +1 -1
- data/docs/parser_translation.md +14 -9
- data/docs/releasing.md +2 -2
- data/docs/ripper_translation.md +50 -0
- data/docs/ruby_api.md +1 -0
- data/docs/serialization.md +26 -5
- data/ext/prism/api_node.c +911 -815
- data/ext/prism/api_pack.c +9 -0
- data/ext/prism/extconf.rb +27 -11
- data/ext/prism/extension.c +313 -66
- data/ext/prism/extension.h +5 -4
- data/include/prism/ast.h +213 -64
- data/include/prism/defines.h +106 -2
- data/include/prism/diagnostic.h +134 -71
- data/include/prism/encoding.h +22 -4
- data/include/prism/node.h +93 -0
- data/include/prism/options.h +82 -7
- data/include/prism/pack.h +11 -0
- data/include/prism/parser.h +198 -53
- data/include/prism/prettyprint.h +8 -0
- data/include/prism/static_literals.h +118 -0
- data/include/prism/util/pm_buffer.h +65 -2
- data/include/prism/util/pm_constant_pool.h +18 -1
- data/include/prism/util/pm_integer.h +119 -0
- data/include/prism/util/pm_list.h +1 -1
- data/include/prism/util/pm_newline_list.h +8 -0
- data/include/prism/util/pm_string.h +26 -2
- data/include/prism/version.h +2 -2
- data/include/prism.h +59 -1
- data/lib/prism/compiler.rb +8 -1
- data/lib/prism/debug.rb +46 -3
- data/lib/prism/desugar_compiler.rb +1 -1
- data/lib/prism/dispatcher.rb +29 -0
- data/lib/prism/dot_visitor.rb +87 -16
- data/lib/prism/dsl.rb +24 -12
- data/lib/prism/ffi.rb +67 -12
- data/lib/prism/lex_compat.rb +17 -15
- data/lib/prism/mutation_compiler.rb +11 -0
- data/lib/prism/node.rb +2096 -2499
- data/lib/prism/node_ext.rb +77 -29
- data/lib/prism/pack.rb +4 -0
- data/lib/prism/parse_result/comments.rb +34 -17
- data/lib/prism/parse_result/newlines.rb +3 -1
- data/lib/prism/parse_result.rb +78 -32
- data/lib/prism/pattern.rb +16 -4
- data/lib/prism/polyfill/string.rb +12 -0
- data/lib/prism/serialize.rb +439 -102
- data/lib/prism/translation/parser/compiler.rb +152 -50
- data/lib/prism/translation/parser/lexer.rb +103 -22
- data/lib/prism/translation/parser/rubocop.rb +41 -13
- data/lib/prism/translation/parser.rb +119 -7
- data/lib/prism/translation/parser33.rb +1 -1
- data/lib/prism/translation/parser34.rb +1 -1
- data/lib/prism/translation/ripper/sexp.rb +125 -0
- data/lib/prism/translation/ripper/shim.rb +5 -0
- data/lib/prism/translation/ripper.rb +3212 -462
- data/lib/prism/translation/ruby_parser.rb +35 -18
- data/lib/prism/translation.rb +3 -1
- data/lib/prism/visitor.rb +10 -0
- data/lib/prism.rb +8 -2
- data/prism.gemspec +33 -4
- data/rbi/prism/compiler.rbi +14 -0
- data/rbi/prism/desugar_compiler.rbi +5 -0
- data/rbi/prism/mutation_compiler.rbi +5 -0
- data/rbi/prism/node.rbi +8221 -0
- data/rbi/prism/node_ext.rbi +102 -0
- data/rbi/prism/parse_result.rbi +304 -0
- data/rbi/prism/translation/parser/compiler.rbi +13 -0
- data/rbi/prism/translation/ripper/ripper_compiler.rbi +5 -0
- data/rbi/prism/translation/ripper.rbi +25 -0
- data/rbi/prism/translation/ruby_parser.rbi +11 -0
- data/rbi/prism/visitor.rbi +470 -0
- data/rbi/prism.rbi +39 -7749
- data/sig/prism/compiler.rbs +9 -0
- data/sig/prism/dispatcher.rbs +16 -0
- data/sig/prism/dot_visitor.rbs +6 -0
- data/sig/prism/dsl.rbs +462 -0
- data/sig/prism/mutation_compiler.rbs +158 -0
- data/sig/prism/node.rbs +3529 -0
- data/sig/prism/node_ext.rbs +78 -0
- data/sig/prism/pack.rbs +43 -0
- data/sig/prism/parse_result.rbs +127 -0
- data/sig/prism/pattern.rbs +13 -0
- data/sig/prism/serialize.rbs +7 -0
- data/sig/prism/visitor.rbs +168 -0
- data/sig/prism.rbs +188 -4767
- data/src/diagnostic.c +575 -230
- data/src/encoding.c +211 -108
- data/src/node.c +7526 -447
- data/src/options.c +36 -12
- data/src/pack.c +33 -17
- data/src/prettyprint.c +1294 -1385
- data/src/prism.c +3628 -1099
- data/src/regexp.c +17 -2
- data/src/serialize.c +47 -28
- data/src/static_literals.c +552 -0
- data/src/token_type.c +1 -0
- data/src/util/pm_buffer.c +147 -20
- data/src/util/pm_char.c +4 -4
- data/src/util/pm_constant_pool.c +35 -11
- data/src/util/pm_integer.c +629 -0
- data/src/util/pm_list.c +1 -1
- data/src/util/pm_newline_list.c +14 -5
- data/src/util/pm_string.c +134 -5
- data/src/util/pm_string_list.c +2 -2
- metadata +35 -6
- data/docs/ripper.md +0 -36
- data/rbi/prism_static.rbi +0 -207
- data/sig/prism_static.rbs +0 -201
data/src/regexp.c
CHANGED
@@ -565,21 +565,36 @@ pm_regexp_parse_group(pm_regexp_parser_t *parser) {
|
|
565
565
|
*/
|
566
566
|
static bool
|
567
567
|
pm_regexp_parse_item(pm_regexp_parser_t *parser) {
|
568
|
-
switch (*parser->cursor
|
568
|
+
switch (*parser->cursor) {
|
569
569
|
case '^':
|
570
570
|
case '$':
|
571
|
+
parser->cursor++;
|
571
572
|
return true;
|
572
573
|
case '\\':
|
574
|
+
parser->cursor++;
|
573
575
|
if (!pm_regexp_char_is_eof(parser)) {
|
574
576
|
parser->cursor++;
|
575
577
|
}
|
576
578
|
return pm_regexp_parse_quantifier(parser);
|
577
579
|
case '(':
|
580
|
+
parser->cursor++;
|
578
581
|
return pm_regexp_parse_group(parser) && pm_regexp_parse_quantifier(parser);
|
579
582
|
case '[':
|
583
|
+
parser->cursor++;
|
580
584
|
return pm_regexp_parse_lbracket(parser) && pm_regexp_parse_quantifier(parser);
|
581
|
-
default:
|
585
|
+
default: {
|
586
|
+
size_t width;
|
587
|
+
if (!parser->encoding_changed) {
|
588
|
+
width = pm_encoding_utf_8_char_width(parser->cursor, (ptrdiff_t) (parser->end - parser->cursor));
|
589
|
+
} else {
|
590
|
+
width = parser->encoding->char_width(parser->cursor, (ptrdiff_t) (parser->end - parser->cursor));
|
591
|
+
}
|
592
|
+
|
593
|
+
if (width == 0) return false; // TODO: add appropriate error
|
594
|
+
parser->cursor += width;
|
595
|
+
|
582
596
|
return pm_regexp_parse_quantifier(parser);
|
597
|
+
}
|
583
598
|
}
|
584
599
|
}
|
585
600
|
|
data/src/serialize.c
CHANGED
@@ -5,8 +5,14 @@
|
|
5
5
|
/* if you are looking to modify the */
|
6
6
|
/* template */
|
7
7
|
/******************************************************************************/
|
8
|
+
|
8
9
|
#include "prism.h"
|
9
10
|
|
11
|
+
// We optionally support serializing to a binary string. For systems that don't
|
12
|
+
// want or need this functionality, it can be turned off with the
|
13
|
+
// PRISM_EXCLUDE_SERIALIZATION define.
|
14
|
+
#ifndef PRISM_EXCLUDE_SERIALIZATION
|
15
|
+
|
10
16
|
#include <stdio.h>
|
11
17
|
|
12
18
|
static inline uint32_t
|
@@ -32,7 +38,7 @@ pm_serialize_location(const pm_parser_t *parser, const pm_location_t *location,
|
|
32
38
|
}
|
33
39
|
|
34
40
|
static void
|
35
|
-
pm_serialize_string(pm_parser_t *parser, pm_string_t *string, pm_buffer_t *buffer) {
|
41
|
+
pm_serialize_string(const pm_parser_t *parser, const pm_string_t *string, pm_buffer_t *buffer) {
|
36
42
|
switch (string->type) {
|
37
43
|
case PM_STRING_SHARED: {
|
38
44
|
pm_buffer_append_byte(buffer, 1);
|
@@ -48,9 +54,25 @@ pm_serialize_string(pm_parser_t *parser, pm_string_t *string, pm_buffer_t *buffe
|
|
48
54
|
pm_buffer_append_bytes(buffer, pm_string_source(string), length);
|
49
55
|
break;
|
50
56
|
}
|
57
|
+
#ifdef PRISM_HAS_MMAP
|
51
58
|
case PM_STRING_MAPPED:
|
52
59
|
assert(false && "Cannot serialize mapped strings.");
|
53
60
|
break;
|
61
|
+
#endif
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
static void
|
66
|
+
pm_serialize_integer(const pm_integer_t *integer, pm_buffer_t *buffer) {
|
67
|
+
pm_buffer_append_byte(buffer, integer->negative ? 1 : 0);
|
68
|
+
if (integer->values == NULL) {
|
69
|
+
pm_buffer_append_varuint(buffer, pm_sizet_to_u32(1));
|
70
|
+
pm_buffer_append_varuint(buffer, integer->value);
|
71
|
+
} else {
|
72
|
+
pm_buffer_append_varuint(buffer, pm_sizet_to_u32(integer->length));
|
73
|
+
for (size_t i = 0; i < integer->length; i++) {
|
74
|
+
pm_buffer_append_varuint(buffer, integer->values[i]);
|
75
|
+
}
|
54
76
|
}
|
55
77
|
}
|
56
78
|
|
@@ -531,12 +553,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
|
|
531
553
|
pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_write_node_t *)node)->name));
|
532
554
|
pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->name_loc, buffer);
|
533
555
|
pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_write_node_t *)node)->value, buffer);
|
534
|
-
|
535
|
-
pm_buffer_append_byte(buffer, 0);
|
536
|
-
} else {
|
537
|
-
pm_buffer_append_byte(buffer, 1);
|
538
|
-
pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->operator_loc, buffer);
|
539
|
-
}
|
556
|
+
pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->operator_loc, buffer);
|
540
557
|
break;
|
541
558
|
}
|
542
559
|
case PM_CONSTANT_AND_WRITE_NODE: {
|
@@ -787,6 +804,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
|
|
787
804
|
break;
|
788
805
|
}
|
789
806
|
case PM_FLOAT_NODE: {
|
807
|
+
pm_buffer_append_double(buffer, ((pm_float_node_t *)node)->value);
|
790
808
|
break;
|
791
809
|
}
|
792
810
|
case PM_FOR_NODE: {
|
@@ -1102,6 +1120,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
|
|
1102
1120
|
}
|
1103
1121
|
case PM_INTEGER_NODE: {
|
1104
1122
|
pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
|
1123
|
+
pm_serialize_integer(&((pm_integer_node_t *)node)->value, buffer);
|
1105
1124
|
break;
|
1106
1125
|
}
|
1107
1126
|
case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
|
@@ -1127,6 +1146,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
|
|
1127
1146
|
break;
|
1128
1147
|
}
|
1129
1148
|
case PM_INTERPOLATED_STRING_NODE: {
|
1149
|
+
pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
|
1130
1150
|
if (((pm_interpolated_string_node_t *)node)->opening_loc.start == NULL) {
|
1131
1151
|
pm_buffer_append_byte(buffer, 0);
|
1132
1152
|
} else {
|
@@ -1176,6 +1196,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
|
|
1176
1196
|
pm_serialize_location(parser, &((pm_interpolated_x_string_node_t *)node)->closing_loc, buffer);
|
1177
1197
|
break;
|
1178
1198
|
}
|
1199
|
+
case PM_IT_PARAMETERS_NODE: {
|
1200
|
+
break;
|
1201
|
+
}
|
1179
1202
|
case PM_KEYWORD_HASH_NODE: {
|
1180
1203
|
pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
|
1181
1204
|
uint32_t elements_size = pm_sizet_to_u32(((pm_keyword_hash_node_t *)node)->elements.size);
|
@@ -1613,6 +1636,11 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
|
|
1613
1636
|
case PM_SELF_NODE: {
|
1614
1637
|
break;
|
1615
1638
|
}
|
1639
|
+
case PM_SHAREABLE_CONSTANT_NODE: {
|
1640
|
+
pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
|
1641
|
+
pm_serialize_node(parser, (pm_node_t *)((pm_shareable_constant_node_t *)node)->write, buffer);
|
1642
|
+
break;
|
1643
|
+
}
|
1616
1644
|
case PM_SINGLETON_CLASS_NODE: {
|
1617
1645
|
uint32_t locals_size = pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.size);
|
1618
1646
|
pm_buffer_append_varuint(buffer, locals_size);
|
@@ -1634,6 +1662,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
|
|
1634
1662
|
break;
|
1635
1663
|
}
|
1636
1664
|
case PM_SOURCE_FILE_NODE: {
|
1665
|
+
pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
|
1637
1666
|
pm_serialize_string(parser, &((pm_source_file_node_t *)node)->filepath, buffer);
|
1638
1667
|
break;
|
1639
1668
|
}
|
@@ -1787,6 +1816,12 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
|
|
1787
1816
|
for (uint32_t index = 0; index < conditions_size; index++) {
|
1788
1817
|
pm_serialize_node(parser, (pm_node_t *) ((pm_when_node_t *)node)->conditions.nodes[index], buffer);
|
1789
1818
|
}
|
1819
|
+
if (((pm_when_node_t *)node)->then_keyword_loc.start == NULL) {
|
1820
|
+
pm_buffer_append_byte(buffer, 0);
|
1821
|
+
} else {
|
1822
|
+
pm_buffer_append_byte(buffer, 1);
|
1823
|
+
pm_serialize_location(parser, &((pm_when_node_t *)node)->then_keyword_loc, buffer);
|
1824
|
+
}
|
1790
1825
|
if (((pm_when_node_t *)node)->statements == NULL) {
|
1791
1826
|
pm_buffer_append_byte(buffer, 0);
|
1792
1827
|
} else {
|
@@ -1909,6 +1944,9 @@ pm_serialize_data_loc(const pm_parser_t *parser, pm_buffer_t *buffer) {
|
|
1909
1944
|
|
1910
1945
|
static void
|
1911
1946
|
pm_serialize_diagnostic(pm_parser_t *parser, pm_diagnostic_t *diagnostic, pm_buffer_t *buffer) {
|
1947
|
+
// serialize the type
|
1948
|
+
pm_buffer_append_varuint(buffer, (uint32_t) diagnostic->diag_id);
|
1949
|
+
|
1912
1950
|
// serialize message
|
1913
1951
|
size_t message_length = strlen(diagnostic->message);
|
1914
1952
|
pm_buffer_append_varuint(buffer, pm_sizet_to_u32(message_length));
|
@@ -1952,7 +1990,7 @@ pm_serialize_metadata(pm_parser_t *parser, pm_buffer_t *buffer) {
|
|
1952
1990
|
pm_serialize_diagnostic_list(parser, &parser->warning_list, buffer);
|
1953
1991
|
}
|
1954
1992
|
|
1955
|
-
#line
|
1993
|
+
#line 271 "serialize.c.erb"
|
1956
1994
|
/**
|
1957
1995
|
* Serialize the metadata, nodes, and constant pool.
|
1958
1996
|
*/
|
@@ -2084,23 +2122,4 @@ pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size,
|
|
2084
2122
|
pm_options_free(&options);
|
2085
2123
|
}
|
2086
2124
|
|
2087
|
-
|
2088
|
-
* Parse the source and return true if it parses without errors or warnings.
|
2089
|
-
*/
|
2090
|
-
PRISM_EXPORTED_FUNCTION bool
|
2091
|
-
pm_parse_success_p(const uint8_t *source, size_t size, const char *data) {
|
2092
|
-
pm_options_t options = { 0 };
|
2093
|
-
pm_options_read(&options, data);
|
2094
|
-
|
2095
|
-
pm_parser_t parser;
|
2096
|
-
pm_parser_init(&parser, source, size, &options);
|
2097
|
-
|
2098
|
-
pm_node_t *node = pm_parse(&parser);
|
2099
|
-
pm_node_destroy(&parser, node);
|
2100
|
-
|
2101
|
-
bool result = parser.error_list.size == 0 && parser.warning_list.size == 0;
|
2102
|
-
pm_parser_free(&parser);
|
2103
|
-
pm_options_free(&options);
|
2104
|
-
|
2105
|
-
return result;
|
2106
|
-
}
|
2125
|
+
#endif
|