260808.1.1 · 938e0847dc900866de7418030e788a1835648826
#189 highlight svelte block keywords with a nested syntax definition
reading declarations
@@ -0,0 +1,51 @@++Description="Svelte template block (nested in svelte.lang)"++Categories = {"markup", "script"}++Digits=[[ (?:0x)[0-9a-fA-F]+|(?:0b)[01]+|(?:0o)[0-8]+|\d*[\.]?\d+(?:[eE][\-\+]\d+)?[lLuU]* ]]++Keywords={+ -- the sigil belongs to the block marker: {#if, {:else, {/each, {@render+ { Id=1,+ Regex=[[[#:\/@]\w+]],+ Group=0,+ },+ -- block keywords plus the javascript ones an expression may contain+ { Id=1,+ List={"if", "else", "each", "as", "await", "then", "catch", "key", "snippet",+ "html", "const", "debug", "render", "attach",+ "break", "class", "continue", "default", "delete", "export", "extends",+ "finally", "instanceof", "import", "in", "new", "of", "from", "return",+ "super", "switch", "this", "throw", "try", "typeof", "var", "let",+ "function", "yield", "static", "true", "false", "null", "do", "for", "while",+ },+ },+ { Id=2,+ List={"boolean", "undefined", "void"},+ },+ { Id=4,+ Regex=[[(\w+)(\s*[:=]\s*function)?\s*\(]],+ Group=1+ },+}++Strings={+ Delimiter=[["|'|`]],+ Interpolation=[[ \$\{[^}]+\} ]],+ Escape = [=[ \\u\{?[[:xdigit:]]{4,6}\}?|\\\d{3}|\\x[[:xdigit:]]{2}|\\[ntvbrfa\\\?'\"] ]=]+}++IgnoreCase=false++Comments={+ { Block=false,+ Delimiter= { [[\/\/]] },+ },+ { Block=true,+ Nested=false,+ Delimiter= { [[\/\*]],[[\*\/]],}+ }+}++Operators=[[\(|\)|\[|\]|\{|\}|\,|\;|\:|\?|\&|<|>|\!|\=|\/|\*|\%|\+|\-|\~|\||\.]]
@@ -11,12 +11,14 @@ Keywords={ { Id=2, Regex=[=[([-\w\.\:\|]+)=["'{]]=], },+ -- full marker: also catches markers after the first on a line, which the+ -- nested section cannot (only one embedded section may open per line) { Id=3, Regex=[[\{[#\/](?:if|each|await|key|snippet)\b|\{:(?:else|then|catch)\b|\{@(?:html|const|debug|render|attach)\b]], Group=0, }, { Id=3,- Regex=[=[[\{\}]]=],+ Regex=[=[\{[#:\/@]?|\}]=], Group=0, }, { Id=4,@@ -38,6 +40,10 @@ Comments={ } NestedSections = {+ -- template blocks and interpolations: the block keyword and the expression are+ -- highlighted by inc_svelteblock instead of a single pattern per marker, so+ -- {:else if} and {#each x as y} keep both of their keywords+ { Lang="inc_svelteblock", Delimiter= { [=[\{[#:\/@]]=], [[\}]] } }, { Lang="css", Delimiter= { [[<style[^>]*>]], [[<\/style>]] } }, { Lang="javascript", Delimiter= { [[<script[^>]*>]], [[<\/script>]] } }, -- must come after the generic entry: the last matching delimiter wins