mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 05:22:23 +00:00
Some template lexers
This commit is contained in:
parent
746abe53ea
commit
7f4296e9d7
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ pygments/
|
|||||||
shard.lock
|
shard.lock
|
||||||
.vscode/
|
.vscode/
|
||||||
.crystal/
|
.crystal/
|
||||||
|
venv/
|
||||||
|
130
lexers/LiquidLexer.xml
Normal file
130
lexers/LiquidLexer.xml
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
|
||||||
|
<lexer>
|
||||||
|
<config>
|
||||||
|
<name>liquid</name>
|
||||||
|
<alias>liquid</alias>
|
||||||
|
<filename>*.liquid</filename>
|
||||||
|
</config>
|
||||||
|
<rules>
|
||||||
|
<state name="root">
|
||||||
|
<rule pattern="[^{]+"><token type="Text"/></rule>
|
||||||
|
<rule pattern="(\{%)(\s*)"><bygroups><token type="Punctuation"/><token type="TextWhitespace"/></bygroups><push state="tag-or-block"/></rule>
|
||||||
|
<rule pattern="(\{\{)(\s*)([^\s}]+)"><bygroups><token type="Punctuation"/><token type="TextWhitespace"/><usingself state="generic"/></bygroups><push state="output"/></rule>
|
||||||
|
<rule pattern="\{"><token type="Text"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="tag-or-block">
|
||||||
|
<rule pattern="(if|unless|elsif|case)(?=\s+)"><token type="KeywordReserved"/><push state="condition"/></rule>
|
||||||
|
<rule pattern="(when)(\s+)"><bygroups><token type="KeywordReserved"/><token type="TextWhitespace"/></bygroups><combined state="end-of-block" state="whitespace" state="generic"/></rule>
|
||||||
|
<rule pattern="(else)(\s*)(%\})"><bygroups><token type="KeywordReserved"/><token type="TextWhitespace"/><token type="Punctuation"/></bygroups><pop depth="1"/></rule>
|
||||||
|
<rule pattern="(capture)(\s+)([^\s%]+)(\s*)(%\})"><bygroups><token type="NameTag"/><token type="TextWhitespace"/><usingself state="variable"/><token type="TextWhitespace"/><token type="Punctuation"/></bygroups><pop depth="1"/></rule>
|
||||||
|
<rule pattern="(comment)(\s*)(%\})"><bygroups><token type="NameTag"/><token type="TextWhitespace"/><token type="Punctuation"/></bygroups><push state="comment"/></rule>
|
||||||
|
<rule pattern="(raw)(\s*)(%\})"><bygroups><token type="NameTag"/><token type="TextWhitespace"/><token type="Punctuation"/></bygroups><push state="raw"/></rule>
|
||||||
|
<rule pattern="(end(case|unless|if))(\s*)(%\})"><bygroups><token type="KeywordReserved"/>None<token type="TextWhitespace"/><token type="Punctuation"/></bygroups><pop depth="1"/></rule>
|
||||||
|
<rule pattern="(end([^\s%]+))(\s*)(%\})"><bygroups><token type="NameTag"/>None<token type="TextWhitespace"/><token type="Punctuation"/></bygroups><pop depth="1"/></rule>
|
||||||
|
<rule pattern="(cycle)(\s+)(?:([^\s:]*)(:))?(\s*)"><bygroups><token type="NameTag"/><token type="TextWhitespace"/><usingself state="generic"/><token type="Punctuation"/><token type="TextWhitespace"/></bygroups><push state="variable-tag-markup"/></rule>
|
||||||
|
<rule pattern="([^\s%]+)(\s*)"><bygroups><token type="NameTag"/><token type="TextWhitespace"/></bygroups><push state="tag-markup"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="output">
|
||||||
|
<rule><include state="whitespace"/></rule>
|
||||||
|
<rule pattern="\}\}"><token type="Punctuation"/><pop depth="1"/></rule>
|
||||||
|
<rule pattern="\|"><token type="Punctuation"/><push state="filters"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="filters">
|
||||||
|
<rule><include state="whitespace"/></rule>
|
||||||
|
<rule pattern="\}\}"><token type="Punctuation"/><push state="#pop" state="#pop"/></rule>
|
||||||
|
<rule pattern="([^\s|:]+)(:?)(\s*)"><bygroups><token type="NameFunction"/><token type="Punctuation"/><token type="TextWhitespace"/></bygroups><push state="filter-markup"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="filter-markup">
|
||||||
|
<rule pattern="\|"><token type="Punctuation"/><pop depth="1"/></rule>
|
||||||
|
<rule><include state="end-of-tag"/></rule>
|
||||||
|
<rule><include state="default-param-markup"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="condition">
|
||||||
|
<rule><include state="end-of-block"/></rule>
|
||||||
|
<rule><include state="whitespace"/></rule>
|
||||||
|
<rule pattern="([^\s=!><]+)(\s*)([=!><]=?)(\s*)(\S+)(\s*)(%\})"><bygroups><usingself state="generic"/><token type="TextWhitespace"/><token type="Operator"/><token type="TextWhitespace"/><usingself state="generic"/><token type="TextWhitespace"/><token type="Punctuation"/></bygroups></rule>
|
||||||
|
<rule pattern="\b!"><token type="Operator"/></rule>
|
||||||
|
<rule pattern="\bnot\b"><token type="OperatorWord"/></rule>
|
||||||
|
<rule pattern="([\w.\'"]+)(\s+)(contains)(\s+)([\w.\'"]+)"><bygroups><usingself state="generic"/><token type="TextWhitespace"/><token type="OperatorWord"/><token type="TextWhitespace"/><usingself state="generic"/></bygroups></rule>
|
||||||
|
<rule><include state="generic"/></rule>
|
||||||
|
<rule><include state="whitespace"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="generic-value">
|
||||||
|
<rule><include state="generic"/></rule>
|
||||||
|
<rule><include state="end-at-whitespace"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="operator">
|
||||||
|
<rule pattern="(\s*)((=|!|>|<)=?)(\s*)"><bygroups><token type="TextWhitespace"/><token type="Operator"/>None<token type="TextWhitespace"/></bygroups><pop depth="1"/></rule>
|
||||||
|
<rule pattern="(\s*)(\bcontains\b)(\s*)"><bygroups><token type="TextWhitespace"/><token type="OperatorWord"/><token type="TextWhitespace"/></bygroups><pop depth="1"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="end-of-tag">
|
||||||
|
<rule pattern="\}\}"><token type="Punctuation"/><pop depth="1"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="end-of-block">
|
||||||
|
<rule pattern="%\}"><token type="Punctuation"/><push state="#pop" state="#pop"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="end-at-whitespace">
|
||||||
|
<rule pattern="\s+"><token type="TextWhitespace"/><pop depth="1"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="param-markup">
|
||||||
|
<rule><include state="whitespace"/></rule>
|
||||||
|
<rule pattern="([^\s=:]+)(\s*)(=|:)"><bygroups><token type="NameAttribute"/><token type="TextWhitespace"/><token type="Operator"/></bygroups></rule>
|
||||||
|
<rule pattern="(\{\{)(\s*)([^\s}])(\s*)(\}\})"><bygroups><token type="Punctuation"/><token type="TextWhitespace"/><usingself state="variable"/><token type="TextWhitespace"/><token type="Punctuation"/></bygroups></rule>
|
||||||
|
<rule><include state="string"/></rule>
|
||||||
|
<rule><include state="number"/></rule>
|
||||||
|
<rule><include state="keyword"/></rule>
|
||||||
|
<rule pattern=","><token type="Punctuation"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="default-param-markup">
|
||||||
|
<rule><include state="param-markup"/></rule>
|
||||||
|
<rule pattern="."><token type="Text"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="variable-param-markup">
|
||||||
|
<rule><include state="param-markup"/></rule>
|
||||||
|
<rule><include state="variable"/></rule>
|
||||||
|
<rule pattern="."><token type="Text"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="tag-markup">
|
||||||
|
<rule pattern="%\}"><token type="Punctuation"/><push state="#pop" state="#pop"/></rule>
|
||||||
|
<rule><include state="default-param-markup"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="variable-tag-markup">
|
||||||
|
<rule pattern="%\}"><token type="Punctuation"/><push state="#pop" state="#pop"/></rule>
|
||||||
|
<rule><include state="variable-param-markup"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="keyword">
|
||||||
|
<rule pattern="\b(false|true)\b"><token type="KeywordConstant"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="variable">
|
||||||
|
<rule pattern="[a-zA-Z_]\w*"><token type="NameVariable"/></rule>
|
||||||
|
<rule pattern="(?<=\w)\.(?=\w)"><token type="Punctuation"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="string">
|
||||||
|
<rule pattern="'[^']*'"><token type="LiteralStringSingle"/></rule>
|
||||||
|
<rule pattern=""[^"]*""><token type="LiteralStringDouble"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="number">
|
||||||
|
<rule pattern="\d+\.\d+"><token type="LiteralNumberFloat"/></rule>
|
||||||
|
<rule pattern="\d+"><token type="LiteralNumberInteger"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="generic">
|
||||||
|
<rule><include state="keyword"/></rule>
|
||||||
|
<rule><include state="string"/></rule>
|
||||||
|
<rule><include state="number"/></rule>
|
||||||
|
<rule><include state="variable"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="whitespace">
|
||||||
|
<rule pattern="[ \t]+"><token type="TextWhitespace"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="comment">
|
||||||
|
<rule pattern="(\{%)(\s*)(endcomment)(\s*)(%\})"><bygroups><token type="Punctuation"/><token type="TextWhitespace"/><token type="NameTag"/><token type="TextWhitespace"/><token type="Punctuation"/></bygroups><push state="#pop" state="#pop"/></rule>
|
||||||
|
<rule pattern="."><token type="Comment"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="raw">
|
||||||
|
<rule pattern="[^{]+"><token type="Text"/></rule>
|
||||||
|
<rule pattern="(\{%)(\s*)(endraw)(\s*)(%\})"><bygroups><token type="Punctuation"/><token type="TextWhitespace"/><token type="NameTag"/><token type="TextWhitespace"/><token type="Punctuation"/></bygroups><pop depth="1"/></rule>
|
||||||
|
<rule pattern="\{"><token type="Text"/></rule>
|
||||||
|
</state>
|
||||||
|
</rules>
|
||||||
|
</lexer>
|
||||||
|
|
47
lexers/TwigLexer.xml
Normal file
47
lexers/TwigLexer.xml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
<lexer>
|
||||||
|
<config>
|
||||||
|
<name>Twig</name>
|
||||||
|
<alias>twig</alias>
|
||||||
|
<mime_type>application/x-twig</mime_type>
|
||||||
|
<dot_all>true</dot_all>
|
||||||
|
</config>
|
||||||
|
<rules>
|
||||||
|
<state name="root">
|
||||||
|
<rule pattern="[^{]+"><token type="Other"/></rule>
|
||||||
|
<rule pattern="\{\{"><token type="CommentPreproc"/><push state="var"/></rule>
|
||||||
|
<rule pattern="\{\#.*?\#\}"><token type="Comment"/></rule>
|
||||||
|
<rule pattern="(\{%)(-?\s*)(raw)(\s*-?)(%\})(.*?)(\{%)(-?\s*)(endraw)(\s*-?)(%\})"><bygroups><token type="CommentPreproc"/><token type="Text"/><token type="Keyword"/><token type="Text"/><token type="CommentPreproc"/><token type="Other"/><token type="CommentPreproc"/><token type="Text"/><token type="Keyword"/><token type="Text"/><token type="CommentPreproc"/></bygroups></rule>
|
||||||
|
<rule pattern="(\{%)(-?\s*)(verbatim)(\s*-?)(%\})(.*?)(\{%)(-?\s*)(endverbatim)(\s*-?)(%\})"><bygroups><token type="CommentPreproc"/><token type="Text"/><token type="Keyword"/><token type="Text"/><token type="CommentPreproc"/><token type="Other"/><token type="CommentPreproc"/><token type="Text"/><token type="Keyword"/><token type="Text"/><token type="CommentPreproc"/></bygroups></rule>
|
||||||
|
<rule pattern="(\{%)(-?\s*)(filter)(\s+)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w-]|[^\x00-\x7f])*)"><bygroups><token type="CommentPreproc"/><token type="Text"/><token type="Keyword"/><token type="Text"/><token type="NameFunction"/></bygroups><push state="tag"/></rule>
|
||||||
|
<rule pattern="(\{%)(-?\s*)([a-zA-Z_]\w*)"><bygroups><token type="CommentPreproc"/><token type="Text"/><token type="Keyword"/></bygroups><push state="tag"/></rule>
|
||||||
|
<rule pattern="\{"><token type="Other"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="varnames">
|
||||||
|
<rule pattern="(\|)(\s*)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w-]|[^\x00-\x7f])*)"><bygroups><token type="Operator"/><token type="Text"/><token type="NameFunction"/></bygroups></rule>
|
||||||
|
<rule pattern="(is)(\s+)(not)?(\s*)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w-]|[^\x00-\x7f])*)"><bygroups><token type="Keyword"/><token type="Text"/><token type="Keyword"/><token type="Text"/><token type="NameFunction"/></bygroups></rule>
|
||||||
|
<rule pattern="(?i)(true|false|none|null)\b"><token type="KeywordPseudo"/></rule>
|
||||||
|
<rule pattern="(in|not|and|b-and|or|b-or|b-xor|isif|elseif|else|importconstant|defined|divisibleby|empty|even|iterable|odd|sameasmatches|starts\s+with|ends\s+with)\b"><token type="Keyword"/></rule>
|
||||||
|
<rule pattern="(loop|block|parent)\b"><token type="NameBuiltin"/></rule>
|
||||||
|
<rule pattern="(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w-]|[^\x00-\x7f])*"><token type="NameVariable"/></rule>
|
||||||
|
<rule pattern="\.(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w-]|[^\x00-\x7f])*"><token type="NameVariable"/></rule>
|
||||||
|
<rule pattern="\.[0-9]+"><token type="LiteralNumber"/></rule>
|
||||||
|
<rule pattern=":?"(\\\\|\\[^\\]|[^"\\])*""><token type="LiteralStringDouble"/></rule>
|
||||||
|
<rule pattern=":?'(\\\\|\\[^\\]|[^'\\])*'"><token type="LiteralStringSingle"/></rule>
|
||||||
|
<rule pattern="([{}()\[\]+\-*/,:~%]|\.\.|\?|:|\*\*|\/\/|!=|[><=]=?)"><token type="Operator"/></rule>
|
||||||
|
<rule pattern="[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?"><token type="LiteralNumber"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="var">
|
||||||
|
<rule pattern="\s+"><token type="Text"/></rule>
|
||||||
|
<rule pattern="(-?)(\}\})"><bygroups><token type="Text"/><token type="CommentPreproc"/></bygroups><pop depth="1"/></rule>
|
||||||
|
<rule><include state="varnames"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="tag">
|
||||||
|
<rule pattern="\s+"><token type="Text"/></rule>
|
||||||
|
<rule pattern="(-?)(%\})"><bygroups><token type="Text"/><token type="CommentPreproc"/></bygroups><pop depth="1"/></rule>
|
||||||
|
<rule><include state="varnames"/></rule>
|
||||||
|
<rule pattern="."><token type="Punctuation"/></rule>
|
||||||
|
</state>
|
||||||
|
</rules>
|
||||||
|
</lexer>
|
||||||
|
|
55
lexers/VelocityLexer.xml
Normal file
55
lexers/VelocityLexer.xml
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
|
||||||
|
<lexer>
|
||||||
|
<config>
|
||||||
|
<name>Velocity</name>
|
||||||
|
<alias>velocity</alias>
|
||||||
|
<filename>*.vm</filename>
|
||||||
|
<filename>*.fhtml</filename>
|
||||||
|
<dot_all>true</dot_all>
|
||||||
|
</config>
|
||||||
|
<rules>
|
||||||
|
<state name="root">
|
||||||
|
<rule pattern="[^{#$]+"><token type="Other"/></rule>
|
||||||
|
<rule pattern="(#)(\*.*?\*)(#)"><bygroups><token type="CommentPreproc"/><token type="Comment"/><token type="CommentPreproc"/></bygroups></rule>
|
||||||
|
<rule pattern="(##)(.*?$)"><bygroups><token type="CommentPreproc"/><token type="Comment"/></bygroups></rule>
|
||||||
|
<rule pattern="(#\{?)([a-zA-Z_]\w*)(\}?)(\s?\()"><bygroups><token type="CommentPreproc"/><token type="NameFunction"/><token type="CommentPreproc"/><token type="Punctuation"/></bygroups><push state="directiveparams"/></rule>
|
||||||
|
<rule pattern="(#\{?)([a-zA-Z_]\w*)(\}|\b)"><bygroups><token type="CommentPreproc"/><token type="NameFunction"/><token type="CommentPreproc"/></bygroups></rule>
|
||||||
|
<rule pattern="\$!?\{?"><token type="Punctuation"/><push state="variable"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="variable">
|
||||||
|
<rule pattern="[a-zA-Z_]\w*"><token type="NameVariable"/></rule>
|
||||||
|
<rule pattern="\("><token type="Punctuation"/><push state="funcparams"/></rule>
|
||||||
|
<rule pattern="(\.)([a-zA-Z_]\w*)"><bygroups><token type="Punctuation"/><token type="NameVariable"/></bygroups><push/></rule>
|
||||||
|
<rule pattern="\}"><token type="Punctuation"/><pop depth="1"/></rule>
|
||||||
|
<rule><pop depth="1"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="directiveparams">
|
||||||
|
<rule pattern="(&&|\|\||==?|!=?|[-<>+*%&|^/])|\b(eq|ne|gt|lt|ge|le|not|in)\b"><token type="Operator"/></rule>
|
||||||
|
<rule pattern="\["><token type="Operator"/><push state="rangeoperator"/></rule>
|
||||||
|
<rule pattern="\b[a-zA-Z_]\w*\b"><token type="NameFunction"/></rule>
|
||||||
|
<rule><include state="funcparams"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="rangeoperator">
|
||||||
|
<rule pattern="\.\."><token type="Operator"/></rule>
|
||||||
|
<rule><include state="funcparams"/></rule>
|
||||||
|
<rule pattern="\]"><token type="Operator"/><pop depth="1"/></rule>
|
||||||
|
</state>
|
||||||
|
<state name="funcparams">
|
||||||
|
<rule pattern="\$!?\{?"><token type="Punctuation"/><push state="variable"/></rule>
|
||||||
|
<rule pattern="\s+"><token type="Text"/></rule>
|
||||||
|
<rule pattern="[,:]"><token type="Punctuation"/></rule>
|
||||||
|
<rule pattern=""(\\\\|\\[^\\]|[^"\\])*""><token type="LiteralStringDouble"/></rule>
|
||||||
|
<rule pattern="'(\\\\|\\[^\\]|[^'\\])*'"><token type="LiteralStringSingle"/></rule>
|
||||||
|
<rule pattern="0[xX][0-9a-fA-F]+[Ll]?"><token type="LiteralNumber"/></rule>
|
||||||
|
<rule pattern="\b[0-9]+\b"><token type="LiteralNumber"/></rule>
|
||||||
|
<rule pattern="(true|false|null)\b"><token type="KeywordConstant"/></rule>
|
||||||
|
<rule pattern="\("><token type="Punctuation"/><push/></rule>
|
||||||
|
<rule pattern="\)"><token type="Punctuation"/><pop depth="1"/></rule>
|
||||||
|
<rule pattern="\{"><token type="Punctuation"/><push/></rule>
|
||||||
|
<rule pattern="\}"><token type="Punctuation"/><pop depth="1"/></rule>
|
||||||
|
<rule pattern="\["><token type="Punctuation"/><push/></rule>
|
||||||
|
<rule pattern="\]"><token type="Punctuation"/><pop depth="1"/></rule>
|
||||||
|
</state>
|
||||||
|
</rules>
|
||||||
|
</lexer>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user