dovecot-1.2-sieve: Lexer: made sure source code positions are re...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Fri May 14 13:35:07 EEST 2010


details:   http://hg.rename-it.nl/dovecot-1.2-sieve/rev/6639e0f78bcc
changeset: 1257:6639e0f78bcc
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Fri May 14 12:34:59 2010 +0200
description:
Lexer: made sure source code positions are recorded at start of token.

diffstat:

 src/lib-sieve/sieve-lexer.c  |  45 ++++++++++++++++++++++++---------------------
 src/lib-sieve/sieve-lexer.h  |   6 +++---
 src/lib-sieve/sieve-parser.c |  24 ++++++++++++------------
 3 files changed, 39 insertions(+), 36 deletions(-)

diffs (truncated from 335 to 300 lines):

diff -r 544ec4e9c3b7 -r 6639e0f78bcc src/lib-sieve/sieve-lexer.c
--- a/src/lib-sieve/sieve-lexer.c	Fri May 14 12:16:52 2010 +0200
+++ b/src/lib-sieve/sieve-lexer.c	Fri May 14 12:34:59 2010 +0200
@@ -56,6 +56,8 @@
 	size_t buffer_pos;
 
 	struct sieve_lexer lexer;
+	
+	int current_line;
 };
 
 const struct sieve_lexer *sieve_lexer_create
@@ -100,10 +102,12 @@
 	scanner->buffer_size = 0;
 	scanner->buffer_pos = 0;
 	
-	scanner->lexer.current_line = 1;	
 	scanner->lexer.token_type = STT_NONE;
 	scanner->lexer.token_str_value = str_new(pool, 256);
 	scanner->lexer.token_int_value = 0;
+	scanner->lexer.token_line = 1;
+
+	scanner->current_line = 1;	
 		
 	return &scanner->lexer;
 }
@@ -138,7 +142,7 @@
 
 	T_BEGIN {
 		sieve_verror(scanner->ehandler, 
-			sieve_error_script_location(scanner->script, lexer->current_line),
+			sieve_error_script_location(scanner->script, scanner->current_line),
 			fmt, args);
 	} T_END;
 		
@@ -155,7 +159,7 @@
 
 	T_BEGIN { 
 		sieve_vwarning(scanner->ehandler, 
-			sieve_error_script_location(scanner->script, lexer->current_line),
+			sieve_error_script_location(scanner->script, scanner->current_line),
 			fmt, args);
 	} T_END;
 		
@@ -237,7 +241,7 @@
 static void sieve_lexer_shift(struct sieve_lexical_scanner *scanner) 
 {
 	if ( scanner->buffer != NULL && scanner->buffer[scanner->buffer_pos] == '\n' ) 
-		scanner->lexer.current_line++;	
+		scanner->current_line++;	
 	
 	if ( scanner->buffer != NULL && 
 		scanner->buffer_pos + 1 < scanner->buffer_size )
@@ -278,7 +282,6 @@
 static bool sieve_lexer_scan_raw_token(struct sieve_lexical_scanner *scanner) 
 {
 	struct sieve_lexer *lexer = &scanner->lexer;
-	sieve_number_t start_line;
 	string_t *str;
 
 	/* Read first character */
@@ -286,14 +289,17 @@
 		i_stream_read(scanner->input);
 		sieve_lexer_shift(scanner);
 	}
+
+	lexer->token_line = scanner->current_line;
   
 	switch ( sieve_lexer_curchar(scanner) ) {
 	
 	/* whitespace */
 	
 	// hash-comment = ( "#" *CHAR-NOT-CRLF CRLF )
-	case '#': 
+	case '#':
 		sieve_lexer_shift(scanner);
+
 		while ( sieve_lexer_curchar(scanner) != '\n' ) {
 			switch( sieve_lexer_curchar(scanner) ) {
 			case -1:
@@ -325,8 +331,7 @@
 	//        ;; (No * is allowed unless it is the last character,
 	//        ;; or unless it is followed by a character that isn't a
 	//        ;; slash.)
-	case '/': 
-		start_line = lexer->current_line;
+	case '/':
 		sieve_lexer_shift(scanner);
 		
 		if ( sieve_lexer_curchar(scanner) == '*' ) { 
@@ -337,7 +342,7 @@
 				case -1:
 					sieve_lexer_error(lexer, 
 						"end of file before end of bracket comment ('/* ... */') "
-						"started at line %d", start_line);
+						"started at line %d", lexer->token_line);
 					lexer->token_type = STT_ERROR;
 					return FALSE;
 				case '*':
@@ -352,7 +357,7 @@
 					} else if ( sieve_lexer_curchar(scanner) == -1 ) {
 						sieve_lexer_error(lexer, 
 							"end of file before end of bracket comment ('/* ... */') "
-							"started at line %d", start_line);
+							"started at line %d", lexer->token_line);
 						lexer->token_type = STT_ERROR;
 						return FALSE;
 					}
@@ -395,8 +400,8 @@
 		
 	/* quoted-string */
 	case '"':
-		start_line = lexer->current_line;
 		sieve_lexer_shift(scanner);
+
 		str_truncate(lexer->token_str_value, 0);
 		str = lexer->token_str_value;
 		
@@ -411,7 +416,7 @@
 			case -1:
 				sieve_lexer_error(lexer, 
 					"end of file before end of quoted string "
-					"started at line %d", start_line);
+					"started at line %d", lexer->token_line);
 				lexer->token_type = STT_ERROR;
 				return FALSE;
 
@@ -419,7 +424,7 @@
 			case '\0':
 				sieve_lexer_error(lexer,
 					"encountered NUL character in quoted string "
-					"started at line %d", start_line);
+					"started at line %d", lexer->token_line);
 				lexer->token_type = STT_ERROR;
 				return FALSE;
 
