Python Forum
Weird Python tags syntax coloring bug
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Weird Python tags syntax coloring bug
#1
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...ion-issues
Reply
#2
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.
Reply
#3
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
Recommended Tutorials:
Reply
#4
ok so i re-found the post where i show the code
https://python-forum.io/Thread-syntax-hi...d=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' }
                ];
Recommended Tutorials:
Reply
#5
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Do not know how to add "Code Tags" or "Error Tags" to my submissions mattkrebs 2 3,717 Mar-21-2017, 04:15 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020