| 1 | # Do not edit this file - Generated by Perlito5 9.027 | ||
| 2 | |||
| 3 | { | ||
| 4 | package main; | ||
| 5 | package Perlito5::Grammar::Expression; | ||
| 6 | use Perlito5::Grammar::Precedence ; | ||
| 7 | use Perlito5::Grammar::Bareword ; | ||
| 8 | use Perlito5::Grammar::Attribute ; | ||
| 9 | use Perlito5::Grammar::Statement ; | ||
| 10 | sub Perlito5::Grammar::Expression::expand_list_fat_arrow { | ||
| 11 | my $param_list = shift; | ||
| 12 | if (ref($param_list) eq "Perlito5::AST::Apply" && $param_list->{"code"} eq "infix:<=>>") {; | ||
| 13 | return (Perlito5::AST::Lookup::->autoquote($param_list->{"arguments"}->[0]), Perlito5::Grammar::Expression::expand_list_fat_arrow($param_list->{"arguments"}->[1])) | ||
| 14 | } | ||
| 15 | return $param_list | ||
| 16 | } | ||
| 17 | sub Perlito5::Grammar::Expression::expand_list { | ||
| 18 | my $param_list = shift; | ||
| 19 | if (ref($param_list) eq "Perlito5::AST::Apply" && $param_list->{"code"} eq "list:<,>") {; | ||
| 20 | return [map {; | ||
| 21 | Perlito5::Grammar::Expression::expand_list_fat_arrow($_) | ||
| 22 | } grep {; | ||
| 23 | defined($_) | ||
| 24 | } @{$param_list->arguments()}] | ||
| 25 | } | ||
| 26 | if (ref($param_list) eq "Perlito5::AST::Apply" && $param_list->{"code"} eq "infix:<=>>") {; | ||
| 27 | return [Perlito5::Grammar::Expression::expand_list_fat_arrow($param_list)] | ||
| 28 | } | ||
| 29 | elsif ($param_list eq "*undef*") {; | ||
| 30 | return [] | ||
| 31 | } | ||
| 32 | else {; | ||
| 33 | return [$param_list] | ||
| 34 | } | ||
| 35 | } | ||
| 36 | sub Perlito5::Grammar::Expression::block_or_hash { | ||
| 37 | my $o = shift; | ||
| 38 | if (defined($o->sig())) {; | ||
| 39 | return $o | ||
| 40 | } | ||
| 41 | my $stmts = $o->stmts(); | ||
| 42 | if (!defined($stmts) || scalar(@{$stmts}) == 0) {; | ||
| 43 | return Perlito5::AST::Apply::->new("code", "circumfix:<{ }>", "namespace", '', "arguments", []) | ||
| 44 | } | ||
| 45 | if (scalar(@{$stmts}) != 1) {; | ||
| 46 | return $o | ||
| 47 | } | ||
| 48 | my $stmt = $stmts->[0]; | ||
| 49 | if (ref($stmt) eq "Perlito5::AST::Var") {; | ||
| 50 | return Perlito5::AST::Apply::->new("code", "circumfix:<{ }>", "namespace", '', "arguments", [$stmt]) | ||
| 51 | } | ||
| 52 | if (ref($stmt) ne "Perlito5::AST::Apply") {; | ||
| 53 | return $o | ||
| 54 | } | ||
| 55 | if ($stmt->{"code"} eq "infix:<=>>" || $stmt->{"code"} eq "prefix:<%>" || $stmt->{"code"} eq "prefix:<\@>" || $stmt->{"code"} eq "list:<,>") { | ||
| 56 | if (@{$stmt->{"arguments"}}) { | ||
| 57 | my $arg = $stmt->{"arguments"}->[0]; | ||
| 58 | if (ref($arg) eq "Perlito5::AST::Apply" && $arg->{"code"} eq "prefix:<&>") {; | ||
| 59 | return $o | ||
| 60 | } | ||
| 61 | } | ||
| 62 | return Perlito5::AST::Apply::->new("code", "circumfix:<{ }>", "namespace", '', "arguments", [$stmt]) | ||
| 63 | } | ||
| 64 | return Perlito5::AST::Apply::->new("code", "circumfix:<{ }>", "namespace", '', "arguments", Perlito5::Grammar::Expression::expand_list($stmt)) | ||
| 65 | } | ||
| 66 | sub Perlito5::Grammar::Expression::pop_term { | ||
| 67 | my $num_stack = shift; | ||
| 68 | my $v = pop(@{$num_stack}); | ||
| 69 | if (ref($v) eq "ARRAY") { | ||
| 70 | ref($v->[1]) && return $v->[1]; | ||
| 71 | if ($v->[1] eq "methcall_no_params") { | ||
| 72 | $v = Perlito5::AST::Call::->new("invocant", undef, "method", $v->[2], "arguments", []); | ||
| 73 | return $v | ||
| 74 | } | ||
| 75 | if ($v->[1] eq "funcall_no_params") { | ||
| 76 | $v = $v->[2]; | ||
| 77 | return $v | ||
| 78 | } | ||
| 79 | if ($v->[1] eq "methcall") { | ||
| 80 | my $param_list = Perlito5::Grammar::Expression::expand_list(($v->[3])); | ||
| 81 | $v = Perlito5::AST::Call::->new("invocant", undef, "method", $v->[2], "arguments", $param_list); | ||
| 82 | return $v | ||
| 83 | } | ||
| 84 | if ($v->[1] eq "funcall") { | ||
| 85 | $v = Perlito5::AST::Apply::->new("code", $v->[3], "arguments", $v->[4], "namespace", $v->[2]); | ||
| 86 | return $v | ||
| 87 | } | ||
| 88 | if ($v->[1] eq "( )") { | ||
| 89 | my $param_list = Perlito5::Grammar::Expression::expand_list($v->[2]); | ||
| 90 | $v = Perlito5::AST::Apply::->new("code", "circumfix:<( )>", "arguments", $param_list, "namespace", ''); | ||
| 91 | return $v | ||
| 92 | } | ||
| 93 | if ($v->[1] eq "[ ]") { | ||
| 94 | my $param_list = Perlito5::Grammar::Expression::expand_list($v->[2]); | ||
| 95 | $v = Perlito5::AST::Apply::->new("code", "circumfix:<[ ]>", "arguments", $param_list, "namespace", ''); | ||
| 96 | return $v | ||
| 97 | } | ||
| 98 | if ($v->[1] eq "block") { | ||
| 99 | $v = Perlito5::AST::Block::->new("stmts", $v->[2], "sig", $v->[3]); | ||
| 100 | $v = Perlito5::Grammar::Expression::block_or_hash($v); | ||
| 101 | return $v | ||
| 102 | } | ||
| 103 | if ($v->[1] eq ".( )") { | ||
| 104 | $v = Perlito5::AST::Call::->new("invocant", undef, "method", "postcircumfix:<( )>", "arguments", $v->[2]); | ||
| 105 | return $v | ||
| 106 | } | ||
| 107 | if ($v->[1] eq ".[ ]") { | ||
| 108 | $v = Perlito5::AST::Index::->new("obj", undef, "index_exp", $v->[2]); | ||
| 109 | return $v | ||
| 110 | } | ||
| 111 | if ($v->[1] eq ".{ }") { | ||
| 112 | $v = Perlito5::AST::Lookup::->new("obj", undef, "index_exp", $v->[2]); | ||
| 113 | return $v | ||
| 114 | } | ||
| 115 | return $v->[1] | ||
| 116 | } | ||
| 117 | return $v | ||
| 118 | } | ||
| 119 | sub Perlito5::Grammar::Expression::reduce_postfix { | ||
| 120 | my $op = shift; | ||
| 121 | my $value = shift; | ||
| 122 | my $v = $op; | ||
| 123 | if ($v->[1] eq ".{ }") { | ||
| 124 | $v = Perlito5::AST::Call::->new("invocant", $value, "method", "postcircumfix:<{ }>", "arguments", $v->[2]); | ||
| 125 | return $v | ||
| 126 | } | ||
| 127 | if ($v->[1] eq ".[ ]") { | ||
| 128 | $v = Perlito5::AST::Call::->new("invocant", $value, "method", "postcircumfix:<[ ]>", "arguments", $v->[2]); | ||
| 129 | return $v | ||
| 130 | } | ||
| 131 | if ($v->[1] eq "methcall_no_params") { | ||
| 132 | if ($v->[2] eq "\@*") {; | ||
| 133 | return Perlito5::AST::Apply::->new("code", "prefix:<\@>", "arguments", [$value]) | ||
| 134 | } | ||
| 135 | $v = Perlito5::AST::Call::->new("invocant", $value, "method", $v->[2], "arguments", [], (ref($v->[2]) ? () : ("_no_params", 1))); | ||
| 136 | return $v | ||
| 137 | } | ||
| 138 | if ($v->[1] eq "funcall_no_params") {; | ||
| 139 | Perlito5::Compiler::error("Bareword found where operator expected") | ||
| 140 | } | ||
| 141 | if ($v->[1] eq "methcall") { | ||
| 142 | my $param_list = Perlito5::Grammar::Expression::expand_list($v->[3]); | ||
| 143 | $v = Perlito5::AST::Call::->new("invocant", $value, "method", $v->[2], "arguments", $param_list); | ||
| 144 | return $v | ||
| 145 | } | ||
| 146 | if ($v->[1] eq "funcall") {; | ||
| 147 | Perlito5::Compiler::error("unexpected function call") | ||
| 148 | } | ||
| 149 | if ($v->[1] eq "( )") { | ||
| 150 | my $param_list = Perlito5::Grammar::Expression::expand_list($v->[2]); | ||
| 151 | if (ref($value) eq "Perlito5::AST::Apply" && !defined($value->arguments())) { | ||
| 152 | $value->{"arguments"} = $param_list; | ||
| 153 | return $value | ||
| 154 | } | ||
| 155 | if (ref($value) eq "Perlito5::AST::Call" && !defined($value->arguments())) { | ||
| 156 | $value->{"arguments"} = $param_list; | ||
| 157 | return $value | ||
| 158 | } | ||
| 159 | if (ref($value) eq "Perlito5::AST::Var" && $value->{"sigil"} eq "&") { | ||
| 160 | $v = Perlito5::AST::Apply::->new("ignore_proto", 1, "code", $value->{"name"}, "namespace", $value->{"namespace"}, "arguments", $param_list, "proto", undef); | ||
| 161 | return $v | ||
| 162 | } | ||
| 163 | if (ref($value) eq "Perlito5::AST::Apply" && $value->{"code"} eq "prefix:<&>") { | ||
| 164 | $v = Perlito5::AST::Apply::->new("ignore_proto", 1, "code", $value, "namespace", '', "arguments", $param_list, "proto", undef); | ||
| 165 | return $v | ||
| 166 | } | ||
| 167 | if (ref($value) eq "Perlito5::AST::Var") {; | ||
| 168 | Perlito5::Compiler::error("syntax error") | ||
| 169 | } | ||
| 170 | $v = Perlito5::AST::Call::->new("invocant", $value, "method", "postcircumfix:<( )>", "arguments", $param_list); | ||
| 171 | return $v | ||
| 172 | } | ||
| 173 | if ($v->[1] eq "[ ]") { | ||
| 174 | if (ref($value) eq "Perlito5::AST::Var") {; | ||
| 175 | $value->{"_real_sigil"} = "\@" | ||
| 176 | } | ||
| 177 | $v = Perlito5::AST::Index::->new("obj", $value, "index_exp", $v->[2]); | ||
| 178 | return $v | ||
| 179 | } | ||
| 180 | if ($v->[1] eq "block") { | ||
| 181 | if (ref($value) eq "Perlito5::AST::Var") { | ||
| 182 | $value->{"_real_sigil"} = "%"; | ||
| 183 | $value->{"sigil"} eq "*" && ($value->{"_real_sigil"} = "*") | ||
| 184 | } | ||
| 185 | $v = Perlito5::AST::Lookup::->new("obj", $value, "index_exp", $v->[2]->[0]); | ||
| 186 | return $v | ||
| 187 | } | ||
| 188 | if ($v->[1] eq ".( )") { | ||
| 189 | my $param_list = Perlito5::Grammar::Expression::expand_list($v->[2]); | ||
| 190 | $v = Perlito5::AST::Call::->new("invocant", $value, "method", "postcircumfix:<( )>", "arguments", $param_list); | ||
| 191 | return $v | ||
| 192 | } | ||
| 193 | push(@{$op}, $value); | ||
| 194 | return $op | ||
| 195 | } | ||
| 196 | sub Perlito5::Grammar::Expression::reduce_to_ast { | ||
| 197 | my $op_stack = shift; | ||
| 198 | my $num_stack = shift; | ||
| 199 | my $last_op = shift(@{$op_stack}); | ||
| 200 | if ($last_op->[0] eq "prefix") { | ||
| 201 | my $v = Perlito5::Grammar::Expression::pop_term($num_stack); | ||
| 202 | if (ref($v) eq "Perlito5::AST::Apply" && $v->{"code"} eq "circumfix:<( )>" && @{$v->{"arguments"}} == 1) {; | ||
| 203 | $v = $v->{"arguments"} | ||
| 204 | } | ||
| 205 | else {; | ||
| 206 | $v = [$v] | ||
| 207 | } | ||
| 208 | push(@{$num_stack}, Perlito5::AST::Apply::->new("namespace", '', "code", "prefix:<" . ($last_op->[1]) . ">", "arguments", $v)) | ||
| 209 | } | ||
| 210 | elsif ($last_op->[0] eq "postfix") {; | ||
| 211 | push(@{$num_stack}, Perlito5::AST::Apply::->new("namespace", '', "code", "postfix:<" . ($last_op->[1]) . ">", "arguments", [Perlito5::Grammar::Expression::pop_term($num_stack)])) | ||
| 212 | } | ||
| 213 | elsif ($last_op->[0] eq "postfix_or_term") {; | ||
| 214 | push(@{$num_stack}, Perlito5::Grammar::Expression::reduce_postfix($last_op, Perlito5::Grammar::Expression::pop_term($num_stack))) | ||
| 215 | } | ||
| 216 | elsif (Perlito5::Grammar::Precedence::is_assoc_type("list", $last_op->[1])) { | ||
| 217 | my $arg; | ||
| 218 | if (scalar(@{$num_stack}) < 2) { | ||
| 219 | my $v2 = Perlito5::Grammar::Expression::pop_term($num_stack); | ||
| 220 | if (ref($v2) eq "Perlito5::AST::Apply" && $v2->{"code"} eq ("list:<" . ($last_op->[1]) . ">")) {; | ||
| 221 | push(@{$num_stack}, Perlito5::AST::Apply::->new("namespace", $v2->namespace(), "code", $v2->{"code"}, "arguments", [@{$v2->arguments()}])) | ||
| 222 | } | ||
| 223 | else {; | ||
| 224 | push(@{$num_stack}, Perlito5::AST::Apply::->new("namespace", '', "code", "list:<" . ($last_op->[1]) . ">", "arguments", [$v2])) | ||
| 225 | } | ||
| 226 | return | ||
| 227 | } | ||
| 228 | else { | ||
| 229 | my $v2 = Perlito5::Grammar::Expression::pop_term($num_stack); | ||
| 230 | $arg = [Perlito5::Grammar::Expression::pop_term($num_stack), $v2] | ||
| 231 | } | ||
| 232 | if (ref($arg->[0]) eq "Perlito5::AST::Apply" && $last_op->[0] eq "infix" && ($arg->[0]->{"code"} eq "list:<" . ($last_op->[1]) . ">")) { | ||
| 233 | push(@{$num_stack}, Perlito5::AST::Apply::->new("namespace", '', "code", ($arg->[0])->{"code"}, "arguments", [@{($arg->[0])->arguments()}, $arg->[1]])); | ||
| 234 | return | ||
| 235 | } | ||
| 236 | push(@{$num_stack}, Perlito5::AST::Apply::->new("namespace", '', "code", "list:<" . ($last_op->[1]) . ">", "arguments", $arg)) | ||
| 237 | } | ||
| 238 | elsif (Perlito5::Grammar::Precedence::is_assoc_type("chain", $last_op->[1])) { | ||
| 239 | if (scalar(@{$num_stack}) < 2) {; | ||
| 240 | Perlito5::Compiler::error("Missing value after operator " . ($last_op->[1])) | ||
| 241 | } | ||
| 242 | my $v2 = Perlito5::Grammar::Expression::pop_term($num_stack); | ||
| 243 | my $arg = [Perlito5::Grammar::Expression::pop_term($num_stack), $v2]; | ||
| 244 | push(@{$num_stack}, Perlito5::AST::Apply::->new("namespace", '', "code", "infix:<" . ($last_op->[1]) . ">", "arguments", $arg)) | ||
| 245 | } | ||
| 246 | elsif ($last_op->[0] eq "ternary") { | ||
| 247 | if (scalar(@{$num_stack}) < 2) {; | ||
| 248 | Perlito5::Compiler::error("Missing value after ternary operator") | ||
| 249 | } | ||
| 250 | my $v2 = Perlito5::Grammar::Expression::pop_term($num_stack); | ||
| 251 | push(@{$num_stack}, Perlito5::AST::Apply::->new("namespace", '', "code", "ternary:<" . ($last_op->[1]) . ">", "arguments", [Perlito5::Grammar::Expression::pop_term($num_stack), $last_op->[2], $v2])) | ||
| 252 | } | ||
| 253 | else { | ||
| 254 | if (scalar(@{$num_stack}) < 2) {; | ||
| 255 | Perlito5::Compiler::error("missing value after operator '" . ($last_op->[1]) . "'") | ||
| 256 | } | ||
| 257 | my $v2 = Perlito5::Grammar::Expression::pop_term($num_stack); | ||
| 258 | my $op = $last_op->[1]; | ||
| 259 | push(@{$num_stack}, Perlito5::AST::Apply::->new("namespace", '', "code", "infix:<" . $op . ">", "arguments", [Perlito5::Grammar::Expression::pop_term($num_stack), $v2], Perlito5::integer_flag($op), Perlito5::overloading_flag())) | ||
| 260 | } | ||
| 261 | } | ||
| 262 | sub Perlito5::Grammar::Expression::term_arrow { | ||
| 263 | my $str = $_[0]; | ||
| 264 | my $pos = $_[1]; | ||
| 265 | my $MATCH = {"str" => $str, "from" => $pos, "to" => $pos, }; | ||
| 266 | my $tmp = (((("-" eq $str->[($MATCH->{"to"}) + 0]) && (">" eq $str->[($MATCH->{"to"}) + 1]) && ($MATCH->{"to"} += 2)) && (do { | ||
| 267 | my $m2 = Perlito5::Grammar::Space::opt_ws($str, $MATCH->{"to"}); | ||
| 268 | if ($m2) { | ||
| 269 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 270 | 1 | ||
| 271 | } | ||
| 272 | else {; | ||
| 273 | 0 | ||
| 274 | } | ||
| 275 | }) && (do { | ||
| 276 | my $tmp129 = $MATCH->{"to"}; | ||
| 277 | (((("(" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 278 | my $m2 = Perlito5::Grammar::Expression::paren_parse($str, $MATCH->{"to"}); | ||
| 279 | if ($m2) { | ||
| 280 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 281 | $MATCH->{"paren_parse"} = $m2; | ||
| 282 | 1 | ||
| 283 | } | ||
| 284 | else {; | ||
| 285 | 0 | ||
| 286 | } | ||
| 287 | }) && ((")" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 288 | $MATCH->{"capture"} = ["postfix_or_term", ".( )", Perlito5::Match::flat($MATCH->{"paren_parse"})]; | ||
| 289 | 1 | ||
| 290 | }))) || ($MATCH->{"to"} = $tmp129, ((("[" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 291 | my $m2 = Perlito5::Grammar::Expression::square_parse($str, $MATCH->{"to"}); | ||
| 292 | if ($m2) { | ||
| 293 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 294 | $MATCH->{"square_parse"} = $m2; | ||
| 295 | 1 | ||
| 296 | } | ||
| 297 | else {; | ||
| 298 | 0 | ||
| 299 | } | ||
| 300 | }) && (("]" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 301 | $MATCH->{"capture"} = ["postfix_or_term", ".[ ]", Perlito5::Match::flat($MATCH->{"square_parse"})]; | ||
| 302 | 1 | ||
| 303 | }))) || ($MATCH->{"to"} = $tmp129, ((("{" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 304 | my $tmp130 = $MATCH->{"to"}; | ||
| 305 | (((do { | ||
| 306 | my $m2 = Perlito5::Grammar::Space::opt_ws($str, $MATCH->{"to"}); | ||
| 307 | if ($m2) { | ||
| 308 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 309 | 1 | ||
| 310 | } | ||
| 311 | else {; | ||
| 312 | 0 | ||
| 313 | } | ||
| 314 | }) && (do { | ||
| 315 | my $m2 = Perlito5::Grammar::ident($str, $MATCH->{"to"}); | ||
| 316 | if ($m2) { | ||
| 317 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 318 | $MATCH->{"Perlito5::Grammar::ident"} = $m2; | ||
| 319 | 1 | ||
| 320 | } | ||
| 321 | else {; | ||
| 322 | 0 | ||
| 323 | } | ||
| 324 | }) && (do { | ||
| 325 | my $m2 = Perlito5::Grammar::Space::opt_ws($str, $MATCH->{"to"}); | ||
| 326 | if ($m2) { | ||
| 327 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 328 | 1 | ||
| 329 | } | ||
| 330 | else {; | ||
| 331 | 0 | ||
| 332 | } | ||
| 333 | }) && (("}" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 334 | $MATCH->{"capture"} = ["postfix_or_term", ".{ }", Perlito5::AST::Buf::->new("buf", Perlito5::Match::flat($MATCH->{"Perlito5::Grammar::ident"}))]; | ||
| 335 | 1 | ||
| 336 | }))) || ($MATCH->{"to"} = $tmp130, ((do { | ||
| 337 | my $m2 = Perlito5::Grammar::Expression::curly_parse($str, $MATCH->{"to"}); | ||
| 338 | if ($m2) { | ||
| 339 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 340 | $MATCH->{"curly_parse"} = $m2; | ||
| 341 | 1 | ||
| 342 | } | ||
| 343 | else {; | ||
| 344 | 0 | ||
| 345 | } | ||
| 346 | }) && (do { | ||
| 347 | my $tmp131 = $MATCH->{"to"}; | ||
| 348 | ((("}" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1))) || ($MATCH->{"to"} = $tmp131, (do { | ||
| 349 | Perlito5::Compiler::error("Missing right curly or square bracket"); | ||
| 350 | 1 | ||
| 351 | })) | ||
| 352 | }) && (do { | ||
| 353 | $MATCH->{"capture"} = ["postfix_or_term", ".{ }", Perlito5::Match::flat($MATCH->{"curly_parse"})]; | ||
| 354 | 1 | ||
| 355 | }))) | ||
| 356 | }))) || ($MATCH->{"to"} = $tmp129, ((do { | ||
| 357 | my $m2 = Perlito5::Grammar::full_ident($str, $MATCH->{"to"}); | ||
| 358 | if ($m2) { | ||
| 359 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 360 | $MATCH->{"Perlito5::Grammar::full_ident"} = $m2; | ||
| 361 | 1 | ||
| 362 | } | ||
| 363 | else {; | ||
| 364 | 0 | ||
| 365 | } | ||
| 366 | }) && (do { | ||
| 367 | my $m2 = Perlito5::Grammar::Space::opt_ws($str, $MATCH->{"to"}); | ||
| 368 | if ($m2) { | ||
| 369 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 370 | 1 | ||
| 371 | } | ||
| 372 | else {; | ||
| 373 | 0 | ||
| 374 | } | ||
| 375 | }) && (do { | ||
| 376 | my $tmp132 = $MATCH->{"to"}; | ||
| 377 | (((("(" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 378 | my $m2 = Perlito5::Grammar::Expression::paren_parse($str, $MATCH->{"to"}); | ||
| 379 | if ($m2) { | ||
| 380 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 381 | $MATCH->{"paren_parse"} = $m2; | ||
| 382 | 1 | ||
| 383 | } | ||
| 384 | else {; | ||
| 385 | 0 | ||
| 386 | } | ||
| 387 | }) && ((")" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 388 | $MATCH->{"capture"} = ["postfix_or_term", "methcall", Perlito5::Match::flat($MATCH->{"Perlito5::Grammar::full_ident"}), Perlito5::Match::flat($MATCH->{"paren_parse"})]; | ||
| 389 | 1 | ||
| 390 | }))) || ($MATCH->{"to"} = $tmp132, (do { | ||
| 391 | $MATCH->{"capture"} = ["postfix_or_term", "methcall_no_params", Perlito5::Match::flat($MATCH->{"Perlito5::Grammar::full_ident"})]; | ||
| 392 | 1 | ||
| 393 | })) | ||
| 394 | }))) || ($MATCH->{"to"} = $tmp129, ((do { | ||
| 395 | my $tmp = $MATCH; | ||
| 396 | $MATCH = {"from" => $tmp->{"to"}, "to" => $tmp->{"to"}, }; | ||
| 397 | my $res = (("\$" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)); | ||
| 398 | $MATCH = $tmp; | ||
| 399 | $res ? 1 : 0 | ||
| 400 | }) && (do { | ||
| 401 | my $m2 = Perlito5::Grammar::Sigil::term_sigil($str, $MATCH->{"to"}); | ||
| 402 | if ($m2) { | ||
| 403 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 404 | $MATCH->{"Perlito5::Grammar::Sigil::term_sigil"} = $m2; | ||
| 405 | 1 | ||
| 406 | } | ||
| 407 | else {; | ||
| 408 | 0 | ||
| 409 | } | ||
| 410 | }) && (do { | ||
| 411 | my $m2 = Perlito5::Grammar::Space::opt_ws($str, $MATCH->{"to"}); | ||
| 412 | if ($m2) { | ||
| 413 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 414 | 1 | ||
| 415 | } | ||
| 416 | else {; | ||
| 417 | 0 | ||
| 418 | } | ||
| 419 | }) && (do { | ||
| 420 | my $tmp133 = $MATCH->{"to"}; | ||
| 421 | (((("(" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 422 | my $m2 = Perlito5::Grammar::Expression::paren_parse($str, $MATCH->{"to"}); | ||
| 423 | if ($m2) { | ||
| 424 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 425 | $MATCH->{"paren_parse"} = $m2; | ||
| 426 | 1 | ||
| 427 | } | ||
| 428 | else {; | ||
| 429 | 0 | ||
| 430 | } | ||
| 431 | }) && ((")" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 432 | $MATCH->{"capture"} = ["postfix_or_term", "methcall", Perlito5::Match::flat($MATCH->{"Perlito5::Grammar::Sigil::term_sigil"})->[1], Perlito5::Match::flat($MATCH->{"paren_parse"})]; | ||
| 433 | 1 | ||
| 434 | }))) || ($MATCH->{"to"} = $tmp133, (do { | ||
| 435 | $MATCH->{"capture"} = ["postfix_or_term", "methcall_no_params", Perlito5::Match::flat($MATCH->{"Perlito5::Grammar::Sigil::term_sigil"})->[1]]; | ||
| 436 | 1 | ||
| 437 | })) | ||
| 438 | }))) || ($MATCH->{"to"} = $tmp129, ((("\@" eq $str->[($MATCH->{"to"}) + 0]) && ("*" eq $str->[($MATCH->{"to"}) + 1]) && ($MATCH->{"to"} += 2)) && (do { | ||
| 439 | $MATCH->{"capture"} = ["postfix_or_term", "methcall_no_params", "\@*"]; | ||
| 440 | 1 | ||
| 441 | }))) | ||
| 442 | }))); | ||
| 443 | $tmp ? $MATCH : undef | ||
| 444 | } | ||
| 445 | sub Perlito5::Grammar::Expression::term_ternary { | ||
| 446 | my $str = $_[0]; | ||
| 447 | my $pos = $_[1]; | ||
| 448 | my $MATCH = {"str" => $str, "from" => $pos, "to" => $pos, }; | ||
| 449 | my $tmp = (((("?" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 450 | my $m2 = Perlito5::Grammar::Expression::ternary5_parse($str, $MATCH->{"to"}); | ||
| 451 | if ($m2) { | ||
| 452 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 453 | $MATCH->{"ternary5_parse"} = $m2; | ||
| 454 | 1 | ||
| 455 | } | ||
| 456 | else {; | ||
| 457 | 0 | ||
| 458 | } | ||
| 459 | }) && ((":" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 460 | $MATCH->{"capture"} = ["op", "? :", Perlito5::Match::flat($MATCH->{"ternary5_parse"})]; | ||
| 461 | 1 | ||
| 462 | }))); | ||
| 463 | $tmp ? $MATCH : undef | ||
| 464 | } | ||
| 465 | sub Perlito5::Grammar::Expression::term_paren { | ||
| 466 | my $str = $_[0]; | ||
| 467 | my $pos = $_[1]; | ||
| 468 | my $MATCH = {"str" => $str, "from" => $pos, "to" => $pos, }; | ||
| 469 | my $tmp = (((("(" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 470 | my $m2 = Perlito5::Grammar::Expression::paren_parse($str, $MATCH->{"to"}); | ||
| 471 | if ($m2) { | ||
| 472 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 473 | $MATCH->{"paren_parse"} = $m2; | ||
| 474 | 1 | ||
| 475 | } | ||
| 476 | else {; | ||
| 477 | 0 | ||
| 478 | } | ||
| 479 | }) && ((")" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 480 | $MATCH->{"capture"} = ["postfix_or_term", "( )", Perlito5::Match::flat($MATCH->{"paren_parse"})]; | ||
| 481 | 1 | ||
| 482 | }))); | ||
| 483 | $tmp ? $MATCH : undef | ||
| 484 | } | ||
| 485 | sub Perlito5::Grammar::Expression::term_square { | ||
| 486 | my $str = $_[0]; | ||
| 487 | my $pos = $_[1]; | ||
| 488 | my $MATCH = {"str" => $str, "from" => $pos, "to" => $pos, }; | ||
| 489 | my $tmp = (((("[" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 490 | my $m2 = Perlito5::Grammar::Expression::square_parse($str, $MATCH->{"to"}); | ||
| 491 | if ($m2) { | ||
| 492 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 493 | $MATCH->{"square_parse"} = $m2; | ||
| 494 | 1 | ||
| 495 | } | ||
| 496 | else {; | ||
| 497 | 0 | ||
| 498 | } | ||
| 499 | }) && (("]" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 500 | $MATCH->{"capture"} = ["postfix_or_term", "[ ]", Perlito5::Match::flat($MATCH->{"square_parse"})]; | ||
| 501 | 1 | ||
| 502 | }))); | ||
| 503 | $tmp ? $MATCH : undef | ||
| 504 | } | ||
| 505 | sub Perlito5::Grammar::Expression::term_curly { | ||
| 506 | my $str = $_[0]; | ||
| 507 | my $pos = $_[1]; | ||
| 508 | my $MATCH = {"str" => $str, "from" => $pos, "to" => $pos, }; | ||
| 509 | my $tmp = (((("{" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 510 | my $m = $MATCH; | ||
| 511 | if (!(do { | ||
| 512 | my $m2 = Perlito5::Grammar::Space::ws($str, $MATCH->{"to"}); | ||
| 513 | if ($m2) { | ||
| 514 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 515 | 1 | ||
| 516 | } | ||
| 517 | else {; | ||
| 518 | 0 | ||
| 519 | } | ||
| 520 | })) {; | ||
| 521 | $MATCH = $m | ||
| 522 | } | ||
| 523 | 1 | ||
| 524 | }) && (do { | ||
| 525 | my $tmp173 = $MATCH->{"to"}; | ||
| 526 | (((do { | ||
| 527 | my $m2 = Perlito5::Grammar::ident($str, $MATCH->{"to"}); | ||
| 528 | if ($m2) { | ||
| 529 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 530 | $MATCH->{"Perlito5::Grammar::ident"} = $m2; | ||
| 531 | 1 | ||
| 532 | } | ||
| 533 | else {; | ||
| 534 | 0 | ||
| 535 | } | ||
| 536 | }) && (do { | ||
| 537 | my $m = $MATCH; | ||
| 538 | if (!(do { | ||
| 539 | my $m2 = Perlito5::Grammar::Space::ws($str, $MATCH->{"to"}); | ||
| 540 | if ($m2) { | ||
| 541 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 542 | 1 | ||
| 543 | } | ||
| 544 | else {; | ||
| 545 | 0 | ||
| 546 | } | ||
| 547 | })) {; | ||
| 548 | $MATCH = $m | ||
| 549 | } | ||
| 550 | 1 | ||
| 551 | }) && (("}" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1)) && (do { | ||
| 552 | $MATCH->{"capture"} = ["postfix_or_term", "block", [Perlito5::AST::Apply::->new("arguments", [], "bareword", 1, "code", Perlito5::Match::flat($MATCH->{"Perlito5::Grammar::ident"}), "namespace", '')]]; | ||
| 553 | 1 | ||
| 554 | }))) || ($MATCH->{"to"} = $tmp173, ((do { | ||
| 555 | $MATCH->{"_save_scope"} = [@Perlito5::SCOPE_STMT]; | ||
| 556 | @Perlito5::SCOPE_STMT = (); | ||
| 557 | 1 | ||
| 558 | }) && (do { | ||
| 559 | my $m2 = Perlito5::Grammar::exp_stmts($str, $MATCH->{"to"}); | ||
| 560 | if ($m2) { | ||
| 561 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 562 | $MATCH->{"Perlito5::Grammar::exp_stmts"} = $m2; | ||
| 563 | 1 | ||
| 564 | } | ||
| 565 | else {; | ||
| 566 | 0 | ||
| 567 | } | ||
| 568 | }) && (do { | ||
| 569 | @Perlito5::SCOPE_STMT = @{$MATCH->{"_save_scope"}}; | ||
| 570 | 1 | ||
| 571 | }) && (do { | ||
| 572 | my $m = $MATCH; | ||
| 573 | if (!(do { | ||
| 574 | my $m2 = Perlito5::Grammar::Space::ws($str, $MATCH->{"to"}); | ||
| 575 | if ($m2) { | ||
| 576 | $MATCH->{"to"} = $m2->{"to"}; | ||
| 577 | 1 | ||
| 578 | } | ||
| 579 | else {; | ||
| 580 | 0 | ||
| 581 | } | ||
| 582 | })) {; | ||
| 583 | $MATCH = $m | ||
| 584 | } | ||
| 585 | 1 | ||
| 586 | }) && (do { | ||
| 587 | my $tmp174 = $MATCH->{"to"}; | ||
| 588 | ((("}" eq $str->[($MATCH->{"to"}) + 0]) && ($MATCH->{"to"} += 1))) || ($MATCH->{"to"} = $tmp174, (do { | ||
| 589 | Perlito5::Compiler::error("Missing right curly or square bracket"); | ||
| 590 | 1 | ||
| 591 | })) | ||
| 592 | }) && (do { | ||
| 593 | $MATCH->{"capture"} = ["postfix_or_term", "block", Perlito5::Match::flat($MATCH->{"Perlito5::Grammar::exp_stmts"})]; | ||
| 594 | 1 | ||
| 595 | }))) | ||
| 596 | }))); | ||
| 597 | $tmp ? $MATCH : undef | ||
| 598 | } | ||
| 599 | my $Expr_end_token_chars = [7, 6, 5, 4, 3, 2, 1]; | ||
| 600 | my $Expr_end_token = {"]" => 1, ")" => 1, "}" => 1, ";" => 1, "if" => 1, "for" => 1, "else" => 1, "when" => 1, "while" => 1, "until" => 1, "elsif" => 1, "unless" => 1, "foreach" => 1, }; | ||
| 601 | my $List_end_token = {":" => 1, "or" => 1, "and" => 1, "xor" => 1, %{$Expr_end_token}, }; | ||
| 602 | my $Next_Last_Redo_end_token = {"," => 1, "=>" => 1, %{$List_end_token}, }; | ||
| 603 | my $Argument_end_token = {"," => 1, "<" => 1, ">" => 1, "=" => 1, "|" => 1, "^" => 1, "?" => 1, "=>" => 1, "lt" => 1, "le" => 1, "gt" => 1, "=>" => 1, "lt" => 1, "le" => 1, "gt" => 1, "ge" => 1, "<=" => 1, ">=" => 1, "==" => 1, "!=" => 1, "ne" => 1, "eq" => 1, ".." => 1, "~~" => 1, "&&" => 1, "||" => 1, "+=" => 1, "-=" => 1, "*=" => 1, "/=" => 1, "x=" => 1, "|=" => 1, "&=" => 1, ".=" => 1, "^=" => 1, "%=" => 1, "//" => 1, "|." => 1, "&." => 1, "^." => 1, "..." => 1, "<=>" => 1, "cmp" => 1, "<<=" => 1, ">>=" => 1, "||=" => 1, "&&=" => 1, "//=" => 1, "**=" => 1, "|.=" => 1, "&.=" => 1, "^.=" => 1, "last" => 1, "next" => 1, "redo" => 1, %{$List_end_token}, }; | ||
| 604 | sub Perlito5::Grammar::Expression::list_parser { | ||
| 605 | (my $str, my $pos, my $end_token) = @_; | ||
| 606 | my $last_pos = $pos; | ||
| 607 | my $is_first_token = 1; | ||
| 608 | my $get_token = sub { | ||
| 609 | my $last_is_term = $_[0]; | ||
| 610 | my $v; | ||
| 611 | my $m = Perlito5::Grammar::Precedence::op_parse($str, $last_pos, $last_is_term); | ||
| 612 | if (!$m) {; | ||
| 613 | return ["end", "*end*"] | ||
| 614 | } | ||
| 615 | my $spc = Perlito5::Grammar::Space::ws($str, $m->{"to"}); | ||
| 616 | if ($spc) {; | ||
| 617 | $m->{"to"} = $spc->{"to"} | ||
| 618 | } | ||
| 619 | $v = $m->{"capture"}; | ||
| 620 | if ($is_first_token && ($v->[0] eq "op") && !Perlito5::Grammar::Precedence::is_fixity_type("prefix", $v->[1])) {; | ||
| 621 | $v->[0] = "end" | ||
| 622 | } | ||
| 623 | if ($v->[0] ne "end") {; | ||
| 624 | $last_pos = $m->{"to"} | ||
| 625 | } | ||
| 626 | $is_first_token = 0; | ||
| 627 | return $v | ||
| 628 | }; | ||
| 629 | my $res = Perlito5::Grammar::Precedence::precedence_parse($get_token, $end_token, $Expr_end_token_chars); | ||
| 630 | if (scalar(@{$res}) == 0) {; | ||
| 631 | return {"str" => $str, "from" => $pos, "to" => $last_pos, "capture" => "*undef*", } | ||
| 632 | } | ||
| 633 | my $result = Perlito5::Grammar::Expression::pop_term($res); | ||
| 634 | return {"str" => $str, "from" => $pos, "to" => $last_pos, "capture" => $result, } | ||
| 635 | } | ||
| 636 | sub Perlito5::Grammar::Expression::next_last_redo_parse { | ||
| 637 | (my $str, my $pos) = @_; | ||
| 638 | return Perlito5::Grammar::Expression::list_parser($str, $pos, $Next_Last_Redo_end_token) | ||
| 639 | } | ||
| 640 | sub Perlito5::Grammar::Expression::argument_parse { | ||
| 641 | (my $str, my $pos) = @_; | ||
| 642 | my $m = Perlito5::Grammar::Expression::list_parser($str, $pos, $Argument_end_token); | ||
| 643 | if ($m->{"capture"} eq "*undef*") { | ||
| 644 | my $term = Perlito5::Grammar::String::term_glob($str, $pos); | ||
| 645 | if ($term) { | ||
| 646 | $m->{"capture"} = $term->{"capture"}->[1]; | ||
| 647 | $m->{"to"} = $term->{"to"} | ||
| 648 | } | ||
| 649 | } | ||
| 650 | return $m | ||
| 651 | } | ||
| 652 | sub Perlito5::Grammar::Expression::list_parse { | ||
| 653 | (my $str, my $pos) = @_; | ||
| 654 | return Perlito5::Grammar::Expression::list_parser($str, $pos, $List_end_token) | ||
| 655 | } | ||
| 656 | sub Perlito5::Grammar::Expression::circumfix_parse { | ||
| 657 | (my $str, my $pos, my $delimiter) = @_; | ||
| 658 | my $last_pos = $pos; | ||
| 659 | my $get_token = sub { | ||
| 660 | my $last_is_term = $_[0]; | ||
| 661 | my $m = Perlito5::Grammar::Precedence::op_parse($str, $last_pos, $last_is_term); | ||
| 662 | if (!$m) { | ||
| 663 | my $msg = "Expected closing delimiter: " . $delimiter; | ||
| 664 | ($delimiter eq "}" || $delimiter eq "]") && ($msg = "Missing right curly or square bracket"); | ||
| 665 | Perlito5::Compiler::error($msg . " near ", $last_pos) | ||
| 666 | } | ||
| 667 | my $spc = Perlito5::Grammar::Space::ws($str, $m->{"to"}); | ||
| 668 | if ($spc) {; | ||
| 669 | $m->{"to"} = $spc->{"to"} | ||
| 670 | } | ||
| 671 | my $v = $m->{"capture"}; | ||
| 672 | if ($v->[0] ne "end") {; | ||
| 673 | $last_pos = $m->{"to"} | ||
| 674 | } | ||
| 675 | return $v | ||
| 676 | }; | ||
| 677 | my %delim_token; | ||
| 678 | $delim_token{$delimiter} = 1; | ||
| 679 | my $res = Perlito5::Grammar::Precedence::precedence_parse($get_token, \%delim_token, [length($delimiter)]); | ||
| 680 | $res = Perlito5::Grammar::Expression::pop_term($res); | ||
| 681 | if (!defined($res)) {; | ||
| 682 | $res = "*undef*" | ||
| 683 | } | ||
| 684 | return {"str" => $str, "from" => $pos, "to" => $last_pos, "capture" => $res, } | ||
| 685 | } | ||
| 686 | sub Perlito5::Grammar::Expression::ternary5_parse {; | ||
| 687 | return Perlito5::Grammar::Expression::circumfix_parse(@_, ":") | ||
| 688 | } | ||
| 689 | sub Perlito5::Grammar::Expression::curly_parse {; | ||
| 690 | return Perlito5::Grammar::Expression::circumfix_parse(@_, "}") | ||
| 691 | } | ||
| 692 | sub Perlito5::Grammar::Expression::square_parse {; | ||
| 693 | return Perlito5::Grammar::Expression::circumfix_parse(@_, "]") | ||
| 694 | } | ||
| 695 | sub Perlito5::Grammar::Expression::paren_parse {; | ||
| 696 | return Perlito5::Grammar::Expression::circumfix_parse(@_, ")") | ||
| 697 | } | ||
| 698 | sub Perlito5::Grammar::Expression::exp_parse { | ||
| 699 | (my $str, my $pos) = @_; | ||
| 700 | my $last_pos = $pos; | ||
| 701 | my $get_token = sub { | ||
| 702 | my $last_is_term = $_[0]; | ||
| 703 | my $v; | ||
| 704 | my $m = Perlito5::Grammar::Precedence::op_parse($str, $last_pos, $last_is_term); | ||
| 705 | if (!$m) {; | ||
| 706 | return ["end", "*end*"] | ||
| 707 | } | ||
| 708 | my $spc = Perlito5::Grammar::Space::ws($str, $m->{"to"}); | ||
| 709 | if ($spc) {; | ||
| 710 | $m->{"to"} = $spc->{"to"} | ||
| 711 | } | ||
| 712 | $v = $m->{"capture"}; | ||
| 713 | if ($v->[0] ne "end") {; | ||
| 714 | $last_pos = $m->{"to"} | ||
| 715 | } | ||
| 716 | return $v | ||
| 717 | }; | ||
| 718 | my $res = Perlito5::Grammar::Precedence::precedence_parse($get_token, $Expr_end_token, $Expr_end_token_chars); | ||
| 719 | if (scalar(@{$res}) == 0) {; | ||
| 720 | return 0 | ||
| 721 | } | ||
| 722 | my $result = Perlito5::Grammar::Expression::pop_term($res); | ||
| 723 | return {"str" => $str, "from" => $pos, "to" => $last_pos, "capture" => $result, } | ||
| 724 | } | ||
| 725 | 1 | ||
| 726 | } | ||
| 727 | ;1 |