| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Lingy::Compiler::YAML; |
|
2
|
1
|
|
|
1
|
|
845
|
use Lingy::Base; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
|
|
extends 'Lingy::Compiler'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
has file => (); |
|
6
|
|
|
|
|
|
|
has text => (); |
|
7
|
|
|
|
|
|
|
# XXX should be inherited from Lingy::Compiler. |
|
8
|
|
|
|
|
|
|
has ast => sub { Lingy::AST->new }; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use YAML::XS; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
300
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub BUILD { |
|
13
|
0
|
|
|
0
|
0
|
|
my ($self) = shift; |
|
14
|
0
|
0
|
0
|
|
|
|
die "Lingy Compiler requires 'text' or 'file' attribute" |
|
15
|
|
|
|
|
|
|
unless $self->{text} or $self->{file}; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub compile { |
|
19
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
20
|
0
|
|
|
|
|
|
my $input = $self->get_input; |
|
21
|
0
|
|
|
|
|
|
my $code = $self->{code} = YAML::XS::Load($input); |
|
22
|
0
|
0
|
|
|
|
|
$code->{type} eq 'Module' |
|
23
|
|
|
|
|
|
|
or die "Unknown Lingy type: '$code->{type}'"; |
|
24
|
0
|
|
|
|
|
|
my $ast = $self->ast; |
|
25
|
0
|
|
|
|
|
|
my $module = $ast->module; |
|
26
|
0
|
0
|
|
|
|
|
$module->{name} = $code->{name} |
|
27
|
|
|
|
|
|
|
or die "Unknown name for Lingy Module"; |
|
28
|
0
|
|
|
|
|
|
for my $class (@{$code->{class}}) { |
|
|
0
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
push @{$module->{class}}, $self->compile_class($class); |
|
|
0
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
} |
|
31
|
0
|
|
|
|
|
|
return $ast; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub compile_class { |
|
35
|
0
|
|
|
0
|
0
|
|
my ($self, $code) = @_; |
|
36
|
0
|
|
|
|
|
|
XXX $code; |
|
37
|
0
|
|
|
|
|
|
my $class = Lingy::Class->new; |
|
38
|
0
|
|
|
|
|
|
$class->{name} = $code->{name}; |
|
39
|
0
|
|
|
|
|
|
return $class; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_input { |
|
43
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
44
|
0
|
0
|
|
|
|
|
if ($self->{text}) { |
|
45
|
0
|
|
|
|
|
|
return $self->{text}; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
else { |
|
48
|
0
|
0
|
|
|
|
|
my $file = $self->{file} |
|
49
|
|
|
|
|
|
|
or die "No input for compile"; |
|
50
|
0
|
0
|
|
|
|
|
open my $fh, $file |
|
51
|
|
|
|
|
|
|
or die "Can't open '$file' for input"; |
|
52
|
0
|
|
|
|
|
|
local $/; |
|
53
|
0
|
|
|
|
|
|
return <$fh>; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |