shithub: rgbds

Download patch

ref: efbfeca2921c4c250faadae339374c6294f3939f
parent: 7dd34f1572bf890ed2c415e0a0dd458fb3b06375
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Wed Feb 17 05:36:36 EST 2021

Avoid two peek(1) calls when lexing """multi-line strings"""

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -1457,9 +1457,14 @@
 		case '"':
 			if (multiline) {
 				// Only """ ends a multi-line string
-				if (peek(0) != '"' || peek(1) != '"')
+				if (peek(0) != '"')
 					break;
-				shiftChars(2);
+				shiftChars(1);
+				if (peek(0) != '"') {
+					append_yylval_tzString('"');
+					break;
+				}
+				shiftChars(1);
 			}
 			goto finish;
 
@@ -1604,11 +1609,14 @@
 		case '"':
 			if (multiline) {
 				// Only """ ends a multi-line string
-				if (peek(0) != '"' || peek(1) != '"')
+				if (peek(0) != '"')
 					break;
 				append_yylval_tzString('"');
+				shiftChars(1);
+				if (peek(0) != '"')
+					break;
 				append_yylval_tzString('"');
-				shiftChars(2);
+				shiftChars(1);
 			}
 			append_yylval_tzString('"');
 			goto finish;