| 1 | package Lang::Tree::Builder::Tokenizer; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 4 | 1 | my ($class, $file) = @_; | |||||||||
| 5 | 1 | my $fh = new FileHandle($file); | |||||||||
| 6 | 1 | ▶ | return undef unless $fh; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 7 | 1 | bless { | |||||||||
| 8 | file => $file, | ||||||||||
| 9 | lineno => 0, | ||||||||||
| 10 | error => '', | ||||||||||
| 11 | line => '', | ||||||||||
| 12 | fh => $fh, | ||||||||||
| 13 | }, $class; | ||||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 11 | ▶ | sub next { | ||||||||
|
Subroutine
next: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 17 | 11 | my ($self) = @_; | |||||||||
| 18 | 11 | my $token = $self->_next(); | |||||||||
| 19 | 11 | $self->{last_token} = $token; | |||||||||
| 20 | 11 | return $token; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 11 | ▶ | sub _next { | ||||||||
|
Subroutine
_next: called CC=9 SCAR=22.2
| |||||||||||
| 24 | 11 | my ($self) = @_; | |||||||||
| 25 | |||||||||||
| 26 | 11 | ▶ | return undef unless defined $self->{line}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | 11 | ▶ | while ($self->{line} =~ /^\s*$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 3 | $self->{line} = $self->{fh}->getline(); | |||||||||
| 30 | 3 | $self->{lineno}++; | |||||||||
| 31 | 3 | ▶ | return undef unless defined $self->{line}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 2 | $self->{line} =~ s/^\s+//; | |||||||||
| 33 | 2 | $self->{line} =~ s/#.*//; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 10 | for ($self->{line}) { | |||||||||
| 37 | 10 | ▶ | s/^\(\s*// && return '('; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 9 | ▶ | s/^\)\s*// && return ')'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 8 | ▶ | s/^\,\s*// && return ','; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 6 | ▶ | s/([A-Za-z_][A-Za-z_0-9]*(?:::[A-Za-z_][A-Za-z_0-9]*)*)\s*// | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | sub info { | ||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 51 | 0 | my ($self) = @_; | |||||||||
| 52 | 0 | return "file: $self->{file}" | |||||||||
| 53 | . " line: $self->{lineno}" | ||||||||||
| 54 | . " $self->{lasttoken} <> $self->{line}"; | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 3 | 1; | |||||||||