summaryrefslogtreecommitdiff
path: root/lib/Automake/Parser/Lexer.pm
diff options
context:
space:
mode:
authorVishal Gupta <vishalgupta7972@gmail.com>2018-07-06 15:59:54 +0530
committerVishal Gupta <vishalgupta7972@gmail.com>2018-07-06 15:59:54 +0530
commitaf9641edc78265d69a488869a59bc2c38c00d792 (patch)
tree4e7a110b6ad1c9e7c779c576db78d8e5df193a60 /lib/Automake/Parser/Lexer.pm
parenta7ac93842cf5633d23263271856b7eadb6d0e3fa (diff)
downloadautomake-af9641edc78265d69a488869a59bc2c38c00d792.tar.gz
Updated parser to tokenize and parse line by line.
Lexer tokenizes the current line whenever it is called by parser. "end" token is returned when EOF is encountered. Currently assumes that newline is their before EOF.
Diffstat (limited to 'lib/Automake/Parser/Lexer.pm')
-rw-r--r--lib/Automake/Parser/Lexer.pm17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/Automake/Parser/Lexer.pm b/lib/Automake/Parser/Lexer.pm
index 1b8a22777..ec514c50f 100644
--- a/lib/Automake/Parser/Lexer.pm
+++ b/lib/Automake/Parser/Lexer.pm
@@ -5,18 +5,25 @@ use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(lex);
+# Store end token.
+my @end_tok = ["end"];
+
# lex(string,multiline)
# Takes as input a string of line and multiline variable deciding whether
# current line is related to the previous line. Divides it into tokens as
# specified by Regex and outputs an array of Tokens. Every Token is an
# array having two values: token name and its value. If its an operator,
# it has only one value.
-sub lex($$)
+sub lex($)
{
- my ( $curr_line , $multiline ) = @_;
+ my ( $multiline ) = @_;
my @tokens;
my $rhs = 0;
- $_ = $curr_line;
+ $_ = scalar <>;
+
+ # Send an end token when EOF is reached.
+ return ( \@end_tok, $multiline ) unless $_;
+
while( $_ )
{
if( $multiline )
@@ -130,6 +137,10 @@ sub lex($$)
die "Incorrect input $_";
}
}
+
+ # Returns undef when no tokens.
+ return ( undef, $multiline ) if !@tokens;
+
return ( \@tokens , $multiline );
}