[anjuta/newproject] Fix adding target at the end of the file and add more checks



commit b78050d297769c35a6acdbe653eea4e201edb8ce
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Tue Oct 5 22:55:05 2010 +0200

    Fix adding target at the end of the file and add more checks

 libanjuta/anjuta-token-list.c      |    7 +++--
 plugins/am-project/am-parser.y     |    9 ++-----
 plugins/am-project/am-scanner.l    |   43 +++++++++++++++++++++--------------
 plugins/am-project/tests/target.at |   31 ++++++++++++++++++++++++++
 4 files changed, 64 insertions(+), 26 deletions(-)
---
diff --git a/libanjuta/anjuta-token-list.c b/libanjuta/anjuta-token-list.c
index ccd534d..2d2fc00 100644
--- a/libanjuta/anjuta-token-list.c
+++ b/libanjuta/anjuta-token-list.c
@@ -568,6 +568,8 @@ anjuta_token_insert_word_after (AnjutaToken *list, AnjutaToken *sibling, AnjutaT
 	{
 		AnjutaToken *next;
 		
+		next = anjuta_token_next_item (token);
+		
 		fprintf(stderr, "anjuta_token_first_item list %p sibling %p item %p token %p\n", list, sibling, item, token);
 		switch (anjuta_token_get_type (token))
 		{
@@ -576,9 +578,9 @@ anjuta_token_insert_word_after (AnjutaToken *list, AnjutaToken *sibling, AnjutaT
 			anjuta_token_insert_before (token, item);
 			return item;
 		case ANJUTA_TOKEN_START:		
-			if (token == sibling)
+			if ((sibling == NULL) || (token == sibling))
 			{
-				anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
+				if (next != NULL) anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
 				anjuta_token_insert_after (token, item);
 				return item;
 			}
@@ -601,7 +603,6 @@ anjuta_token_insert_word_after (AnjutaToken *list, AnjutaToken *sibling, AnjutaT
 			break;
 		}
 
-		next = anjuta_token_next_item (token);
 		if (next == NULL)
 		{
 			fprintf(stderr, "anjuta_token_word_after list %p sibling %p item %p token %p\n", list, sibling, item, token);
diff --git a/plugins/am-project/am-parser.y b/plugins/am-project/am-parser.y
index 5dc6a61..8955ff7 100644
--- a/plugins/am-project/am-parser.y
+++ b/plugins/am-project/am-parser.y
@@ -160,14 +160,10 @@ amp_am_automake_variable (AnjutaToken *token)
 
 %%
 
+/* File cannot be empty, there at least the END_OF_FILE token */
 file:
-	/* empty */
-	| statement_list
-	;
-
-statement_list:
 	statement
-	| statement_list statement
+	| file statement
 	;
 
 statement:
@@ -304,6 +300,7 @@ head_list_body:
 value_list:
 	space {
 		$$ = anjuta_token_new_static (ANJUTA_TOKEN_LIST, NULL);
+		if ($1 != NULL) anjuta_token_set_type ($1, ANJUTA_TOKEN_START);
 		anjuta_token_merge ($$, $1);
 	}
 	| optional_space value_list_body optional_space {
diff --git a/plugins/am-project/am-scanner.l b/plugins/am-project/am-scanner.l
index 9c22e29..a871d96 100644
--- a/plugins/am-project/am-scanner.l
+++ b/plugins/am-project/am-scanner.l
@@ -52,7 +52,7 @@ struct _AmpAmScanner
 	AmpProject *project;
 	AnjutaAmGroupNode *group;
 	GHashTable *orphan_properties;
-	gboolean eof;
+	gboolean eof;		/* TRUE to emit EOF at the end */
 };
 
 %}
@@ -206,24 +206,31 @@ NAME          [^ \t\n\r:#=$"'`&@\\]*
 static gint
 amp_am_scanner_parse_end (AmpAmScanner *scanner)
 {
-    if (scanner->stream == NULL)
-    {
-        yyterminate();
-    }
-    else
-    {
-        yypop_buffer_state(scanner->scanner);
+
+   	if (scanner->stream == NULL)
+   	{
+		yyterminate();
+	}
+   	else
+   	{
+		if (scanner->eof)
+		{
+			scanner->eof = FALSE;
+			return END_OF_FILE;
+		}
+       	yypop_buffer_state(scanner->scanner);
         scanner->stream = anjuta_token_stream_pop (scanner->stream);
 
-        if (scanner->stream == NULL)
-        {
-            yyterminate();
-        }
-        else
-        {
-            return 1;
-        }
-    }
+		if (scanner->stream == NULL)
+		{
+			yyterminate();
+		}
+		else
+		{
+			/* Continue parsing the parent file */
+			return 1;
+		}
+	}
 }
 
 /* Parser functions
@@ -307,6 +314,8 @@ amp_am_scanner_parse_token (AmpAmScanner *scanner, AnjutaToken *root, AnjutaToke
     stream = anjuta_token_stream_push (scanner->stream, root, content, filename);
     first = anjuta_token_stream_get_root (stream);
 
+	scanner->eof = filename != NULL;
+
     if (scanner->stream != NULL)
     {
         /* Parse an included file or a expanded variable */
diff --git a/plugins/am-project/tests/target.at b/plugins/am-project/tests/target.at
index 7e8d393..ee56652 100644
--- a/plugins/am-project/tests/target.at
+++ b/plugins/am-project/tests/target.at
@@ -10,12 +10,18 @@ AT_DATA([expect],
 [[    GROUP (0): empty1
         TARGET (0:0): target1
 ]])
+AT_DATA([reference],
+[[## Process this file with automake to produce Makefile.in
+
+bin_PROGRAMS = target1
+]])
 AT_PARSER_CHECK([load empty \
 		 move empty1 \
 		 add target 0 target1 3 \
 		 list \
 		 save])
 AT_CHECK([diff output expect])
+AT_CHECK([diff -b empty1/Makefile.am reference])
 AT_PARSER_CHECK([load empty1 \
 		 list])
 AT_CHECK([diff output expect])
@@ -25,12 +31,19 @@ AT_DATA([expect],
         TARGET (0:0): target1
         TARGET (0:1): target2
 ]])
+AT_DATA([reference],
+[[## Process this file with automake to produce Makefile.in
+
+bin_PROGRAMS = target1 \
+	target2
+]])
 AT_PARSER_CHECK([load empty1 \
 		 move empty2 \
 		 add target 0 target2 3 after 0:0\
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty2/Makefile.am reference])
 AT_PARSER_CHECK([load empty2 \
 		 list])
 AT_CHECK([diff -b output expect])
@@ -39,12 +52,18 @@ AT_DATA([expect],
 [[    GROUP (0): empty3
         TARGET (0:0): target2
 ]])
+AT_DATA([reference],
+[[## Process this file with automake to produce Makefile.in
+
+bin_PROGRAMS = target2
+]])
 AT_PARSER_CHECK([load empty2 \
 		 move empty3 \
 		 remove 0:0 \
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty3/Makefile.am reference])
 AT_PARSER_CHECK([load empty3 \
 		 list])
 AT_CHECK([diff -b output expect])
@@ -52,12 +71,18 @@ AT_CHECK([diff -b output expect])
 AT_DATA([expect],
 [[    GROUP (0): empty4
 ]])
+AT_DATA([reference],
+[[## Process this file with automake to produce Makefile.in
+
+bin_PROGRAMS =
+]])
 AT_PARSER_CHECK([load empty3 \
 		 move empty4 \
 		 remove 0:0 \
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty4/Makefile.am reference])
 AT_PARSER_CHECK([load empty4 \
 		 list])
 AT_CHECK([diff -b output expect])
@@ -66,12 +91,18 @@ AT_DATA([expect],
 [[    GROUP (0): empty5
         TARGET (0:0): target1
 ]])
+AT_DATA([reference],
+[[## Process this file with automake to produce Makefile.in
+
+bin_PROGRAMS = target1
+]])
 AT_PARSER_CHECK([load empty4 \
 		 move empty5 \
 		 add target 0 target1 3 \
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty5/Makefile.am reference])
 AT_PARSER_CHECK([load empty5 \
 		 list])
 AT_CHECK([diff -b output expect])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]