-
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 #811 from Golmote/prism-haxe
Add support for Haxe
- Loading branch information
Showing
13 changed files
with
326 additions
and
2 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,43 @@ | ||
Prism.languages.haxe = Prism.languages.extend('clike', { | ||
// Strings can be multi-line | ||
'string': { | ||
pattern: /(["'])(?:(?!\1)[^\\]|\\[\s\S])*\1/, | ||
inside: { | ||
'interpolation': { | ||
pattern: /(^|[^\\])\$(?:\w+|\{[^}]+\})/, | ||
lookbehind: true, | ||
inside: { | ||
'interpolation': { | ||
pattern: /^\$\w*/, | ||
alias: 'variable' | ||
} | ||
// See rest below | ||
} | ||
} | ||
} | ||
}, | ||
// The final look-ahead prevents highlighting of keywords if expressions such as "haxe.macro.Expr" | ||
'keyword': /\bthis\b|\b(?:abstract|as|break|case|cast|catch|class|continue|default|do|dynamic|else|enum|extends|extern|from|for|function|if|implements|import|in|inline|interface|macro|new|null|override|public|private|return|static|super|switch|throw|to|try|typedef|using|var|while)(?!\.)\b/, | ||
'operator': /\.{3}|\+\+?|-[->]?|[=!]=?|&&?|\|\|?|<[<=]?|>[>=]?|[*\/%~^]/ | ||
}); | ||
Prism.languages.insertBefore('haxe', 'class-name', { | ||
'regex': { | ||
pattern: /~\/(?:[^\/\\\r\n]|\\.)+\/[igmsu]*/ | ||
} | ||
}); | ||
Prism.languages.insertBefore('haxe', 'keyword', { | ||
'preprocessor': { | ||
pattern: /#\w+/, | ||
alias: 'builtin' | ||
}, | ||
'metadata': { | ||
pattern: /@:?\w+/, | ||
alias: 'symbol' | ||
}, | ||
'reification': { | ||
pattern: /\$(?:\w+|(?=\{))/, | ||
alias: 'variable' | ||
} | ||
}); | ||
Prism.languages.haxe['string'].inside['interpolation'].inside.rest = Prism.util.clone(Prism.languages.haxe); | ||
delete Prism.languages.haxe['class-name']; |
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,53 @@ | ||
<h1>Haxe</h1> | ||
<p>To use this language, use the class "language-haxe".</p> | ||
|
||
<h2>Strings and string interpolation</h2> | ||
<pre><code>"Foo | ||
bar $baz" | ||
'Foo | ||
bar' | ||
"${4 + 2}"</code></pre> | ||
|
||
<h2>Regular expressions</h2> | ||
<pre><code>~/haxe/i | ||
~/[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z][A-Z][A-Z]?/i | ||
~/(dog|fox)/g</code></pre> | ||
|
||
<h2>Conditional compilation</h2> | ||
<pre><code>#if !debug | ||
trace("ok"); | ||
#elseif (debug_level > 3) | ||
trace(3); | ||
#else | ||
trace("debug level too low"); | ||
#end</code></pre> | ||
|
||
<h2>Metadata</h2> | ||
<pre><code>@author("Nicolas") | ||
@debug | ||
class MyClass { | ||
@range(1, 8) | ||
var value:Int; | ||
|
||
@broken | ||
@:noCompletion | ||
static function method() { } | ||
}</code></pre> | ||
|
||
<h2>Reification</h2> | ||
<pre><code>macro static function add(e:Expr) { | ||
return macro $e + $e; | ||
}</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>Comment-like substrings</h3> | ||
<pre><code>"foo // var"</code></pre> | ||
|
||
<h3>Two quotes of the same type (i.e. both single or both double) inside a regex</h3> | ||
<pre><code>~/"foo"/</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
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,93 @@ | ||
this | ||
abstract | ||
as | ||
break | ||
case | ||
cast | ||
catch | ||
class | ||
continue | ||
default | ||
do | ||
dynamic | ||
else | ||
enum | ||
extends | ||
extern | ||
from | ||
for | ||
function | ||
if | ||
implements | ||
import | ||
in | ||
inline | ||
interface | ||
macro | ||
new | ||
null | ||
override | ||
public | ||
private | ||
return | ||
static | ||
super | ||
switch | ||
throw | ||
to | ||
try | ||
typedef | ||
using | ||
var | ||
while | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "this"], | ||
["keyword", "abstract"], | ||
["keyword", "as"], | ||
["keyword", "break"], | ||
["keyword", "case"], | ||
["keyword", "cast"], | ||
["keyword", "catch"], | ||
["keyword", "class"], | ||
["keyword", "continue"], | ||
["keyword", "default"], | ||
["keyword", "do"], | ||
["keyword", "dynamic"], | ||
["keyword", "else"], | ||
["keyword", "enum"], | ||
["keyword", "extends"], | ||
["keyword", "extern"], | ||
["keyword", "from"], | ||
["keyword", "for"], | ||
["keyword", "function"], | ||
["keyword", "if"], | ||
["keyword", "implements"], | ||
["keyword", "import"], | ||
["keyword", "in"], | ||
["keyword", "inline"], | ||
["keyword", "interface"], | ||
["keyword", "macro"], | ||
["keyword", "new"], | ||
["keyword", "null"], | ||
["keyword", "override"], | ||
["keyword", "public"], | ||
["keyword", "private"], | ||
["keyword", "return"], | ||
["keyword", "static"], | ||
["keyword", "super"], | ||
["keyword", "switch"], | ||
["keyword", "throw"], | ||
["keyword", "to"], | ||
["keyword", "try"], | ||
["keyword", "typedef"], | ||
["keyword", "using"], | ||
["keyword", "var"], | ||
["keyword", "while"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for 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,15 @@ | ||
@author("Nicolas") | ||
@debug | ||
@:noCompletion | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["metadata", "@author"], ["punctuation", "("], ["string", ["\"Nicolas\""]], ["punctuation", ")"], | ||
["metadata", "@debug"], | ||
["metadata", "@:noCompletion"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for metadata. |
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,29 @@ | ||
... | ||
+ ++ | ||
- -- -> | ||
= == | ||
! != | ||
& && | ||
| || | ||
< <= << | ||
> >= >> | ||
* / % ~ ^ | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["operator", "..."], | ||
["operator", "+"], ["operator", "++"], | ||
["operator", "-"], ["operator", "--"], ["operator", "->"], | ||
["operator", "="], ["operator", "=="], | ||
["operator", "!"], ["operator", "!="], | ||
["operator", "&"], ["operator", "&&"], | ||
["operator", "|"], ["operator", "||"], | ||
["operator", "<"], ["operator", "<="], ["operator", "<<"], | ||
["operator", ">"], ["operator", ">="], ["operator", ">>"], | ||
["operator", "*"], ["operator", "/"], ["operator", "%"], ["operator", "~"], ["operator", "^"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for operators. |
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,17 @@ | ||
#if | ||
#elseif | ||
#else | ||
#end | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["preprocessor", "#if"], | ||
["preprocessor", "#elseif"], | ||
["preprocessor", "#else"], | ||
["preprocessor", "#end"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for preprocessor directives. |
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,15 @@ | ||
~/ha\/xe/i | ||
~/[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z][A-Z][A-Z]?/i | ||
~/(dog|fox)/igmsu | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["regex", "~/ha\\/xe/i"], | ||
["regex", "~/[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z][A-Z][A-Z]?/i"], | ||
["regex", "~/(dog|fox)/igmsu"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for regexes. |
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,16 @@ | ||
$e | ||
${4+2} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["reification", "$e"], | ||
["reification", "$"], | ||
["punctuation", "{"], | ||
["number", "4"], ["operator", "+"], ["number", "2"], | ||
["punctuation", "}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for reification. |
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 @@ | ||
"" | ||
"Foo | ||
\"bar\" | ||
baz" | ||
"$bar ${4+2}" | ||
'' | ||
'Foo | ||
\'bar\' | ||
baz' | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["string", ["\"\""]], | ||
["string", ["\"Foo\r\n\\\"bar\\\"\r\nbaz\""]], | ||
["string", [ | ||
"\"", | ||
["interpolation", [ | ||
["interpolation", "$bar"] | ||
]], | ||
["interpolation", [ | ||
["interpolation", "$"], | ||
["punctuation", "{"], | ||
["number", "4"], | ||
["operator", "+"], | ||
["number", "2"], | ||
["punctuation", "}"] | ||
]], | ||
"\"" | ||
]], | ||
["string", ["''"]], | ||
["string", ["'Foo\r\n\\'bar\\'\r\nbaz'"]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for strings and string interpolation. |