Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Haxe #811

Merged
merged 3 commits into from
Oct 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ var components = {
"title": "Haskell",
"owner": "bholst"
},
"haxe": {
"title": "Haxe",
"require": "clike",
"owner": "Golmote"
},
"http": {
"title": "HTTP",
"owner": "danielgtaylor"
Expand Down
43 changes: 43 additions & 0 deletions components/prism-haxe.js
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'];
1 change: 1 addition & 0 deletions components/prism-haxe.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions examples/prism-haxe.html
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>
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

// The dependencies map is built automatically with gulp
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","fsharp":"clike","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup","jade":"javascript","java":"clike","less":"css","markdown":"markup","nginx":"clike","objectivec":"c","parser":"markup","php":"clike","php-extras":"php","processing":"clike","qore":"clike","jsx":["markup","javascript"],"ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","wiki":"markup"}/*]*/;
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","fsharp":"clike","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup","haxe":"clike","jade":"javascript","java":"clike","less":"css","markdown":"markup","nginx":"clike","objectivec":"c","parser":"markup","php":"clike","php-extras":"php","processing":"clike","qore":"clike","jsx":["markup","javascript"],"ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","wiki":"markup"}/*]*/;

var lang_data = {};

Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions tests/languages/haxe/keyword_feature.test
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.
15 changes: 15 additions & 0 deletions tests/languages/haxe/metadata_feature.test
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.
29 changes: 29 additions & 0 deletions tests/languages/haxe/operator_feature.test
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.
17 changes: 17 additions & 0 deletions tests/languages/haxe/preprocessor_feature.test
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.
15 changes: 15 additions & 0 deletions tests/languages/haxe/regex_feature.test
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.
16 changes: 16 additions & 0 deletions tests/languages/haxe/reification_feature.test
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.
37 changes: 37 additions & 0 deletions tests/languages/haxe/string_feature.test
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.