refactored to use parser object
Robin Edwards [Fri, 4 Dec 2009 17:33:29 +0000 (17:33 +0000)]
lib/Keyword/Parser.pm [new file with mode: 0644]

diff --git a/lib/Keyword/Parser.pm b/lib/Keyword/Parser.pm
new file mode 100644 (file)
index 0000000..9ad1616
--- /dev/null
@@ -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;