shithub: libmujs

Download patch

ref: a3aa9e7dccf3392395789a33048bd2a88a14b565
parent: 8c7f4dc57396e542b1e24a849f95561739a88887
author: Tor Andersson <[email protected]>
date: Sat Jan 18 11:27:10 EST 2014

Simplify newline tests since we normalize line endings in next().

--- a/jslex.c
+++ b/jslex.c
@@ -134,7 +134,6 @@
 
 #define PEEK (J->lexchar)
 #define NEXT() next(J, sp)
-#define NEXTPEEK (NEXT(), PEEK)
 #define ACCEPT(x) (PEEK == x ? (NEXT(), 1) : 0)
 #define EXPECT(x) (ACCEPT(x) || (jsP_error(J, "expected '%c'", x), 0))
 
@@ -196,7 +195,7 @@
 
 static inline void lexlinecomment(js_State *J, const char **sp)
 {
-	while (PEEK && !isnewline(PEEK))
+	while (PEEK && PEEK != '\n')
 		NEXT();
 }
 
@@ -303,10 +302,8 @@
 
 	/* already consumed '\' */
 
-	if (isnewline(PEEK)) {
-		NEXT();
+	if (ACCEPT('\n'))
 		return 0;
-	}
 
 	switch (PEEK) {
 	case 'u':
@@ -348,7 +345,7 @@
 	textinit(J);
 
 	while (PEEK != q) {
-		if (PEEK == 0 || isnewline(PEEK))
+		if (PEEK == 0 || PEEK == '\n')
 			return jsP_error(J, "string not terminated");
 		if (ACCEPT('\\')) {
 			if (lexescape(J, sp))
@@ -398,11 +395,11 @@
 
 	/* regexp body */
 	while (PEEK != '/') {
-		if (PEEK == 0 || isnewline(PEEK)) {
+		if (PEEK == 0 || PEEK == '\n') {
 			return jsP_error(J, "regular expression not terminated");
 		} else if (ACCEPT('\\')) {
 			textpush(J, '\\');
-			if (PEEK == 0 || isnewline(PEEK))
+			if (PEEK == 0 || PEEK == '\n')
 				return jsP_error(J, "regular expression not terminated");
 			textpush(J, PEEK);
 			NEXT();
@@ -461,8 +458,7 @@
 		while (iswhite(PEEK))
 			NEXT();
 
-		if (isnewline(PEEK)) {
-			NEXT();
+		if (ACCEPT('\n')) {
 			J->newline = 1;
 			if (isnlthcontext(J->lasttoken))
 				return ';';