shithub: libmujs

Download patch

ref: 7bf5257d008758f60bdffe0b68f4fa8fdca2e0f3
parent: 442b8d27a1ef17c3127a4ca58f2df62523243270
author: Tor Andersson <[email protected]>
date: Sat Jan 18 10:05:43 EST 2014

Save line number where the token starts for improved error messages.

--- a/jslex.c
+++ b/jslex.c
@@ -423,6 +423,7 @@
 	J->newline = 0;
 
 	while (1) {
+		J->lexline = J->line; /* save location of beginning of token */
 		int c = NEXT();
 
 		while (iswhite(c))
--- a/jsparse.c
+++ b/jsparse.c
@@ -31,7 +31,7 @@
 	js_Ast *node = malloc(sizeof(js_Ast));
 
 	node->type = type;
-	node->line = J->line;
+	node->line = J->lexline;
 	node->a = a;
 	node->b = b;
 	node->c = c;
@@ -842,7 +842,7 @@
 {
 	va_list ap;
 
-	fprintf(stderr, "%s:%d: warning: ", J->filename, J->line);
+	fprintf(stderr, "%s:%d: warning: ", J->filename, J->lexline);
 	va_start(ap, fmt);
 	vfprintf(stderr, fmt, ap);
 	va_end(ap);
@@ -853,7 +853,7 @@
 {
 	va_list ap;
 
-	fprintf(stderr, "%s:%d: error: ", J->filename, J->line);
+	fprintf(stderr, "%s:%d: error: ", J->filename, J->lexline);
 	va_start(ap, fmt);
 	vfprintf(stderr, fmt, ap);
 	va_end(ap);
--- a/jsstate.h
+++ b/jsstate.h
@@ -19,6 +19,7 @@
 
 	/* lexer */
 	struct { char *text; size_t len, cap; } buf;
+	int lexline;
 	int lasttoken;
 	int newline;