]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
Added support for SUBDIRS and nested if/else statement
authorVishal Gupta <vishalgupta7972@gmail.com>
Mon, 2 Jul 2018 17:44:25 +0000 (23:14 +0530)
committerVishal Gupta <vishalgupta7972@gmail.com>
Mon, 2 Jul 2018 17:44:25 +0000 (23:14 +0530)
lib/Automake/Parser/Lexer.pm
lib/Automake/Parser/Makefile
lib/Automake/Parser/ParserTable.pm
lib/Automake/Parser/Tree.pm
lib/Automake/Parser/input.txt
lib/Automake/Parser/t/nestedcond.txt [new file with mode: 0644]

index 6f09291b93ca9eac7025caa4522d3acfb4404616..1b8a2277756352da3513963c2c07c07b15681cda 100644 (file)
@@ -98,7 +98,7 @@ sub lex($$)
                {
                        push @tokens, [$1];
                }
-               elsif( s/^([a-zA-Z0-9]+)//o )
+               elsif( s/^([a-zA-Z0-9_]+)//o )
                {
                        push @tokens, ["value",$1];
                }
@@ -113,7 +113,7 @@ sub lex($$)
                        push @tokens, [$1];
                        $rhs = 1;
                }
-               elsif( s/^(:|_)//o )
+               elsif( s/^(:|_|!)//o )
                {
                        push @tokens, [$1];
                }
index 84c1ca9e204ed491b9a26ee86e33a873dc056310..5df91c3a23d6c8acd4a1b88f2e906045845d459b 100644 (file)
@@ -2,7 +2,7 @@
 all: ast.png
 
 ast.png: Lexer.pm Tree.pm ParserTable.pm parser.pl input.txt
-       perl -I. parser.pl input.txt > ast.gv
+       perl -I. Parser.pl input.txt > ast.gv
        unflatten -f -l 10 -c 10 -o ast1.gv ast.gv
        dot -Tpng ast1.gv > ast.png
        rm ast.gv ast1.gv       
index 4a678166061c094cd939b4f2ddff56a454e99edf..13b607821cd87a28e33ff0669d36a7b173b007ac 100644 (file)
@@ -9,20 +9,20 @@ our @Export=qw(@table $accept);
 our $accept=17;
 
 our @table=(
-               {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},
+               {stmts => 5, makerule => 8, comment => 2, lhs => 11, input => 4, ifblock => 10, stmt => 6, optionlist => 13, automakerule => 7, conditional => 9, if => 3, commentlist => 12, value => 1},
                {reduce => [1,  \&lhs], ':' => 14, '_' => 15},
                {reduce => [1,  \&commentlist]},
                {value => 16},
                {end => 17},
-               {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},
+               {makerule => 8, comment => 2, lhs => 11, ifblock => 10, stmt => 18, optionlist => 13, automakerule => 7, conditional => 9, if => 3, reduce => [1,  \&input], commentlist => 12, value => 1},
                {newline => 19},
                {reduce => [1,  \&stmt]},
                {reduce => [1,  \&stmt]},
                {reduce => [1,  \&stmt]},
-               {else => 20, reduce => [0,  \&optionalelse], optionalelse => 21},
-               {'=' => 22, '+' => 23},
+               {optionalelse => 21, reduce => [0,  \&optionalelse], else => 20},
+               {'+' => 23, '=' => 22},
                {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},
+               {PYTHON => 30, SCRIPTS => 32, JAVA => 31, LTLIBRARIES => 28, DATA => 33, value => 25, HEADERS => 34, TEXINFOS => 36, primaries => 37, LIBRARIES => 27, PROGRAMS => 26, LISP => 29, MASN => 35},
                {rhs => 39, rhsval => 38},
                {reduce => [2,  \&optionlist]},
                {newline => 40},
@@ -31,7 +31,7 @@ our @table=(
                {reduce => [2,  \&stmts]},
                {newline => 42},
                {endif => 43},
-               {reduce => [0,  \&optionalrhs], rhs => 45, optionalrhs => 44, rhsval => 38},
+               {optionalrhs => 44, rhs => 45, rhsval => 38, reduce => [0,  \&optionalrhs]},
                {'=' => 46},
                {reduce => [2,  \&commentlist]},
                {reduce => [1,  \&primaries], '_' => 47},
@@ -49,21 +49,21 @@ our @table=(
                {reduce => [2,  \&lhs]},
                {reduce => [1,  \&rhs]},
                {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},
+               {lhs => 11, ifblock => 10, stmts => 49, makerule => 8, comment => 2, conditional => 9, if => 3, commentlist => 12, value => 1, stmt => 6, optionlist => 13, automakerule => 7},
                {reduce => [3,  \&stmts]},
-               {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},
+               {comment => 2, stmts => 50, makerule => 8, ifblock => 10, lhs => 11, automakerule => 7, optionlist => 13, stmt => 6, value => 1, commentlist => 12, if => 3, conditional => 9},
+               {reduce => [0,  \&optionalcond], value => 51, optionalcond => 52},
+               {optionalcomments => 53, comment => 2, commentlist => 54, reduce => [0,  \&optionalcomments]},
                {reduce => [1,  \&optionalrhs], rhsval => 48},
-               {rhsval => 38, optionalrhs => 55, reduce => [0,  \&optionalrhs], rhs => 45},
+               {rhs => 45, optionalrhs => 55, reduce => [0,  \&optionalrhs], rhsval => 38},
                {reduce => [3,  \&optionlist]},
                {reduce => [2,  \&rhs]},
-               {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 => [4,  \&ifblock], value => 1, commentlist => 12, if => 3, conditional => 9, automakerule => 7, optionlist => 13, stmt => 18, ifblock => 10, lhs => 11, comment => 2, makerule => 8},
+               {comment => 2, makerule => 8, ifblock => 10, lhs => 11, automakerule => 7, optionlist => 13, stmt => 18, reduce => [3,  \&optionalelse], value => 1, commentlist => 12, if => 3, conditional => 9},
                {reduce => [1,  \&optionalcond]},
                {reduce => [4,  \&conditional]},
                {reduce => [4,  \&automakerule]},
-               {comment => 24, reduce => [1,  \&optionalcomments]},
-               {comment => 2, optionalcomments => 56, commentlist => 54, reduce => [0,  \&optionalcomments]},
+               {reduce => [1,  \&optionalcomments], comment => 24},
+               {reduce => [0,  \&optionalcomments], commentlist => 54, comment => 2, optionalcomments => 56},
                {reduce => [5,  \&automakerule]}
 );
\ No newline at end of file
index b814cedf7996661e3364e6aa46590fcd2622021f..a997db8f419a187885a375fa58a20c577e8c3a9e 100644 (file)
@@ -7,12 +7,25 @@ our @EXPORT = qw(input stmts stmt automakerule makerule conditional ifblock
 optionalelse optionalcond optionalrhs optionalcomments lhs rhs commentlist primaries 
 optionlist traverse printgraph);
 
+my $isSubdir = 0 , @subdirnodes = ();
+
 # Grammar Rule : (1) input => stmts
 # Create a node having child as stmts.
 sub input($)
 {
        my ( $val ) = @_;
-       my %node = (name => input, childs => [ $val ]);
+       my %node = ( name => input, childs => [ $val ] );
+       push @{$node -> {childs}}, subdirNode() if $#subdirnodes > -1;
+       return \%node;
+}
+
+# Creates a Node having all the sub directories which are to be recursed.
+sub subdirNode()
+{
+       my %node = ( name => subdir, empty => 1 );
+       my @subdir = ();
+       push @subdir, @{ $_ -> { value }} foreach @subdirnodes;
+       $node{ subdirs } = \@subdir;
        return \%node;
 }
 
@@ -26,7 +39,7 @@ sub stmts($$;$)
        my ( $val1, $val2, $val3) = @_;
        if($val3 == undef)
        {
-               my %node=(name => stmts, childs => [ $val1 ]);
+               my %node = ( name => stmts, childs => [ $val1 ]);
                return \%node;
        }
        else
@@ -56,7 +69,7 @@ sub automakerule($$$$;$)
 {
        my ( $val1, $val2, $val3, $val4, $val5 ) = @_;
        my %node = (name => automakerule, childs => [ $val1 ]);
-       if($val2 == '=')
+       if($val2->[0] eq '=')
        {
                push @{ $node{ childs }}, $val3;
                push @{ $node{ childs }}, $val4 if $val4;
@@ -94,7 +107,9 @@ sub optionalrhs(;$)
        else
        {
                $node{ childs } = [ $val ];
+               push @subdirnodes, $val if $isSubdir;
        }
+       $isSubdir = 0;
        return \%node;
 }
 
@@ -186,6 +201,7 @@ sub lhs($;$)
        if( $val2 == undef )
        {
                $node{ value } = $val1 -> [1];
+               $isSubdir = 1 if $node{value} eq 'SUBDIRS';
        }
        else
        {
@@ -227,7 +243,7 @@ sub commentlist($;$)
        }
        else
        {
-               push @{ $val1 -> {value}} , $val2 -> [1];
+               push @{ $val1 -> { value }} , $val2 -> [1];
                return $val1;
        }
 }
@@ -251,11 +267,11 @@ sub primaries($)
        my %node = ( name => primaries );
        if( $val -> [0] eq 'value')
        {
-               $node{value}= $val -> [1];
+               $node{ value } = $val -> [1];
        }
        else
        {
-               $node{value}= $val;
+               $node{ value } = $val;
        }
        return \%node;
 }
@@ -291,7 +307,7 @@ sub printgraph($)
 }
 
 #Stores the next id to be alloted to new node.
-my $id=0;
+my $id = 0;
 
 # traverse(Hash, Parent Id)
 # Traverses the tree recursively. Prints the information about the current node to Standard Output. Call all its child with Parent Id equal to current Node Id.
@@ -323,7 +339,7 @@ sub traverse($$)
                my $val1 = $node{childs};
                foreach $child (@$val1)
                {
-                       traverse($child,$curr_id);
+                       traverse( $child, $curr_id );
                }
        }
 }
index fc746ee7212324f36a1357ee5d8839e8eabce6b5..77e2ba539b0fc15f48b62e6f0e66e77c863b8c06 100644 (file)
@@ -9,7 +9,8 @@ Database Files
 #c
 #END
 
-
+SUBDIRS = app app1
+SUBDIRS += app2
 
 client_SOURCES =  #Multiline comment \
 Client dependencies
diff --git a/lib/Automake/Parser/t/nestedcond.txt b/lib/Automake/Parser/t/nestedcond.txt
new file mode 100644 (file)
index 0000000..99d9ae9
--- /dev/null
@@ -0,0 +1,20 @@
+SUBDIRS = a
+if CASE_A
+SUBDIRS += b
+endif
+SUBDIRS += c
+if CASE_A
+SUBDIRS += d
+if CASE_B
+SUBDIRS += e
+endif
+SUBDIRS += f
+endif
+SUBDIRS += g
+if CASE_B
+SUBDIRS += h
+endif
+if CASE_B
+SUBDIRS += iXYZ
+SUBDIRS += jZYX
+endif
\ No newline at end of file