TextHighlight/Bash.pm

filter: Statementstmt 13.0% 15 / 115 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 26.6% 4 / 15 Podpod 0.0% 0 / 11 totaltotal 9.7% 19 / 194 CC 26 SCAR 47.7
CC
26
Cov
9%
parseText
272.0
parseIString
42.0
new
12.0
CRAP 117.6
« TextHighlight/HTML.pm ↑ Summary TextHighlight/Xresources.pm »
1 package Tk::TextHighlight::Bash;
2  
3 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $VERSION = '0.1'; # Initial release;
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use base('Tk::TextHighlight::Template');
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 my $separators = '\||&|;|(|)|<|>|\s|\'|"|`|#|$';
11  
12 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
13 0 my ($proto, $rules) = @_;
14 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
15 0 ▶ if (not defined($rules)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rules) 0 0 0
16 0 $rules = [
17 ['Text'],
18 ['Comment', -foreground => 'gray'],
19 ['Reserved', -foreground => 'brown'],
20 ['Keyword', -foreground => 'orange'],
21 ['String', -foreground => 'red'],
22 ['Backticked', -foreground => 'purple'],
23 ['String intrapolated', -foreground => 'red'],
24 ['Escaped character', -foreground => 'magenta'],
25 ['Operator', -foreground => 'darkblue'],
26 ['Variable', -foreground => 'blue'],
27 ];
28 };
29 0 my $self = $class->SUPER::new($rules);
30 0 $self->lists({
31 'Reserved' => [
32 '!', 'case', 'do', 'done', 'elif', 'else', 'esac', 'fi', 'for',
33 'function', 'if', 'in', 'select', 'then', 'until', 'while', '{',
34 '}', 'time', '[[', ']]',
35 ],
36 'Keyword' => [
37 'alias', 'bind', 'bg','builtin', 'break', 'cd', 'command', 'compgen',
38 'complete', 'continue', 'cp', 'declare', 'disown', 'dirs', 'echo',
39 'enable', 'eval', 'exec', 'exit', 'export', 'false', 'fc', 'fg',
40 'function', 'getopts', 'hash', 'help', 'history', 'jobs', 'kill',
41 'let', 'local', 'logout', 'mv', 'popd', 'printf', 'pushd','pwd', 'read',
42 'readonly', 'return', 'rm', 'select', 'set', 'shift', 'shopt', 'source',
43 'suspend', 'test', 'trap', 'true', 'type', 'typeset', 'ulimit',
44 'umask', 'unalias', 'unset', 'variables', 'wait',
45 ],
46 });
47 0 bless ($self, $class);
48 0 $self->callbacks({
49 'Backticked' => \&parseBackticked,
50 'Comment' => \&parseComment,
51 'Escaped character' => \&parseEscaped,
52 'Keyword' => \&parseKeyword,
53 'Operator' => \&parseOperator,
54 'Reserved' => \&parseReserved,
55 'String' => \&parseString,
56 'String intrapolated' => \&parseIString,
57 'Text' => \&parseText,
58 'Variable' => \&parseVariable,
59 });
60 0 $self->stackPush('Text');
61 0 return $self;
62 }
63  
64 0 ▶sub parseBackticked {
Subroutine parseBackticked: not called CC=2 SCAR=17.9
Pod undocumented
65 0 my ($self, $text) = @_;
66 0 ▶ if ($text =~ s/^(`)//o) { #backtick stop
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(`)//o) 0 0 0
67 0 $self->snippetParse($1);
68 0 $self->stackPull;
69 0 return $text;
70 }
71 0 return $self->parseText($text);
72 }
73  
74 0 ▶sub parseComment {
Subroutine parseComment: not called CC=1 SCAR=6.9
Pod undocumented
75 0 my ($self, $text) = @_;
76 0 return $self->parserError($text);
77 }
78  
79 0 ▶sub parseEscaped {
Subroutine parseEscaped: not called CC=1 SCAR=6.9
Pod undocumented
80 0 my ($self, $text) = @_;
81 0 return $self->parserError($text);
82 }
83  
84 0 ▶sub parseIString {
Subroutine parseIString: not called CC=6 SCAR=37.4
Pod undocumented
85 0 my ($self, $text) = @_;
86 0 ▶ if ($text =~ s/^(\\.)//o) { #escaped character
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(\\.)//o) 0 0 0
87 0 $self->snippetParse($1, 'Escaped character');
88 0 return $text;
89 }
90 0 ▶ if ($text =~ s/^(\$[^$separators]*)//) { #variable
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(\$[^$separators]*)//) 0 0 0
91 0 $self->snippetParse($1, 'Variable');
92 0 return $text;
93 }
94 0 ▶ if ($text =~ s/^(`)//o) { #backticked
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(`)//o) 0 0 0
95 0 $self->stackPush('Backticked');
96 0 $self->snippetParse($1);
97 0 return $text;
98 }
99 0 ▶ if ($text =~ s/^(")//o) { #string stop
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(")//o) 0 0 0
100 0 $self->snippetParse($1);
101 0 $self->stackPull;
102 0 return $text;
103 }
104 0 ▶ if ($text =~ s/^([^"|\$|`]+)//o) { #string content
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^([^"|\$|`]+)//o) 0 0 0
105 0 $self->snippetParse($1);
106 0 return $text;
107 }
108 0 return $self->parserError($text);
109 }
110  
111 0 ▶sub parseKeyword {
Subroutine parseKeyword: not called CC=1 SCAR=6.9
Pod undocumented
112 0 my ($self, $text) = @_;
113 0 return $self->parserError($text);
114 }
115  
116 0 ▶sub parseOperator {
Subroutine parseOperator: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my ($self, $text) = @_;
118 0 return $self->parserError($text);
119 }
120  
121 0 ▶sub parseReserved {
Subroutine parseReserved: not called CC=1 SCAR=6.9
Pod undocumented
122 0 my ($self, $text) = @_;
123 0 return $self->parserError($text);
124 }
125  
126 0 ▶sub parseString {
Subroutine parseString: not called CC=3 SCAR=24.8
Pod undocumented
127 0 my ($self, $text) = @_;
128 0 ▶ if ($text =~ s/^([^']+)//o) { #string content
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^([^']+)//o) 0 0 0
129 0 $self->snippetParse($1);
130 0 return $text;
131 }
132 0 ▶ if ($text =~ s/^(')//o) { #string stop
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(')//o) 0 0 0
133 0 $self->snippetParse($1);
134 0 $self->stackPull;
135 0 return $text;
136 }
137 0 return $self->parserError($text);
138 }
139  
140 0 ▶sub parseText {
Subroutine parseText: not called CC=16 SCAR=56.1
Pod undocumented
141 0 my ($self, $text) = @_;
142 0 ▶ if ($text =~ s/^(^#!\/.*)//o) { #launch line
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s[^(^#!/.*)][]o) 0 0 0
143 0 $self->snippetParse($1, 'Reserved');
144 0 return $text;
145 }
146 0 ▶ if ($text =~ s/^(#.*)//o) { #comment
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(#.*)//o) 0 0 0
147 0 $self->snippetParse($1, 'Comment');
148 0 return $text;
149 }
150 0 ▶ if ($text =~ s/^(\s+)//o) { #spaces
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(\s+)//o) 0 0 0
151 0 $self->snippetParse($1);
152 0 return $text;
153 }
154 0 ▶ if ($text =~ s/^(`)//) { #backticked
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(`)//) 0 0 0
155 0 $self->stackPush('Backticked');
156 0 $self->snippetParse($1);
157 0 return $text;
158 }
159 0 ▶ if ($text =~ s/^(")//o) { #string intrapolated
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(")//o) 0 0 0
160 0 $self->stackPush('String intrapolated');
161 0 $self->snippetParse($1);
162 0 return $text;
163 }
164 0 ▶ if ($text =~ s/^('[^']*)//o) { #string start
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^('[^']*)//o) 0 0 0
165 0 $self->snippet($1);
166 0 ▶ if ($text) { #if there is still text to be parsed, string ends at same line
Branch: 1 branch
BranchTrueFalseTotal
if ($text) { } 0 0 0
167 0 ▶ if ($text =~ s/(^')//o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/(^')//o) 0 0 0
168 0 $self->snippetParse($1)
169 }
170 } else {
171 0 $self->stackPush('String');
172 }
173 0 return $text;
174 }
175 0 ▶ if ($text =~ s/^(\$[^$separators]*)//) { #variable
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(\$[^$separators]*)//) 0 0 0
176 0 $self->snippetParse($1, 'Variable');
177 0 return $text;
178 }
179 0 ▶ if ($text =~ s/^([\|\||\||&&|&|;;|;|(|)])//o) { #operator
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^([\|\||\||&&|&|;;|;|(|)])//o) 0 0 0
180 0 $self->snippetParse($1, 'Operator');
181 0 return $text
182 }
183 0 ▶ if ($text =~ s/^([<|>])//o) { #remaining separators
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^([<|>])//o) 0 0 0
184 0 $self->snippetParse($1);
185 0 return $text
186 }
187 0 ▶ if ($text =~ s/^(\\.)//o) { #escaped character
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(\\.)//o) 0 0 0
188 0 $self->snippet($1, 'Escaped character');
189 0 return $text;
190 }
191 0 ▶ if ($text =~ s/^([^$separators]+)//) { #fetching a bare part
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^([^$separators]+)//) 0 0 0
192 0 ▶ if ($self->tokenTest($1, 'Reserved')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->tokenTest($1, 'Reserved')) { } 0 0 0
elsif ($self->tokenTest($1, 'Keyword')) { } 0 0 0
193 0 $self->snippetParse($1, 'Reserved');
194 } elsif ($self->tokenTest($1, 'Keyword')) {
195 0 $self->snippetParse($1, 'Keyword');
196 } else { #unrecognized text
197 0 $self->snippetParse($1);
198 }
199 0 return $text
200 }
201 #It shouldn't have come this far, but it has.
202 0 return $self->parserError($text);
203 }
204  
205 0 ▶sub parseVariable {
Subroutine parseVariable: not called CC=1 SCAR=6.9
Pod undocumented
206 0 my ($self, $text) = @_;
207 0 return $self->parserError($text);
208 }
209  
210 1 1;
211  
212 __END__
« TextHighlight/HTML.pm ↑ Summary TextHighlight/Xresources.pm »