Python Forum
Weird Python tags syntax coloring bug - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Board (https://python-forum.io/forum-26.html)
+--- Thread: Weird Python tags syntax coloring bug (/thread-3549.html)



Weird Python tags syntax coloring bug - micseydel - Jun-01-2017

Take a look at this:
filename != "" and foldername != ""
Note that the close string appears to be interpreted as an open.

Saw it less simplified at https://python-forum.io/Thread-Help-with-tkinter-Button-and-Label-interaction-issues


RE: Weird Python tags syntax coloring bug - nilamo - Jun-01-2017

filename != "" and foldername != ""
filename != """""" and foldername != """"""
filename != '' and foldername != ''
filename != '''''' and foldername != ''''''
Interestingly, it works fine for triple quoted strings.
Issue presents with both single and double quotes.


RE: Weird Python tags syntax coloring bug - metulburr - Jun-02-2017

interesting....Im surprised we caught that so late in the process of seeing code in syntax highlighter for awhile now.

Wondering if it only occurs on empty strings
py tags
filename != "" and foldername != ""
code tags
filename != "" and foldername != ""
---

py tags
filename != " " and foldername != " "
code tags
filename != " " and foldername != " "
filename != """and foldername != """
EDIT:
yup so its interpreting it as
Quote:filename != (")(" and foldername != ")(")
odd


RE: Weird Python tags syntax coloring bug - metulburr - Jun-02-2017

ok so i re-found the post where i show the code
https://python-forum.io/Thread-syntax-highlighting?pid=79#pid79

it appears that it handles that via regex....and i suck at regex. Anyone want to take a whack at it for figuring out where this regex for strings would cause this problem?
Quote:
        this.regexList = [
                { regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' },
                { regex: /^\s*@\w+/gm,                                      css: 'decorator' },
                { regex: /(['\"]{3})([^\1])*?\1/gm,                         css: 'comments' },
                { regex: /"(?!")(?:\.|\\\"|[^\""\n])*"/gm,                  css: 'string' },
                { regex: /'(?!')(?:\.|(\\\')|[^\''\n])*'/gm,                css: 'string' },
                { regex: /\+|\-|\*|\/|\%|=|==/gm,                           css: 'keyword' },
                { regex: /\b\d+\.?\w*/g,                                    css: 'value' },
                { regex: new RegExp(this.getKeywords(funcs), 'gmi'),        css: 'functions' },
                { regex: new RegExp(this.getKeywords(keywords), 'gm'),      css: 'keyword' },
                { regex: new RegExp(this.getKeywords(special), 'gm'),       css: 'color1' }
                ];



RE: Weird Python tags syntax coloring bug - nilamo - Jun-02-2017

(Jun-02-2017, 01:49 AM)metulburr Wrote:               { regex: /"(?!")(?:\.|\\\"|[^\""\n])*"/gm,                  css: 'string' },
              { regex: /'(?!')(?:\.|(\\\')|[^\''\n])*'/gm,                css: 'string' },


Playing around in regexpal makes me think the negative lookahead can either just be removed, or be made optional.  ie: the beginning of the regex should change from /"(?!") to /"(?!")? (note the trailing question mark). But testing with more strings would be pretty much required to make sure it'll still parse as expected.