Skip to content

Comment on Highlighting Parts of Lua as Bash

Comments

An alternative approach is to use comments, which allow changing arbitrary string literals into injected contexts, as JetBrains does: https://www.jetbrains.com/help/idea/using-language-injection... I have found that to be more helpful in cases where the data flow can't or doesn't prove how a string is being used, as in:

  def doit():
    # language=SQL
    s = "SELECT * FROM FOO"
    run_sql(s)
  def run_sql(s: str):
    cur = conn.cursor()
    cur.execute(s)
Although I am not certain if tree-sitter allows matching on comments, but https://github.com/tree-sitter/tree-sitter/issues/1138 seems to imply that it does
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.