]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
Added support for include directive
authorVishal Gupta <vishalgupta7972@gmail.com>
Wed, 25 Jul 2018 17:53:24 +0000 (23:23 +0530)
committerVishal Gupta <vishalgupta7972@gmail.com>
Wed, 25 Jul 2018 17:53:24 +0000 (23:23 +0530)
Added lexer and parser support for include directive to handle fragements.

lib/Automake/Parser/Lexer.pm
lib/Automake/Parser/ParserTable.pm
lib/Automake/Parser/Tree.pm
lib/Automake/Parser/automake.y
lib/Automake/Parser/test.sh

index ec514c50fffaad99a0eb062b7d30334901434c33..5a206769ee080893472b67f7842d1b5d1e320928 100644 (file)
@@ -101,7 +101,7 @@ sub lex($)
                                push @tokens, [ "newline" ];
                        }
                }
-               elsif( s/^(PROGRAMS|LIBRARIES|LTLIBRARIES|LISP|PYTHON|JAVA|SCRIPTS|DATA|HEADERS|MASN|TEXINFOS|if|else|endif)//o)
+               elsif( s/^(PROGRAMS|LIBRARIES|LTLIBRARIES|LISP|PYTHON|JAVA|SCRIPTS|DATA|HEADERS|MASN|TEXINFOS|if|else|endif|include)//o)
                {
                        push @tokens, [$1];
                }
index 1647af076e01dc4ab8cf1c96e67285cbd1451db3..ae54f0db8b74d2764255846637136903570ebae3 100644 (file)
@@ -6,35 +6,38 @@ use Tree;
 our @ISA=qw(Exporter);
 our @Export=qw(@table $accept);
 
-our $accept=17;
+our $accept=20;
 
 our @table=(
-               {makerule => 8, stmt => 6, value => 1, input => 4, if => 3, automakerule => 7, ifblock => 10, comment => 2, optionlist => 13, lhs => 11, stmts => 5, conditional => 9, commentlist => 12},
-               {'_' => 15, reduce => [1,  \&lhs], ':' => 14},
+               {makerule => 9, include => 4, comment => 2, stmt => 7, conditional => 11, stmts => 6, ifblock => 12, value => 1, input => 5, includerule => 10, optionlist => 15, automakerule => 8, if => 3, commentlist => 14, lhs => 13},
+               {reduce => [1,  \&lhs], ':' => 16, '_' => 17},
                {reduce => [1,  \&commentlist]},
-               {value => 16},
-               {end => 17},
-               {optionlist => 13, comment => 2, commentlist => 12, lhs => 11, conditional => 9, automakerule => 7, ifblock => 10, reduce => [1,  \&input], if => 3, stmt => 18, makerule => 8, value => 1},
-               {newline => 19},
+               {value => 18},
+               {value => 19},
+               {end => 20},
+               {conditional => 11, include => 4, comment => 2, stmt => 21, makerule => 9, if => 3, reduce => [1,  \&input], lhs => 13, commentlist => 14, optionlist => 15, automakerule => 8, includerule => 10, ifblock => 12, value => 1},
+               {newline => 22},
                {reduce => [1,  \&stmt]},
                {reduce => [1,  \&stmt]},
                {reduce => [1,  \&stmt]},
-               {else => 20, reduce => [0,  \&optionalelse], optionalelse => 21},
-               {'+' => 23, '=' => 22},
-               {comment => 24, reduce => [1,  \&stmt]},
-               {primaries => 37, value => 25, PROGRAMS => 26, MASN => 35, TEXINFOS => 36, LIBRARIES => 27, HEADERS => 34, SCRIPTS => 32, DATA => 33, LTLIBRARIES => 28, LISP => 29, JAVA => 31, PYTHON => 30},
-               {rhsval => 38, rhs => 39},
+               {reduce => [1,  \&stmt]},
+               {reduce => [0,  \&optionalelse], optionalelse => 24, else => 23},
+               {'+' => 26, '=' => 25},
+               {reduce => [1,  \&stmt], comment => 27},
+               {SCRIPTS => 35, LIBRARIES => 30, LISP => 32, HEADERS => 37, PYTHON => 33, PROGRAMS => 29, LTLIBRARIES => 31, JAVA => 34, DATA => 36, TEXINFOS => 39, primaries => 40, value => 28, MASN => 38},
+               {rhsval => 41, rhs => 42},
                {reduce => [2,  \&optionlist]},
-               {newline => 40},
+               {newline => 43},
+               {reduce => [2,  \&includerule]},
                {},
-               {newline => 41},
+               {newline => 44},
                {reduce => [2,  \&stmts]},
-               {newline => 42},
-               {endif => 43},
-               {optionalrhs => 44, rhs => 45, rhsval => 38, reduce => [0,  \&optionalrhs]},
-               {'=' => 46},
+               {newline => 45},
+               {endif => 46},
+               {optionalrhs => 47, rhsval => 41, rhs => 48, reduce => [0,  \&optionalrhs]},
+               {'=' => 49},
                {reduce => [2,  \&commentlist]},
-               {reduce => [1,  \&primaries], '_' => 47},
+               {reduce => [1,  \&primaries], '_' => 50},
                {reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},
@@ -48,22 +51,22 @@ our @table=(
                {reduce => [1,  \&primaries]},
                {reduce => [2,  \&lhs]},
                {reduce => [1,  \&rhs]},
-               {reduce => [3,  \&makerule], rhsval => 48},
-               {automakerule => 7, ifblock => 10, comment => 2, optionlist => 13, commentlist => 12, lhs => 11, stmts => 49, conditional => 9, stmt => 6, makerule => 8, value => 1, if => 3},
+               {rhsval => 51, reduce => [3,  \&makerule]},
+               {comment => 2, stmt => 7, include => 4, makerule => 9, stmts => 52, conditional => 11, includerule => 10, value => 1, ifblock => 12, lhs => 13, commentlist => 14, if => 3, automakerule => 8, optionlist => 15},
                {reduce => [3,  \&stmts]},
-               {if => 3, value => 1, stmt => 6, makerule => 8, commentlist => 12, lhs => 11, stmts => 50, conditional => 9, comment => 2, optionlist => 13, ifblock => 10, automakerule => 7},
-               {value => 51, optionalcond => 52, reduce => [0,  \&optionalcond]},
-               {comment => 2, reduce => [0,  \&optionalcomments], optionalcomments => 53, commentlist => 54},
-               {rhsval => 48, reduce => [1,  \&optionalrhs]},
-               {optionalrhs => 55, rhsval => 38, reduce => [0,  \&optionalrhs], rhs => 45},
+               {stmts => 53, conditional => 11, stmt => 7, comment => 2, include => 4, makerule => 9, commentlist => 14, lhs => 13, if => 3, automakerule => 8, optionlist => 15, includerule => 10, ifblock => 12, value => 1},
+               {value => 54, optionalcond => 55, reduce => [0,  \&optionalcond]},
+               {commentlist => 57, reduce => [0,  \&optionalcomments], optionalcomments => 56, comment => 2},
+               {reduce => [1,  \&optionalrhs], rhsval => 51},
+               {rhsval => 41, optionalrhs => 58, rhs => 48, reduce => [0,  \&optionalrhs]},
                {reduce => [3,  \&optionlist]},
                {reduce => [2,  \&rhs]},
-               {if => 3, reduce => [4,  \&ifblock], value => 1, stmt => 18, makerule => 8, commentlist => 12, conditional => 9, lhs => 11, optionlist => 13, comment => 2, ifblock => 10, automakerule => 7},
-               {value => 1, stmt => 18, makerule => 8, if => 3, reduce => [3,  \&optionalelse], ifblock => 10, automakerule => 7, commentlist => 12, conditional => 9, lhs => 11, optionlist => 13, comment => 2},
+               {value => 1, ifblock => 12, includerule => 10, optionlist => 15, automakerule => 8, if => 3, lhs => 13, reduce => [4,  \&ifblock], commentlist => 14, makerule => 9, include => 4, stmt => 21, comment => 2, conditional => 11},
+               {comment => 2, stmt => 21, include => 4, makerule => 9, conditional => 11, includerule => 10, value => 1, ifblock => 12, lhs => 13, reduce => [3,  \&optionalelse], commentlist => 14, if => 3, automakerule => 8, optionlist => 15},
                {reduce => [1,  \&optionalcond]},
                {reduce => [4,  \&conditional]},
                {reduce => [4,  \&automakerule]},
-               {comment => 24, reduce => [1,  \&optionalcomments]},
-               {comment => 2, reduce => [0,  \&optionalcomments], optionalcomments => 56, commentlist => 54},
+               {comment => 27, reduce => [1,  \&optionalcomments]},
+               {comment => 2, commentlist => 57, reduce => [0,  \&optionalcomments], optionalcomments => 59},
                {reduce => [5,  \&automakerule]}
 );
\ No newline at end of file
index abb44ff992ad537144bce69b58a403ef306b5967..8230ce5f14a67ca25eef077eb9e4d4e661dbf6e8 100644 (file)
@@ -54,6 +54,7 @@ sub stmts($$;$)
 #                               (2) stmt => makerule
 #                               (3) stmt => commentlist
 #                               (4) stmt => conditional
+#                               (5) stmt => includerule
 # Create a node with corresponding child node.
 sub stmt($)
 {
@@ -295,6 +296,14 @@ sub optionlist($$;$)
        }
 }
 
+sub includerule($$)
+{
+       my ( $val1, $val2 ) = @_;
+       print STDERR $val2;
+       my %node = (name => includerule, value => $val2);
+       return \%node;
+}
+
 # printgraph(Hash)
 # prints the AST to Standard Output by traversing the tree starting at node pointed by hash.
 sub printgraph($)
index 0814d73f326443f865b307adb6b82af172d1ffb6..43af61072dd0e86039cbd05f77c72732e5c486e3 100644 (file)
@@ -1,4 +1,4 @@
-%token value rhsval comment PROGRAMS LIBRARIES LTLIBRARIES LISP PYTHON JAVA SCRIPTS DATA HEADERS MASN TEXINFOS newline if else endif
+%token value rhsval comment PROGRAMS LIBRARIES LTLIBRARIES LISP PYTHON JAVA SCRIPTS DATA HEADERS MASN TEXINFOS newline if else endif include
 %%
 
 input : stmts
@@ -10,12 +10,15 @@ stmt  : automakerule
                | makerule
                | commentlist
                | conditional
+               | includerule
 ;
 automakerule : lhs '=' optionalrhs optionalcomments
                         | lhs '+' '=' optionalrhs optionalcomments
 ;
 makerule : value ':' rhs
 ;
+includerule : include value
+;
 conditional : ifblock optionalelse endif optionalcond
 ;
 ifblock : if value newline stmts
index f20e0097bc28909e6c61e72778d445bda1fbc6fc..6f49ad1bd4397c3b56708b2d4cfe35cb0671da10 100644 (file)
@@ -3,7 +3,8 @@ testfile()
 {
        filename=$1
        echo $filename
-       perl -I. parser.pl $filename > $filename.gv
+       echo `pwd`
+       perl parser.pl $filename > $filename.gv
        unflatten -f -l 10 -c 10 -o $filename1.gv $filename.gv
        dot -Tpng $filename1.gv > $filename.png
        rm $filename.gv $filename1.gv