File tree 1 file changed +104
-0
lines changed
1 file changed +104
-0
lines changed Original file line number Diff line number Diff line change
1
+ # !/usr/bin/env perl
2
+
3
+
4
+ # ### RE's
5
+
6
+ my $decl_re = qr /
7
+ ^
8
+ \s *
9
+ (method|func)
10
+ \s *
11
+ ([\w _]+)
12
+ \s *
13
+ [(]
14
+ (.+?)
15
+ [)]
16
+ \s *
17
+ [{]
18
+ $
19
+ / x ;
20
+
21
+ my $match_self_name = qr /
22
+ \s *
23
+ \$
24
+ ([\w _]+)
25
+ :
26
+ \s *
27
+ ,?
28
+ \s *
29
+ / x ;
30
+
31
+ my $match_pos_protos = qr /
32
+ \s *
33
+ \$
34
+ ([\w _]+)
35
+ \s *
36
+ (\? )?
37
+ \s *
38
+ ,?
39
+ \s *
40
+ / x ;
41
+
42
+ my $match_named_protos = qr /
43
+ \s *
44
+ :
45
+ \$
46
+ ([\w _]+)
47
+ \s *
48
+ (?:
49
+ =
50
+ \s *
51
+ (
52
+ (?:
53
+ ["']
54
+ .*?
55
+ ['"]
56
+ )
57
+ |
58
+ (?:
59
+ [{\] ]
60
+ .*?
61
+ [}\] ]
62
+ )
63
+ |
64
+ (?:
65
+ [^,]*
66
+ )
67
+ )
68
+ \s *
69
+ )?
70
+ \s *
71
+ ,?
72
+ \s *
73
+ / x ;
74
+
75
+
76
+ # ### Code
77
+
78
+ my $decl = do { local $\ ; <> };
79
+ my ($type , $name , $proto ) = $decl =~ m /$decl_re / ;
80
+ my @perl = (" sub $name {" );
81
+
82
+ if ($type eq ' method' ) {
83
+ if ($proto =~ s / ^$match_self_name// ) {
84
+ push @perl , " my \$ $1 = shift;" ;
85
+ }
86
+ else {
87
+ push @perl , ' my $self = shift;' ;
88
+ }
89
+ }
90
+
91
+ # # collect fixed pos args
92
+ my @fixed ;
93
+ while ($proto =~ s / ^$match_pos_protos// ) {
94
+
95
+ }
96
+
97
+ # # collect named args
98
+ my @named ;
99
+ while ($proto =~ s / ^$match_named_protos// ) {
100
+ push @named , { name => $1 , default => $2 };
101
+ }
102
+
103
+ print " # $decl \n " , join (" \n " , @perl ), " \n " ;
104
+ use Data::Dump qw( pp) ; print " proto '$proto ' = " , pp(\@named ), " \n " ;
You can’t perform that action at this time.
0 commit comments