Changeset 21193

Show
Ignore:
Timestamp:
07/03/08 22:05:08 (3 months ago)
Author:
pmurias
Message:

[sm0p] initial version of the new grammar

Location:
misc/sm0p
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • misc/sm0p/sm0p.pm

    r20888 r21193  
    11grammar sm0p; 
    22token frame { 
    3     <ws> <identifier> <ws> '=' <ws> 'q:sm0p' <ws> '{' <ws> <node>+ <ws> '}' <ws> ';' 
     3    <ws> <identifier>  <ws> '=' <ws> 'q:sm0p' <ws> '{' <ws> <nodes> <ws> '}' <ws> ';'? 
    44    { make $<identifier> ~ ' = SMOP_DISPATCH(interpreter, ' 
    55      ~ 'SMOP__SLIME__Frame, SMOP__ID__new, SMOP__NATIVE__capture_create(' 
    66      ~ 'interpreter, SMOP__SLIME__Frame, (SMOP__Object*[]){ ' 
    7       ~ ($$<node>).join(',') ~ ' }, NULL)); ' } 
    8 }; 
     7      ~ $<nodes> ~ ' }, NULL)); ' } 
     8} 
     9 
     10token nodes { 
     11    <node>* 
     12    { make $<node>.join(', ') } 
     13} 
    914 
    1015token node { 
     16    <node_empty> { make $<node_empty> ~ '' } 
     17    || <node_result> { make $<node_result> ~ '' } 
     18    || <node_capturized> { make $<node_capturized> ~ '' } 
     19    || <node_full> { make $<node_full> ~ '' } 
     20} 
     21 
     22token node_empty { 
     23    # <ws> 
     24  ';' 
     25    { make 'SMOP_DISPATCH(interpreter, SMOP__SLIME__Node, SMOP__ID__new, ' 
     26      ~ ' SMOP__NATIVE__capture_create(interpreter, SMOP__SLIME__Node, NULL, NULL))' } 
     27} 
     28 
     29token node_full { 
    1130    <ws> <responder> '.' <identifier> '(' 
    12     [ <ws> <invocant> <ws> ':' ]? <ws> <positional> <ws> <named> <ws> ')' ';' 
     31    [ <invocant>||'' ] <ws> <named> <ws> <positional> <ws> ')' <ws> ';' <ws> 
    1332    { make 'SMOP_DISPATCH(interpreter, SMOP__SLIME__Node, SMOP__ID__new, ' 
    1433      ~ ' SMOP__NATIVE__capture_create(interpreter, SMOP__SLIME__Node, NULL, (SMOP__Object*[]){' 
    15       ~ ' SMOP__ID__responder, SMOP_RI(' ~ $<responder> ~ '), ' 
    16       ~ ' SMOP__ID__identifier, ' ~ $<identifier> ~ ', ' 
     34      ~ ' SMOP__ID__responder, SMOP_REFERENCE(interpreter,(SMOP__Object*)SMOP_RI(' ~ $<responder> ~ ')), ' 
     35      ~ ' SMOP__ID__identifier, SMOP_REFERENCE(interpreter,' ~ $<identifier> ~ '), ' 
    1736      ~ ' SMOP__ID__capture, SMOP__NATIVE__capture_create(interpreter, ' 
    18       ~ ($<invocant> ?? $<invocant> !! $<responder>) ~ ', '~ $<positional> ~', '~ $<named> ~') ' 
    19       ~ ',NULL }))' } 
    20   | <ws> <identifier> <ws> ';' 
     37      ~ 'SMOP_REFERENCE(interpreter,' ~ ($<invocant> ?? $<invocant> !! $<responder>) ~ '), '~ $<positional> ~', '~ $<named> ~') ' 
     38      ~ ' , NULL  }))' } 
     39} 
     40 
     41token node_capturized { 
     42    <ws> <responder> '.' <identifier> '(' 
     43    <ws> '|' <identifier2> <ws> ')' <ws> ';' <ws> 
    2144    { make 'SMOP_DISPATCH(interpreter, SMOP__SLIME__Node, SMOP__ID__new, ' 
    2245      ~ ' SMOP__NATIVE__capture_create(interpreter, SMOP__SLIME__Node, NULL, (SMOP__Object*[]){' 
    23       ~ ' SMOP__ID__result, ' ~ $<identifier> 
    24       ~ ',NULL }))' } 
    25   | <ws> ';' 
     46      ~ ' SMOP__ID__responder, SMOP_REFERENCE(interpreter,(SMOP__Object*)SMOP_RI(' ~ $<responder> ~ ')), ' 
     47      ~ ' SMOP__ID__identifier, SMOP_REFERENCE(interpreter,' ~ $<identifier> ~ '), ' 
     48      ~ ' SMOP__ID__capture, ' ~ $<identifier2>  
     49      ~ ' , NULL  }))' } 
     50} 
     51 
     52token node_result { 
     53    <ws> <identifier> <ws> ';' 
    2654    { make 'SMOP_DISPATCH(interpreter, SMOP__SLIME__Node, SMOP__ID__new, ' 
    27       ~ ' SMOP__NATIVE__capture_create(interpreter, SMOP__SLIME__Node, NULL, NULL))' } 
    28 }; 
     55      ~ ' SMOP__NATIVE__capture_create(interpreter, SMOP__SLIME__Node, NULL, (SMOP__Object*[]){' 
     56      ~ ' SMOP__ID__result, SMOP_REFERENCE(interpreter,' ~ $<identifier> ~ ')' 
     57      ~ ' , NULL}))' } 
     58} 
    2959 
    3060token invocant { 
    31     <identifier> 
    32 }; 
     61    <ws> <identifier> <ws> ':' <ws> 
     62    { make $<identifier> ~ '' } 
     63} 
    3364 
    3465token responder { 
    3566    <identifier> 
    36 }; 
     67    { make $<identifier> ~ '' } 
     68} 
    3769 
    3870token positional { 
    3971    <positionals> 
    40     { make '(SMOP__Object*[]){' ~ ($$<positionals>).join(',') ~ ',NULL}'  } 
    41   | { make 'NULL' } 
    42 }; 
     72    { make '(SMOP__Object*[]){' ~ $<positionals> ~ '}'  } 
     73 ||{ make ' NULL' } 
     74} 
    4375 
    4476token positionals { 
    4577    <identifier> 
    4678    [ 
    47     |   <ws> \, <ws> <positionals> 
    48         { make [ $$<identifier>, ( $$<positionals> ).values ] } 
    49     |   <ws> [ \, <ws> | '' ] 
    50         { make [ $$<identifier> ] } 
     79   ||  <ws> \, <ws> <positionals> 
     80        { make $<identifier> ~ ', ' ~ $<positionals> } 
     81   ||  <ws> 
     82        { make $<identifier> ~ ', NULL' } 
    5183    ] 
    52 |   { make [ ] } 
    5384} 
    5485 
    5586token named { 
    5687    <pairs> 
    57     { make '(SMOP__Object*[]){' ~ ($$<pairs>).join(',') ~ ',NULL}'  } 
    58   | { make 'NULL' } 
    59 }; 
     88    { make '(SMOP__Object*[]){' ~ $<pairs> ~ '}'  } 
     89 ||{ make ' NULL' } 
     90} 
    6091 
    6192token pairs { 
    6293    <pair> 
    6394    [ 
    64     |   <ws> \, <ws> <pairs> 
    65         { make [ $$<pair>, ( $$<pairs> ).values ] } 
    66     |   <ws> [ \, <ws> | '' ] 
    67         { make [ $$<pair> ] } 
     95        <ws> \, <ws> <pairs> 
     96        { make $<pair> ~ ', ' ~ $<pairs> } 
     97   ||  <ws> [ \, <ws> | '' ] 
     98        { make $<pair> ~ ', NULL' } 
    6899    ] 
    69 |   { make [ ] } 
    70100} 
    71101 
     
    73103    <identifier> <ws> '=>' <ws> <identifier2> 
    74104    { make $<identifier> ~ ', ' ~ $<identifier2> } 
    75 }; 
     105} 
    76106 
    77107token identifier2 { 
    78     <identifier> 
    79 }; 
     108    <identifier> { make $<identifier> ~ '' } 
     109} 
    80110 
    81111token identifier { 
    82     '$' <name> { make $<name> } 
    83   | <idconst> { make $<idconst> } 
    84   | <name> { make $<name> } 
    85 }; 
     112    <capturize> { make $<capturize> ~ '' } 
     113 ||'$' <name> { make $<name> ~ '' } 
     114 ||<idconst> { make $<idconst> ~ ''} 
     115 ||<name> { make $<name> ~ '' } 
     116 ||<nativeint> { make $<nativeint> ~ '' } 
     117} 
    86118 
    87119token idconst { 
    88     new { make 'SMOP__ID__new' } 
    89   | lexical { make 'SMOP__ID__lexical' } 
    90 }; 
     120  <idconst_list> { make 'SMOP__ID__' ~ $/ ~ '' } 
     121} 
     122 
     123token idconst_list {(new|lexical|back|capture|continuation|continues|copy|current|debug|drop|DESTROYALL|eval|forget|free|goto|has_next|identifier|jail|lexical|loop|move_capturize|move_identifier|move_responder|new|next|past|push|responder|result|setr|outer)} 
    91124 
    92125token name { 
    93     <.alpha> [ <.alpha> | <.digit> ]+ 
    94 }; 
     126    <nameP5> 
     127} 
    95128 
    96 token ws { 
    97     [ \s | \n  | '#' .+? \n ]* 
    98 }; 
     129token ws  {\s*}  
    99130 
    100 token digit { 
    101     <[0-9]> 
    102 }; 
     131token capturize { 
     132    <ws> SMOP__SLIME__Capturize '.'  new  '(' <ws> 
     133    <cint1> <ws> ',' <ws> <cintlist1> <ws> ',' <ws> 
     134    <cintlist2> <ws> ',' <ws> <cint2> ')' 
     135    { make 'SMOP__SLIME__Capturize_create(' ~ $<cint1> ~ ',' 
     136      ~ $<cintlist1> ~ ',' ~ $<cintlist2> ~ ',' 
     137      ~ $<cint2> ~ ')' } 
     138} 
     139 
     140token cint1 { <cint> { make $<cint> ~ '' } } 
     141token cint2 { <cint> { make $<cint> ~ '' } } 
     142token cint { 
     143    <digitsP5> { make $/ ~ '' } 
     144} 
     145 
     146token cintlist1 { <cintlist> { make $<cintlist> ~ '' } } 
     147token cintlist2 { <cintlist> { make $<cintlist> ~ '' } } 
     148token cintlist { 
     149    '(' 
     150    [ <cintlistbody> ')' {make '(int[]){ '~ $<cintlistbody> ~ ' }' } 
     151   ||')' {make 'NULL'} ]  
     152  ||'' {make 'NULL'} 
     153} 
     154 
     155token cintlistbody { 
     156    <ws> <cint> <ws> 
     157[ 
     158     ',' <ws> <cintlistbody> <ws> 
     159     { make $<cint> ~ ', ' ~ $<cintlistbody> } 
     160   ||'' { make $<cint> ~ ', 0 '} 
     161    ] 
     162} 
     163 
     164token nativeint { 
     165    <digitsP5> { make 'SMOP__NATIVE__int_create(' ~ $/ ~ ')' } 
     166} 
     167 
     168token nativeint_list { 
     169    '(' <nativeint_list_body> 
     170    ')' {make '(SMOP__Object*[]){ '~ $<nativeint_list_body> ~ ' }' } 
     171  ||'' {make 'NULL'} 
     172} 
     173 
     174token nativeint_list_body { 
     175    <ws> <nativeint> <ws> 
     176    [ 
     177     ',' <ws> <nativeint_list_body> <ws> 
     178     { make $<nativeint> ~ ', ' ~ $<nativeint_list_body> } 
     179   ||'' { make $<nativeint> ~ ', NULL '} 
     180    ] 
     181} 
     182 
     183token nameP5 {<[a-zA-Z_]>\w*} 
     184#token nameP5 {<[a-zA-Z_]>\w*} 
     185token digitsP5 {\d+} 
  • misc/sm0p/sm0p_with_actions

    r20992 r21193  
    5454    exit; 
    5555} elsif ($vertical || $horizontal) { 
    56     print dump_match($what=>$r,{actions=>sub {@_},vertical=>$vertical}),"\n"; 
     56    print dump_match($what=>$r,{actions=>sub {"@_"},vertical=>$vertical}),"\n"; 
    5757} 
    5858print $r->item,"\n"; 
  • misc/sm0p/strip_out_actions

    r20904 r21193  
    2727    my $body = $3; 
    2828    my $end = $4; 
    29     $body =~ s/(?<!')\{ ($block) \}/push(@blocks,["${name}__sm0p_$nr",$1]);'{*}' . "  #= sm0p_" . $nr++/egx; 
     29    $body =~ s/(?<!')\{ ($block) \}/push(@blocks,["${name}__sm0p_$nr",$1]);'{*}' . "  #= sm0p_" . $nr++ . "\n" 
     30/egx; 
    3031    $start.$body.$end; 
    3132]exg; 
     
    4344} 
    4445sub adapter { 
    45     local $_; 
    4646    if (ref $_[0] eq 'ARRAY') { 
    4747        [map {$_->item} @{$_[0]}]; 
     48    } elsif ($_[0]) { 
     49        $_[0]->item; 
    4850    } else { 
    49         $_[0]->item; 
     51        $_[0] 
    5052    } 
    5153}