prism 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/Makefile +6 -0
- data/README.md +2 -0
- data/config.yml +21 -20
- data/docs/configuration.md +2 -0
- data/docs/javascript.md +90 -0
- data/docs/releasing.md +27 -0
- data/docs/ruby_api.md +2 -0
- data/ext/prism/api_node.c +66 -68
- data/ext/prism/extension.c +73 -0
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +40 -40
- data/include/prism/defines.h +9 -0
- data/include/prism/enc/pm_encoding.h +1 -0
- data/include/prism/node.h +0 -17
- data/include/prism/parser.h +1 -0
- data/include/prism/prettyprint.h +15 -0
- data/include/prism/util/pm_buffer.h +10 -4
- data/include/prism/util/pm_constant_pool.h +1 -1
- data/include/prism/util/pm_newline_list.h +1 -1
- data/include/prism/version.h +3 -3
- data/include/prism.h +11 -11
- data/lib/prism/compiler.rb +0 -3
- data/lib/prism/debug.rb +20 -6
- data/lib/prism/desugar_compiler.rb +1 -1
- data/lib/prism/dispatcher.rb +0 -14
- data/lib/prism/dsl.rb +8 -13
- data/lib/prism/ffi.rb +25 -0
- data/lib/prism/lex_compat.rb +1 -1
- data/lib/prism/mutation_compiler.rb +3 -8
- data/lib/prism/node.rb +123 -159
- data/lib/prism/node_ext.rb +23 -16
- data/lib/prism/parse_result.rb +21 -5
- data/lib/prism/pattern.rb +3 -3
- data/lib/prism/serialize.rb +901 -305
- data/lib/prism/visitor.rb +0 -3
- data/prism.gemspec +8 -1
- data/rbi/prism.rbi +7261 -0
- data/rbi/prism_static.rbi +182 -0
- data/sig/prism.rbs +4439 -0
- data/sig/prism_static.rbs +110 -0
- data/src/enc/pm_unicode.c +1 -1
- data/src/node.c +28 -29
- data/src/prettyprint.c +7674 -1647
- data/src/prism.c +353 -300
- data/src/regexp.c +2 -0
- data/src/serialize.c +392 -381
- data/src/util/pm_buffer.c +47 -12
- data/src/util/pm_constant_pool.c +1 -1
- data/src/util/pm_newline_list.c +8 -54
- metadata +9 -2
@@ -0,0 +1,110 @@
|
|
1
|
+
module Prism
|
2
|
+
class ParseResult
|
3
|
+
def value: () -> ProgramNode
|
4
|
+
def comments: () -> Array[Comment]
|
5
|
+
def errors: () -> Array[ParseError]
|
6
|
+
def warnings: () -> Array[ParseWarning]
|
7
|
+
def source: () -> Source
|
8
|
+
end
|
9
|
+
|
10
|
+
class ParseError
|
11
|
+
def message: () -> String
|
12
|
+
def location: () -> Location
|
13
|
+
end
|
14
|
+
|
15
|
+
class ParseWarning
|
16
|
+
def message: () -> String
|
17
|
+
def location: () -> Location
|
18
|
+
end
|
19
|
+
|
20
|
+
class Node
|
21
|
+
def child_nodes: () -> Array[Node?]
|
22
|
+
def location: () -> Location
|
23
|
+
def slice: () -> String
|
24
|
+
end
|
25
|
+
|
26
|
+
class Comment
|
27
|
+
def location: () -> Location
|
28
|
+
end
|
29
|
+
|
30
|
+
class Location
|
31
|
+
def initialize: (source: Source, start_offset: Integer, length: Integer) -> void
|
32
|
+
def slice: () -> String
|
33
|
+
def comments: () -> Array[Comment]
|
34
|
+
def copy: (**untyped) -> Location
|
35
|
+
def start_offset: () -> Integer
|
36
|
+
def end_offset: () -> Integer
|
37
|
+
def start_line: () -> Integer
|
38
|
+
def end_line: () -> Integer
|
39
|
+
def start_column: () -> Integer
|
40
|
+
def end_column: () -> Integer
|
41
|
+
end
|
42
|
+
|
43
|
+
class Source
|
44
|
+
attr_reader source: String
|
45
|
+
attr_reader offsets: Array[Integer]
|
46
|
+
|
47
|
+
@source: String
|
48
|
+
@offsets: Array[Integer]
|
49
|
+
|
50
|
+
def initialize: (source: String, offsets: Array[Integer]) -> void
|
51
|
+
def slice: (offset: Integer, length: Integer) -> String
|
52
|
+
def line: (value: Integer) -> Integer
|
53
|
+
def line_offset: (value: Integer) -> Integer
|
54
|
+
def column: (value: Integer) -> Integer
|
55
|
+
end
|
56
|
+
|
57
|
+
class Token
|
58
|
+
attr_reader type: untyped
|
59
|
+
attr_reader value: String
|
60
|
+
attr_reader location: Location
|
61
|
+
|
62
|
+
@type: untyped
|
63
|
+
@value: String
|
64
|
+
@location: Location
|
65
|
+
|
66
|
+
def initialize: (type: untyped, value: String, location: Location) -> void
|
67
|
+
def deconstruct_keys: (keys: untyped) -> untyped
|
68
|
+
def pretty_print: (q: untyped) -> untyped
|
69
|
+
def ==: (other: untyped) -> bool
|
70
|
+
end
|
71
|
+
|
72
|
+
class NodeInspector
|
73
|
+
attr_reader prefix: String
|
74
|
+
attr_reader output: String
|
75
|
+
|
76
|
+
@prefix: String
|
77
|
+
@output: String
|
78
|
+
|
79
|
+
def initialize: (prefix: String) -> void
|
80
|
+
|
81
|
+
# Appends a line to the output with the current prefix.
|
82
|
+
def <<: (line: String) -> void
|
83
|
+
|
84
|
+
# This generates a string that is used as the header of the inspect output
|
85
|
+
# for any given node.
|
86
|
+
def header: (node: Node) -> String
|
87
|
+
|
88
|
+
# Generates a string that represents a list of nodes. It handles properly
|
89
|
+
# using the box drawing characters to make the output look nice.
|
90
|
+
def list: (prefix: String, nodes: Array[Node]) -> String
|
91
|
+
|
92
|
+
# Generates a string that represents a location field on a node.
|
93
|
+
def location: (value: Location) -> String
|
94
|
+
|
95
|
+
# Generates a string that represents a child node.
|
96
|
+
def child_node: (node: Node, append: String) -> String
|
97
|
+
|
98
|
+
# Returns a new inspector that can be used to inspect a child node.
|
99
|
+
def child_inspector: (append: String) -> NodeInspector
|
100
|
+
|
101
|
+
# Returns the output as a string.
|
102
|
+
def to_str: () -> String
|
103
|
+
end
|
104
|
+
|
105
|
+
class BasicVisitor
|
106
|
+
def visit: (node: Node?) -> void
|
107
|
+
def visit_all: (nodes: Array[Node?]) -> void
|
108
|
+
def visit_child_nodes: (node: Node) -> void
|
109
|
+
end
|
110
|
+
end
|
data/src/enc/pm_unicode.c
CHANGED
@@ -2285,7 +2285,7 @@ pm_encoding_utf_8_alnum_char(const uint8_t *b, ptrdiff_t n) {
|
|
2285
2285
|
}
|
2286
2286
|
}
|
2287
2287
|
|
2288
|
-
|
2288
|
+
bool
|
2289
2289
|
pm_encoding_utf_8_isupper_char(const uint8_t *b, ptrdiff_t n) {
|
2290
2290
|
if (*b < 0x80) {
|
2291
2291
|
return (pm_encoding_unicode_table[*b] & PRISM_ENCODING_UPPERCASE_BIT) ? true : false;
|
data/src/node.c
CHANGED
@@ -529,9 +529,9 @@ pm_node_destroy(pm_parser_t *parser, pm_node_t *node) {
|
|
529
529
|
if (cast->constant != NULL) {
|
530
530
|
pm_node_destroy(parser, (pm_node_t *)cast->constant);
|
531
531
|
}
|
532
|
-
pm_node_list_free(parser, &cast->
|
533
|
-
if (cast->
|
534
|
-
pm_node_destroy(parser, (pm_node_t *)cast->
|
532
|
+
pm_node_list_free(parser, &cast->elements);
|
533
|
+
if (cast->rest != NULL) {
|
534
|
+
pm_node_destroy(parser, (pm_node_t *)cast->rest);
|
535
535
|
}
|
536
536
|
break;
|
537
537
|
}
|
@@ -785,13 +785,21 @@ pm_node_destroy(pm_parser_t *parser, pm_node_t *node) {
|
|
785
785
|
#line 57 "node.c.erb"
|
786
786
|
case PM_MULTI_TARGET_NODE: {
|
787
787
|
pm_multi_target_node_t *cast = (pm_multi_target_node_t *) node;
|
788
|
-
pm_node_list_free(parser, &cast->
|
788
|
+
pm_node_list_free(parser, &cast->lefts);
|
789
|
+
if (cast->rest != NULL) {
|
790
|
+
pm_node_destroy(parser, (pm_node_t *)cast->rest);
|
791
|
+
}
|
792
|
+
pm_node_list_free(parser, &cast->rights);
|
789
793
|
break;
|
790
794
|
}
|
791
795
|
#line 57 "node.c.erb"
|
792
796
|
case PM_MULTI_WRITE_NODE: {
|
793
797
|
pm_multi_write_node_t *cast = (pm_multi_write_node_t *) node;
|
794
|
-
pm_node_list_free(parser, &cast->
|
798
|
+
pm_node_list_free(parser, &cast->lefts);
|
799
|
+
if (cast->rest != NULL) {
|
800
|
+
pm_node_destroy(parser, (pm_node_t *)cast->rest);
|
801
|
+
}
|
802
|
+
pm_node_list_free(parser, &cast->rights);
|
795
803
|
pm_node_destroy(parser, (pm_node_t *)cast->value);
|
796
804
|
break;
|
797
805
|
}
|
@@ -916,12 +924,6 @@ pm_node_destroy(pm_parser_t *parser, pm_node_t *node) {
|
|
916
924
|
pm_string_free(&cast->unescaped);
|
917
925
|
break;
|
918
926
|
}
|
919
|
-
#line 57 "node.c.erb"
|
920
|
-
case PM_REQUIRED_DESTRUCTURED_PARAMETER_NODE: {
|
921
|
-
pm_required_destructured_parameter_node_t *cast = (pm_required_destructured_parameter_node_t *) node;
|
922
|
-
pm_node_list_free(parser, &cast->parameters);
|
923
|
-
break;
|
924
|
-
}
|
925
927
|
#line 57 "node.c.erb"
|
926
928
|
case PM_REQUIRED_PARAMETER_NODE: {
|
927
929
|
break;
|
@@ -1685,9 +1687,9 @@ pm_node_memsize_node(pm_node_t *node, pm_memsize_t *memsize) {
|
|
1685
1687
|
if (cast->constant != NULL) {
|
1686
1688
|
pm_node_memsize_node((pm_node_t *)cast->constant, memsize);
|
1687
1689
|
}
|
1688
|
-
memsize->memsize += pm_node_list_memsize(&cast->
|
1689
|
-
if (cast->
|
1690
|
-
pm_node_memsize_node((pm_node_t *)cast->
|
1690
|
+
memsize->memsize += pm_node_list_memsize(&cast->elements, memsize);
|
1691
|
+
if (cast->rest != NULL) {
|
1692
|
+
pm_node_memsize_node((pm_node_t *)cast->rest, memsize);
|
1691
1693
|
}
|
1692
1694
|
break;
|
1693
1695
|
}
|
@@ -2003,8 +2005,12 @@ pm_node_memsize_node(pm_node_t *node, pm_memsize_t *memsize) {
|
|
2003
2005
|
pm_multi_target_node_t *cast = (pm_multi_target_node_t *) node;
|
2004
2006
|
memsize->memsize += sizeof(*cast);
|
2005
2007
|
// Node lists will add in their own sizes below.
|
2006
|
-
memsize->memsize -= sizeof(pm_node_list_t) *
|
2007
|
-
memsize->memsize += pm_node_list_memsize(&cast->
|
2008
|
+
memsize->memsize -= sizeof(pm_node_list_t) * 2;
|
2009
|
+
memsize->memsize += pm_node_list_memsize(&cast->lefts, memsize);
|
2010
|
+
if (cast->rest != NULL) {
|
2011
|
+
pm_node_memsize_node((pm_node_t *)cast->rest, memsize);
|
2012
|
+
}
|
2013
|
+
memsize->memsize += pm_node_list_memsize(&cast->rights, memsize);
|
2008
2014
|
break;
|
2009
2015
|
}
|
2010
2016
|
#line 102 "node.c.erb"
|
@@ -2012,8 +2018,12 @@ pm_node_memsize_node(pm_node_t *node, pm_memsize_t *memsize) {
|
|
2012
2018
|
pm_multi_write_node_t *cast = (pm_multi_write_node_t *) node;
|
2013
2019
|
memsize->memsize += sizeof(*cast);
|
2014
2020
|
// Node lists will add in their own sizes below.
|
2015
|
-
memsize->memsize -= sizeof(pm_node_list_t) *
|
2016
|
-
memsize->memsize += pm_node_list_memsize(&cast->
|
2021
|
+
memsize->memsize -= sizeof(pm_node_list_t) * 2;
|
2022
|
+
memsize->memsize += pm_node_list_memsize(&cast->lefts, memsize);
|
2023
|
+
if (cast->rest != NULL) {
|
2024
|
+
pm_node_memsize_node((pm_node_t *)cast->rest, memsize);
|
2025
|
+
}
|
2026
|
+
memsize->memsize += pm_node_list_memsize(&cast->rights, memsize);
|
2017
2027
|
pm_node_memsize_node((pm_node_t *)cast->value, memsize);
|
2018
2028
|
break;
|
2019
2029
|
}
|
@@ -2163,15 +2173,6 @@ pm_node_memsize_node(pm_node_t *node, pm_memsize_t *memsize) {
|
|
2163
2173
|
memsize->memsize += pm_string_memsize(&cast->unescaped);
|
2164
2174
|
break;
|
2165
2175
|
}
|
2166
|
-
#line 102 "node.c.erb"
|
2167
|
-
case PM_REQUIRED_DESTRUCTURED_PARAMETER_NODE: {
|
2168
|
-
pm_required_destructured_parameter_node_t *cast = (pm_required_destructured_parameter_node_t *) node;
|
2169
|
-
memsize->memsize += sizeof(*cast);
|
2170
|
-
// Node lists will add in their own sizes below.
|
2171
|
-
memsize->memsize -= sizeof(pm_node_list_t) * 1;
|
2172
|
-
memsize->memsize += pm_node_list_memsize(&cast->parameters, memsize);
|
2173
|
-
break;
|
2174
|
-
}
|
2175
2176
|
#line 102 "node.c.erb"
|
2176
2177
|
case PM_REQUIRED_PARAMETER_NODE: {
|
2177
2178
|
pm_required_parameter_node_t *cast = (pm_required_parameter_node_t *) node;
|
@@ -2643,8 +2644,6 @@ pm_node_type_to_str(pm_node_type_t node_type)
|
|
2643
2644
|
return "PM_REDO_NODE";
|
2644
2645
|
case PM_REGULAR_EXPRESSION_NODE:
|
2645
2646
|
return "PM_REGULAR_EXPRESSION_NODE";
|
2646
|
-
case PM_REQUIRED_DESTRUCTURED_PARAMETER_NODE:
|
2647
|
-
return "PM_REQUIRED_DESTRUCTURED_PARAMETER_NODE";
|
2648
2647
|
case PM_REQUIRED_PARAMETER_NODE:
|
2649
2648
|
return "PM_REQUIRED_PARAMETER_NODE";
|
2650
2649
|
case PM_RESCUE_MODIFIER_NODE:
|