git: 9front

Download patch

ref: 02fdefe15a8152dbee66519fc3a14c186650485f
parent: 7d6f64c59093d5a8e6ef35d8c012395a6eff64c1
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Dec 6 06:53:44 EST 2019

hoc: don't nest calls to follow() when lexing ++/+= and --/-= (#287)

The code had a nested use of the follow() function that could cause +=+
and -=- to register as ++ and --.  The first follow() to execute could
consume a character and match and then the second follow() could consume
another character and match.  For example i-=-10 would result in a syntax
error and i-=- would decrement i.

(imported from plan9port commit f1dd3f065a97f57bf59db2e3284868e181734159)

--- a/sys/src/cmd/hoc/hoc.y
+++ b/sys/src/cmd/hoc/hoc.y
@@ -214,8 +214,8 @@
 		return STRING;
 	}
 	switch (c) {
-	case '+':	return follow('+', INC, follow('=', ADDEQ, '+'));
-	case '-':	return follow('-', DEC, follow('=', SUBEQ, '-'));
+	case '+':	return follow('+', INC, '+') == INC ? INC : follow('=', ADDEQ, '+');
+	case '-':	return follow('-', DEC, '-') == DEC ? DEC : follow('=', SUBEQ, '-');
 	case '*':	return follow('=', MULEQ, '*');
 	case '/':	return follow('=', DIVEQ, '/');
 	case '%':	return follow('=', MODEQ, '%');
--