diff options
author | Vishal Gupta <vishalgupta7972@gmail.com> | 2018-06-24 12:23:37 +0530 |
---|---|---|
committer | Vishal Gupta <vishalgupta7972@gmail.com> | 2018-06-24 12:23:37 +0530 |
commit | 3ef92ce4411f13c2c3f2e6d1e6d5ed7de647e71e (patch) | |
tree | 8574b4e2dc5fb82cd6ec3d56b5852a88e46e1885 /lib/Automake/Parser/Lexer.pm | |
parent | c538dc193d39be7df03615d4d4792ec4c1aedf97 (diff) | |
download | automake-3ef92ce4411f13c2c3f2e6d1e6d5ed7de647e71e.tar.gz |
Updated multiline statement and conditional statements.
* Added new test cases.
* Added support for += .
* Updated conditional statements to handle multiple statements inside
* if/else block.
* Prints error when comment follow trailing backslash.
Diffstat (limited to 'lib/Automake/Parser/Lexer.pm')
-rw-r--r-- | lib/Automake/Parser/Lexer.pm | 75 |
1 files changed, 29 insertions, 46 deletions
diff --git a/lib/Automake/Parser/Lexer.pm b/lib/Automake/Parser/Lexer.pm index d4190eedd..6f09291b9 100644 --- a/lib/Automake/Parser/Lexer.pm +++ b/lib/Automake/Parser/Lexer.pm @@ -21,49 +21,32 @@ sub lex($$) { if( $multiline ) { - my @vals = split; - if( $multiline eq 'automake_comment' ) + if( $multiline eq 'comment' ) { - if( $vals[ -1 ] ne '\\' ) - { - $multiline = undef; - push @tokens, [ "newline" ]; - } + die 'comment following trailing backslash' if m/^#/o; + die 'blank line following trailing backslash' if m/^\s*$/; + chomp; + $multiline = undef unless s/\\//o; + push @tokens, [ "comment" , $_ ]; + push @tokens, [ "newline" ] unless $multiline; $_ = undef; - last; } - elsif( $multiline eq 'comment' ) + else { - my $comment; - foreach my $val ( @vals ) + if( m/^##/ ) + { + $_ = undef; + last; + } + elsif( m/^#/ ) { - if($val =~ m/^##/) - { - $multiline = 'automake_comment' if $vals[ -1 ] eq '\\'; - $_ = undef; - last; - } - elsif( $val eq '\\' ) - { - last; - } - else - { - $comment .= " ".$val; - } + die 'comment following trailing backslash'; } - push @tokens, [ "comment" , $comment ] if $comment; - if($vals[ -1 ] ne '\\') + else { $multiline = undef; - push @tokens, [ "newline" ]; + $rhs = 1; } - $_ = undef; - } - else - { - $multiline = undef; - $rhs = 1; } } elsif( $rhs ) @@ -72,20 +55,14 @@ sub lex($$) my $comment; foreach my $val ( @vals ) { - if( $val =~ m/^##/ ) - { - $multiline = 'automake_comment' if $vals[ -1 ] eq '\\'; - $_ = undef; - last; - } - elsif( $val =~ m/^#(.*)/ ) + if( $val =~ m/^#(.*)/ ) { $multiline = 'comment' if $vals[ -1 ] eq '\\'; $comment .= " ".$1; } elsif( $val =~ m/\\/ ) { - $multiline = 'rhsval' if !$multiline; + $multiline = 'rhsval' unless$multiline; } elsif( $comment ) { @@ -97,7 +74,7 @@ sub lex($$) } } push @tokens, [ "comment" , $comment] if $comment; - push @tokens, [ "newline" ] if !$multiline; + push @tokens, [ "newline" ] unless $multiline; $_ = undef; } elsif( s/^##.*\n$//o ) @@ -106,7 +83,7 @@ sub lex($$) elsif( s/^#(.*)\n$//o ) { my $val = $1; - if($val =~ m/(.*?)\\/o) + if( $val =~ m/(.*?)\\/o ) { push @tokens, [ "comment" , substr( $1 , 0 , -1 )]; $multiline = 'comment'; @@ -125,6 +102,12 @@ sub lex($$) { push @tokens, ["value",$1]; } + elsif( s/^(\+=)//o ) + { + push @tokens,['+']; + push @tokens,['=']; + $rhs = 1; + } elsif( s/^(=)//o ) { push @tokens, [$1]; @@ -136,10 +119,10 @@ sub lex($$) } elsif( s/^\n//o ) { - push @tokens, ["newline"]; + push @tokens, ["newline"] if $#tokens > -1; $multiline = undef; } - elsif( s/^(\r|\s*)//o ) + elsif( s/^(\r|\s+)//o ) { } else |