Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
upstream namespace variable for version
  • Loading branch information
ingydotnet committed Mar 12, 2013
1 parent 38dbccc commit bfd1e00
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 2 additions & 0 deletions lib/TestML/Compiler.pm
Expand Up @@ -20,6 +20,8 @@ sub compile {
XXX($self->function);
}

$self->function->namespace->{TestML} = $self->directives->{TestML};

$self->function->outer(TestML::Function->new());
return $self->function;
}
Expand Down
30 changes: 13 additions & 17 deletions lib/TestML/Compiler/Lite.pm
Expand Up @@ -4,33 +4,28 @@

package TestML::Compiler::Lite;
use TestML::Base;
extends 'TestML::Compiler';

use TestML::Runtime;

has function => ();

# TODO Use more constants for regexes
use constant POINT => qr/^\*(\w+)/;


# Take a TestML(Lite) document and compile to a TestML::Function.
sub compile {
my ($self, $document) = @_;
sub compile_code {
my ($self) = @_;
$self->{function} = TestML::Function->new;
$document =~ /\A(.*?)(^===.*)?\z/ms or die;
my ($code, $data) = ($1, $2);
my $code = $self->code;
while (length $code) {
$code =~ s{(.*)$/}{};
$code =~ s{^(.*)\r?\n?}{};
my $line = $1;
$self->parse_comment($line) ||
$self->parse_directive($line) ||
$self->parse_assignment($line) ||
$self->parse_assertion($line) ||
die "Failed to parse TestML document, here:\n$line$/$code";
}
if ($data) {
$self->function->{data} = $self->compile_data($data);
}
$self->function->outer(TestML::Function->new());
return $self->function;
}

sub parse_comment {
Expand Down Expand Up @@ -190,10 +185,11 @@ sub get_token {
}

sub compile_data {
my ($self, $string);
$_[1] =~ s/^#.*\n/\n/mg;
$_[1] =~ s/^\\//mg;
my @blocks = grep $_, split /(^===.*?(?=^===|\z))/ms, $_[1];
my ($self) = @_;
my $input = $self->data;
$input =~ s/^#.*\n/\n/mg;
$input =~ s/^\\//mg;
my @blocks = grep $_, split /(^===.*?(?=^===|\z))/ms, $input;
for my $block (@blocks) {
$block =~ s/\n+\z/\n/;
}
Expand Down Expand Up @@ -224,7 +220,7 @@ sub compile_data {
}
push @$data, $block;
}
return $data;
$self->function->{data} = $data if @$data;
}

1;
3 changes: 0 additions & 3 deletions lib/TestML/Compiler/Pegex.pm
Expand Up @@ -38,9 +38,6 @@ sub fixup_grammar {

my $parser = $self->parser;

my $namespace = $parser->receiver->function->namespace;
$namespace->{TestML} = $self->directives->{TestML};

my $tree = $parser->grammar->tree;

my $point_lines = $tree->{point_lines}{'.rgx'};
Expand Down

0 comments on commit bfd1e00

Please sign in to comment.