| Filename | /Users/smash/playground/Parse-Lexer/lib/Parse/Lexer.pm |
| Statements | Executed 1703 statements in 14.0ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 7.94ms | 13.4ms | Parse::Lexer::BEGIN@17 |
| 551 | 2 | 1 | 4.23ms | 4.23ms | Parse::Lexer::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 3.91ms | 3.97ms | Parse::Lexer::BEGIN@5 |
| 80 | 1 | 1 | 3.10ms | 7.78ms | Parse::Lexer::__lex |
| 16 | 1 | 1 | 881µs | 8.83ms | Parse::Lexer::next |
| 1 | 1 | 1 | 831µs | 924µs | Parse::Lexer::BEGIN@4 |
| 325 | 3 | 1 | 288µs | 288µs | Parse::Lexer::CORE:subst (opcode) |
| 306 | 1 | 1 | 271µs | 271µs | Parse::Lexer::CORE:match (opcode) |
| 1 | 1 | 1 | 129µs | 129µs | Parse::Lexer::BEGIN@3 |
| 81 | 2 | 1 | 76µs | 76µs | Parse::Lexer::CORE:getc (opcode) |
| 1 | 1 | 1 | 17µs | 17µs | Parse::Lexer::new |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Parse::Lexer; | ||||
| 2 | |||||
| 3 | 3 | 170µs | 1 | 129µs | # spent 129µs within Parse::Lexer::BEGIN@3 which was called:
# once (129µs+0s) by main::BEGIN@2 at line 3 # spent 129µs making 1 call to Parse::Lexer::BEGIN@3 |
| 4 | 3 | 786µs | 2 | 931µs | # spent 924µs (831+93) within Parse::Lexer::BEGIN@4 which was called:
# once (831µs+93µs) by main::BEGIN@2 at line 4 # spent 924µs making 1 call to Parse::Lexer::BEGIN@4
# spent 7µs making 1 call to strict::import |
| 5 | 3 | 3.71ms | 2 | 3.99ms | # spent 3.97ms (3.91+53µs) within Parse::Lexer::BEGIN@5 which was called:
# once (3.91ms+53µs) by main::BEGIN@2 at line 5 # spent 3.97ms making 1 call to Parse::Lexer::BEGIN@5
# spent 22µs making 1 call to warnings::import |
| 6 | |||||
| 7 | =head1 NAME | ||||
| 8 | |||||
| 9 | Parse::Lexer - The great new Parse::Lexer! | ||||
| 10 | |||||
| 11 | =head1 VERSION | ||||
| 12 | |||||
| 13 | Version 0.01 | ||||
| 14 | |||||
| 15 | =cut | ||||
| 16 | |||||
| 17 | 3 | 727µs | 2 | 13.4ms | # spent 13.4ms (7.94+5.46) within Parse::Lexer::BEGIN@17 which was called:
# once (7.94ms+5.46ms) by main::BEGIN@2 at line 17 # spent 13.4ms making 1 call to Parse::Lexer::BEGIN@17
# spent 48µs making 1 call to Exporter::import |
| 18 | |||||
| 19 | 1 | 1µs | our $VERSION = '0.01'; | ||
| 20 | |||||
| 21 | # XXX | ||||
| 22 | 1 | 300ns | our $c = ''; | ||
| 23 | 1 | 300ns | our $buf = ''; | ||
| 24 | 1 | 25µs | 1 | 16µs | our $la = getc(STDIN); # spent 16µs making 1 call to Parse::Lexer::CORE:getc |
| 25 | |||||
| 26 | =head1 SYNOPSIS | ||||
| 27 | |||||
| 28 | Quick summary of what the module does. | ||||
| 29 | |||||
| 30 | Perhaps a little code snippet. | ||||
| 31 | |||||
| 32 | use Parse::Lexer; | ||||
| 33 | |||||
| 34 | my $tokenizer = Parse::Lexer->new( | ||||
| 35 | PLUS => qr/\+/, | ||||
| 36 | MINUS => qr/\-/, | ||||
| 37 | NUMBER => qr/[0-9]+/, | ||||
| 38 | IDENT => qr/[a-z]+/, | ||||
| 39 | ); | ||||
| 40 | $tokenizer->parse; | ||||
| 41 | |||||
| 42 | =head1 EXPORT | ||||
| 43 | |||||
| 44 | A list of functions that can be exported. You can delete this section | ||||
| 45 | if you don't export anything, such as for a purely object-oriented module. | ||||
| 46 | |||||
| 47 | =head1 SUBROUTINES/METHODS | ||||
| 48 | |||||
| 49 | =head2 new | ||||
| 50 | |||||
| 51 | =cut | ||||
| 52 | |||||
| 53 | # spent 17µs within Parse::Lexer::new which was called:
# once (17µs+0s) by main::RUNTIME at line 4 of lexer.pl | ||||
| 54 | 3 | 19µs | my ($class, %re) = @_; | ||
| 55 | my $self = bless({re=>{%re}}, $class); | ||||
| 56 | |||||
| 57 | return $self; | ||||
| 58 | } | ||||
| 59 | |||||
| 60 | =head2 next | ||||
| 61 | |||||
| 62 | =cut | ||||
| 63 | |||||
| 64 | # spent 8.83ms (881µs+7.95) within Parse::Lexer::next which was called 16 times, avg 552µs/call:
# 16 times (881µs+7.95ms) by main::RUNTIME at line 11 of lexer.pl, avg 552µs/call | ||||
| 65 | 528 | 919µs | my ($self, $stream, $sub) = @_; | ||
| 66 | $stream = 'STDIN' unless $stream; | ||||
| 67 | |||||
| 68 | while (defined $la) { | ||||
| 69 | $c = $la if defined($la); | ||||
| 70 | |||||
| 71 | $buf .= $c; | ||||
| 72 | 80 | 59µs | $la = getc($stream); # spent 59µs making 80 calls to Parse::Lexer::CORE:getc, avg 740ns/call | ||
| 73 | |||||
| 74 | 80 | 114µs | $buf =~ s/^[ \n\t]+//; # XXX # spent 114µs making 80 calls to Parse::Lexer::CORE:subst, avg 1µs/call | ||
| 75 | |||||
| 76 | 80 | 7.78ms | my @r = $self->__lex(); # spent 7.78ms making 80 calls to Parse::Lexer::__lex, avg 97µs/call | ||
| 77 | #&$sub(@r) if (@r>1); | ||||
| 78 | return(@r) if (@r>1); | ||||
| 79 | } | ||||
| 80 | } | ||||
| 81 | |||||
| 82 | # spent 7.78ms (3.10+4.67) within Parse::Lexer::__lex which was called 80 times, avg 97µs/call:
# 80 times (3.10ms+4.67ms) by Parse::Lexer::next at line 76, avg 97µs/call | ||||
| 83 | 1155 | 7.67ms | my ($self) = @_; | ||
| 84 | |||||
| 85 | #print "BUF $buf C $c LA $la\n"; | ||||
| 86 | foreach my $token (keys %{$self->{re}}) { | ||||
| 87 | my $re = $self->{re}->{$token}; | ||||
| 88 | |||||
| 89 | if (defined $la) { | ||||
| 90 | #if ($buf =~ m/^$re$/ and "$buf$la" !~ m/^$re$/) { | ||||
| 91 | 1094 | 4.63ms | if ( ("$buf$la" !~ m/^$re$/) and ($buf =~ s/^($re)//) ) { # spent 4.19ms making 547 calls to Parse::Lexer::CORE:regcomp, avg 8µs/call
# spent 271µs making 306 calls to Parse::Lexer::CORE:match, avg 885ns/call
# spent 170µs making 241 calls to Parse::Lexer::CORE:subst, avg 705ns/call | ||
| 92 | return ($token => $1); | ||||
| 93 | } | ||||
| 94 | } | ||||
| 95 | else { | ||||
| 96 | 8 | 45µs | return ($token => $1) if $buf =~ s/^($re)$//; # spent 40µs making 4 calls to Parse::Lexer::CORE:regcomp, avg 10µs/call
# spent 4µs making 4 calls to Parse::Lexer::CORE:subst, avg 1µs/call | ||
| 97 | } | ||||
| 98 | } | ||||
| 99 | |||||
| 100 | return undef; | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | =head1 AUTHOR | ||||
| 104 | |||||
| 105 | Nuno Carvalho, C<< <smash at cpan.org> >> | ||||
| 106 | |||||
| 107 | =head1 BUGS | ||||
| 108 | |||||
| 109 | Please report any bugs or feature requests to C<bug-parse-lexer at rt.cpan.org>, or through | ||||
| 110 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Parse-Lexer>. I will be notified, and then you'll | ||||
| 111 | automatically be notified of progress on your bug as I make changes. | ||||
| 112 | |||||
| - - | |||||
| 116 | =head1 SUPPORT | ||||
| 117 | |||||
| 118 | You can find documentation for this module with the perldoc command. | ||||
| 119 | |||||
| 120 | perldoc Parse::Lexer | ||||
| 121 | |||||
| 122 | |||||
| 123 | You can also look for information at: | ||||
| 124 | |||||
| 125 | =over 4 | ||||
| 126 | |||||
| 127 | =item * RT: CPAN's request tracker (report bugs here) | ||||
| 128 | |||||
| 129 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Parse-Lexer> | ||||
| 130 | |||||
| 131 | =item * AnnoCPAN: Annotated CPAN documentation | ||||
| 132 | |||||
| 133 | L<http://annocpan.org/dist/Parse-Lexer> | ||||
| 134 | |||||
| 135 | =item * CPAN Ratings | ||||
| 136 | |||||
| 137 | L<http://cpanratings.perl.org/d/Parse-Lexer> | ||||
| 138 | |||||
| 139 | =item * Search CPAN | ||||
| 140 | |||||
| 141 | L<http://search.cpan.org/dist/Parse-Lexer/> | ||||
| 142 | |||||
| 143 | =back | ||||
| 144 | |||||
| 145 | |||||
| 146 | =head1 ACKNOWLEDGEMENTS | ||||
| 147 | |||||
| 148 | |||||
| 149 | =head1 LICENSE AND COPYRIGHT | ||||
| 150 | |||||
| 151 | Copyright 2012 Nuno Carvalho. | ||||
| 152 | |||||
| 153 | This program is free software; you can redistribute it and/or modify it | ||||
| 154 | under the terms of either: the GNU General Public License as published | ||||
| 155 | by the Free Software Foundation; or the Artistic License. | ||||
| 156 | |||||
| 157 | See http://dev.perl.org/licenses/ for more information. | ||||
| 158 | |||||
| 159 | |||||
| 160 | =cut | ||||
| 161 | |||||
| 162 | 1 | 9µs | 1; # End of Parse::Lexer | ||
sub Parse::Lexer::CORE:getc; # opcode | |||||
# spent 271µs within Parse::Lexer::CORE:match which was called 306 times, avg 885ns/call:
# 306 times (271µs+0s) by Parse::Lexer::__lex at line 91, avg 885ns/call | |||||
sub Parse::Lexer::CORE:regcomp; # opcode | |||||
sub Parse::Lexer::CORE:subst; # opcode |