| 29 | | NumInt.newp(*text*) |
| 30 | | |
| 31 | | term |
| 32 | | if $o<args> { |
| 33 | | my $ident = 'sub_name_missing_from_STD_ast'; #XXX :( |
| 34 | | my $args = $m<args>; |
| 35 | | Apply.newp($ident,Capture.newp($args||[])) |
| 36 | | } |
| 37 | | |
| 38 | | args |
| 39 | | $m<in> || $m<arglist> |
| 40 | | |
| 41 | | arglist |
| 42 | | # Actually an arg :/ |
| 43 | | $m<EXPR> |
| 44 | | |
| 45 | | in |
| | 123 | NumInt.newp(*text*,10) |
| | 124 | |
| | 125 | fatarrow |
| | 126 | Pair.newp($m<key>,$m<val>) |
| | 127 | |
| | 128 | |
| | 129 | term:identifier |
| | 130 | my $args = $m<args><semilist>; |
| | 131 | if not($args) && $o<args><arglist>[0]<EXPR> { |
| | 132 | $args = [ irbuild_ir($o<args><arglist>[0]<EXPR>) ]; |
| | 133 | } |
| | 134 | Apply.newp($m<identifier>,Capture.newp1($args||[])) |
| | 135 | |
| | 136 | |
| | 137 | statement_control:use |
| | 138 | Use.newp('use',$m<module_name>,$m<EXPR>) |
| | 139 | |
| | 140 | module_name:depreciated |
| | 141 | *text* |
| | 142 | |
| | 143 | module_name:normal |
| | 144 | *text* |
| | 145 | |
| | 146 | role_name |
| | 147 | *text* |
| | 148 | |
| | 149 | |
| | 150 | circumfix |
| | 151 | my $s = *text*; |
| | 152 | my $name = substr($s,0,1)~' '~substr($s,-1,1); # XXX :( |
| | 153 | my $args = $m<kludge_name>; |
| | 154 | if $args && ($args.WHAT ne 'Array') { $args = [$args] } |
| | 155 | Apply.newp("circumfix:"~$name,Capture.newp1($args||[])) |
| | 156 | |
| | 157 | |
| | 158 | quote |
| | 159 | my $nibs = $m<nibble><nibbles>; |
| | 160 | my $args = $nibs.map(sub($x){if $x.WHAT eq 'Str' {Buf.newp($x);} else {$x}}); |
| | 161 | Apply.newp('infix:~',Capture.newp1($args||[])) |
| | 162 | |
| | 163 | nibbles:\ |
| | 164 | my $which = $m<item><sym_name>; |
| | 165 | if $which eq 'n' { "\n" } |
| | 166 | if $which eq 't' { "\t" } |
| | 167 | else { $which } |
| | 168 | |
| | 169 | |
| | 170 | scope_declarator:my |
| | 171 | temp $blackboard::scope = 'my'; |
| | 172 | $m<scoped> |
| | 173 | |
| | 174 | scope_declarator:has |
| | 175 | temp $blackboard::scope = 'has'; |
| | 176 | $m<scoped> |
| | 177 | |
| | 178 | scope_declarator:our |
| | 179 | temp $blackboard::scope = 'our'; |
| | 180 | $m<scoped> |
| | 181 | |
| | 182 | scope_declarator:temp |
| | 183 | temp $blackboard::scope = 'temp'; |
| | 184 | $m<scoped> |
| | 185 | |
| | 186 | scoped |
| | 187 | temp $blackboard::typenames = $m<fulltypename>; |
| | 188 | $m<declarator> |
| | 189 | |
| | 190 | declarator |
| | 191 | $m<variable_declarator> || $m<signature> || $m<plurality_declarator> || $m<routine_declarator> || $m<type_declarator> |
| | 192 | |
| | 193 | variable_declarator |
| | 194 | my $scope = $blackboard::scope; temp $blackboard::scope; |
| | 195 | my $typenames = $blackboard::typenames; temp $blackboard::typenames = undef; |
| | 196 | VarDecl.newp($scope,$typenames,undef,$m<variable>,undef,$m<traits>,'=',$m<default_value>) |
| | 197 | #XXX default_value is going to take some non-local work. |
| | 198 | |
| | 199 | variable |
| | 200 | my $tw = $m<twigil>; |
| | 201 | if $o<postcircumfix> { |
| | 202 | if $tw eq "." { |
| | 203 | my $slf = Apply.newp('self',Capture.newp1([])); |
| | 204 | my $args = $m<postcircumfix><kludge_name>; |
| | 205 | if $args && ($args.WHAT ne 'Array') { $args = [$args] } |
| | 206 | Call.newp($slf,$m<desigilname>,Capture.newp1($args||[])) |
| | 207 | } else { |
| | 208 | my $v = Var.newp($m<sigil>,$tw,$m<desigilname>); |
| | 209 | temp $blackboard::expect_term_base = $v; |
| | 210 | $m<postcircumfix>; |
| | 211 | } |
| | 212 | } else { |
| | 213 | Var.newp($m<sigil>,$tw,$m<desigilname>); |
| | 214 | } |
| | 215 | |
| | 216 | sigil |
| | 217 | *text* |
| | 218 | |
| | 219 | twigil |
| | 220 | *text* |
| | 221 | |
| | 222 | special_variable |
| | 223 | my $v = *text*; |
| | 224 | my $s = substr($v,0,1); |
| | 225 | my $n = substr($v,1,$v.chars); |
| | 226 | Var.newp($s,undef,$n) |
| | 227 | |
| | 228 | |
| | 229 | statement_control:BEGIN |
| | 230 | ClosureTrait.newp('BEGIN',$m<block>) |
| | 231 | |
| | 232 | statement_control:for |
| | 233 | For.newp($m<EXPR>,$m<xblock>) |
| | 234 | |
| | 235 | statement_mod_loop:for |
| | 236 | For.newp($m<modifier_expr>,$blackboard::statement_expr) |
| | 237 | |
| | 238 | statement_control:while |
| | 239 | Loop.newp($m<EXPR>,$m<block>,undef,undef) |
| | 240 | |
| | 241 | statement_mod_loop:while |
| | 242 | Loop.newp($m<modifier_expr>,$blackboard::statement_expr,undef,undef) |
| | 243 | |
| | 244 | statement_control:until |
| | 245 | my $test = Apply.newp("not",Capture.newp1([$m<EXPR>])); |
| | 246 | Loop.newp($test,$m<block>,undef,undef) |
| | 247 | |
| | 248 | statement_mod_loop:until |
| | 249 | my $test = Apply.newp("not",Capture.newp1([$m<modifier_expr>])); |
| | 250 | Loop.newp($test,$blackboard::statement_expr,undef,undef) |
| | 251 | |
| | 252 | statement_control:loop |
| | 253 | my $e1 = $m<loop_eee><loop_e1>; |
| | 254 | my $e2 = $m<loop_eee><loop_e2>; |
| | 255 | my $e3 = $m<loop_eee><loop_e3>; |
| | 256 | my $block = $m<loop_block>; |
| | 257 | my $body = Loop.newp($e2,Block.newp([$block,$e3]),undef,undef); |
| | 258 | Block.newp([$e1,$body]) |
| | 259 | |
| | 260 | statement_control:if |
| | 261 | my $els = $m<else>; |
| | 262 | if $els { $els = $els[0] } |
| | 263 | Cond.newp([[$m<if_expr>,$m<if_block>]].push($m<elsif>.flatten),$els,undef) |
| | 264 | |
| | 265 | elsif |
| | 266 | [$m<elsif_expr>,$m<elsif_block>] |
| | 267 | |
| | 268 | if__else |
| 48 | | semilist |
| 49 | | $m<statement> # actuall a statement list :( |
| 50 | | |
| | 271 | statement_mod_cond:if |
| | 272 | Cond.newp([[$m<modifier_expr>,$blackboard::statement_expr]],undef,undef) |
| | 273 | |
| | 274 | statement_control:unless |
| | 275 | Cond.newp([[$m<EXPR>,$m<block>]],undef,1) |
| | 276 | |
| | 277 | statement_mod_cond:unless |
| | 278 | Cond.newp([[$m<modifier_expr>,$blackboard::statement_expr]],undef,1) |
| | 279 | |
| | 280 | |
| | 281 | statement_control:given |
| | 282 | Given.newp($m<EXPR>,$m<block>) |
| | 283 | |
| | 284 | statement_mod_loop:given |
| | 285 | Given.newp($m<modifier_expr>,$blackboard::statement_expr) |
| | 286 | |
| | 287 | statement_control:when |
| | 288 | When.newp($m<EXPR>,$m<block>) |
| | 289 | |
| | 290 | statement_mod_cond:when |
| | 291 | When.newp($m<modifier_expr>,$blackboard::statement_expr) |
| | 292 | |
| | 293 | statement_control:default |
| | 294 | When.newp(undef,$m<block>) |
| | 295 | |
| | 296 | |
| | 297 | statement_prefix:do |
| | 298 | Apply.newp("statement_prefix:do",Capture.newp1([$m<statement>])) |
| | 299 | |
| | 300 | statement_prefix:try |
| | 301 | Apply.newp("statement_prefix:try",Capture.newp1([$m<statement>])) |
| | 302 | |
| | 303 | statement_prefix:gather |
| | 304 | Apply.newp("statement_prefix:gather",Capture.newp1([$m<statement>])) |
| | 305 | |
| | 306 | statement_prefix:contend |
| | 307 | Apply.newp("statement_prefix:contend",Capture.newp1([$m<statement>])) |
| | 308 | |
| | 309 | statement_prefix:async |
| | 310 | Apply.newp("statement_prefix:async",Capture.newp1([$m<statement>])) |
| | 311 | |
| | 312 | statement_prefix:lazy |
| | 313 | Apply.newp("statement_prefix:lazy",Capture.newp1([$m<statement>])) |
| | 314 | |
| | 315 | |
| | 316 | pblock |
| | 317 | if $o<signature> { |
| | 318 | SubDecl.newp(undef,undef,undef,undef,$m<signature>,undef,$m<block>) |
| | 319 | } else { |
| | 320 | $m<block> |
| | 321 | } |
| | 322 | |
| | 323 | block |
| | 324 | Block.newp($m<statementlist>) |
| | 325 | |
| | 326 | xblock |
| | 327 | $m<pblock> |
| | 328 | |
| | 329 | plurality_declarator:multi |
| | 330 | temp $blackboard::plurality = 'multi'; |
| | 331 | $m<pluralized> || $m<routine_def> |
| | 332 | |
| | 333 | routine_declarator:routine_def |
| | 334 | my $scope = $blackboard::scope; temp $blackboard::scope; |
| | 335 | my $plurality = $blackboard::plurality; temp $blackboard::plurality; |
| | 336 | my $ident = ""; |
| | 337 | if $o<ident> { $ident = $m<ident> }; |
| | 338 | if ($o<ident> && not($scope)) { $scope = "our" }; |
| | 339 | my $sig = Signature.newp([],undef); |
| | 340 | if $m<multisig> { $sig = $m<multisig>.[0] }; |
| | 341 | SubDecl.newp($scope,undef,$plurality,$ident,$sig,$m<trait>,$m<block>) |
| | 342 | |
| | 343 | # routine_def is the same as routine_declarator:routine_def |
| | 344 | # This is a workaround for STD.pm not recognizing multi f(){} . |
| | 345 | routine_def |
| | 346 | my $scope = $blackboard::scope; temp $blackboard::scope; |
| | 347 | my $plurality = $blackboard::plurality; temp $blackboard::plurality; |
| | 348 | my $ident = ""; |
| | 349 | if $o<ident> { $ident = $m<ident> }; |
| | 350 | if ($o<ident> && not($scope)) { $scope = "our" }; |
| | 351 | my $sig = Signature.newp([],undef); |
| | 352 | if $m<multisig> { $sig = $m<multisig>.[0] }; |
| | 353 | SubDecl.newp($scope,undef,$plurality,$ident,$sig,$m<trait>,$m<block>) |
| | 354 | |
| | 355 | routine_declarator:method_def |
| | 356 | my $plurality = $blackboard::plurality; temp $blackboard::plurality; |
| | 357 | my $multisig = $m<multisig>; |
| | 358 | if not($multisig) { $multisig = [Signature.newp([],undef)]; } |
| | 359 | MethodDecl.newp(undef,undef,$plurality,$m<ident>,$multisig.[0],$m<trait>,$m<block>,undef,undef) |
| | 360 | |
| | 361 | signature |
| | 362 | Signature.newp($m<parsep>,undef) |
| | 363 | |
| | 364 | parameter |
| | 365 | Parameter.newp($m<type_constraint>,$m<quantchar>,$m<param_var>,undef,undef,undef,undef) |
| | 366 | |
| | 367 | param_var |
| | 368 | ParamVar.newp($m<sigil>,$m<twigil>,$m<ident>) |
| | 369 | |
| | 370 | capture |
| | 371 | if not($o<EXPR>) { |
| | 372 | Capture.newp1([]) |
| | 373 | } |
| | 374 | elsif $o<EXPR><noun> { |
| | 375 | Capture.newp1([$m<EXPR><noun>]) |
| | 376 | } |
| | 377 | elsif $o<EXPR><sym> && $o<EXPR><sym> eq ':' { |
| | 378 | my $args = $m<EXPR><args>; |
| | 379 | my $inv = $args.shift; |
| | 380 | Capture.newp($args||[],$inv) |
| | 381 | } |
| | 382 | elsif $o<EXPR><sym> && $o<EXPR><sym> eq ',' { |
| | 383 | my $args = $o<EXPR><args>; |
| | 384 | my $arg0 = $args && $args[0]; |
| | 385 | my $inv = undef; |
| | 386 | if $arg0 && $arg0<sym> && $arg0<sym> eq ':' { |
| | 387 | $args.shift; |
| | 388 | $inv = $arg0<args>[0]; |
| | 389 | if $arg0<args>[1] { |
| | 390 | $args.unshift($arg0<args>[1]); |
| | 391 | } |
| | 392 | } |
| | 393 | Capture.newp(ir($args)||[],ir($inv)) |
| | 394 | } |
| | 395 | else { die "capture AST form not recognized" } |
| | 396 | |
| | 397 | colonpair |
| | 398 | *1* |
| | 399 | |
| | 400 | colonpair__false |
| | 401 | Pair.newp($m<ident>,NumInt.newp(0)) |
| | 402 | |
| | 403 | colonpair__value |
| | 404 | my $value; |
| | 405 | if $o<postcircumfix> { |
| | 406 | $value = $m<postcircumfix><kludge_name>; |
| | 407 | } else { |
| | 408 | $value = NumInt.newp(1); |
| | 409 | } |
| | 410 | Pair.newp($m<ident>,$value) |
| | 411 | |
| | 412 | quotepair |
| | 413 | *1* |
| | 414 | |
| | 415 | quotepair__false |
| | 416 | Pair.newp($m<ident>,NumInt.newp(0)) |
| | 417 | |
| | 418 | quotepair__value |
| | 419 | my $value; |
| | 420 | if $o<postcircumfix> { |
| | 421 | $value = $m<postcircumfix><kludge_name>; |
| | 422 | } else { |
| | 423 | $value = NumInt.newp(1); |
| | 424 | } |
| | 425 | Pair.newp($m<ident>,$value) |
| | 426 | |
| | 427 | quotepair__nth |
| | 428 | Pair.newp('nth',$m<n>) |
| | 429 | |
| | 430 | |
| | 431 | package_declarator:role |
| | 432 | temp $blackboard::package_declarator = 'role'; |
| | 433 | $m<package_def> |
| | 434 | |
| | 435 | package_declarator:class |
| | 436 | temp $blackboard::package_declarator = 'class'; |
| | 437 | $m<package_def> |
| | 438 | |
| | 439 | package_declarator:module |
| | 440 | temp $blackboard::package_declarator = 'module'; |
| | 441 | $m<package_def> |
| | 442 | |
| | 443 | package_declarator:package |
| | 444 | temp $blackboard::package_declarator = 'package'; |
| | 445 | $m<package_def> |
| | 446 | |
| | 447 | package_declarator:grammar |
| | 448 | temp $blackboard::package_declarator = 'grammar'; |
| | 449 | $m<package_def> |
| | 450 | |
| | 451 | package_def |
| | 452 | PackageDecl.newp(undef,undef,$blackboard::package_declarator,$m<module_name>.[0],$m<traits>,$m<block>) |
| | 453 | |
| | 454 | fulltypename |
| | 455 | $m<typename>.join("::") |
| | 456 | |
| | 457 | typename |
| | 458 | *text* # $m<name> |
| | 459 | |
| | 460 | trait_verb:is |
| | 461 | Trait.newp('is',$m<ident>) |
| | 462 | |
| | 463 | trait_verb:does |
| | 464 | Trait.newp('does',$m<role_name>) |
| | 465 | |
| | 466 | |
| | 467 | circumfix:pblock |
| | 468 | if $o<block><statementlist>.elems == 0 or $o<block><statementlist>[0].match_string.re_matchp('^:') { |
| | 469 | Hash.newp($m<block><statementlist>) |
| | 470 | } elsif $o<block><statementlist>[0]<EXPR> and $o<block><statementlist>[0]<EXPR><sym> and $o<block><statementlist>[0]<EXPR><sym> eq "," { # XXX Not p6. Remove once off elf_e, and Match updated. |
| | 471 | Hash.newp($m<block><statementlist>) |
| | 472 | } elsif $o<block><statementlist>[0]<EXPR> and $o<block><statementlist>[0]<EXPR><sym> and $o<block><statementlist>[0]<EXPR><sym> eq "=>" { |
| | 473 | Hash.newp($m<block><statementlist>) |
| | 474 | } elsif not($m<lambda>) and not($m<signature>) { |
| | 475 | $m<block> |
| | 476 | } else { |
| | 477 | die "AST handler circumfix:pblock partially unimplemented"; |
| | 478 | } |
| | 479 | |
| | 480 | |
| | 481 | quote:regex |
| | 482 | my $s = $m<text> || $m<quotesnabber><text>; |
| | 483 | Rx.newp($s,$m<quotepair>) |
| | 484 | |
| | 485 | regex_declarator:regex_def |
| | 486 | RegexDef.newp($m<ident>,$m<regex_block>) |
| | 487 | |
| | 488 | regex_block |
| | 489 | $m<regex> |
| | 490 | |
| | 491 | regex |
| | 492 | Regex.newp($m<pattern>) |
| | 493 | |
| | 494 | regex_first |
| | 495 | RxFirst.newp($m<patterns>) |
| | 496 | |
| | 497 | regex_every |
| | 498 | RxEvery.newp($m<patterns>) |
| | 499 | |
| | 500 | regex_submatch |
| | 501 | RxSubmatch.newp($m<patterns>) |
| | 502 | |
| | 503 | regex_any |
| | 504 | RxAny.newp($m<patterns>) |
| | 505 | |
| | 506 | regex_all |
| | 507 | RxAll.newp($m<patterns>) |
| | 508 | |
| | 509 | regex_sequence |
| | 510 | RxSequence.newp($m<patterns>) |
| | 511 | |
| | 512 | regex_quantified_atom |
| | 513 | RxQuantifiedAtom.newp($m<regex_atom>,$m<regex_quantifier>) |
| | 514 | |
| | 515 | regex_quantifier |
| | 516 | *text* |
| | 517 | |
| | 518 | regex_atom |
| | 519 | if $m<char> { RxLiteral.newp($m<char>,"'") } else { *1* } |
| | 520 | |
| | 521 | regex_metachar:regex_backslash |
| | 522 | RxBackslash.newp(*text*) |
| | 523 | |
| | 524 | regex_metachar:regex_mod_internal |
| | 525 | RxModInternal.newp(*text*) |
| | 526 | |
| | 527 | regex_assertion:ident |
| | 528 | RxAssertion.newp($m<ident>) |
| | 529 | |
| | 530 | regex_metachar:capture |
| | 531 | RxCapture.newp($m<regex><pattern>) |
| | 532 | |
| | 533 | regex_metachar:group |
| | 534 | RxGroup.newp($m<regex><pattern>) |
| | 535 | |
| | 536 | regex_metachar:block |
| | 537 | RxBlock.newp($m<block>) |
| | 538 | |
| | 539 | regex_metachar:var |
| | 540 | RxBind.newp($m<variable>,$m<binding>) |
| | 541 | |
| | 542 | regex_metachar:q |
| | 543 | RxLiteral.newp($m<text>,"'") |
| | 544 | |
| | 545 | regex_metachar:qq |
| | 546 | RxLiteral.newp($m<text>,'"') |
| | 547 | |
| | 548 | regex_metachar |
| | 549 | RxSymbol.newp(*text*) |