Skip to content

Commit

Permalink
pegex rafactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Sep 20, 2011
1 parent 8bd34e2 commit 1682c86
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
11 changes: 6 additions & 5 deletions lib/TestML/AST.pm
Expand Up @@ -66,7 +66,6 @@ sub got_code_expression {
push @$units, shift @$list if @$list;
$list = shift @$list || [];
for (@$list) {
# WWW $_;
my $unit = $_->[0]; #->{unit_call}[0][0];
push @$units, $unit;
}
Expand Down Expand Up @@ -152,10 +151,10 @@ sub got_function_object {
my $function = $self->function;
$self->function($self->function->outer);

if (@{$object->[0]} and @{$object->[0][0]}) {
if (ref($object->[0]) and ref($object->[0][0])) {
$function->signature($object->[0][0]);
}
$function->statements($object->[2]);
$function->statements($object->[-1]);

return $function;
}
Expand All @@ -180,13 +179,15 @@ sub got_transform_name {
sub got_transform_object {
my ($self, $object) = @_;
my $transform = $object->[0];
if ($object->[1][-1] and $object->[1][-1] eq 'explicit') {
$transform->explicit_call(1);
splice @{$object->[1]}, -1, 1;
}
my $args = [];
push @$args, $object->[1][0][0],
if $object->[1][0][0];
push @$args, map $_->[0], @{$object->[1][0][1]};
$transform->args($args) if @$args;
$transform->explicit_call(1)
if $object->[1][1];
return $transform;
}

Expand Down
49 changes: 48 additions & 1 deletion t/ast/types.tml
Expand Up @@ -12,7 +12,7 @@ statements:
- !!perl/hash:TestML::Expression
units:
- !!perl/hash:TestML::Num
value: '11'
value: '14'
name: Set
- !!perl/hash:TestML::Statement
expression: !!perl/hash:TestML::Expression
Expand Down Expand Up @@ -117,6 +117,53 @@ statements:
statements: []
- !!perl/hash:TestML::Transform
name: Type
- !!perl/hash:TestML::Statement
assertion: !!perl/hash:TestML::Assertion
expression: !!perl/hash:TestML::Expression
units:
- !!perl/hash:TestML::Str
value: Func
name: EQ
expression: !!perl/hash:TestML::Expression
units:
- !!perl/hash:TestML::Function
signature:
- a
statements: []
- !!perl/hash:TestML::Transform
name: Type
- !!perl/hash:TestML::Statement
assertion: !!perl/hash:TestML::Assertion
expression: !!perl/hash:TestML::Expression
units:
- !!perl/hash:TestML::Str
value: Func
name: EQ
expression: !!perl/hash:TestML::Expression
units:
- !!perl/hash:TestML::Function
signature:
- a
- b
statements: []
- !!perl/hash:TestML::Transform
name: Type
- !!perl/hash:TestML::Statement
assertion: !!perl/hash:TestML::Assertion
expression: !!perl/hash:TestML::Expression
units:
- !!perl/hash:TestML::Str
value: Func
name: EQ
expression: !!perl/hash:TestML::Expression
units:
- !!perl/hash:TestML::Function
signature:
- a
- b
statements: []
- !!perl/hash:TestML::Transform
name: Type
- !!perl/hash:TestML::Statement
expression: !!perl/hash:TestML::Expression
units:
Expand Down
3 changes: 1 addition & 2 deletions t/compile.t
@@ -1,9 +1,8 @@
# BEGIN { $Pegex::Parser::Debug = 1 }
# use Test::Differences; *is = \&eq_or_diff;
use Test::More tests => 12;
use strict;

# use Test::Differences; *is = \&eq_or_diff;

use TestML::Compiler;
use YAML::XS;

Expand Down
5 changes: 4 additions & 1 deletion t/testml/types.tml
@@ -1,6 +1,6 @@
%TestML 1.0

Plan = 11;
Plan = 14;

Label = 'Test $TestNumber';

Expand All @@ -11,6 +11,9 @@ List(1,2,3).Type == 'List';
# [].Type == 'List';
{}.Type == 'Func';
(){}.Type == 'Func';
(a){}.Type == 'Func';
(a,b){}.Type == 'Func';
(a, b){}.Type == 'Func';

s = 'Foo';
s.Type == 'Str';
Expand Down

0 comments on commit 1682c86

Please sign in to comment.