From 4fe5980065f21ab3a1a0cb259ebb5654524f25c5 Mon Sep 17 00:00:00 2001 From: ellemenno Date: Wed, 12 Nov 2014 02:30:00 -0500 Subject: [PATCH 1/6] add language declaration and samples for LoomScript LoomScript is the scripting language for the Loom SDK. It has an ActionScript3-like syntax with added C#-esque capabilities. Loom SDK: https://github.com/LoomSDK/LoomSDK --- lib/linguist/languages.yml | 6 ++ samples/LoomScript/HelloWorld.ls | 38 ++++++++ samples/LoomScript/SyntaxExercise.ls | 137 +++++++++++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 samples/LoomScript/HelloWorld.ls create mode 100644 samples/LoomScript/SyntaxExercise.ls diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index da18b25a..f51b690a 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1492,6 +1492,12 @@ LookML: - .lookml tm_scope: source.yaml +LoomScript: + type: programming + lexer: ActionScript 3 + extensions: + - .ls + Lua: type: programming ace_mode: lua diff --git a/samples/LoomScript/HelloWorld.ls b/samples/LoomScript/HelloWorld.ls new file mode 100644 index 00000000..d3ba35f7 --- /dev/null +++ b/samples/LoomScript/HelloWorld.ls @@ -0,0 +1,38 @@ +package +{ + import loom.Application; + import loom2d.display.StageScaleMode; + import loom2d.ui.SimpleLabel; + + /** + The HelloWorld app renders a label with its name on it, + and traces 'hello' to the log. + */ + public class HelloWorld extends Application + { + + override public function run():void + { + stage.scaleMode = StageScaleMode.LETTERBOX; + centeredMessage(simpleLabel, this.getFullTypeName()); + + trace("hello"); + } + + // a convenience getter that generates a label and adds it to the stage + private function get simpleLabel():SimpleLabel + { + return stage.addChild(new SimpleLabel("assets/Curse-hd.fnt")) as SimpleLabel; + } + + // a utility to set the label's text and then center it on the stage + private function centeredMessage(label:SimpleLabel, msg:String):void + { + label.text = msg; + label.center(); + label.x = stage.stageWidth / 2; + label.y = (stage.stageHeight / 2) - (label.height / 2); + } + + } +} diff --git a/samples/LoomScript/SyntaxExercise.ls b/samples/LoomScript/SyntaxExercise.ls new file mode 100644 index 00000000..444ee1da --- /dev/null +++ b/samples/LoomScript/SyntaxExercise.ls @@ -0,0 +1,137 @@ +package +{ + import loom.Application; + + public interface I {} + public class C {} + public class B extends C implements I {} + final public class A extends B {} + + delegate ToCompute(s:String, o:Object):Number; + + public enum Enumeration + { + foo, + baz, + cat, + } + + struct P { + public var x:Number = 0; + public var y:Number = 0; + public static operator function =(a:P, b:P):P + { + a.x = b.x; + a.y = b.y; + + return a; + } + } + + // single-line comment + + /* + Multi-line comment + */ + + /** + Doc comment + */ + public class SyntaxExercise extends Application + { + static public var classVar:String = 'class variable'; + public const CONST:String = 'constant'; + private var _a:A = new A(); + public var _d:ToCompute; + + override public function run():void + { + trace("hello"); + } + + private function get a():A { return _a; } + private function set a(value:A):void { _a = value; } + + private function variousTypes(defaultValue:String = ''):void + { + var nil:Object = null; + var b1:Boolean = true; + var b2:Boolean = false; + var n1:Number = 0.123; + var n2:Number = 12345; + var n3:Number = 0xfed; + var s1:String = 'single-quotes with "quotes" inside'; + var s2:String = "double-quotes with 'quotes' inside"; + var f1:Function = function (life:String, universe:Object, ...everything):Number { return 42; }; + var v1:Vector. = [1, 2]; + var d1:Dictionary. = { 'three': 3, 'four': 4 }; + + _d += f1; + _d -= f1; + } + + private function variousOps():void + { + var a = ((100 + 200 - 0) / 300) % 2; + var b = 100 * 30; + var d = true && (b > 301); + var e = 0x10 | 0x01; + + b++; b--; + a += 300; a -= 5; a *= 4; a /= 2; a %= 7; + + var castable1:Boolean = (a is B); + var castable2:Boolean = (a as B) != null; + var cast:String = B(a).toString(); + var instanced:Boolean = (_a instanceof A); + } + + private function variousFlow():void + { + var n:Number = Math.random(); + if (n > 0.6) + trace('top 40!'); + else if(n > 0.3) + trace('mid 30!'); + else + trace('bottom 30'); + + var flip:String = (Math.random() > 0.5) ? 'heads' : 'tails'; + + for (var i = 0; i < 100; i++) + trace(i); + + var v:Vector. = ['a', 'b', 'c']; + for each (var s:String in v) + trace(s); + + var d:Dictionary. = { 'one': 1 }; + for (var key1:String in d) + trace(key1); + + for (var key2:Number in v) + trace(key2); + + while (i > 0) + { + i--; + if (i == 13) continue; + trace(i); + } + + do + { + i++; + } + while (i < 10); + + switch (Math.floor(Math.random()) * 3 + 1) + { + case 1 : trace('rock'); break; + case 2 : trace('paper'); break; + default: trace('scissors'); break; + } + } + + } +} From 88f196e4d4db5d49d0a928d23093d8fe05abe597 Mon Sep 17 00:00:00 2001 From: ellemenno Date: Mon, 17 Nov 2014 01:55:59 -0500 Subject: [PATCH 2/6] add a heuristic to disambiguate LiveScript from LoomScript Keying off of `package {`, since LoomScript code must be enclosed in a package definition, whereas that would be invalid LiveScript --- lib/linguist/heuristics.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index c203b1ba..c85fe964 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -144,6 +144,15 @@ module Linguist disambiguate "Gosu", "JavaScript" do |data| Language["Gosu"] if /^uses java\./.match(data) - end + end + + disambiguate "LoomScript", "LiveScript" do |data| + if /^\s*package[\w\W]*{/.match(data) + Language["LoomScript"] + else + Language["LiveScript"] + end + end + end end From c76137efc0fd8ab6e86d363168331df5851b0920 Mon Sep 17 00:00:00 2001 From: ellemenno Date: Thu, 27 Nov 2014 09:40:31 -0500 Subject: [PATCH 3/6] improve regex for loomscript --- lib/linguist/heuristics.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index c85fe964..569276fc 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -147,7 +147,7 @@ module Linguist end disambiguate "LoomScript", "LiveScript" do |data| - if /^\s*package[\w\W]*{/.match(data) + if /^\s*package\s*[\w\.\/\*\s]*\s*{/.match(data) Language["LoomScript"] else Language["LiveScript"] From 72c00f869ccd5cd9216298f80ee63ff0ee2ebe07 Mon Sep 17 00:00:00 2001 From: ellemenno Date: Thu, 27 Nov 2014 10:36:03 -0500 Subject: [PATCH 4/6] add textmate scope for loomscript --- grammars.yml | 2 ++ lib/linguist/languages.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/grammars.yml b/grammars.yml index bd2bdd8e..d79fbe59 100644 --- a/grammars.yml +++ b/grammars.yml @@ -61,6 +61,8 @@ https://github.com/Varriount/NimLime: - source.nimrod - source.nimrod_filter - source.nimrodcfg +https://github.com/ambethia/Sublime-Loom: +- source.loomscript https://github.com/angryant0007/VBDotNetSyntax: - source.vbnet https://github.com/anunayk/cool-tmbundle: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index f51b690a..1861bb8c 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1494,9 +1494,9 @@ LookML: LoomScript: type: programming - lexer: ActionScript 3 extensions: - .ls + tm_scope: source.loomscript Lua: type: programming From 1e68a45515ae12f1a7a158c8677e8c2bfd4ad7d5 Mon Sep 17 00:00:00 2001 From: ellemenno Date: Fri, 28 Nov 2014 11:59:48 -0500 Subject: [PATCH 5/6] add test of ls disambiguation --- test/test_heuristics.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index 2c78d87c..03b26415 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -122,4 +122,15 @@ class TestHeuristcs < Test::Unit::TestCase end end end + + # Candidate languages = ["LiveScript", "LoomScript"] + def test_ls_livescript_by_heuristics + results = Heuristics.disambiguate_ls(fixture("LiveScript/hello.ls")) + assert_equal Language["LiveScript"], results.first + end + + def test_ls_loomscript_by_heuristics + results = Heuristics.disambiguate_ls(fixture("LoomScript/HelloWorld.ls")) + assert_equal Language["LoomScript"], results.first + end end From 211cb9567a6fd0eb1fc5fde0e4c8a488074950d9 Mon Sep 17 00:00:00 2001 From: ellemenno Date: Mon, 1 Dec 2014 01:37:55 -0500 Subject: [PATCH 6/6] refactor heuristic tests to use new helper --- test/test_heuristics.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index 03b26415..0bd01bb5 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -123,14 +123,10 @@ class TestHeuristcs < Test::Unit::TestCase end end - # Candidate languages = ["LiveScript", "LoomScript"] - def test_ls_livescript_by_heuristics - results = Heuristics.disambiguate_ls(fixture("LiveScript/hello.ls")) - assert_equal Language["LiveScript"], results.first - end - - def test_ls_loomscript_by_heuristics - results = Heuristics.disambiguate_ls(fixture("LoomScript/HelloWorld.ls")) - assert_equal Language["LoomScript"], results.first + def test_ls_by_heuristics + assert_heuristics({ + "LiveScript" => "LiveScript/hello.ls", + "LoomScript" => "LoomScript/HelloWorld.ls" + }) end end