From: Robin Edwards Date: Fri, 4 Dec 2009 17:33:29 +0000 (+0000) Subject: refactored to use parser object X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e055ab12e2272a538765c12060f7cf224cef78d1;p=p5sagit%2FDevel-Declare-Keyword.git refactored to use parser object --- diff --git a/lib/Keyword/Parser.pm b/lib/Keyword/Parser.pm new file mode 100644 index 0000000..9ad1616 --- /dev/null +++ b/lib/Keyword/Parser.pm @@ -0,0 +1,66 @@ +package Keyword::Parser; +use strict; +use warnings; +use Devel::Declare; + +sub new { + my ($class, $self) = @_; + $self = {} unless $self; + no strict 'refs'; + $self->{offset} = \${caller()."::_PARSER_OFFSET"}; + ${$self->{offset}} = 0; + bless($self,__PACKAGE__); +} + +sub offset { + my ($self, $offset) = @_; + ${$self->{offset}} = $offset if $offset; + return ${$self->{offset}}; +} + +sub next_token { + my ($self) = @_; + ${$self->{offset}} += Devel::Declare::toke_move_past_token($self->offset); +} + +sub skip_ws { + my ($self) = @_; + ${$self->{offset}} += Devel::Declare::toke_skipspace($self->offset); +} + +sub scan_word { + my ($self, $n) = @_; + return Devel::Declare::toke_scan_word($self->offset, $n); +} + +#scan string eg "blah blsah " or q( some string ) +sub scan_string { + my ($self) = @_; + return Devel::Declare::toke_scan_str($self->offset); +} + +#returns whatevers been scanned +sub scanned { + my ($self) = @_; + my $stream = Devel::Declare::get_lex_stuff(); + Devel::Declare::clear_lex_stuff(); + return $stream; +} + +#set line +sub line { + my ($self, $line) = @_; + Devel::Declare::set_linestr($line) if $line; + return Devel::Declare::get_linestr; +} + +# package - returns name of package being compiled +sub package { + return Devel::Declare::get_curstash_name; +} + +sub line_offset { + return Devel::Declare::get_linestr_offset; +} + +1;