From 2bd003c2e4525b2b4d63c4f879d31165de598d8f Mon Sep 17 00:00:00 2001 From: Malthe Borch <mborch@gmail.com> Date: Sun, 23 Oct 2016 21:48:54 +0200 Subject: [PATCH] Add support for Pony language --- CHANGELOG | 5 +++ README.md | 1 + build.xml | 3 +- src/lang/sunlight.pony.js | 53 ++++++++++++++++++++++++ src/plugins/sunlight-plugin.doclinks.js | 9 +++- tests/test-pony.html | 55 +++++++++++++++++++++++++ 6 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 src/lang/sunlight.pony.js create mode 100644 tests/test-pony.html diff --git a/CHANGELOG b/CHANGELOG index 4ca4c04..9e6e3b1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +Next release... +----------------- +- Enhancements + - new languages: pony + 1.22.0 2014-01-06 ----------------- - Bugfixes diff --git a/README.md b/README.md index 4696070..e91f189 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ for other options. - PowerShell - Objective-C - Lua +- Pony ## Plugins - sunlight-plugin.linenumbers.js (bundled) diff --git a/build.xml b/build.xml index aa6e473..d87dc20 100644 --- a/build.xml +++ b/build.xml @@ -80,6 +80,7 @@ <fileset dir="${temp.dir}" includes="sunlight.css.js"/> <fileset dir="${temp.dir}" includes="sunlight.bash.js"/> <fileset dir="${temp.dir}" includes="sunlight.tsql.js"/> + <fileset dir="${temp.dir}" includes="sunlight.pony.js"/> <fileset dir="${temp.dir}" includes="sunlight.python.js"/> <fileset dir="${temp.dir}" includes="sunlight.ruby.js"/> <fileset dir="${temp.dir}" includes="sunlight.java.js"/> @@ -194,4 +195,4 @@ <os family="winnt"/> </condition> </target> -</project> \ No newline at end of file +</project> diff --git a/src/lang/sunlight.pony.js b/src/lang/sunlight.pony.js new file mode 100644 index 0000000..fc8ce11 --- /dev/null +++ b/src/lang/sunlight.pony.js @@ -0,0 +1,53 @@ +(function(sunlight, undefined){ + + if (sunlight === undefined || sunlight["registerLanguage"] === undefined) { + throw "Include sunlight.js before including language files"; + } + + sunlight.registerLanguage("pony", { + keywords: [ + "actor", "addressof", "as", "be", "break", "class", "compiler_intrinsic", "consume", "continue", "do", "else", "elseif", "embed", "end", "error", "for", "fun", "if", "ifdef", "in", "interface", "is", "isnt", "lambda", "let", "match", "new", "not", "object", "primitive", "recover", "repeat", "return", "struct", "then", "this", "trait", "try", "type", "until", "use", "var", "where", "while", "with" + ], + + scopes: { + longString: [ + ["\"\"\"", "\"\"\"", sunlight.util.escapeSequences.concat(["\\\""])], + ["'''", "'''", sunlight.util.escapeSequences.concat(["\\'"])] + ], + string: [ ["\"", "\"", sunlight.util.escapeSequences.concat(["\\\""])] ], + comment: [ ["//", "\n", null, true], ["/*", "*/"] ] + }, + + customTokens: { + binops: { + values: ["or", "and", "isnt"], + boundary: " " + }, + booleans: { + values: ["true", "false"], + boundary: "" + } + }, + + customParseRules: [], + + identFirstLetter: /[@A-Za-z_]/, + identAfterFirstLetter: /\w/, + + namedIdentRules: { + follows: [ + //class names + //function names + [{ token: "keyword", values: ["actor", "be", "class", "fun", "lambda", "new", "use"] }, sunlight.util.whitespace] + ] + }, + + operators: [ + "!", "->", "^", "@", "&", "->", "=>", "~", "?", "'", "<:" + ], + + contextItems: { + heredocQueue: [] + } + }); +}(this["Sunlight"])); \ No newline at end of file diff --git a/src/plugins/sunlight-plugin.doclinks.js b/src/plugins/sunlight-plugin.doclinks.js index 48cf337..3d1ded2 100644 --- a/src/plugins/sunlight-plugin.doclinks.js +++ b/src/plugins/sunlight-plugin.doclinks.js @@ -31,7 +31,14 @@ + word.replace(/!/g, "_bang").replace(/\?/g, "_p"); } }, - + + pony: { + "function": function(word) { + return "http://www.ponylang.org/ponyc/search.html?q=" + word; + } + }, + + python: { "function": function(word) { return "http://docs.python.org/py3k/library/functions.html#" + word; diff --git a/tests/test-pony.html b/tests/test-pony.html new file mode 100644 index 0000000..2126d3b --- /dev/null +++ b/tests/test-pony.html @@ -0,0 +1,55 @@ +<html> + + <head> + <script type="text/javascript" src="../src/sunlight.js"></script> + <script type="text/javascript" src="../src/lang/sunlight.pony.js"></script> + <link rel="stylesheet" type="text/css" href="../src/themes/sunlight.default.css" /> + </head> + + <body> +<pre id="code" class="sunlight-highlight-pony">use "collections" + +class Circle + """Represents a circle.""" + + // The radius is a 32-bit floating point number. + var _radius: F32 + + new create(radius: F32) => + _radius = radius + + fun area(): F32 => + """Return circle area.""" + F32.pi() * _radius.pow(2) + + fun circumference(): F32 => + """Return circumference.""" + 2 * _radius * F32.pi() + + fun valid(): Bool => + """Return true if radius is > 0.""" + _radius > 0.0 + +use @memcmp[I32](dst: Pointer[U8] box, src: Pointer[U8] box, len: USize) + +actor Main + new create(env: Env) => + + for i in Range[F32](1.0, 101.0) do + let c = Circle(i) + + var str = + "Circumference: " + c.circumference().string() + "\n" + + "Area: " + c.area().string() + "\n" + + /* This prints out the output to stdout */ + env.out.print(str) + end</pre> + + </body> + + <script type="text/javascript" src="test.js"></script> + <script type="text/javascript">//<![CDATA[ + assertExists("comment", "// The radius is a 32-bit floating point number.", "comment"); + //]]></script> +</html>