@@ -430,7 +435,7 @@
 				if ( sieve_lexer_curchar(scanner) != '\n' ) {
 					sieve_lexer_error(lexer, 
 						"found stray carriage-return (CR) character "
-						"in quoted string started at line %d", start_line);
+						"in quoted string started at line %d", lexer->token_line);
 					lexer->token_type = STT_ERROR;
 					return FALSE;
 				}
@@ -459,7 +464,7 @@
 		if ( str_len(str) > SIEVE_MAX_STRING_LEN ) {
 			sieve_lexer_error(lexer, 
 				"quoted string started at line %d is too long "
-				"(longer than %llu bytes)", start_line,
+				"(longer than %llu bytes)", lexer->token_line,
 				(long long) SIEVE_MAX_STRING_LEN);
 			lexer->token_type = STT_ERROR;
 			return FALSE;
@@ -614,8 +619,6 @@
 				type == STT_IDENTIFIER && str_len(str) == 4 &&
 				strncasecmp(str_c(str), "text", 4) == 0 ) {
 				sieve_lexer_shift(scanner); // discard colon
-
-				start_line = lexer->current_line;
   			
 				/* Discard SP and HTAB whitespace */
 				while ( sieve_lexer_curchar(scanner) == ' ' || 
@@ -678,7 +681,7 @@
 							if ( str_len(str) > SIEVE_MAX_STRING_LEN ) {
 								sieve_lexer_error(lexer, 
 									"multi-line string started at line %d is too long "
-									"(longer than %llu bytes)", start_line,
+									"(longer than %llu bytes)", lexer->token_line,
 									(long long) SIEVE_MAX_STRING_LEN);
 									lexer->token_type = STT_ERROR;
 									return FALSE;
@@ -690,7 +693,7 @@
 							/* Seen CR, but no LF */
 							sieve_lexer_error(lexer, 
 								"found stray carriage-return (CR) character "
-								"in multi-line string started at line %d", start_line);
+								"in multi-line string started at line %d", lexer->token_line);
 							lexer->token_type = STT_ERROR;
 							return FALSE;
 						}
@@ -715,7 +718,7 @@
 						case '\0':
 							sieve_lexer_error(lexer,
 								"encountered NUL character in quoted string "
-								"started at line %d", start_line);
+								"started at line %d", lexer->token_line);
 							lexer->token_type = STT_ERROR;
 							return FALSE;
 						default:
@@ -735,7 +738,7 @@
 					if ( sieve_lexer_curchar(scanner) != '\n' ) {					
 						sieve_lexer_error(lexer, 
 							"found stray carriage-return (CR) character "
-							"in multi-line string started at line %d", start_line);
+							"in multi-line string started at line %d", lexer->token_line);
  						lexer->token_type = STT_ERROR;
  						return FALSE;
 					}
