-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubst.yp
97 lines (87 loc) · 1.73 KB
/
subst.yp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl
%%
input:
| input '('
{
# print "hi1\n";
"$_[1]$_[2]";
}
| input ')'
{
# print "hi2\n";
"$_[1]$_[2]";
}
| input WORD
{
# print "hi3\n";
"$_[1]$_[2]";
}
| input '.'
{
# print "hi4\n";
"$_[1]$_[2]";
}
| input subst
{
# print "hi5\n";
"$_[1]$_[2]";
}
;
subst: '%' WORD '%'
{
# print "hi6\n";
"($_[2])";
}
| '%' WORD '(' args ')' '%'
{
# print "hi7\n";
"($_[2]($_[4]))";
}
| '%' WORD '.' WORD '%'
{
# print "hi8\n";
"($_[2].$_[4])";
}
| '%' WORD '.' WORD '(' args ')' '%'
{
# print "hi9\n";
"($_[2].$_[4]($_[6]))";
}
;
args:
| args WORD
{
# print "hi10\n";
"$_[1]$_[2]";
}
| args '.'
{
# print "hi11\n";
"$_[1]$_[2]";
}
| args subst
{
# print "hi12\n";
"$_[1]$_[2]";
}
;
%%
sub make_lexer {
my $line = shift;
return sub {
my $parser = shift;
# print "lexer for $line\n";
$line =~ s/^%%// and return ('WORD', '%');
$line =~ s/^%// and return ('%', '%');
$line =~ s/^\.// and return ('.', '.');
$line =~ s/^\(// and return ('(', '(');
$line =~ s/^\)// and return (')', ')');
$line =~ s/^([^.%()]+)// and return ('WORD', $1);
return ('', undef);
};
};
sub parse_subst {
my $line = shift;
my $parser=new SubstParser();
$parser->YYParse(yylex => &make_lexer($line));
};