Skip to content

Commit

Permalink
Perlito5 - grammar - parsing rules for sort()
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Aug 10, 2013
1 parent 3f3ac31 commit 8370a18
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 61 deletions.
164 changes: 135 additions & 29 deletions html/perlito5.js

Large diffs are not rendered by default.

122 changes: 104 additions & 18 deletions perlito5.pl

Large diffs are not rendered by default.

67 changes: 59 additions & 8 deletions src5/lib/Perlito5/Grammar/Map.pm
Expand Up @@ -47,11 +47,14 @@ token term_map_or_grep {
# @contact = sort(find_records @key);
# @contact = sort(find_records (@key));

# TODO: sort VAR LIST

token term_sort {
# Note: this is sort-block; sort-expr is parsed as a normal subroutine
'sort' <.Perlito5::Grammar::Space.opt_ws>
[
<before '{'> <Perlito5::Expression.term_curly>
# sort BLOCK LIST
<Perlito5::Expression.term_curly>
<Perlito5::Expression.list_parse>
{
$MATCH->{capture} = [ 'term',
Expand All @@ -66,16 +69,64 @@ token term_sort {
]
}
|
'('
# sort SUBNAME LIST
<Perlito5::Grammar.full_ident>
<Perlito5::Expression.list_parse>
{
# TODO: '(' <opt_ws> SUBNAME <ws> LIST ')'
return;
my $name = Perlito5::Match::flat($MATCH->{"Perlito5::Grammar.full_ident"}); # TODO - split namespace
return if $Perlito5::CORE_PROTO->{$name} || $Perlito5::CORE_PROTO->{'CORE::' . $name};
$MATCH->{capture} = [ 'term',
Perlito5::AST::Apply->new(
code => 'sort',
arguments => [
$name,
@{ Perlito5::Expression::expand_list($MATCH->{'Perlito5::Expression.list_parse'}{capture}) }
],
namespace => ''
)
]
}
|
{
# TODO: SUBNAME LIST
return;
}
'(' <.Perlito5::Grammar::Space.opt_ws>

[
# sort '(' <opt_ws> SUBNAME <ws> LIST ')'
<Perlito5::Grammar.full_ident>
<.Perlito5::Grammar::Space.ws> # must have space
<Perlito5::Expression.paren_parse>
')'
{
my $name = Perlito5::Match::flat($MATCH->{"Perlito5::Grammar.full_ident"}); # TODO - split namespace
return if $Perlito5::CORE_PROTO->{$name} || $Perlito5::CORE_PROTO->{'CORE::' . $name};
$MATCH->{capture} = [ 'term',
Perlito5::AST::Apply->new(
code => 'sort',
arguments => [
$name,
@{ Perlito5::Expression::expand_list($MATCH->{'Perlito5::Expression.list_parse'}{capture}) }
],
namespace => ''
)
]
}
|
# sort '(' <opt_ws> BLOCK LIST ')'
<Perlito5::Expression.term_curly>
<Perlito5::Expression.list_parse>
')'
{
$MATCH->{capture} = [ 'term',
Perlito5::AST::Apply->new(
code => 'sort',
arguments => [
Perlito5::AST::Lit::Block->new( stmts => $MATCH->{'Perlito5::Expression.term_curly'}{capture}[2] ),
@{ Perlito5::Expression::expand_list($MATCH->{'Perlito5::Expression.list_parse'}{capture}) }
],
namespace => ''
)
]
}
]
]
};

Expand Down
14 changes: 8 additions & 6 deletions src5/lib/Perlito5/Javascript2/Runtime.pm
Expand Up @@ -160,13 +160,15 @@ function p5get_class_for_method(method, class_name, seen) {
return class_name
}
var isa = p5pkg[class_name].List_ISA;
for (var i = 0; i < isa.length; i++) {
if (!seen[isa[i]]) {
var m = p5get_class_for_method(method, isa[i], seen);
if (m) {
return m
if (isa) {
for (var i = 0; i < isa.length; i++) {
if (!seen[isa[i]]) {
var m = p5get_class_for_method(method, isa[i], seen);
if (m) {
return m
}
seen[isa[i]]++;
}
seen[isa[i]]++;
}
}
}
Expand Down

0 comments on commit 8370a18

Please sign in to comment.