sublimehq / Packages

Syntax highlighting files shipped with Sublime Text and Sublime Merge
https://sublimetext.com
Other
2.95k stars 586 forks source link

SQL Syntax in Python not highlighting #1763

Closed ausiddiqui closed 5 years ago

ausiddiqui commented 5 years ago

Having issues with SQL syntax within a .py file.

query = """
select top 100 *
from mydb.mytable
"""

The string will be syntax highlighted in a single color, without keyword highlighting, i.e. treated as a vanilla string object.

Have looked into #148 and this does not remedy it. I am running on Sublime Text Build 3176 on macOS.

The installed packages for me are:

A File Icon Alignment Anaconda AutoFileName Base16 BracketHighlighter Color Highlighter Colorcoder Conda Dotfiles Syntax Highlighting ExportHtml Git GitGutter Gutter Color Jedi - Python autocompletion LiveReload Log Highlight MarkdownEditing Material Theme Material Theme - Appbar Material Theme - White Panels Package Control Predawn Python Imports Sorter Python PEP8 Autoformat SAS Programming Sass SCSS SideBarEnhancement SublimeLinter SublimeLinter-flake8 SublimeLinter-pycodestyle SublimeREPL Swift Theme - Argonaut Theme - Glacier Theme - Seti Monkai Theme - Spacegray TrailingSpaces

michaelblyons commented 5 years ago

Use all-caps for your SQL terms (or even just the first one).

ausiddiqui commented 5 years ago

Thanks for the suggestion. Unfortunately, it didn't work in my instance.

gh
keith-hall commented 5 years ago

I believe it is currently only looking for uppercase identifiers that occur on the same line as the opening string punctuation. image https://github.com/sublimehq/Packages/commit/80aa6a0c681d715534e90c9fe92828735ab22366#diff-62db422a04a96e067da114ba6ed7d6e9R549

ausiddiqui commented 5 years ago

I think in my case the issue was passing the string into another function, i.e. db.exc(). Any idea of getting around that?

michaelblyons commented 5 years ago
screen shot 2018-11-12 at 4 52 01 pm
import tdpy as db

db.exc("""
SELECT top 100 *
from mydb.mytable
""")

db.exc("""
CREATE TABLE mydb.mytable as (
    col1 VARCHAR(50),
    col2 INTEGER,
    col3 VARCHAR(5)
) WITH NO DATA PRIMARY KEY(
    col1);
""")

db.exc("""
select top 100 *
from mydb.mytable
""")

@keith-hall Mine does not need to be on the same line. I have a little bit of extra sauce in my repo, but I don't think it's anything relating to this. (I'm pretty sure the only Python changes are #1676)

ausiddiqui commented 5 years ago

Thanks Michael and Keith, I think it was the Colorcoder package that prevented the same output as @michaelblyons. I created a new Python (SQL) syntax and added the lowercase keywords to this line sql_indicator: \s*(?:SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|WITH)\b

And voila!

image