2

I'm using atom editor for python with embedded SQL similar to this:

import sqlite3

conn = sqlite3.connect('spider.sqlite')
cur = conn.cursor()

cur.execute('''SELECT COUNT(from_id) AS inbound, old_rank, new_rank, id, url 
     FROM Pages JOIN Links ON Pages.id = Links.to_id
     WHERE html IS NOT NULL
     GROUP BY id ORDER BY inbound DESC''')

count = 0
for row in cur :
    if count < 50 : print(row)
    count = count + 1
print(count, 'rows.')
cur.close()

Any of you who've taken the Coursera python courses will recognize the above code--what's odd is that in the videos, Dr. Chuck's atom environment highlights at least the conventionally capitalized sql keywords such as SELECT, CREATE, FROM, etc. but he never mentions having to do anything to atom to have this happen. What I see in my installation, on the other hand, is that everything within the triple quotes is highlighted as comment text (all green in my theme).

This comment, even though the main thread is referring to MagicPython, (https://github.com/MagicStack/MagicPython/issues/27#issuecomment-418155497) suggests that Atom and SublimeText both support highlighting SQL natively, but even installing the sublime package into Atom does nothing but give me a light "sublimify" sidebar when I just want to keep my native dark UI.

Can anyone point me in the right direction to get triple quoted SQL within python highlighted properly in atom? Thanks!

Edit: I'm running MacOS Sierra (10.12.6) if it matters.

  • Odd: the grammar should recognize a block that starts with SELECT or other keywords as meta.embedded.sql. I'm having the same problem on Mojave with atom 1.37.0, FWIW. – Steven Kalt Jun 6 at 20:16
1

Answer: go to settings > core and uncheck Use Tree Sitter Parsers (it's at the bottom of the core settings menu. You may have to close and reopen the document for the changes to take effect.

What caused the problem:

At the moment, language-sql does not yet provide a Tree-sitter grammar, so Atom cannot provide SQL syntax highlighting [where other grammars try to inject it]

[gh issue with explanation] [relevant language-python issue]

If you want to contribute to fixing the root issue, take a look at the tree-sitter documentation and contribute to language-sql!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.