[prev in list] [next in list] [prev in thread] [next in thread]
List: ktexteditor-devel
Subject: Haxe Syntax Highlighting
From: Chad J <chadj () postboredom ! org>
Date: 2008-11-17 17:41:10
Message-ID: 4921ACB6.4000408 () postboredom ! org
[Download RAW message or body]
Greetings,
Here is an improved version of the Haxe syntax highlighting I posted
before. I have also included a sample file (highlight.hx) that
exercises the Haxe syntax highlighting.
Enjoy!
- Chad
["haxe.xml" (text/xml)]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<!--
========================================================================
Haxe Language highlighting.
========================================================================
Author: Chad Joan
Versions:
0.2: Added 'do' and 'dynamic' keywords, added regular expression literals,
fixed numeric literals, and fixed preprocessor.
0.1: Initial
========================================================================
-->
<language name="Haxe" section="Sources" extensions="*.hx;*.Hx;*.hX;*.HX;" \
mimetype="text/x-hxsrc" version="0.2" kateversion="3.1" casesensitive="true" \
author="Chad Joan" license="MIT"> <highlighting>
<list name="keywords">
<item> break </item>
<item> case </item>
<item> cast </item>
<item> catch </item>
<item> class </item>
<item> continue </item>
<item> default </item>
<item> do </item>
<item> dynamic </item>
<item> else </item>
<item> enum </item>
<item> extends </item>
<item> false </item>
<item> for </item>
<item> function </item>
<item> if </item>
<item> implements </item>
<item> in </item>
<item> inline </item>
<item> interface </item>
<item> new </item>
<item> null </item>
<item> override </item>
<item> private </item>
<item> public </item>
<item> return </item>
<item> static </item>
<item> super </item>
<item> switch </item>
<item> this </item>
<item> throw </item>
<item> trace </item>
<item> true </item>
<item> try </item>
<item> typedef </item>
<item> untyped </item>
<item> var </item>
<item> while </item>
</list>
<list name="modules">
<item> package </item>
<item> import </item>
</list>
<list name="types">
<item> Array </item>
<item> Void </item>
<item> Bool </item>
<item> Int </item>
<item> UInt </item>
<item> Float </item>
<item> Dynamic </item>
<item> String </item>
<item> List </item>
<item> Error </item>
<item> Unknown </item>
<item> Type </item>
</list>
<contexts>
<context attribute="Normal Text" lineEndContext="#stay" name="normal">
<RegExpr attribute="Preprocessor" context="#pop" String="#if(\s+\w+)?" />
<RegExpr attribute="Preprocessor" context="#pop" String="#elseif(\s+\w+)?" />
<RegExpr attribute="Preprocessor" context="#pop" String="#(else|end|error)" \
/>
<keyword attribute="Keyword" context="#stay" String="keywords"/>
<keyword attribute="Module" context="ModuleName" String="modules"/>
<keyword attribute="Type" context="#stay" String="types"/>
<DetectIdentifier attribute="Normal Text"/>
<HlCStringChar attribute="EscapeString" context="#pop"/>
<DetectChar attribute="RawString" context="RawString" char="'"/>
<DetectChar attribute="String" context="String" char="""/>
<Detect2Chars attribute="RegularExp" context="RegularExp" char="~" char1="/"/>
<Detect2Chars attribute="Comment" context="CommentLine" char="/" \
char1="/"/>
<Detect2Chars attribute="Comment" context="CommentBlock" char="/" char1="*" \
beginRegion="CommentBlock"/>
<DetectChar attribute="Normal Text" context="#stay" char="{" \
beginRegion="BraceA" />
<DetectChar attribute="Normal Text" context="#stay" char="}" \
endRegion="BraceA" />
<!-- Match ... and .. before numbers are matched. -->
<StringDetect attribute="Normal Text" context="#pop" String="..."/>
<Detect2Chars attribute="Normal Text" char="." char1="."/>
<!-- Numerics -->
<RegExpr attribute="Hex" context="#pop" String="[-+]?0[xX][\da-fA-F]+"/>
<RegExpr attribute="Float" context="#pop" \
String="[-+]?[\d][\d]*(\.(?!\.)[\d]*([eE][-+]?[\d]+)?)"/>
<RegExpr attribute="Float" context="#pop" \
String="[-+]?\.?[\d][\d]*([eE][-+]?[\d]+)?"/>
<RegExpr attribute="Integer" context="#pop" String="[-+]?\d+"/>
</context>
<context attribute="Module Name" lineEndContext="#stay" name="ModuleName">
<Detect2Chars attribute="Comment" context="CommentLine" char="/" \
char1="/"/>
<Detect2Chars attribute="Comment" context="CommentBlock" char="/" \
char1="*" beginRegion="CommentBlock"/> <RegExpr context="#pop" String="[^\s\w.:,]"/>
</context>
<!-- Strings -->
<!-- '...' -->
<context attribute="RawString" lineEndContext="#stay" name="RawString">
<DetectChar attribute="RawString" context="#pop" char="'"/>
</context>
<!-- "..." -->
<context attribute="String" lineEndContext="#stay" name="String">
<Detect2Chars attribute="String" context="#stay" char="\" char1="""/>
<DetectChar attribute="String" context="#pop" char="""/>
<HlCStringChar attribute="EscapeSequence"/>
<RegExpr attribute="EscapeSequence" context="#stay" \
String="\\(u[\da-fA-F]{4}|U[\da-fA-F]{8}|&[a-zA-Z]\w+;)" /> </context>
<!-- "~/.../igm" regular expression literals -->
<context attribute="RegularExp" lineEndContext="#stay" name="RegularExp">
<Detect2Chars attribute="RegularExp" context="#stay" char="\" char1="/"/>
<RegExpr attribute="RegularExp" context="#pop" String="/[igm]*"/>
</context>
<!-- Comments -->
<context attribute="Comment" lineEndContext="#pop" name="CommentLine"/>
<context attribute="Comment" lineEndContext="#stay" name="CommentBlock">
<Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" \
endRegion="CommentBlock"/> </context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal"/>
<itemData name="Keyword" defStyleNum="dsKeyword"/>
<itemData name="Type" defStyleNum="dsDataType"/>
<itemData name="Integer" defStyleNum="dsDecVal"/>
<itemData name="Hex" defStyleNum="dsBaseN"/>
<itemData name="Float" defStyleNum="dsFloat"/>
<itemData name="Module" defStyleNum="dsKeyword" color="#0000ff" \
selColor="#ffffff"/>
<itemData name="Module Name" defStyleNum="dsNormal" color="#0000ff" \
selColor="#ffffff"/>
<itemData name="EscapeSequence" defStyleNum="dsString" color="#00aa88" \
selColor="#ff0000"/> <itemData name="String" defStyleNum="dsString"/>
<itemData name="RawString" defStyleNum="dsString"/>
<itemData name="RegularExp" defStyleNum="dsString"/>
<itemData name="Comment" defStyleNum="dsComment"/>
<itemData name="Preprocessor" defStyleNum="dsOthers"/>
</itemDatas>
</highlighting>
<general>
<comments>
<comment name="singleLine" start="//"/>
<comment name="multiLine" start="/*" end="*/" />
</comments>
<keywords casesensitive="true"/>
</general>
</language>
["highlight.hx" (text/plain)]
/******************************************************************************
This file is an example of Syntax Highlighting in KWrite/Kate for the Haxe
programming language.
Author: Chad Joan
******************************************************************************/
package highlight.test;
import some.package;
/* literals and the like */
0; // Int
-134; // Int
0xFF00; // Int
123.0; // Float
.14179; // Float
13e50; // Float
-1e-99; // Float
"hello"; // String
"hello \"world\" !"; // String
'hello "world" !'; // String
"hello world\n"; // String
true; // Bool
false; // Bool
null; // Unknown<0>
~/[a-z]+/i; // EReg : regular expression
~/foo\/bar/igmig; // EReg : regular expression, a contrived one.
/* preprocessor stuff */
#if preprocessor
#elseif flash
#elseif flash9
#elseif neko
#elseif whatever
# elseif // This won't compile, so no highlighting. (haxe compiler v2.01)
#else if // This is also not on the list.
#else
#error
#end
/* Types, attributes, etc. */
enum Cell<T> {
empty;
cons( item : T, next : Cell<T> );
}
typedef User = {
var age : Int;
var name : String;
}
// ....
var u : User = { age : 26, name : "Tom" }
// PointCube is a 3-dimensional array of points
typedef PointCube = Array<Array<Array<Point>>>
interface Baz {
var x : Float;
var y : Float;
function length() : Float;
}
class B implements Dynamic<Int> {
public var name : String;
public var address : String;
}
class C extends B {
public static inline var someString = "attributes";
private dynamic var anotherString = "moar attributes";
dynamic override function() : String { return 'hmmm...'; }
// properties
public var ro(default,null) : Int;
public var wo(null,default) : Int;
public var q(dynamic,dynamic) : Int; // dynamic can show up here too.
// getP and setP are just functions that we define below.
public var p(getP,setP) : Int;
private var m_p;
function getP() { return m_p; }
function setP( v : Int ) { m_p = v; return m_p; }
// constructor
function new() {
super(); // Call's B constructor.
}
public inline function foo() : Void {
var bar : Dynamic = ""; // Dynamic type.
bar = true;
var a : A = new A();
var b : B = cast(a,B); // cast keyword.
var y : B = cast 0; // more cast keyword.
untyped { a["hello"] = 0; } // untyped keyword
throw new Error("Oh noes!"); // throw, new, Error
// for loops/iterators
var arr : Array<B>;
for( i in 0...arr.length ) {
foo(arr[i]);
}
// while loops
var chillin : Bool = true;
var len : Float = 0;
var i : Float = 0;
while ( chillin )
{
do
{
chillin = false;
break;
}
while ( i < len )
}
}
static function f() {
// trace is a builtin text output function.
trace("We've reached the 'f' function.");
var me = this;
var add = function(n) { me.p += n; };
return;
try {
foo();
} catch( e : String ) {
// handle this kind of error
} catch( e : Error ) {
// handle another kind of error
} catch( e : Dynamic ) {
// handle all other errors
}
if( v == 0 )
e1
else if( v == foo(1) )
e2
else if( v == 65 )
e3
else
e4;
switch( v ) {
case 0:
e1;
case foo(1):
e2;
case 65:
e3;
default:
e4;
}
}
}
_______________________________________________
KTextEditor-Devel mailing list
KTextEditor-Devel@kde.org
https://mail.kde.org/mailman/listinfo/ktexteditor-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic