-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #780 from MakeNowJust/crystal-lang
Crystal support
- Loading branch information
Showing
8 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
(function(Prism) { | ||
Prism.languages.crystal = Prism.languages.extend('ruby', { | ||
keyword: [ | ||
/\b(?:abstract|alias|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|for|fun|if|ifdef|include|instance_sizeof|lib|macro|module|next|of|out|pointerof|private|protected|rescue|return|require|self|sizeof|struct|super|then|type|typeof|undef|union|unless|until|when|while|with|yield|__DIR__|__FILE__|__LINE__)\b/, | ||
{ | ||
pattern: /(\.\s*)(?:is_a|responds_to)\?/, | ||
lookbehind: true | ||
} | ||
], | ||
|
||
number: /\b(?:0b[01_]*[01]|0o[0-7_]*[0-7]|0x[0-9a-fA-F_]*[0-9a-fA-F]|(?:[0-9](?:[0-9_]*[0-9])?)(?:\.[0-9_]*[0-9])?(?:[eE][+-]?[0-9_]*[0-9])?)(?:_(?:[uif](?:8|16|32|64))?)?\b/, | ||
}); | ||
|
||
var rest = Prism.util.clone(Prism.languages.crystal); | ||
|
||
Prism.languages.insertBefore('crystal', 'string', { | ||
attribute: { | ||
pattern: /@\[.+?\]/, | ||
alias: 'attr-name', | ||
inside: { | ||
delimiter: { | ||
pattern: /^@\[|\]$/, | ||
alias: 'tag' | ||
}, | ||
rest: rest | ||
} | ||
}, | ||
|
||
expansion: [ | ||
{ | ||
pattern: /\{\{.+?\}\}/, | ||
inside: { | ||
delimiter: { | ||
pattern: /^\{\{|\}\}$/, | ||
alias: 'tag' | ||
}, | ||
rest: rest | ||
} | ||
}, | ||
{ | ||
pattern: /\{%.+?%\}/, | ||
inside: { | ||
delimiter: { | ||
pattern: /^\{%|%\}$/, | ||
alias: 'tag' | ||
}, | ||
rest: rest | ||
} | ||
} | ||
] | ||
}); | ||
|
||
}(Prism)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<h1>Crystal</h1> | ||
<p>To use this language, use the class "language-crystal".</p> | ||
|
||
<h2>Number literals with underscores and postfix</h2> | ||
<pre><code>1_u32 | ||
123_456.789e-10_f64</code></pre> | ||
|
||
<h2>Attributes</h2> | ||
<pre><code>@[AlwaysInline] | ||
def foo | ||
1 | ||
end</code></pre> | ||
|
||
<h2>Macro expansions</h2> | ||
<pre><code>{% for key, value in {foo: 100, bar: 20} %} | ||
def {{ key.id }} | ||
{{ value }} | ||
end | ||
{% end %}</code></pre> | ||
|
||
<h2>Known failures</h2> | ||
<p>There are certain edge cases where Prism will fail. | ||
There are always such cases in every regex-based syntax highlighter. | ||
However, Prism dares to be open and honest about them. | ||
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug. | ||
</p> | ||
|
||
<h3>Attriubte-like substrings</h3> | ||
<pre><code>" @[AlwaysInline] "</code></pre> | ||
|
||
<h3>Macro expansions in strings</h3> | ||
<pre><code>" {{ foo }} " | ||
" {% bar %} "</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@[AlwaysInline] | ||
@[CallConvention("X86_StdCall")] | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["attribute", [ | ||
["delimiter", "@["], | ||
["constant", "AlwaysInline"], | ||
["delimiter", "]"] | ||
]], | ||
["attribute", [ | ||
["delimiter", "@["], | ||
["function", "CallConvention"], ["punctuation", "("], ["string", [ "\"X86_StdCall\"" ]], ["punctuation", ")"], | ||
["delimiter", "]"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for attributes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{{ 1_u32 }} | ||
{% 2_u32 %} | ||
{{ { 3_u32 } }} | ||
{% % 4_u32 % %} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["expansion", [ | ||
["delimiter", "{{"], | ||
["number", "1_u32"], | ||
["delimiter", "}}"] | ||
]], | ||
["expansion", [ | ||
["delimiter", "{%"], | ||
["number", "2_u32"], | ||
["delimiter", "%}"] | ||
]], | ||
["expansion", [ | ||
["delimiter", "{{"], | ||
["punctuation", "{"], | ||
["number", "3_u32"], | ||
["punctuation", "}"], | ||
["delimiter", "}}"] | ||
]], | ||
["expansion", [ | ||
["delimiter", "{%"], | ||
["operator", "%"], | ||
["number", "4_u32"], | ||
["operator", "%"], | ||
["delimiter", "%}"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for macro expansions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
abstract alias as asm begin break case | ||
class; | ||
def do else elsif | ||
end ensure enum extend for fun | ||
if ifdef include instance_sizeof | ||
.is_a? | ||
lib macro module next of out pointerof | ||
private protected rescue | ||
.responds_to? | ||
return require self sizeof struct super | ||
then type typeof undef union unless until when | ||
while with yield __DIR__ __FILE__ __LINE__ | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "abstract"], ["keyword", "alias"], ["keyword", "as"], ["keyword", "asm"], ["keyword", "begin"], ["keyword", "break"], ["keyword", "case"], | ||
["keyword", "class"], ["punctuation", ";"], | ||
["keyword", "def"], ["keyword", "do"], ["keyword", "else"], ["keyword", "elsif"], | ||
["keyword", "end"], ["keyword", "ensure"], ["keyword", "enum"], ["keyword", "extend"], ["keyword", "for"], ["keyword", "fun"], | ||
["keyword", "if"], ["keyword", "ifdef"], ["keyword", "include"], ["keyword", "instance_sizeof"], | ||
["punctuation", "."], ["keyword", "is_a?"], | ||
["keyword", "lib"], ["keyword", "macro"], ["keyword", "module"], ["keyword", "next"], ["keyword", "of"], ["keyword", "out"], ["keyword", "pointerof"], | ||
["keyword", "private"], ["keyword", "protected"], ["keyword", "rescue"], | ||
["punctuation", "."], ["keyword", "responds_to?"], | ||
["keyword", "return"], ["keyword", "require"], ["keyword", "self"], ["keyword", "sizeof"], ["keyword", "struct"], ["keyword", "super"], | ||
["keyword", "then"], ["keyword", "type"], ["keyword", "typeof"], ["keyword", "undef"], ["keyword", "union"], ["keyword", "unless"], ["keyword", "until"], ["keyword", "when"], | ||
["keyword", "while"], ["keyword", "with"], ["keyword", "yield"], ["keyword", "__DIR__"], ["keyword", "__FILE__"], ["keyword", "__LINE__"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for all keywords. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
1 | ||
1_1 | ||
1_1_1 | ||
0b10_01 | ||
0o1_2_3 | ||
0x123456789abcdef | ||
012_345.678_9e+10_f64 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["number", "1"], | ||
["number", "1_1"], | ||
["number", "1_1_1"], | ||
["number", "0b10_01"], | ||
["number", "0o1_2_3"], | ||
["number", "0x123456789abcdef"], | ||
["number", "012_345.678_9e+10_f64"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for number literals. |