| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Spp; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
47005
|
use 5.012; |
|
|
2
|
|
|
|
|
12
|
|
|
4
|
2
|
|
|
2
|
|
16
|
no warnings 'experimental'; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
80
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Exporter; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
165
|
|
|
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.02'; |
|
12
|
2
|
|
|
2
|
|
525
|
use Spp::Builtin; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
324
|
|
|
13
|
2
|
|
|
2
|
|
581
|
use Spp::Tools; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
194
|
|
|
14
|
2
|
|
|
2
|
|
464
|
use Spp::Ast; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
78
|
|
|
15
|
2
|
|
|
2
|
|
418
|
use Spp::Grammar; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
74
|
|
|
16
|
2
|
|
|
2
|
|
413
|
use Spp::Cursor; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
102
|
|
|
17
|
2
|
|
|
2
|
|
494
|
use Spp::MatchRule; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
233
|
|
|
18
|
2
|
|
|
2
|
|
576
|
use Spp::OptAst; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
164
|
|
|
19
|
2
|
|
|
2
|
|
526
|
use Spp::LintAst; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
93
|
|
|
20
|
2
|
|
|
2
|
|
11
|
use Spp::ToSpp; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
889
|
|
|
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
|
18
|
my ($ast, $text) = @_; |
|
45
|
3
|
|
|
|
|
17
|
my $table = ast_to_table($ast); |
|
46
|
3
|
|
|
|
|
11
|
my $rule = $table->{'door'}; |
|
47
|
3
|
|
|
|
|
20
|
my $cursor = new_cursor($text, $table); |
|
48
|
3
|
|
|
|
|
20
|
my $match = match_spp_rule($cursor, $rule); |
|
49
|
3
|
50
|
|
|
|
11
|
if (is_false($match)) { |
|
50
|
0
|
|
|
|
|
0
|
my $report = fail_report($cursor); |
|
51
|
0
|
|
|
|
|
0
|
return $report, 0; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
3
|
|
|
|
|
77
|
return $match, 1; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub grammar_to_ast { |
|
57
|
0
|
|
|
0
|
0
|
0
|
my $grammar = shift; |
|
58
|
0
|
|
|
|
|
0
|
my $spp_ast = get_spp_ast(); |
|
59
|
0
|
|
|
|
|
0
|
my $estr_ast = to_ejson($spp_ast); |
|
60
|
0
|
|
|
|
|
0
|
my ($match, $ok) = match_text($estr_ast, $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 ($match, $ok) = match_text($ast, $text); |
|
81
|
0
|
0
|
|
|
|
0
|
if ($ok) { return $match } |
|
|
0
|
|
|
|
|
0
|
|
|
82
|
0
|
|
|
|
|
0
|
else { error($match) } |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub spp_to_spp { |
|
86
|
3
|
|
|
3
|
0
|
2027
|
my $str = shift; |
|
87
|
3
|
|
|
|
|
17
|
my $spp_ast = to_ejson(get_spp_ast()); |
|
88
|
3
|
|
|
|
|
25
|
my ($match, $ok) = match_text($spp_ast, $str); |
|
89
|
3
|
50
|
|
|
|
48
|
if ($ok) { |
|
90
|
3
|
|
|
|
|
23
|
my $ast = opt_spp_ast($match); |
|
91
|
3
|
|
|
|
|
18
|
return ast_to_spp($ast); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
1; |