On Fri, Feb 21, 2020 at 9:26 PM Steven D'Aprano <[email protected]> wrote:
> > And what's so special about SQL over, say, regular expressions, XML,
> > JSON, YAML, Markdown, ReST, LaTeX, etc? I might want to use the s''
> > prefix for embedded Scheme code rather than SQL.
>
> Um, regular expressions are not precisely the best example there, since
> we do have raw strings specifically for regular expressions.
>
I mentioned them also in my similar list, but deliberately. *Raw strings*
are not per-se for regexen, even if that is one of the more common uses.
That said, I wonder why no text editors I know of try special highlighting
of `r"..."` strings. We already (often) have that hint that the quoted
thing might be a regular expression. Maybe it's just that those patterns
are so densely coded that adding colors doesn't really help.
Doing a search, the only editor I find easily that seems to highlight
regexen is JetBrains Rider. The examples it shows look kinda-sorta
useful. Probably someone made a plugin or something that does it elsewhere.
Here's another idea that is purely convention, as the comment convention
is. Use functions! They are just cruft from a runtime point-of-view, but
they provide a really obvious hint to IDEs or other tools:
SQL = REGX = XPATH = MD = lambda s: s
pat = REGX(r"\$\d{1,10}.\d{2}")
sql = SQL("SELECT foo, bar FROM table WHERE baz > 42;")
query = XPATH("/bookstore/book[1]/title")
These decorations are doing nothing functionally, but they would be easy
for any IDE that wanted to to look for. This is completely extensible to
any mini-language that might occur in strings. You'd just need some sort
of configuration for the editor to know how to look for and highlight each
syntax.
I kinda like the look of this better than the end of line comment (which
gets more complex to figure out with multi-line, triple-quoted strings.
The function just handles that automatically. Of course, those functions
*could* do something more than identity if they wanted to.
> But the rest of the list is still valid. Why is SQL more important than
> any other language or text format? I don't think it is.
>
I might even go so far as saying SQL is more important than any other
SINGLE other embedded language. But out of the hundreds, it's nowhere
close to a majority.
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/RSG4N6VGSOYFIWZKIL4RUUP7XFO3UZNR/
Code of Conduct: http://python.org/psf/codeofconduct/