line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lang::Tree::Builder::Tokenizer; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
sub new { |
4
|
1
|
|
|
1
|
0
|
2
|
my ($class, $file) = @_; |
5
|
1
|
|
|
|
|
11
|
my $fh = new FileHandle($file); |
6
|
1
|
50
|
|
|
|
238
|
return undef unless $fh; |
7
|
1
|
|
|
|
|
11
|
bless { |
8
|
|
|
|
|
|
|
file => $file, |
9
|
|
|
|
|
|
|
lineno => 0, |
10
|
|
|
|
|
|
|
error => '', |
11
|
|
|
|
|
|
|
line => '', |
12
|
|
|
|
|
|
|
fh => $fh, |
13
|
|
|
|
|
|
|
}, $class; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub next { |
17
|
11
|
|
|
11
|
0
|
18
|
my ($self) = @_; |
18
|
11
|
|
|
|
|
25
|
my $token = $self->_next(); |
19
|
11
|
|
|
|
|
28
|
$self->{last_token} = $token; |
20
|
11
|
|
|
|
|
50
|
return $token; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _next { |
24
|
11
|
|
|
11
|
|
17
|
my ($self) = @_; |
25
|
|
|
|
|
|
|
|
26
|
11
|
50
|
|
|
|
33
|
return undef unless defined $self->{line}; |
27
|
|
|
|
|
|
|
|
28
|
11
|
|
|
|
|
52
|
while ($self->{line} =~ /^\s*$/) { |
29
|
3
|
|
|
|
|
110
|
$self->{line} = $self->{fh}->getline(); |
30
|
3
|
|
|
|
|
142
|
$self->{lineno}++; |
31
|
3
|
100
|
|
|
|
12
|
return undef unless defined $self->{line}; |
32
|
2
|
|
|
|
|
8
|
$self->{line} =~ s/^\s+//; |
33
|
2
|
|
|
|
|
11
|
$self->{line} =~ s/#.*//; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
10
|
|
|
|
|
27
|
for ($self->{line}) { |
37
|
10
|
100
|
|
|
|
28
|
s/^\(\s*// && return '('; |
38
|
9
|
100
|
|
|
|
23
|
s/^\)\s*// && return ')'; |
39
|
8
|
100
|
|
|
|
36
|
s/^\,\s*// && return ','; |
40
|
6
|
50
|
|
|
|
54
|
s/([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)\s*// |
41
|
|
|
|
|
|
|
&& return $1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$self->{error} = "can't parse: '$self->{line}'" |
45
|
|
|
|
|
|
|
. " in $self->{file}" |
46
|
|
|
|
|
|
|
. " at line $self->{lineno}"; |
47
|
0
|
|
|
|
|
|
return undef; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub info { |
51
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
52
|
0
|
|
|
|
|
|
return "file: $self->{file}" |
53
|
|
|
|
|
|
|
. " line: $self->{lineno}" |
54
|
|
|
|
|
|
|
. " $self->{lasttoken} <> $self->{line}"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |