Skip to content

Commit 389c744

Browse files
authored
allow the creation of "language regions" in syntax (#172)
- use a comment block containing `#language:<name>` to start a langauge regions e.g. '<%# #langauge:cpp %>' - use a comment block containing `#endlangaue` to end a region e.g. '<%# #endlangauge $>' contains definitions for `rust`, `cpp`, and `html` blocks in vscode and vim syntax
1 parent 69a76ac commit 389c744

2 files changed

Lines changed: 85 additions & 1 deletion

File tree

syntax/vim/syntax/sailfish.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
" Maintainer: Ryohei Machida <orcinus4627@gmail.com>
44
" License: MIT
55

6+
let main_syntax = 'sailfish'
67
runtime! syntax/html.vim
78
unlet b:current_syntax
89

910
syn include @rustSyntax syntax/rust.vim
11+
unlet b:current_syntax
12+
13+
syn include @cppSyntax syntax/cpp.vim
1014

1115
syn region sailfishCodeBlock matchgroup=sailfishTag start=/<%/ keepend end=/%>/ contains=@rustSyntax
1216
syn region sailfishBufferBlock matchgroup=sailfishTag start=/<%=/ keepend end=/%>/ contains=@rustSyntax
1317
syn region sailfishCommentBlock start=/<%#/ end=/%>/
1418

19+
syn region sailfishLanguageBlockCpp matchgroup=sailfishTag start=/<%#\s*#language:cpp\s*%>/ keepend end=/<%#\s*#endlanguage\s*%>/ contains=@cppSyntax,sailfishCodeBlock,sailfishBufferBlock,sailfishCommentBlock
20+
syn region sailfishLanguageBlockRust matchgroup=sailfishTag start=/<%#\s*#language:rust\s*%>/ keepend end=/<%#\s*#endlanguage\s*%>/ contains=@rustSyntax,sailfishCodeBlock,sailfishBufferBlock,sailfishCommentBlock
21+
22+
1523
" Redefine htmlTag so that it can contain jspExpr
1624
syn clear htmlString
1725
syn region htmlString contained start=+"+ end=+"+ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc,sailfishCodeBlock,sailfishBufferBlock

syntax/vscode/syntaxes/sailfish.tmLanguage.json

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@
356356
},
357357
"name": "sailfish",
358358
"patterns": [
359+
{
360+
"include": "#languagemarkerblock"
361+
},
359362
{
360363
"include": "#commentblock"
361364
},
@@ -367,6 +370,79 @@
367370
}
368371
],
369372
"repository": {
373+
"languagemarkerblock": {
374+
"patterns": [
375+
{
376+
"name": "meta.block.embedded.cpp",
377+
"begin": "<(%|\\?)#\\s*#language:cpp\\s*(%|\\?)>",
378+
"beginCaptures": {
379+
"0": {
380+
"name": "punctuation.definition.tag.begin.html"
381+
}
382+
},
383+
"end": "<(%|\\?)#\\s*#endlanguage\\s*(%|\\?)>",
384+
"endCaptures": {
385+
"0": {
386+
"name": "punctuation.definition.tag.end.html"
387+
}
388+
},
389+
"patterns": [
390+
{
391+
"include": "$self"
392+
},
393+
{
394+
"include": "source.cpp"
395+
}
396+
]
397+
},
398+
{
399+
"name": "meta.block.embedded.rust",
400+
"begin": "<(%|\\?)#\\s*#language:rust\\s*(%|\\?)>",
401+
"beginCaptures": {
402+
"0": {
403+
"name": "punctuation.definition.tag.begin.html"
404+
}
405+
},
406+
"end": "<(%|\\?)#\\s*#endlanguage\\s*(%|\\?)>",
407+
"endCaptures": {
408+
"0": {
409+
"name": "punctuation.definition.tag.end.html"
410+
}
411+
},
412+
"patterns": [
413+
{
414+
"include": "$self"
415+
},
416+
{
417+
"include": "source.rust"
418+
}
419+
]
420+
},
421+
{
422+
"name": "meta.block.embedded.html",
423+
"begin": "<(%|\\?)#\\s*#language:html\\s*(%|\\?)>",
424+
"beginCaptures": {
425+
"0": {
426+
"name": "punctuation.definition.tag.begin.html"
427+
}
428+
},
429+
"end": "<(%|\\?)#\\s*#endlanguage\\s*(%|\\?)>",
430+
"endCaptures": {
431+
"0": {
432+
"name": "punctuation.definition.tag.end.html"
433+
}
434+
},
435+
"patterns": [
436+
{
437+
"include": "$self"
438+
},
439+
{
440+
"include": "text.html.basic"
441+
}
442+
]
443+
}
444+
]
445+
},
370446
"commentblock": {
371447
"patterns": [
372448
{
@@ -384,7 +460,7 @@
384460
"codeblock": {
385461
"patterns": [
386462
{
387-
"name": "source.rust.embedded.html",
463+
"name": "meta.block.embedded.rust",
388464
"begin": "<(%|\\?)(=|-)?",
389465
"beginCaptures": {
390466
"0": {

0 commit comments

Comments
 (0)