Permalink
Browse files

Perlito5 - parser - subroutine attributes

  • Loading branch information...
1 parent 174d943 commit c2716c02af5946964adfc5af4417e213f34debfd @fglock committed Aug 6, 2013
Showing with 123 additions and 12 deletions.
  1. +1 −0 TODO-perlito5
  2. +55 −4 html/perlito5.js
  3. +48 −4 perlito5.pl
  4. +1 −0 src5/lib/Perlito5/AST.pm
  5. +9 −2 src5/lib/Perlito5/Grammar.pm
  6. +9 −2 src5/lib/Perlito5/Grammar/Block.pm
View
@@ -34,6 +34,7 @@ TODO list for Perlito5
-- attributes
http://perldoc.perl.org/attributes.html
+ missing MODIFY_CODE_ATTRIBUTES handlers
-- create __DATA__
http://perldoc.perl.org/SelfLoader.html#The-__DATA__-token
View
@@ -8310,7 +8310,7 @@ return r;
var v_pos1;
(v_pos1 = ((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')));
return (p5context([(function () {
- return (p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5context([(function () {
+ return (p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5context([(function () {
var v_m2;
(v_m2 = (p5call(p5pkg["Perlito5::Grammar"], "optional_namespace_before_ident", p5list_to_a(v_str, (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')), 0)));
if ( p5bool(v_m2) ) {
@@ -8357,6 +8357,29 @@ return r;
else {
return (p5context([0], p5want));
}
+ })()], 0) }), function () { return p5context([(function () {
+ var v_m2;
+ (v_m2 = (p5call(p5pkg["Perlito5::Grammar::Attribute"], "opt_attribute", p5list_to_a(v_str, (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')), 0)));
+ if ( p5bool(v_m2) ) {
+ (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('to', ((v_m2 || (v_m2 = new p5HashRef({})))._hash_.p5hget('to')));
+ (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('Perlito5::Grammar::Attribute.opt_attribute', (v_m2));
+ return (p5context([1], p5want));
+ }
+
+ else {
+ return (p5context([0], p5want));
+ }
+ })()], 0) }), function () { return p5context([(function () {
+ var v_m2;
+ (v_m2 = (p5call(p5pkg["Perlito5::Grammar"], "opt_ws", p5list_to_a(v_str, (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')), 0)));
+ if ( p5bool(v_m2) ) {
+ (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('to', ((v_m2 || (v_m2 = new p5HashRef({})))._hash_.p5hget('to')));
+ return (p5context([1], p5want));
+ }
+
+ else {
+ return (p5context([0], p5want));
+ }
})()], 0) }), function () { return p5context([p5and(('{' == p5pkg["Perlito5::Grammar::Block"].substr([v_str, (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to'), 1], 0)), function () { return p5context([(v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('to', ((1 + p5num((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')))))], 0) })], 0) }), function () { return p5context([(function () {
var v_m2;
(v_m2 = (p5call(p5pkg["Perlito5::Grammar"], "opt_ws", p5list_to_a(v_str, (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')), 0)));
@@ -8428,7 +8451,7 @@ return r;
(p5make_package("Perlito5")["v_PROTO"] || (p5make_package("Perlito5")["v_PROTO"] = new p5HashRef({})))._hash_.p5hset(p5str(v_full_name), (v_sig));
})();
};
- (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('capture', (p5call(p5pkg["Perlito5::AST::Sub"], "new", p5list_to_a('name', v_name, 'namespace', v_namespace, 'sig', v_sig, 'block', p5pkg["Perlito5::Match"].flat(p5list_to_a((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('Perlito5::Grammar.exp_stmts')), 1)), 0)));
+ (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('capture', (p5call(p5pkg["Perlito5::AST::Sub"], "new", p5list_to_a('name', v_name, 'namespace', v_namespace, 'sig', v_sig, 'block', p5pkg["Perlito5::Match"].flat(p5list_to_a((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('Perlito5::Grammar.exp_stmts')), 1), 'attributes', p5pkg["Perlito5::Match"].flat(p5list_to_a((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('Perlito5::Grammar::Attribute.opt_attribute')), 1)), 0)));
return (p5context([1], p5want));
})()], p5want) }));
})()], p5want));
@@ -9351,6 +9374,8 @@ return r;
;
// use Perlito5::Grammar::Print
;
+ // use Perlito5::Grammar::Attribute
+;
p5make_sub("Perlito5::Grammar", "word", function (List__, p5want) {
return (( p5bool((p5str(p5pkg["Perlito5::Grammar"].substr([List__.p5aget(1), List__.p5aget(2), 1], p5want)).match(/\w/) ? 1 : 0)) ? (new p5HashRef(p5a_to_h(p5list_to_a('str', List__.p5aget(1), 'from', List__.p5aget(2), 'to', (p5num(List__.p5aget(2)) + 1))))) : 0));
});
@@ -10932,7 +10957,7 @@ return r;
var v_pos1;
(v_pos1 = ((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')));
return (p5context([(function () {
- return (p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5context([(function () {
+ return (p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5and(p5context([(function () {
var v_m2;
(v_m2 = (p5call(v_grammar, "prototype", p5list_to_a(v_str, (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')), 0)));
if ( p5bool(v_m2) ) {
@@ -10955,6 +10980,29 @@ return r;
else {
return (p5context([0], p5want));
}
+ })()], 0) }), function () { return p5context([(function () {
+ var v_m2;
+ (v_m2 = (p5call(p5pkg["Perlito5::Grammar::Attribute"], "opt_attribute", p5list_to_a(v_str, (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')), 0)));
+ if ( p5bool(v_m2) ) {
+ (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('to', ((v_m2 || (v_m2 = new p5HashRef({})))._hash_.p5hget('to')));
+ (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('Perlito5::Grammar::Attribute.opt_attribute', (v_m2));
+ return (p5context([1], p5want));
+ }
+
+ else {
+ return (p5context([0], p5want));
+ }
+ })()], 0) }), function () { return p5context([(function () {
+ var v_m2;
+ (v_m2 = (p5call(p5pkg["Perlito5::Grammar"], "opt_ws", p5list_to_a(v_str, (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')), 0)));
+ if ( p5bool(v_m2) ) {
+ (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('to', ((v_m2 || (v_m2 = new p5HashRef({})))._hash_.p5hget('to')));
+ return (p5context([1], p5want));
+ }
+
+ else {
+ return (p5context([0], p5want));
+ }
})()], 0) }), function () { return p5context([p5and(('{' == p5pkg["Perlito5::Grammar"].substr([v_str, (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to'), 1], 0)), function () { return p5context([(v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('to', ((1 + p5num((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')))))], 0) })], 0) }), function () { return p5context([(function () {
var v_m2;
(v_m2 = (p5call(v_grammar, "opt_ws", p5list_to_a(v_str, (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('to')), 0)));
@@ -11009,7 +11057,7 @@ return r;
if ( (p5str(v_sig) == '*undef*') ) {
(v_sig = (null));
};
- (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('capture', (p5call(p5pkg["Perlito5::AST::Sub"], "new", p5list_to_a('name', null, 'namespace', null, 'sig', v_sig, 'block', p5pkg["Perlito5::Match"].flat(p5list_to_a((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('exp_stmts')), 1)), 0)));
+ (v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hset('capture', (p5call(p5pkg["Perlito5::AST::Sub"], "new", p5list_to_a('name', null, 'namespace', null, 'sig', v_sig, 'block', p5pkg["Perlito5::Match"].flat(p5list_to_a((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('exp_stmts')), 1), 'attributes', p5pkg["Perlito5::Match"].flat(p5list_to_a((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('Perlito5::Grammar::Attribute.opt_attribute')), 1)), 0)));
return (p5context([1], p5want));
})()], p5want) }));
})()], p5want));
@@ -11483,6 +11531,9 @@ return r;
p5make_sub("Perlito5::AST::Sub", "block", function (List__, p5want) {
return (List__.p5aget_hash(0)._hash_.p5hget('block'));
});
+ p5make_sub("Perlito5::AST::Sub", "attributes", function (List__, p5want) {
+ return (List__.p5aget_hash(0)._hash_.p5hget('attributes'));
+ });
var p5140 = p5make_package("Perlito5::AST::Do");
p5make_sub("Perlito5::AST::Do", "new", function (List__, p5want) {
var v_class;
View
@@ -6153,7 +6153,7 @@ sub Perlito5::Grammar::Block::named_sub_def {
((my $tmp) = (((do {
((my $pos1) = $MATCH->{'to'});
((do {
- (((((((((((do {
+ (((((((((((((do {
((my $m2) = Perlito5::Grammar->optional_namespace_before_ident($str, $MATCH->{'to'}));
if ($m2) {
($MATCH->{'to'} = $m2->{'to'});
@@ -6192,6 +6192,25 @@ sub Perlito5::Grammar::Block::named_sub_def {
else {
0
}
+}))) && ((do {
+ ((my $m2) = Perlito5::Grammar::Attribute->opt_attribute($str, $MATCH->{'to'}));
+ if ($m2) {
+ ($MATCH->{'to'} = $m2->{'to'});
+ ($MATCH->{'Perlito5::Grammar::Attribute.opt_attribute'} = $m2);
+ 1
+ }
+ else {
+ 0
+ }
+}))) && ((do {
+ ((my $m2) = Perlito5::Grammar->opt_ws($str, $MATCH->{'to'}));
+ if ($m2) {
+ ($MATCH->{'to'} = $m2->{'to'});
+ 1
+ }
+ else {
+ 0
+ }
}))) && ((('{' eq substr($str, $MATCH->{'to'}, 1)) && (($MATCH->{'to'} = (1 + $MATCH->{'to'})))))) && ((do {
((my $m2) = Perlito5::Grammar->opt_ws($str, $MATCH->{'to'}));
if ($m2) {
@@ -6250,7 +6269,7 @@ sub Perlito5::Grammar::Block::named_sub_def {
};
($Perlito5::PROTO->{$full_name} = $sig)
};
- ($MATCH->{'capture'} = Perlito5::AST::Sub->new('name', $name, 'namespace', $namespace, 'sig', $sig, 'block', Perlito5::Match::flat($MATCH->{'Perlito5::Grammar.exp_stmts'})));
+ ($MATCH->{'capture'} = Perlito5::AST::Sub->new('name', $name, 'namespace', $namespace, 'sig', $sig, 'block', Perlito5::Match::flat($MATCH->{'Perlito5::Grammar.exp_stmts'}), 'attributes', Perlito5::Match::flat($MATCH->{'Perlito5::Grammar::Attribute.opt_attribute'})));
1
})))
}))
@@ -6964,6 +6983,9 @@ package Perlito5::Grammar;
# use Perlito5::Grammar::Print
;
+
+# use Perlito5::Grammar::Attribute
+;
sub Perlito5::Grammar::word {
((substr($_[1], $_[2], 1) =~ m!\w!) ? {'str', $_[1], 'from', $_[2], 'to', ($_[2] + 1)} : 0)
};
@@ -8261,7 +8283,7 @@ sub Perlito5::Grammar::anon_sub_def {
((my $tmp) = (((do {
((my $pos1) = $MATCH->{'to'});
((do {
- (((((((((do {
+ (((((((((((do {
((my $m2) = $grammar->prototype($str, $MATCH->{'to'}));
if ($m2) {
($MATCH->{'to'} = $m2->{'to'});
@@ -8280,6 +8302,25 @@ sub Perlito5::Grammar::anon_sub_def {
else {
0
}
+}))) && ((do {
+ ((my $m2) = Perlito5::Grammar::Attribute->opt_attribute($str, $MATCH->{'to'}));
+ if ($m2) {
+ ($MATCH->{'to'} = $m2->{'to'});
+ ($MATCH->{'Perlito5::Grammar::Attribute.opt_attribute'} = $m2);
+ 1
+ }
+ else {
+ 0
+ }
+}))) && ((do {
+ ((my $m2) = Perlito5::Grammar->opt_ws($str, $MATCH->{'to'}));
+ if ($m2) {
+ ($MATCH->{'to'} = $m2->{'to'});
+ 1
+ }
+ else {
+ 0
+ }
}))) && ((('{' eq substr($str, $MATCH->{'to'}, 1)) && (($MATCH->{'to'} = (1 + $MATCH->{'to'})))))) && ((do {
((my $m2) = $grammar->opt_ws($str, $MATCH->{'to'}));
if ($m2) {
@@ -8326,7 +8367,7 @@ sub Perlito5::Grammar::anon_sub_def {
if (($sig eq '*undef*')) {
($sig = undef())
};
- ($MATCH->{'capture'} = Perlito5::AST::Sub->new('name', undef(), 'namespace', undef(), 'sig', $sig, 'block', Perlito5::Match::flat($MATCH->{'exp_stmts'})));
+ ($MATCH->{'capture'} = Perlito5::AST::Sub->new('name', undef(), 'namespace', undef(), 'sig', $sig, 'block', Perlito5::Match::flat($MATCH->{'exp_stmts'}), 'attributes', Perlito5::Match::flat($MATCH->{'Perlito5::Grammar::Attribute.opt_attribute'})));
1
})))
}))
@@ -8582,6 +8623,9 @@ sub Perlito5::AST::Sub::sig {
sub Perlito5::AST::Sub::block {
$_[0]->{ 'block'}
};
+sub Perlito5::AST::Sub::attributes {
+ $_[0]->{ 'attributes'}
+};
package Perlito5::AST::Do;
sub Perlito5::AST::Do::new {
((my $class) = shift());
View
@@ -167,6 +167,7 @@ sub new { my $class = shift; bless {@_}, $class }
sub name { $_[0]->{name} }
sub sig { $_[0]->{sig} }
sub block { $_[0]->{block} }
+sub attributes { $_[0]->{attributes} }
@@ -8,6 +8,7 @@ use Perlito5::Grammar::Use;
use Perlito5::Grammar::Block;
use Perlito5::Grammar::Space;
use Perlito5::Grammar::Print;
+use Perlito5::Grammar::Attribute;
sub word {
substr( $_[1], $_[2], 1 ) =~ m/\w/
@@ -183,7 +184,12 @@ token prototype {
};
token anon_sub_def {
- <prototype> <.opt_ws> \{ <.opt_ws> <exp_stmts> <.opt_ws>
+ <prototype> <.opt_ws>
+ <Perlito5::Grammar::Attribute.opt_attribute> <.Perlito5::Grammar.opt_ws>
+ \{
+ <.opt_ws>
+ <exp_stmts>
+ <.opt_ws>
[ \} | { die 'Syntax Error in anon sub' } ]
{
my $sig = Perlito5::Match::flat($MATCH->{prototype});
@@ -192,7 +198,8 @@ token anon_sub_def {
name => undef,
namespace => undef,
sig => $sig,
- block => Perlito5::Match::flat($MATCH->{exp_stmts})
+ block => Perlito5::Match::flat($MATCH->{exp_stmts}),
+ attributes => Perlito5::Match::flat($MATCH->{"Perlito5::Grammar::Attribute.opt_attribute"}),
)
}
};
@@ -99,7 +99,13 @@ sub term_block {
}
token named_sub_def {
- <Perlito5::Grammar.optional_namespace_before_ident> <Perlito5::Grammar.ident> <Perlito5::Grammar.prototype> <.Perlito5::Grammar.opt_ws> \{ <.Perlito5::Grammar.opt_ws> <Perlito5::Grammar.exp_stmts> <.Perlito5::Grammar.opt_ws>
+ <Perlito5::Grammar.optional_namespace_before_ident> <Perlito5::Grammar.ident>
+ <Perlito5::Grammar.prototype> <.Perlito5::Grammar.opt_ws>
+ <Perlito5::Grammar::Attribute.opt_attribute> <.Perlito5::Grammar.opt_ws>
+ \{
+ <.Perlito5::Grammar.opt_ws>
+ <Perlito5::Grammar.exp_stmts>
+ <.Perlito5::Grammar.opt_ws>
[ \} | { die 'Syntax Error in sub \'', Perlito5::Match::flat($MATCH->{"Perlito5::Grammar.ident"}), '\'' } ]
{
my $name = Perlito5::Match::flat($MATCH->{"Perlito5::Grammar.ident"});
@@ -125,7 +131,8 @@ token named_sub_def {
name => $name,
namespace => $namespace,
sig => $sig,
- block => Perlito5::Match::flat($MATCH->{"Perlito5::Grammar.exp_stmts"})
+ block => Perlito5::Match::flat($MATCH->{"Perlito5::Grammar.exp_stmts"}),
+ attributes => Perlito5::Match::flat($MATCH->{"Perlito5::Grammar::Attribute.opt_attribute"}),
)
}
};

0 comments on commit c2716c0

Please sign in to comment.