line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TypeLessTranslator; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Nigel Hamilton |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
7
|
|
|
|
|
|
|
# All Rights Reserved |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
10
|
|
|
|
|
|
|
# Filename: TypeLessTranslator.pm |
11
|
|
|
|
|
|
|
# Description: Translate typeless text to full code - sms 4 codng |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Date Change |
14
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
# 09/05/2005 Auto generated file |
16
|
|
|
|
|
|
|
# 09/05/2005 Needed for faster GOO editing - trying to eclipse eclispe |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
############################################################################### |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
5
|
use Goo::FileUtilities; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
23
|
1
|
|
|
1
|
|
483
|
use Goo::Thing::pm::Perl5; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
679
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
############################################################################### |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
# translate_file - translate a file |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
############################################################################### |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub translate_file { |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
|
|
my ($file) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $newfile; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# added a new line - testing |
39
|
0
|
|
|
|
|
|
foreach my $line (Goo::FileUtilities::get_file_as_lines($file)) { |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# skip if the line is a comment |
42
|
0
|
0
|
|
|
|
|
if ($line =~ m/^\s*\#/) { |
43
|
0
|
|
|
|
|
|
$newfile .= $line; |
44
|
0
|
|
|
|
|
|
next; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# skip if the line is blank |
48
|
0
|
0
|
|
|
|
|
if ($line =~ m/^\s*$/) { |
49
|
|
|
|
|
|
|
# print "skipping!!!! \n"; |
50
|
0
|
|
|
|
|
|
$newfile .= $line; |
51
|
0
|
|
|
|
|
|
next; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# skip if the line contains a regex |
55
|
0
|
0
|
|
|
|
|
if ($line =~ m/\=\~/) { |
56
|
|
|
|
|
|
|
# print "skipping!!!! \n"; |
57
|
0
|
|
|
|
|
|
$newfile .= $line; |
58
|
0
|
|
|
|
|
|
next; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# skip if the line contains a doublequote |
62
|
0
|
0
|
|
|
|
|
if ($line =~ m/\"/) { |
63
|
|
|
|
|
|
|
# print "skipping!!!! \n"; |
64
|
0
|
|
|
|
|
|
$newfile .= $line; |
65
|
0
|
|
|
|
|
|
next; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$newfile .= translate_line($line); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
Goo::FileUtilities::write_file($file, $newfile); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
############################################################################### |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
# translate_line - translate a line |
81
|
|
|
|
|
|
|
# |
82
|
|
|
|
|
|
|
############################################################################### |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub translate_line { |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
0
|
|
|
my ($line, $language) = @_; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# turn this off!!! |
89
|
0
|
|
|
|
|
|
return $line; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# don't translate comments |
92
|
0
|
0
|
|
|
|
|
return $line if ($line =~ /^\s+#/); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# don't translate HEREDOC's tokens or variables at the start of a line |
95
|
0
|
0
|
|
|
|
|
return $line if ($line =~ /^[A-Z\$]+/); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# preserve whitespace |
98
|
0
|
|
|
|
|
|
my ($whitespace, $code) = $line =~ m/^(\s*)(.*)$/; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# sometimes the code contains comments |
101
|
|
|
|
|
|
|
# don't expand comments |
102
|
0
|
|
|
|
|
|
$code =~ m/(.*?)\ (.*)$/; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
0
|
|
|
|
$code = $1 || $code; |
105
|
0
|
|
|
|
|
|
my $comments = $2; # is abs glob |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# expand packages references |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# expand reserved words in line |
110
|
0
|
|
|
|
|
|
return $whitespace . expand_reserved_words($code). $comments . "\n"; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
############################################################################### |
116
|
|
|
|
|
|
|
# |
117
|
|
|
|
|
|
|
# expand_reserved_words - turn any abbreviated reserved words into full words |
118
|
|
|
|
|
|
|
# |
119
|
|
|
|
|
|
|
############################################################################### |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub expand_reserved_words { |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
0
|
|
|
my ($line, $language) = @_; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# at the moment everything is Perl5 but I will add Perl6 ASAP |
126
|
|
|
|
|
|
|
# go through all bareword letters and expand them |
127
|
0
|
|
|
|
|
|
my @tokens = split(/\s+/, $line); |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my $newline; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
foreach my $token (@tokens) { |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# ignore capitalised tokens - package names and barewords |
134
|
0
|
0
|
|
|
|
|
if ($token =~ /[A-Z]/) { $newline .= $token." "; next; } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# ignore sigil tokens |
137
|
0
|
0
|
|
|
|
|
if ($token =~ /[\$\@\%]/) { $newline .= $token." "; next; } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# find lowercase barewords! |
140
|
|
|
|
|
|
|
# for version 1 only allow "pure" tokens i.e., m => my |
141
|
|
|
|
|
|
|
# this [(m] token is not valid: (m $row = |
142
|
|
|
|
|
|
|
# had problems with regexes too: $row =~ m/ |
143
|
0
|
0
|
|
|
|
|
if ($token =~ /^[a-z]*$/) { |
144
|
|
|
|
|
|
|
# extract any contiguous lowercase letters from the token |
145
|
|
|
|
|
|
|
# $token =~ s/([a-z]*)/Perl5::match_reserved_word($1)/x; |
146
|
0
|
|
|
|
|
|
$token =~ s/([a-z]+)/matchReservedWord($1)/e; |
|
0
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
$newline .= $token." "; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
return $newline; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
############################################################################### |
160
|
|
|
|
|
|
|
# |
161
|
|
|
|
|
|
|
# match_reserved_word - match abbreviated letters to full reserved words |
162
|
|
|
|
|
|
|
# if nothing is found return the letters |
163
|
|
|
|
|
|
|
# |
164
|
|
|
|
|
|
|
############################################################################### |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub match_reserved_word { |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
0
|
|
|
my ($letters) = @_; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# go no further is this the full word |
171
|
0
|
0
|
|
|
|
|
return $letters if Goo::Thing::pm::Perl5::is_reserved_word($letters); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# f => for |
174
|
|
|
|
|
|
|
# w => while |
175
|
|
|
|
|
|
|
# fk => fork |
176
|
|
|
|
|
|
|
# fe => foreach |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# take a string of letters and create a pattern |
179
|
|
|
|
|
|
|
# f => f.* matches for |
180
|
|
|
|
|
|
|
# fe => f.*?e.* matches foreach |
181
|
|
|
|
|
|
|
# fre => f.*?r.*?e.* matches foreach |
182
|
|
|
|
|
|
|
# fk => f.*?k.* matches fork |
183
|
0
|
|
|
|
|
|
my $pattern = join(".*?", split(//, $letters)); |
184
|
0
|
|
|
|
|
|
$pattern .= ".*"; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# print "pattern = ".$pattern."\n"; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# translate a letter sequence into a regex - could be more efficient |
189
|
0
|
|
|
|
|
|
foreach my $word (sort { length($a) <=> length($b) } Goo::Thing::pm::Perl5::get_common_words()) { |
|
0
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# find a matching reserved word |
192
|
0
|
0
|
|
|
|
|
if ($word =~ /^$pattern/) { |
193
|
|
|
|
|
|
|
# in the short term tell me when it happens! |
194
|
|
|
|
|
|
|
# print "expanding $letters to $word\n"; |
195
|
0
|
|
|
|
|
|
return $word; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
return $letters; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
__END__ |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 NAME |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
TypeLessTranslator - Experimental module. It translates "typeless" text to full code. It's like |
213
|
|
|
|
|
|
|
writing abbreviate sms txt for Perl code. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 SYNOPSIS |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
use TypeLessTranslator; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 DESCRIPTION |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 METHODS |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=over |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item translate_file |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
translate a file by expanding typeless code to full code |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item translate_line |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
translate a line |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item expand_reserved_words |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
turn any abbreviated reserved words into full reserved words |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item match_reserved_word |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
match abbreviated letters to full reserved words |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=back |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 AUTHOR |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head1 SEE ALSO |
250
|
|
|
|
|
|
|
|