Skip to content

Commit

Permalink
nested function dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Goebel committed May 29, 2023
1 parent 0d6065c commit 7192863
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
64 changes: 38 additions & 26 deletions src/languages/leaf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,43 @@ export default function(hljs) {
'false',
'in'
];
const PARAMS = {
scope: 'params',
begin: /\(/,
end: /\)(?=\:?)/,
endsParent: true,
relevance: 7,
contains: [
{
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: [
Expand All @@ -38,32 +75,7 @@ export default function(hljs) {
]
},
contains: [
{
scope: 'params',
begin: /\(/,
end: /\)(?=\:?)/,
endsParent: true,
relevance: 7,
contains: [
{
scope: 'string',
begin: '"',
end: '"'
},
{
scope: 'keyword',
match: LITERALS.join("|"),
},
{
scope: 'variable',
match: /[A-Za-z_][A-Za-z_0-9]*/
},
{
scope: 'operator',
match: /\+|\-|\*|\/|\%|\=\=|\=|\!|\>|\<|\&\&|\|\|/
}
]
}
PARAMS
],
},
// #ident or #ident:
Expand Down
2 changes: 1 addition & 1 deletion test/markup/leaf/default.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<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> &lt;li&gt;<span class="hljs-punctuation">#</span><span class="hljs-params">(<span class="hljs-variable">friend</span>.<span class="hljs-variable">name</span>)</span>&lt;/li&gt; <span class="hljs-punctuation">#</span><span class="hljs-keyword">endfor</span>

<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> <span class="hljs-variable">1</span>)</span>:
<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">&quot;Welcome back!&quot;</span>)</span><span class="hljs-punctuation">:</span>
Hello old user
Expand Down

0 comments on commit 7192863

Please sign in to comment.