diff options
Diffstat (limited to 'lib/Automake')
-rw-r--r-- | lib/Automake/Parser/Lexer.pm | 75 | ||||
-rw-r--r-- | lib/Automake/Parser/ParserTable.pm | 53 | ||||
-rw-r--r-- | lib/Automake/Parser/Tree.pm | 52 | ||||
-rw-r--r-- | lib/Automake/Parser/automake.y | 10 | ||||
-rw-r--r-- | lib/Automake/Parser/input.txt | 3 | ||||
-rw-r--r-- | lib/Automake/Parser/parser.pl | 8 | ||||
-rw-r--r-- | lib/Automake/Parser/t/commen10.txt | 4 | ||||
-rw-r--r-- | lib/Automake/Parser/t/commen11.txt | 7 | ||||
-rw-r--r-- | lib/Automake/Parser/t/comment-block.txt | 5 | ||||
-rw-r--r-- | lib/Automake/Parser/t/comment.txt | 1 | ||||
-rw-r--r-- | lib/Automake/Parser/t/comment2.txt | 1 | ||||
-rw-r--r-- | lib/Automake/Parser/t/comment4.txt | 4 | ||||
-rw-r--r-- | lib/Automake/Parser/t/comment7.txt | 7 | ||||
-rw-r--r-- | lib/Automake/Parser/t/comment8.txt | 9 | ||||
-rw-r--r-- | lib/Automake/Parser/t/comment9.txt | 8 |
15 files changed, 158 insertions, 89 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 diff --git a/lib/Automake/Parser/ParserTable.pm b/lib/Automake/Parser/ParserTable.pm index 907a9a9ef..4a6781660 100644 --- a/lib/Automake/Parser/ParserTable.pm +++ b/lib/Automake/Parser/ParserTable.pm @@ -9,31 +9,32 @@ our @Export=qw(@table $accept); our $accept=17; our @table=( - {commentlist => 12, if => 3, lhs => 11, value => 1, makerule => 8, optionlist => 13, comment => 2, input => 4, automakerule => 7, stmt => 6, stmts => 5, conditional => 9, ifblock => 10}, + {input => 4, optionlist => 13, ifblock => 10, value => 1, lhs => 11, if => 3, makerule => 8, automakerule => 7, stmts => 5, stmt => 6, comment => 2, conditional => 9, commentlist => 12}, {reduce => [1, \&lhs], ':' => 14, '_' => 15}, {reduce => [1, \&commentlist]}, {value => 16}, {end => 17}, - {value => 1, lhs => 11, if => 3, commentlist => 12, automakerule => 7, comment => 2, optionlist => 13, makerule => 8, reduce => [1, \&input], stmt => 18, ifblock => 10, conditional => 9}, + {stmt => 18, comment => 2, commentlist => 12, conditional => 9, reduce => [1, \&input], lhs => 11, value => 1, optionlist => 13, ifblock => 10, if => 3, makerule => 8, automakerule => 7}, {newline => 19}, {reduce => [1, \&stmt]}, {reduce => [1, \&stmt]}, {reduce => [1, \&stmt]}, - {optionalelse => 21, reduce => [0, \&optionalelse], else => 20}, - {'=' => 22}, - {comment => 23, reduce => [1, \&stmt]}, - {JAVA => 30, PROGRAMS => 25, TEXINFOS => 35, DATA => 32, primaries => 36, HEADERS => 33, LTLIBRARIES => 27, LISP => 28, PYTHON => 29, SCRIPTS => 31, value => 24, MASN => 34, LIBRARIES => 26}, - {rhs => 38, rhsval => 37}, + {else => 20, reduce => [0, \&optionalelse], optionalelse => 21}, + {'=' => 22, '+' => 23}, + {comment => 24, reduce => [1, \&stmt]}, + {LISP => 29, primaries => 37, HEADERS => 34, LIBRARIES => 27, JAVA => 31, PROGRAMS => 26, TEXINFOS => 36, DATA => 33, MASN => 35, LTLIBRARIES => 28, PYTHON => 30, SCRIPTS => 32, value => 25}, + {rhs => 39, rhsval => 38}, {reduce => [2, \&optionlist]}, - {newline => 39}, - {}, {newline => 40}, - {reduce => [2, \&stmts]}, + {}, {newline => 41}, - {endif => 42}, - {rhsval => 37, rhs => 44, optionalrhs => 43, reduce => [0, \&optionalrhs]}, + {reduce => [2, \&stmts]}, + {newline => 42}, + {endif => 43}, + {reduce => [0, \&optionalrhs], rhs => 45, optionalrhs => 44, rhsval => 38}, + {'=' => 46}, {reduce => [2, \&commentlist]}, - {'_' => 45, reduce => [1, \&primaries]}, + {reduce => [1, \&primaries], '_' => 47}, {reduce => [1, \&primaries]}, {reduce => [1, \&primaries]}, {reduce => [1, \&primaries]}, @@ -47,20 +48,22 @@ our @table=( {reduce => [1, \&primaries]}, {reduce => [2, \&lhs]}, {reduce => [1, \&rhs]}, - {reduce => [3, \&makerule], rhsval => 46}, - {automakerule => 48, optionlist => 13, lhs => 11, value => 47}, + {reduce => [3, \&makerule], rhsval => 48}, + {if => 3, makerule => 8, automakerule => 7, stmts => 49, value => 1, lhs => 11, ifblock => 10, optionlist => 13, commentlist => 12, conditional => 9, stmt => 6, comment => 2}, {reduce => [3, \&stmts]}, - {lhs => 11, value => 47, automakerule => 49, optionlist => 13}, - {reduce => [3, \&conditional]}, - {optionalcomments => 50, comment => 2, commentlist => 51, reduce => [0, \&optionalcomments]}, - {reduce => [1, \&optionalrhs], rhsval => 46}, + {ifblock => 10, optionlist => 13, value => 1, lhs => 11, stmts => 50, makerule => 8, automakerule => 7, if => 3, stmt => 6, comment => 2, conditional => 9, commentlist => 12}, + {optionalcond => 52, reduce => [0, \&optionalcond], value => 51}, + {commentlist => 54, reduce => [0, \&optionalcomments], comment => 2, optionalcomments => 53}, + {reduce => [1, \&optionalrhs], rhsval => 48}, + {rhsval => 38, optionalrhs => 55, reduce => [0, \&optionalrhs], rhs => 45}, {reduce => [3, \&optionlist]}, {reduce => [2, \&rhs]}, - {reduce => [1, \&lhs], '_' => 15}, - {newline => 52}, - {newline => 53}, + {makerule => 8, automakerule => 7, if => 3, value => 1, lhs => 11, ifblock => 10, optionlist => 13, commentlist => 12, reduce => [4, \&ifblock], conditional => 9, stmt => 18, comment => 2}, + {commentlist => 12, conditional => 9, reduce => [3, \&optionalelse], stmt => 18, comment => 2, makerule => 8, automakerule => 7, if => 3, value => 1, lhs => 11, ifblock => 10, optionlist => 13}, + {reduce => [1, \&optionalcond]}, + {reduce => [4, \&conditional]}, {reduce => [4, \&automakerule]}, - {comment => 23, reduce => [1, \&optionalcomments]}, - {reduce => [5, \&ifblock]}, - {reduce => [4, \&optionalelse]} + {comment => 24, reduce => [1, \&optionalcomments]}, + {comment => 2, optionalcomments => 56, commentlist => 54, reduce => [0, \&optionalcomments]}, + {reduce => [5, \&automakerule]} );
\ No newline at end of file diff --git a/lib/Automake/Parser/Tree.pm b/lib/Automake/Parser/Tree.pm index 6e7a4079c..b814cedf7 100644 --- a/lib/Automake/Parser/Tree.pm +++ b/lib/Automake/Parser/Tree.pm @@ -4,7 +4,7 @@ use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(input stmts stmt automakerule makerule conditional ifblock -optionalelse optionalrhs optionalcomments lhs rhs commentlist primaries +optionalelse optionalcond optionalrhs optionalcomments lhs rhs commentlist primaries optionlist traverse printgraph); # Grammar Rule : (1) input => stmts @@ -26,12 +26,12 @@ sub stmts($$;$) my ( $val1, $val2, $val3) = @_; if($val3 == undef) { - my %node=(name=>stmts,childs=>[$val1]); + my %node=(name => stmts, childs => [ $val1 ]); return \%node; } else { - push @{$val1->{childs}},$val2; + push @{$val1 -> { childs }}, $val2; return $val1; } } @@ -44,18 +44,29 @@ sub stmts($$;$) # Create a node with corresponding child node. sub stmt($) { - my ( $val1) = @_; + my ( $val1 ) = @_; my %node = ( name => stmt , childs => [ $val1 ]); return \%node; } # Grammar Rule : (1) automakerule => lhs '=' optionalrhs optionalcomments +# (2) automakerule => lhs '+' '=' optionalrhs optionalcomments # Create a node for automake rule. -sub automakerule($$$$) +sub automakerule($$$$;$) { - my ( $val1, $val2, $val3, $val4 ) = @_; - my %node = (name => automakerule, childs => [ $val1,$val3 ]); - push @{ $node{ childs }}, $val4 if $val4; + my ( $val1, $val2, $val3, $val4, $val5 ) = @_; + my %node = (name => automakerule, childs => [ $val1 ]); + if($val2 == '=') + { + push @{ $node{ childs }}, $val3; + push @{ $node{ childs }}, $val4 if $val4; + } + else + { + push @{ $node{ childs }}, $val4; + push @{ $node{ childs }}, $val5 if $val5; + $node{ append } = true; + } return \%node; } @@ -106,7 +117,7 @@ sub optionalcomments(;$) return \%node; } -# Grammar Rule : (1) conditional => ifblock optionalelse endif +# Grammar Rule : (1) conditional => ifblock optionalelse endif optionalcond # Create a node for conditional statement. sub conditional($$$) { @@ -115,7 +126,7 @@ sub conditional($$$) return \%node; } -# Grammar Rule : (1) ifblock => if value newline automakerule newline +# Grammar Rule : (1) ifblock => if value newline stmts # Create a node for if block. sub ifblock($$$$$) { @@ -126,7 +137,7 @@ sub ifblock($$$$$) # Grammar Rule : (1) optionalelse => # Create an empty node. -# (2) optionalelse => else newline automakerule newline +# (2) optionalelse => else newline stmts # Create a node with child as automakerule. sub optionalelse(;$$$$) { @@ -143,6 +154,25 @@ sub optionalelse(;$$$$) return \%node; } +# Grammar Rule : (1) optionalcond => +# Create an empty node. +# (2) optionalcond => value +# Create a node with child as automakerule. +sub optionalcond(;$) +{ + my ( $val1 ) = @_; + my %node = ( name => optionalcond ); + if( $val1 == undef ) + { + $node{ empty } = 1; + } + else + { + $node{ value } = $val1->[1]; + } + return \%node; +} + # Grammar Rule : (1) lhs => optionlist primaries # Create a node for left hand side of variable defination consisting of # option list and primary. diff --git a/lib/Automake/Parser/automake.y b/lib/Automake/Parser/automake.y index 41f0e6aa6..0814d73f3 100644 --- a/lib/Automake/Parser/automake.y +++ b/lib/Automake/Parser/automake.y @@ -12,15 +12,19 @@ stmt : automakerule | conditional ; automakerule : lhs '=' optionalrhs optionalcomments + | lhs '+' '=' optionalrhs optionalcomments ; makerule : value ':' rhs ; -conditional : ifblock optionalelse endif +conditional : ifblock optionalelse endif optionalcond ; -ifblock : if value newline automakerule newline +ifblock : if value newline stmts ; optionalelse: - | else newline automakerule newline + | else newline stmts +; +optionalcond: + | value ; optionalrhs : | rhs diff --git a/lib/Automake/Parser/input.txt b/lib/Automake/Parser/input.txt index b09e7ef8c..fc746ee72 100644 --- a/lib/Automake/Parser/input.txt +++ b/lib/Automake/Parser/input.txt @@ -8,6 +8,9 @@ Database Files #b #c #END + + + client_SOURCES = #Multiline comment \ Client dependencies if installed diff --git a/lib/Automake/Parser/parser.pl b/lib/Automake/Parser/parser.pl index 64cace1d1..65eda46da 100644 --- a/lib/Automake/Parser/parser.pl +++ b/lib/Automake/Parser/parser.pl @@ -4,6 +4,7 @@ use Lexer; use Tree; use ParserTable; +#To enable debug mode, use 1 my $debug = 0; #Stores the list of tokens generated by lexer. @@ -15,8 +16,8 @@ my $curr_tokens; #Read input from file specified in Arguements or STDIN. while ( <> ) { - ( $curr_tokens, $multiline ) = lex($_ , $multiline); - push @tokens,@$curr_tokens; + ( $curr_tokens, $multiline ) = lex( $_ , $multiline ); + push @tokens, @$curr_tokens; } #Prints to STDERR if Debug mode is on. @@ -28,7 +29,6 @@ if( $debug ) print STDERR join(" ", @{$token}), "\n"; } } - #Push a newline token if last token is not newline if( $tokens[-1][0] ne "newline" ) { @@ -75,7 +75,7 @@ while ( @stack ) } else { - die "Unexpected Token ". @curr_token."\n"; + die "Unexpected Token ". $curr_token[1]."\n"; } print STDERR @stack, "\n" if $debug; }
\ No newline at end of file diff --git a/lib/Automake/Parser/t/commen10.txt b/lib/Automake/Parser/t/commen10.txt new file mode 100644 index 000000000..ca9100c04 --- /dev/null +++ b/lib/Automake/Parser/t/commen10.txt @@ -0,0 +1,4 @@ +SUBDIRS = foo \ +# bar + +END diff --git a/lib/Automake/Parser/t/commen11.txt b/lib/Automake/Parser/t/commen11.txt new file mode 100644 index 000000000..492146aaf --- /dev/null +++ b/lib/Automake/Parser/t/commen11.txt @@ -0,0 +1,7 @@ +# initial comment +variable = value-before-comment \ +# + +# comment +SUBDIRS = foo \ +# bar diff --git a/lib/Automake/Parser/t/comment-block.txt b/lib/Automake/Parser/t/comment-block.txt new file mode 100644 index 000000000..4333868f6 --- /dev/null +++ b/lib/Automake/Parser/t/comment-block.txt @@ -0,0 +1,5 @@ +#START +#a +#b +#c +#END diff --git a/lib/Automake/Parser/t/comment.txt b/lib/Automake/Parser/t/comment.txt new file mode 100644 index 000000000..46aa24e2b --- /dev/null +++ b/lib/Automake/Parser/t/comment.txt @@ -0,0 +1 @@ +AUTOMAKE_OPTIONS = #no such option diff --git a/lib/Automake/Parser/t/comment2.txt b/lib/Automake/Parser/t/comment2.txt new file mode 100644 index 000000000..3692b1c64 --- /dev/null +++ b/lib/Automake/Parser/t/comment2.txt @@ -0,0 +1 @@ +bin_PROGRAMS = sim_products receive_th receive_pos # image_proc diff --git a/lib/Automake/Parser/t/comment4.txt b/lib/Automake/Parser/t/comment4.txt new file mode 100644 index 000000000..37fac66e9 --- /dev/null +++ b/lib/Automake/Parser/t/comment4.txt @@ -0,0 +1,4 @@ +# UnIqUe_COPYRIGHT_BOILERPLATE + +# UnIqUe_MUMBLE_COMMENT +mumble = UnIqUe_MUMBLE_VALUE diff --git a/lib/Automake/Parser/t/comment7.txt b/lib/Automake/Parser/t/comment7.txt new file mode 100644 index 000000000..5566ad8c9 --- /dev/null +++ b/lib/Automake/Parser/t/comment7.txt @@ -0,0 +1,7 @@ +if COND +# Comment for VAR in COND_TRUE. +VAR = foo +else +# Comment for VAR in COND_FALSE. +VAR = bar +endif diff --git a/lib/Automake/Parser/t/comment8.txt b/lib/Automake/Parser/t/comment8.txt new file mode 100644 index 000000000..c96e45fca --- /dev/null +++ b/lib/Automake/Parser/t/comment8.txt @@ -0,0 +1,9 @@ +VAR = valA # comA ## com C +VAR += valB # comB +if COND1 + VAR += val1 # com1 +endif COND1 +VAR += valC +if COND2 + VAR += val2 # com2 +endif COND2 diff --git a/lib/Automake/Parser/t/comment9.txt b/lib/Automake/Parser/t/comment9.txt new file mode 100644 index 000000000..8d58c00c2 --- /dev/null +++ b/lib/Automake/Parser/t/comment9.txt @@ -0,0 +1,8 @@ +TESTS = \ + 1.test \ + 2.test \ + 3.test \ +## 4.test \ + 5.test \ + 6.test \ + 7.test |