diff -r 544ec4e9c3b7 -r 6639e0f78bcc src/lib-sieve/sieve-lexer.h
--- a/src/lib-sieve/sieve-lexer.h	Fri May 14 12:16:52 2010 +0200
+++ b/src/lib-sieve/sieve-lexer.h	Fri May 14 12:34:59 2010 +0200
@@ -55,7 +55,7 @@
 	string_t *token_str_value;
 	int token_int_value;
 
-	int current_line;
+	int token_line;
 };
 
 const struct sieve_lexer *sieve_lexer_create
@@ -110,10 +110,10 @@
 	return lexer->token_type == STT_EOF;
 }
 
-static inline int sieve_lexer_current_line
+static inline int sieve_lexer_token_line
 (const struct sieve_lexer *lexer) 
 {
-	return lexer->current_line;
+	return lexer->token_line;
 }
 
 const char *sieve_lexer_token_description
diff -r 544ec4e9c3b7 -r 6639e0f78bcc src/lib-sieve/sieve-parser.c
--- a/src/lib-sieve/sieve-parser.c	Fri May 14 12:16:52 2010 +0200
+++ b/src/lib-sieve/sieve-parser.c	Fri May 14 12:34:59 2010 +0200
@@ -105,7 +105,7 @@
 		T_BEGIN {
 			sieve_verror(parser->ehandler,
 				sieve_error_script_location(parser->script, 
-					sieve_lexer_current_line(parser->lexer)),
+					sieve_lexer_token_line(parser->lexer)),
 				fmt, args);
 		} T_END; 
 	}
@@ -124,7 +124,7 @@
 	T_BEGIN	{
 		sieve_vwarning(parser->ehandler, 
 			sieve_error_script_location(parser->script, 
-				sieve_lexer_current_line(parser->lexer)),
+				sieve_lexer_token_line(parser->lexer)),
 			fmt, args);
 	} T_END;
 		
@@ -171,7 +171,7 @@
 		case STT_LSQUARE:
 			/* Create stinglist object */
 			arg = sieve_ast_argument_stringlist_create
-				(node, sieve_lexer_current_line(parser->lexer));
+				(node, sieve_lexer_token_line(parser->lexer));
 
 			if ( arg == NULL ) break;
 				
@@ -183,7 +183,7 @@
 				/* Add the string to the list */
 				if ( !sieve_ast_stringlist_add
 					(arg, sieve_lexer_token_str(lexer), 
-						sieve_lexer_current_line(parser->lexer)) )
+						sieve_lexer_token_line(parser->lexer)) )
 					add_failed = TRUE;
 				
 				sieve_lexer_skip_token(lexer);
@@ -201,7 +201,7 @@
 						/* Add the string to the list */
 						if ( !sieve_ast_stringlist_add
 							(arg, sieve_lexer_token_str(lexer), 
-								sieve_lexer_current_line(parser->lexer)) )
+								sieve_lexer_token_line(parser->lexer)) )
 							add_failed = TRUE;
 							
 						sieve_lexer_skip_token(lexer);
@@ -246,7 +246,7 @@
 		case STT_STRING: 
 			arg = sieve_ast_argument_string_create
 				(node, sieve_lexer_token_str(lexer), 
-					sieve_lexer_current_line(parser->lexer));
+					sieve_lexer_token_line(parser->lexer));
 
 			sieve_lexer_skip_token(lexer);
 			break;
@@ -255,7 +255,7 @@
 		case STT_NUMBER:
 			arg = sieve_ast_argument_number_create
 				(node, sieve_lexer_token_int(lexer), 
-					sieve_lexer_current_line(parser->lexer));
+					sieve_lexer_token_line(parser->lexer));
 			sieve_lexer_skip_token(lexer);
 			break;
 			
@@ -263,7 +263,7 @@
 		case STT_TAG:
 			arg = sieve_ast_argument_tag_create
 				(node, sieve_lexer_token_ident(lexer), 
-					sieve_lexer_current_line(parser->lexer));
+					sieve_lexer_token_line(parser->lexer));
 			sieve_lexer_skip_token(lexer);
 			break;
 			
@@ -305,7 +305,7 @@


More information about the dovecot-cvs mailing list