visual studio code - TextMate Grammar -- precedence of rules -


i'm trying modify syntax highlighting csharp language, syntax highlighting sql in c# string. textmate has support embeded languages, seems possible.

i build on csharp.tmlanguage.json , able enable embeded sql special comment before string like

string query = /*sql*/ $@"select ..." 

thanks textmate's language grammars , introduction scopes came json rule

"repository": {     "embeded-sql": {         "contentname": "source.sql",                     "begin": "/\\*\\s*sql\\s*\\*/\\s*\\$?@?\"",         "end": "\";",         "patterns": [             {                 "include": "source.sql"             }         ]     },     ... } 

and vscode's themes, snippets , colorizers , running , debugging extension able test, rule works.

but have 1 problem, i'm unable solve.

my grammar rule works if signifficant portion of csharp rules disabled, if disable #declarations , #script-top-level, embeded sql works:

enter image description here

otherwise, rule overridden csharp rules like

  • punctuation.definition.comment.cs
  • string.quoted.double.cs
  • comment.block
  • etc.

enter image description here

the problem is, rule works on several language elements , csharp definition wins on targeting these elements.

on basis elements tagged? how write rule, win , tag syntax before other language rules? there algorithm calculating weight of rules?


solution

if cannot hijack comment syntax in csharp, lets work comment in sql. made rule enabled -- sql comment , applied verbatim string. works styles mixed string. needs additional improvements, looks promising.

enter image description here

the rule proves work goes this

    "embeded-sql": {         "contentname": "source.sql",         "begin": "--\\s*sql",         "end": "(?:\\b|^)(?=\"\\s*;)",         "patterns": [             {                 "include": "source.sql"             }         ]     }, 

now enable intellisense , error checking in such embedded language.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -