Add variable highlighting widgets

This commit is contained in:
Gregory Schier
2023-02-26 15:06:14 -08:00
parent 38e8ef6535
commit 5658da34a2
11 changed files with 403 additions and 68 deletions

View File

@@ -0,0 +1,7 @@
import { styleTags, tags as t } from '@lezer/highlight';
export const twigHighlight = styleTags({
'if endif': t.controlKeyword,
'{{ }} {% %}': t.meta,
DirectiveContent: t.variableName,
});

View File

@@ -0,0 +1,28 @@
// Very crude grammar for a subset of Twig templating syntax
@top Template { (directive | Text)* }
directive {
// Insert |
// Conditional { ConditionalOpen (directive | Text)* ConditionalClose }
Insert
}
@skip {space} {
Insert { "{{" DirectiveContent "}}" }
// ConditionalOpen { "{%" kw<"if"> DirectiveContent "%}" }
// ConditionalClose { "{%" kw<"endif"> "%}" }
}
kw<word> { @specialize[@name={word}]<Identifier, word> }
@tokens {
Identifier { @asciiLetter+ }
Text { ![{] Text? | "{" (@eof | ![%{] Text?) }
space { @whitespace+ }
DirectiveContent { ![%}] DirectiveContent? | $[%}] (@eof | ![}] DirectiveContent?) }
@precedence { space DirectiveContent }
"{{" "}}" // "{%" "%}"
}
@external propSource twigHighlight from "./twig-highlight.ts"

View File

@@ -0,0 +1,6 @@
// This file was generated by lezer-generator. You probably shouldn't edit it.
export const
Template = 1,
Insert = 2,
DirectiveContent = 4,
Text = 6

View File

@@ -0,0 +1,19 @@
// This file was generated by lezer-generator. You probably shouldn't edit it.
import { LRParser } from '@lezer/lr';
import { twigHighlight } from './twig-highlight';
export const parser = LRParser.deserialize({
version: 14,
states: "zQVOPOOO_QQO'#C^OOOO'#Cc'#CcQVOPOOOdQQO,58xOOOO-E6a-E6aOOOO1G.d1G.d",
stateData: 'l~OYOS~ORPOUQO~OSSO~OTUO~OYS~',
goto: 'cWPPXPPPP]TQORQRORTR',
nodeNames: '⚠ Template Insert {{ DirectiveContent }} Text',
maxTerm: 10,
propSources: [twigHighlight],
skippedNodes: [0],
repeatNodeCount: 1,
tokenData:
",gRRmOX!|X^'u^p!|pq'uqu!|uv#pv#o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