enh(leaf) Update syntax to Leaf 4 (#3794)
This commit is contained in:
parent
e5e0220052
commit
7fb52a23ea
|
@ -24,6 +24,7 @@ Core Grammars:
|
|||
- enh(nsis) Add `!assert` compiler flag [idleberg][]
|
||||
- fix(haskell) do not treat double dashes inside infix operators as comments [Zlondrej][]
|
||||
- enh(rust) added `eprintln!` macro [qoheniac][]
|
||||
- enh(leaf) update syntax to 4.0 [Samuel Bishop][]
|
||||
|
||||
Dev tool:
|
||||
|
||||
|
@ -36,6 +37,7 @@ Dev tool:
|
|||
[Checconio]: https://github.com/Checconio
|
||||
[Bradley Mackey]: https://github.com/bradleymackey
|
||||
[qoheniac]: https://github.com/qoheniac
|
||||
[Samuel Bishop]: https://github.com/dannflor
|
||||
|
||||
|
||||
## Version 11.8.0
|
||||
|
|
|
@ -1,47 +1,95 @@
|
|||
/*
|
||||
Language: Leaf
|
||||
Author: Hale Chan <halechan@qq.com>
|
||||
Description: Based on the Leaf reference from https://vapor.github.io/documentation/guide/leaf.html.
|
||||
Description: A Swift-based templating language created for the Vapor project.
|
||||
Website: https://docs.vapor.codes/leaf/overview
|
||||
Category: template
|
||||
*/
|
||||
|
||||
export default function(hljs) {
|
||||
return {
|
||||
name: 'Leaf',
|
||||
const IDENT = /([A-Za-z_][A-Za-z_0-9]*)?/;
|
||||
const LITERALS = [
|
||||
'true',
|
||||
'false',
|
||||
'in'
|
||||
];
|
||||
const PARAMS = {
|
||||
scope: 'params',
|
||||
begin: /\(/,
|
||||
end: /\)(?=\:?)/,
|
||||
endsParent: true,
|
||||
relevance: 7,
|
||||
contains: [
|
||||
{
|
||||
className: 'function',
|
||||
begin: '#+' + '[A-Za-z_0-9]*' + '\\(',
|
||||
end: / \{/,
|
||||
returnBegin: true,
|
||||
excludeEnd: true,
|
||||
contains: [
|
||||
{
|
||||
className: 'keyword',
|
||||
begin: '#+'
|
||||
},
|
||||
{
|
||||
className: 'title',
|
||||
begin: '[A-Za-z_][A-Za-z_0-9]*'
|
||||
},
|
||||
{
|
||||
className: 'params',
|
||||
begin: '\\(',
|
||||
end: '\\)',
|
||||
endsParent: true,
|
||||
contains: [
|
||||
{
|
||||
className: 'string',
|
||||
begin: '"',
|
||||
end: '"'
|
||||
},
|
||||
{
|
||||
className: 'variable',
|
||||
begin: '[A-Za-z_][A-Za-z_0-9]*'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
scope: 'string',
|
||||
begin: '"',
|
||||
end: '"'
|
||||
},
|
||||
{
|
||||
scope: 'keyword',
|
||||
match: LITERALS.join("|"),
|
||||
},
|
||||
{
|
||||
scope: 'variable',
|
||||
match: /[A-Za-z_][A-Za-z_0-9]*/
|
||||
},
|
||||
{
|
||||
scope: 'operator',
|
||||
match: /\+|\-|\*|\/|\%|\=\=|\=|\!|\>|\<|\&\&|\|\|/
|
||||
}
|
||||
]
|
||||
};
|
||||
const INSIDE_DISPATCH = {
|
||||
match: [
|
||||
IDENT,
|
||||
/(?=\()/,
|
||||
],
|
||||
scope: {
|
||||
1: "keyword"
|
||||
},
|
||||
contains: [ PARAMS ]
|
||||
};
|
||||
PARAMS.contains.unshift(INSIDE_DISPATCH);
|
||||
return {
|
||||
name: 'Leaf',
|
||||
contains: [
|
||||
// #ident():
|
||||
{
|
||||
match: [
|
||||
/#+/,
|
||||
IDENT,
|
||||
/(?=\()/,
|
||||
],
|
||||
scope: {
|
||||
1: "punctuation",
|
||||
2: "keyword"
|
||||
},
|
||||
// will start up after the ending `)` match from line ~44
|
||||
// just to grab the trailing `:` if we can match it
|
||||
starts: {
|
||||
contains: [
|
||||
{
|
||||
match: /\:/,
|
||||
scope: "punctuation"
|
||||
}
|
||||
]
|
||||
},
|
||||
contains: [
|
||||
PARAMS
|
||||
],
|
||||
},
|
||||
// #ident or #ident:
|
||||
{
|
||||
match: [
|
||||
/#+/,
|
||||
IDENT,
|
||||
/:?/,
|
||||
],
|
||||
scope: {
|
||||
1: "punctuation",
|
||||
2: "keyword",
|
||||
3: "punctuation"
|
||||
}
|
||||
},
|
||||
]
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,21 +1,14 @@
|
|||
#empty(friends) {
|
||||
Try adding some friends!
|
||||
} ##loop(friends, "friend") {
|
||||
<li> #(friend.name) </li>
|
||||
}
|
||||
#(variable)
|
||||
#extend("template"): I'm added to a base template! #endextend
|
||||
#import("body")
|
||||
#count(friends)
|
||||
|
||||
#someTag(parameter.list, goes, "here") {
|
||||
This is an optional body here
|
||||
}
|
||||
#for(friend in friends): <li>#(friend.name)</li> #endfor
|
||||
|
||||
#index(friends, "0") {
|
||||
Hello, #(self)!
|
||||
} ##else() {
|
||||
Nobody's there!
|
||||
}
|
||||
|
||||
#()
|
||||
|
||||
#raw() {
|
||||
<li> Hello </li>
|
||||
}
|
||||
#if(count(visit) == 1):
|
||||
Hello new user!
|
||||
#elseif(title == "Welcome back!"):
|
||||
Hello old user
|
||||
#else:
|
||||
Unexpected page!
|
||||
#endif
|
|
@ -1,21 +1,14 @@
|
|||
<span class="hljs-function"><span class="hljs-keyword">#</span><span class="hljs-title">empty</span><span class="hljs-params">(<span class="hljs-variable">friends</span>)</span></span> {
|
||||
Try adding some friends!
|
||||
} <span class="hljs-function"><span class="hljs-keyword">##</span><span class="hljs-title">loop</span><span class="hljs-params">(<span class="hljs-variable">friends</span>, <span class="hljs-string">"friend"</span>)</span></span> {
|
||||
<li> <span class="hljs-function"><span class="hljs-keyword">#</span><span class="hljs-params">(<span class="hljs-variable">friend</span>.<span class="hljs-variable">name</span>)</span></span> </li>
|
||||
}
|
||||
<span class="hljs-punctuation">#</span><span class="hljs-params">(<span class="hljs-variable">variable</span>)</span>
|
||||
<span class="hljs-punctuation">#</span><span class="hljs-keyword">extend</span><span class="hljs-params">(<span class="hljs-string">"template"</span>)</span><span class="hljs-punctuation">:</span> I'm added to a base template! <span class="hljs-punctuation">#</span><span class="hljs-keyword">endextend</span>
|
||||
<span class="hljs-punctuation">#</span><span class="hljs-keyword">import</span><span class="hljs-params">(<span class="hljs-string">"body"</span>)</span>
|
||||
<span class="hljs-punctuation">#</span><span class="hljs-keyword">count</span><span class="hljs-params">(<span class="hljs-variable">friends</span>)</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">#</span><span class="hljs-title">someTag</span><span class="hljs-params">(<span class="hljs-variable">parameter</span>.<span class="hljs-variable">list</span>, <span class="hljs-variable">goes</span>, <span class="hljs-string">"here"</span>)</span></span> {
|
||||
This is an optional body here
|
||||
}
|
||||
<span class="hljs-punctuation">#</span><span class="hljs-keyword">for</span><span class="hljs-params">(<span class="hljs-variable">friend</span> <span class="hljs-keyword">in</span> <span class="hljs-variable">friends</span>)</span><span class="hljs-punctuation">:</span> <li><span class="hljs-punctuation">#</span><span class="hljs-params">(<span class="hljs-variable">friend</span>.<span class="hljs-variable">name</span>)</span></li> <span class="hljs-punctuation">#</span><span class="hljs-keyword">endfor</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">#</span><span class="hljs-title">index</span><span class="hljs-params">(<span class="hljs-variable">friends</span>, <span class="hljs-string">"0"</span>)</span></span> {
|
||||
Hello, <span class="hljs-function"><span class="hljs-keyword">#</span><span class="hljs-params">(<span class="hljs-variable">self</span>)</span></span>!
|
||||
} <span class="hljs-function"><span class="hljs-keyword">##</span><span class="hljs-title">else</span><span class="hljs-params">()</span></span> {
|
||||
Nobody's there!
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">#</span><span class="hljs-params">()</span></span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">#</span><span class="hljs-title">raw</span><span class="hljs-params">()</span></span> {
|
||||
<li> Hello </li>
|
||||
}
|
||||
<span class="hljs-punctuation">#</span><span class="hljs-keyword">if</span><span class="hljs-params">(<span class="hljs-keyword">count</span><span class="hljs-params">(<span class="hljs-variable">visit</span>)</span> <span class="hljs-operator">==</span> 1)</span><span class="hljs-punctuation">:</span>
|
||||
Hello new user!
|
||||
<span class="hljs-punctuation">#</span><span class="hljs-keyword">elseif</span><span class="hljs-params">(<span class="hljs-variable">title</span> <span class="hljs-operator">==</span> <span class="hljs-string">"Welcome back!"</span>)</span><span class="hljs-punctuation">:</span>
|
||||
Hello old user
|
||||
<span class="hljs-punctuation">#</span><span class="hljs-keyword">else</span><span class="hljs-punctuation">:</span>
|
||||
Unexpected page!
|
||||
<span class="hljs-punctuation">#</span><span class="hljs-keyword">endif</span>
|
|
@ -1,21 +1,14 @@
|
|||
#empty(friends) {
|
||||
Try adding some friends!
|
||||
} ##loop(friends, "friend") {
|
||||
<li> #(friend.name) </li>
|
||||
}
|
||||
#(variable)
|
||||
#extend("template"): I'm added to a base template! #endextend
|
||||
#import("body")
|
||||
#count(friends)
|
||||
|
||||
#someTag(parameter.list, goes, "here") {
|
||||
This is an optional body here
|
||||
}
|
||||
#for(friend in friends): <li>#(friend.name)</li> #endfor
|
||||
|
||||
#index(friends, "0") {
|
||||
Hello, #(self)!
|
||||
} ##else() {
|
||||
Nobody's there!
|
||||
}
|
||||
|
||||
#()
|
||||
|
||||
#raw() {
|
||||
<li> Hello </li>
|
||||
}
|
||||
#if(count(visit) == 1):
|
||||
Hello new user!
|
||||
#elseif(title == "Welcome back!"):
|
||||
Hello old user
|
||||
#else:
|
||||
Unexpected page!
|
||||
#endif
|
Loading…
Reference in New Issue