line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spp; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
47666
|
use 5.012; |
|
2
|
|
|
|
|
11
|
|
4
|
2
|
|
|
2
|
|
10
|
no warnings 'experimental'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Exporter; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
125
|
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
our @EXPORT = |
9
|
|
|
|
|
|
|
qw(spp_repl match_text grammar_to_ast lint_grammar parse_text spp_to_spp); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '2.03'; |
12
|
2
|
|
|
2
|
|
495
|
use Spp::Builtin; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
328
|
|
13
|
2
|
|
|
2
|
|
594
|
use Spp::Tools; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
200
|
|
14
|
2
|
|
|
2
|
|
482
|
use Spp::Ast; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
80
|
|
15
|
2
|
|
|
2
|
|
455
|
use Spp::Grammar; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
76
|
|
16
|
2
|
|
|
2
|
|
458
|
use Spp::Cursor; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
104
|
|
17
|
2
|
|
|
2
|
|
486
|
use Spp::MatchRule; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
232
|
|
18
|
2
|
|
|
2
|
|
679
|
use Spp::OptAst; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
486
|
|
19
|
2
|
|
|
2
|
|
499
|
use Spp::LintAst; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
95
|
|
20
|
2
|
|
|
2
|
|
13
|
use Spp::ToSpp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
910
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub spp_repl { |
23
|
0
|
|
|
0
|
0
|
0
|
my $spp_ast = get_spp_ast(); |
24
|
0
|
|
|
|
|
0
|
my $estr_ast = to_ejson($spp_ast); |
25
|
0
|
|
|
|
|
0
|
my $table = ast_to_table($estr_ast); |
26
|
0
|
|
|
|
|
0
|
my $door_rule = $table->{'door'}; |
27
|
0
|
|
|
|
|
0
|
say 'This is Spp REPL, type enter to exit.'; |
28
|
0
|
|
|
|
|
0
|
while (1) { |
29
|
0
|
|
|
|
|
0
|
print '>> '; |
30
|
0
|
|
|
|
|
0
|
my $line = <STDIN>; |
31
|
0
|
0
|
|
|
|
0
|
exit() if ord($line) == 10; |
32
|
0
|
|
|
|
|
0
|
my $cursor = new_cursor($line, $table); |
33
|
0
|
|
|
|
|
0
|
my $match = match_spp_rule($cursor, $door_rule); |
34
|
0
|
0
|
|
|
|
0
|
if (is_false($match)) { say fail_report($cursor) } |
|
0
|
|
|
|
|
0
|
|
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
|
|
|
0
|
say '.. ', see_ast($match); |
37
|
0
|
|
|
|
|
0
|
my $ast = opt_spp_ast($match); |
38
|
0
|
|
|
|
|
0
|
say '.. ', see_ast($ast); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub match_text { |
44
|
3
|
|
|
3
|
0
|
12
|
my ($table, $text) = @_; |
45
|
3
|
|
|
|
|
9
|
my $rule = $table->{'door'}; |
46
|
3
|
|
|
|
|
17
|
my $cursor = new_cursor($text, $table); |
47
|
3
|
|
|
|
|
18
|
my $match = match_spp_rule($cursor, $rule); |
48
|
3
|
50
|
|
|
|
11
|
if (is_false($match)) { |
49
|
0
|
|
|
|
|
0
|
my $report = fail_report($cursor); |
50
|
0
|
|
|
|
|
0
|
return $report, 0; |
51
|
|
|
|
|
|
|
} |
52
|
3
|
|
|
|
|
19
|
return $match, 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub grammar_to_ast { |
56
|
0
|
|
|
0
|
0
|
0
|
my $grammar = shift; |
57
|
0
|
|
|
|
|
0
|
my $spp_ast = get_spp_ast(); |
58
|
0
|
|
|
|
|
0
|
my $estr_ast = to_ejson($spp_ast); |
59
|
0
|
|
|
|
|
0
|
my $table = ast_to_table($estr_ast); |
60
|
0
|
|
|
|
|
0
|
my ($match, $ok) = match_text($table, $grammar); |
61
|
0
|
0
|
|
|
|
0
|
if ($ok) { |
62
|
0
|
|
|
|
|
0
|
my $ast = opt_spp_ast($match); |
63
|
0
|
|
|
|
|
0
|
lint_spp_ast($ast); |
64
|
0
|
|
|
|
|
0
|
return $ast; |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
0
|
else { error($match) } |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub lint_grammar { |
70
|
0
|
|
|
0
|
0
|
0
|
my $grammar = shift; |
71
|
0
|
|
|
|
|
0
|
my $ast = grammar_to_ast($grammar); |
72
|
0
|
|
|
|
|
0
|
lint_spp_ast($ast); |
73
|
0
|
|
|
|
|
0
|
return True; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub parse_text { |
77
|
0
|
|
|
0
|
0
|
0
|
my ($grammar, $text) = @_; |
78
|
0
|
|
|
|
|
0
|
my $ast = grammar_to_ast($grammar); |
79
|
0
|
|
|
|
|
0
|
lint_spp_ast($ast); |
80
|
0
|
|
|
|
|
0
|
my $table = ast_to_table($ast); |
81
|
0
|
|
|
|
|
0
|
my ($match, $ok) = match_text($table, $text); |
82
|
0
|
0
|
|
|
|
0
|
if ($ok) { return $match } |
|
0
|
|
|
|
|
0
|
|
83
|
0
|
|
|
|
|
0
|
else { error($match) } |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub spp_to_spp { |
87
|
3
|
|
|
3
|
0
|
1653
|
my $str = shift; |
88
|
3
|
|
|
|
|
15
|
my $spp_ast = to_ejson(get_spp_ast()); |
89
|
3
|
|
|
|
|
19
|
my $table = ast_to_table($spp_ast); |
90
|
3
|
|
|
|
|
25
|
my ($match, $ok) = match_text($table, $str); |
91
|
3
|
50
|
|
|
|
10
|
if ($ok) { |
92
|
3
|
|
|
|
|
14
|
my $ast = opt_spp_ast($match); |
93
|
3
|
|
|
|
|
14
|
return ast_to_spp($ast); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
1; |