Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
JSON syntax highlighting problems
-
The JSON spec supports the escaping of quotes with a backslash (
\
). From http://json.org/ :A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes
However, it seems that the syntax highlighter ignores this:
I'm also puzzled by the fact that the highlighter sees a double forward slash (
//
) as a comment since comments are not a part of the JSON spec. -
@Webmaster4o , not related to your Pythonista question. But out of interest, have you looked at the JSON designer on iOS? Just interested in your opinion or make you aware of it
JSON Designer by Cribster
https://appsto.re/au/-DWYz.i -
The Pythonista syntax highligher has some issues with escaped quotes in general. In Python, something like
"\""
does not work properly either. -
@dgelessus I don't see that issue at all:
-
Ah, I misremembered. Normal backslash escapes work, but a double-backslash before a quote is handled incorrectly. For example
"\\"
is the string\
, but the syntax highlighter interprets the last backslash as escaping the quote and continues highlighting everything as part of the string. -
Yeah, the JavaScript syntax highlighter has a couple of issues, and I shouldn't really use the same thing for JSON (doesn't make sense to highlight keywords etc.). I'm working on some improvements in that area.
I wasn't aware of the double-backslash issue in the Python highlighter, thanks.
-
@omz I think the JS highlighter also doesn't handle escaping in regex literals (the ones enclosed by slashes) though that's probably the same issue as with normal string literals. And for the multiple backslashes thing, can you check that it works for more than two backslashes too? I remember having used at least 8 in a row, and in any case we should be prepared for Ba'al the Soul Eater.
-
@dgelessus I'll look into it. To be honest, I didn't put that much effort into the JavaScript syntax highlighter so far. I mostly added it as a test case when I re-implemented the syntax highlighter to be more flexible (in v. 1.5, I think), and it seemed like a nice-to-have feature, but not one that a lot of people would actually use in Pythonista. The highlighting rules aren't really fleshed out for JavaScript, and it turns out that highlighting regex literals is really quite complicated because the forward-slash is also the division operator... The current implementation gets this completely wrong, and I'll see what I can do to improve that.
-
@omz The JS regex literals do look challenging to parse. I think they can also take regex flags as a prefix or suffix or something? It's a miracle that a feature like that can even be parsed at all.
The additional syntax-highlighted languages are great. HTML/CSS/JS are logical for Python-powered web servers, but other languages could be useful too, if only to read code in those languages. XML would be nice to have officially supported, at the moment if I need XML syntax highlighting I just add
.html
to the file name. That works for the most part, except that<?xml ...?>
isn't highlighted and tags namedscript
orstyle
cause trouble. -
@omz I bet there are quite a few open-source JavaScript syntax highlighters for Objective-C, so that you wouldn't have to do all the work yourself. Might be worth looking into, though I have no idea how flexible the current implementation might be to get syntax highlighting from an external source.
-
@omz Another quote highlighting issue: long bytes literals
b"""
andbr"""
are highlighted like short literals, i. e. they do not continue into the next line. (The closing triple quote is of course detected, which means that the rest of the file is highlighted as a long string literal.)Example (bug obviously only visible in Pythonista):
# normal code b""" bytes data, highlighted as code """ # normal code again, highlighted as literal