summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVishal Gupta <vishalgupta7972@gmail.com>2018-07-02 23:14:25 +0530
committerVishal Gupta <vishalgupta7972@gmail.com>2018-07-02 23:14:25 +0530
commita7ac93842cf5633d23263271856b7eadb6d0e3fa (patch)
treefe1da2fc094ce9e6458460b4c8f425f8436e29cd
parent3ef92ce4411f13c2c3f2e6d1e6d5ed7de647e71e (diff)
downloadautomake-a7ac93842cf5633d23263271856b7eadb6d0e3fa.tar.gz
Added support for SUBDIRS and nested if/else statement
-rw-r--r--lib/Automake/Parser/Lexer.pm4
-rw-r--r--lib/Automake/Parser/Makefile2
-rw-r--r--lib/Automake/Parser/ParserTable.pm30
-rw-r--r--lib/Automake/Parser/Tree.pm32
-rw-r--r--lib/Automake/Parser/input.txt3
-rw-r--r--lib/Automake/Parser/t/nestedcond.txt20
6 files changed, 64 insertions, 27 deletions
diff --git a/lib/Automake/Parser/Lexer.pm b/lib/Automake/Parser/Lexer.pm
index 6f09291b9..1b8a22777 100644
--- a/lib/Automake/Parser/Lexer.pm
+++ b/lib/Automake/Parser/Lexer.pm
@@ -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];
}
diff --git a/lib/Automake/Parser/Makefile b/lib/Automake/Parser/Makefile
index 84c1ca9e2..5df91c3a2 100644
--- a/lib/Automake/Parser/Makefile
+++ b/lib/Automake/Parser/Makefile
@@ -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
diff --git a/lib/Automake/Parser/ParserTable.pm b/lib/Automake/Parser/ParserTable.pm
index 4a6781660..13b607821 100644
--- a/lib/Automake/Parser/ParserTable.pm
+++ b/lib/Automake/Parser/ParserTable.pm
@@ -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
diff --git a/lib/Automake/Parser/Tree.pm b/lib/Automake/Parser/Tree.pm
index b814cedf7..a997db8f4 100644
--- a/lib/Automake/Parser/Tree.pm
+++ b/lib/Automake/Parser/Tree.pm
@@ -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 );
}
}
}
diff --git a/lib/Automake/Parser/input.txt b/lib/Automake/Parser/input.txt
index fc746ee72..77e2ba539 100644
--- a/lib/Automake/Parser/input.txt
+++ b/lib/Automake/Parser/input.txt
@@ -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
index 000000000..99d9ae9ca
--- /dev/null
+++ b/lib/Automake/Parser/t/nestedcond.txt
@@ -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