From 9bdd24cae96d01fc6b2a940bc87d27edeb5d84a7 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 12 Sep 2020 17:54:43 -0700 Subject: [PATCH] fix: track source line number accurately across newlines in quoted strings The regex for matching arbitrary content within a quoted string (qstring) was too broad, matching also newlines. Due to the way Flex preferences regex matches this prevented the literal newline rule from matching at all within a quoted string. As a result error messages would reference incorrect line numbers. Closes #1411. --- CHANGELOG.md | 1 + lib/cgraph/scan.l | 2 +- rtest/1411.dot | 81 ++++++++++++++++++++++++++++++++++++++++ rtest/test_regression.py | 20 ++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 rtest/1411.dot diff --git a/CHANGELOG.md b/CHANGELOG.md index 3db717d3d..b43ef868c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - a failure to detect OpenGL glGenTextures() errors has been corrected - sfio does compile time benchmarknig #1422 - iffe "lib" check always succeeds when compiler optimises #1521 +- syntax error near text who is not present #1411 ## [2.44.1] - 2020-06-29 diff --git a/lib/cgraph/scan.l b/lib/cgraph/scan.l index c918396c4..b0af41b64 100644 --- a/lib/cgraph/scan.l +++ b/lib/cgraph/scan.l @@ -222,7 +222,7 @@ ID ({NAME}|{NUMBER}) [\\]["] addstr ("\""); [\\][\\] addstr ("\\\\"); [\\][\n] line_num++; /* ignore escaped newlines */ -([^"\\]*|[\\]) addstr(aagtext); +([^"\\\n]*|[\\]) addstr(aagtext); [<] BEGIN(hstring); html_nest = 1; beginstr(); [>] html_nest--; if (html_nest) addstr(aagtext); else {BEGIN(INITIAL); endstr_html(); return (T_qatom);} [<] html_nest++; addstr(aagtext); diff --git a/rtest/1411.dot b/rtest/1411.dot new file mode 100644 index 000000000..47bc8b070 --- /dev/null +++ b/rtest/1411.dot @@ -0,0 +1,81 @@ +digraph G { + "/* + This mess is the project of *manually* .Dot-ify minor .JavaScript projects + Current state: creating nodes, none connection done for the moment + May contain lots of stupid english-speaking mistakes + */" + + "var VERSION=2.0106;" + "var BETA=0;" + + "/*===================================================================================== + MISC HELPER FUNCTIONS + =======================================================================================*/" + "function l(what) {return document.getElementById(what);}" + "function choose(arr) {return arr[Math.floor(Math.random()*arr.length)];}" + + "function escapeRegExp(str){return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");}" + "function replaceAll(find,replace,str){return str.replace(new RegExp(escapeRegExp(find),'g'),replace);}" + + "//disable sounds (sorry)" + "var realAudio=Audio;//backup real audio" + "Audio=function(src){ + if (src && src.indexOf('soundjay')>-1) {Game.Popup('Sorry, no sounds');this.play=function(){};} + else return new realAudio(src); + };" + + "if(!Array.prototype.indexOf) { + Array.prototype.indexOf = function(needle) { + for(var i = 0; i < this.length; i++) { + if(this[i] === needle) {return i;} + } + return -1; + }; + }" + + "function randomFloor(x) {if ((x%1)