| ... | @@ -304,6 +304,7 @@ pub const Tree = struct { | ... | @@ -304,6 +304,7 @@ pub const Tree = struct { |
| 304 | .BoolOr, | 304 | .BoolOr, |
| 305 | .SliceOpen, | 305 | .SliceOpen, |
| 306 | .Slice, | 306 | .Slice, |
| | 307 | .SliceSentinel, |
| 307 | .Deref, | 308 | .Deref, |
| 308 | .ArrayAccess, | 309 | .ArrayAccess, |
| 309 | .ArrayInitOne, | 310 | .ArrayInitOne, |
| ... | @@ -694,19 +695,22 @@ pub const Tree = struct { | ... | @@ -694,19 +695,22 @@ pub const Tree = struct { |
| 694 | return main_tokens[n] + end_offset; | 695 | return main_tokens[n] + end_offset; |
| 695 | } | 696 | } |
| 696 | }, | 697 | }, |
| | 698 | |
| 697 | .SliceOpen => { | 699 | .SliceOpen => { |
| 698 | end_offset += 2; // ellipsis2 and rbracket | 700 | end_offset += 2; // ellipsis2 and rbracket |
| 699 | n = datas[n].rhs; | 701 | n = datas[n].rhs; |
| 700 | }, | 702 | }, |
| 701 | .Slice => { | 703 | .Slice => { |
| 702 | const extra = tree.extraData(datas[n].rhs, Node.Slice); | 704 | const extra = tree.extraData(datas[n].rhs, Node.Slice); |
| 703 | if (extra.sentinel != 0) { | 705 | assert(extra.end != 0); // should have used SliceOpen |
| 704 | n = extra.sentinel; | | |
| 705 | } else { | | |
| 706 | assert(extra.end != 0); // should have used SliceOpen if end and sentinel are 0 | | |
| 707 | n = extra.end; | | |
| 708 | } | | |
| 709 | end_offset += 1; // rbracket | 706 | end_offset += 1; // rbracket |
| | 707 | n = extra.end; |
| | 708 | }, |
| | 709 | .SliceSentinel => { |
| | 710 | const extra = tree.extraData(datas[n].rhs, Node.SliceSentinel); |
| | 711 | assert(extra.sentinel != 0); // should have used Slice |
| | 712 | end_offset += 1; // rbracket |
| | 713 | n = extra.sentinel; |
| 710 | }, | 714 | }, |
| 711 | | 715 | |
| 712 | // These are not supported by lastToken() because implementation would | 716 | // These are not supported by lastToken() because implementation would |
| ... | @@ -1129,6 +1133,21 @@ pub const Tree = struct { | ... | @@ -1129,6 +1133,21 @@ pub const Tree = struct { |
| 1129 | assert(tree.nodes.items(.tag)[node] == .Slice); | 1133 | assert(tree.nodes.items(.tag)[node] == .Slice); |
| 1130 | const data = tree.nodes.items(.data)[node]; | 1134 | const data = tree.nodes.items(.data)[node]; |
| 1131 | const extra = tree.extraData(data.rhs, Node.Slice); | 1135 | const extra = tree.extraData(data.rhs, Node.Slice); |
| | 1136 | return .{ |
| | 1137 | .ast = .{ |
| | 1138 | .sliced = data.lhs, |
| | 1139 | .lbracket = tree.nodes.items(.main_token)[node], |
| | 1140 | .start = extra.start, |
| | 1141 | .end = extra.end, |
| | 1142 | .sentinel = 0, |
| | 1143 | }, |
| | 1144 | }; |
| | 1145 | } |
| | 1146 | |
| | 1147 | pub fn sliceSentinel(tree: Tree, node: Node.Index) Full.Slice { |
| | 1148 | assert(tree.nodes.items(.tag)[node] == .SliceSentinel); |
| | 1149 | const data = tree.nodes.items(.data)[node]; |
| | 1150 | const extra = tree.extraData(data.rhs, Node.SliceSentinel); |
| 1132 | return .{ | 1151 | return .{ |
| 1133 | .ast = .{ | 1152 | .ast = .{ |
| 1134 | .sliced = data.lhs, | 1153 | .sliced = data.lhs, |
| ... | @@ -1922,9 +1941,12 @@ pub const Node = struct { | ... | @@ -1922,9 +1941,12 @@ pub const Node = struct { |
| 1922 | /// `lhs[rhs..]` | 1941 | /// `lhs[rhs..]` |
| 1923 | /// main_token is the lbracket. | 1942 | /// main_token is the lbracket. |
| 1924 | SliceOpen, | 1943 | SliceOpen, |
| 1925 | /// `lhs[b..c :d]`. rhs is index into Slice | 1944 | /// `lhs[b..c]`. rhs is index into Slice |
| 1926 | /// main_token is the lbracket. | 1945 | /// main_token is the lbracket. |
| 1927 | Slice, | 1946 | Slice, |
| | 1947 | /// `lhs[b..c :d]`. rhs is index into SliceSentinel |
| | 1948 | /// main_token is the lbracket. |
| | 1949 | SliceSentinel, |
| 1928 | /// `lhs.*`. rhs is unused. | 1950 | /// `lhs.*`. rhs is unused. |
| 1929 | Deref, | 1951 | Deref, |
| 1930 | /// `lhs[rhs]`. | 1952 | /// `lhs[rhs]`. |
| ... | @@ -2202,6 +2224,11 @@ pub const Node = struct { | ... | @@ -2202,6 +2224,11 @@ pub const Node = struct { |
| 2202 | pub const Slice = struct { | 2224 | pub const Slice = struct { |
| 2203 | start: Index, | 2225 | start: Index, |
| 2204 | end: Index, | 2226 | end: Index, |
| | 2227 | }; |
| | 2228 | |
| | 2229 | pub const SliceSentinel = struct { |
| | 2230 | start: Index, |
| | 2231 | end: Index, |
| 2205 | sentinel: Index, | 2232 | sentinel: Index, |
| 2206 | }; | 2233 | }; |
| 2207 | | 2234 | |