summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/mode/kotlin
diff options
context:
space:
mode:
authorWu Cheng-Han2015-05-04 15:53:29 +0800
committerWu Cheng-Han2015-05-04 15:53:29 +0800
commit4b0ca55eb79e963523eb6c8197825e9e8ae904e2 (patch)
tree574f3923af77b37b41dbf1b00bcd7827ef724a28 /public/vendor/codemirror/mode/kotlin
parent61eb11d23c65c9e5c493c67d055f785cbec139e2 (diff)
First commit, version 0.2.7
Diffstat (limited to 'public/vendor/codemirror/mode/kotlin')
-rwxr-xr-xpublic/vendor/codemirror/mode/kotlin/index.html89
-rwxr-xr-xpublic/vendor/codemirror/mode/kotlin/kotlin.js281
2 files changed, 370 insertions, 0 deletions
diff --git a/public/vendor/codemirror/mode/kotlin/index.html b/public/vendor/codemirror/mode/kotlin/index.html
new file mode 100755
index 00000000..859e109f
--- /dev/null
+++ b/public/vendor/codemirror/mode/kotlin/index.html
@@ -0,0 +1,89 @@
+<!doctype html>
+
+<title>CodeMirror: Kotlin mode</title>
+<meta charset="utf-8"/>
+<link rel=stylesheet href="../../doc/docs.css">
+
+<link rel="stylesheet" href="../../lib/codemirror.css">
+<script src="../../lib/codemirror.js"></script>
+<script src="kotlin.js"></script>
+<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
+<div id=nav>
+ <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
+
+ <ul>
+ <li><a href="../../index.html">Home</a>
+ <li><a href="../../doc/manual.html">Manual</a>
+ <li><a href="https://github.com/codemirror/codemirror">Code</a>
+ </ul>
+ <ul>
+ <li><a href="../index.html">Language modes</a>
+ <li><a class=active href="#">Kotlin</a>
+ </ul>
+</div>
+
+<article>
+<h2>Kotlin mode</h2>
+
+
+<div><textarea id="code" name="code">
+package org.wasabi.http
+
+import java.util.concurrent.Executors
+import java.net.InetSocketAddress
+import org.wasabi.app.AppConfiguration
+import io.netty.bootstrap.ServerBootstrap
+import io.netty.channel.nio.NioEventLoopGroup
+import io.netty.channel.socket.nio.NioServerSocketChannel
+import org.wasabi.app.AppServer
+
+public class HttpServer(private val appServer: AppServer) {
+
+ val bootstrap: ServerBootstrap
+ val primaryGroup: NioEventLoopGroup
+ val workerGroup: NioEventLoopGroup
+
+ {
+ // Define worker groups
+ primaryGroup = NioEventLoopGroup()
+ workerGroup = NioEventLoopGroup()
+
+ // Initialize bootstrap of server
+ bootstrap = ServerBootstrap()
+
+ bootstrap.group(primaryGroup, workerGroup)
+ bootstrap.channel(javaClass<NioServerSocketChannel>())
+ bootstrap.childHandler(NettyPipelineInitializer(appServer))
+ }
+
+ public fun start(wait: Boolean = true) {
+ val channel = bootstrap.bind(appServer.configuration.port)?.sync()?.channel()
+
+ if (wait) {
+ channel?.closeFuture()?.sync()
+ }
+ }
+
+ public fun stop() {
+ // Shutdown all event loops
+ primaryGroup.shutdownGracefully()
+ workerGroup.shutdownGracefully()
+
+ // Wait till all threads are terminated
+ primaryGroup.terminationFuture().sync()
+ workerGroup.terminationFuture().sync()
+ }
+}
+</textarea></div>
+
+ <script>
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
+ mode: {name: "kotlin"},
+ lineNumbers: true,
+ indentUnit: 4
+ });
+ </script>
+ <h3>Mode for Kotlin (http://kotlin.jetbrains.org/)</h3>
+ <p>Developed by Hadi Hariri (https://github.com/hhariri).</p>
+ <p><strong>MIME type defined:</strong> <code>text/x-kotlin</code>.</p>
+</article>
diff --git a/public/vendor/codemirror/mode/kotlin/kotlin.js b/public/vendor/codemirror/mode/kotlin/kotlin.js
new file mode 100755
index 00000000..1efec85d
--- /dev/null
+++ b/public/vendor/codemirror/mode/kotlin/kotlin.js
@@ -0,0 +1,281 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+"use strict";
+
+CodeMirror.defineMode("kotlin", function (config, parserConfig) {
+ function words(str) {
+ var obj = {}, words = str.split(" ");
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
+ return obj;
+ }
+
+ var multiLineStrings = parserConfig.multiLineStrings;
+
+ var keywords = words(
+ "package continue return object while break class data trait throw super" +
+ " when type this else This try val var fun for is in if do as true false null get set");
+ var softKeywords = words("import" +
+ " where by get set abstract enum open annotation override private public internal" +
+ " protected catch out vararg inline finally final ref");
+ var blockKeywords = words("catch class do else finally for if where try while enum");
+ var atoms = words("null true false this");
+
+ var curPunc;
+
+ function tokenBase(stream, state) {
+ var ch = stream.next();
+ if (ch == '"' || ch == "'") {
+ return startString(ch, stream, state);
+ }
+ // Wildcard import w/o trailing semicolon (import smth.*)
+ if (ch == "." && stream.eat("*")) {
+ return "word";
+ }
+ if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
+ curPunc = ch;
+ return null;
+ }
+ if (/\d/.test(ch)) {
+ if (stream.eat(/eE/)) {
+ stream.eat(/\+\-/);
+ stream.eatWhile(/\d/);
+ }
+ return "number";
+ }
+ if (ch == "/") {
+ if (stream.eat("*")) {
+ state.tokenize.push(tokenComment);
+ return tokenComment(stream, state);
+ }
+ if (stream.eat("/")) {
+ stream.skipToEnd();
+ return "comment";
+ }
+ if (expectExpression(state.lastToken)) {
+ return startString(ch, stream, state);
+ }
+ }
+ // Commented
+ if (ch == "-" && stream.eat(">")) {
+ curPunc = "->";
+ return null;
+ }
+ if (/[\-+*&%=<>!?|\/~]/.test(ch)) {
+ stream.eatWhile(/[\-+*&%=<>|~]/);
+ return "operator";
+ }
+ stream.eatWhile(/[\w\$_]/);
+
+ var cur = stream.current();
+ if (atoms.propertyIsEnumerable(cur)) {
+ return "atom";
+ }
+ if (softKeywords.propertyIsEnumerable(cur)) {
+ if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
+ return "softKeyword";
+ }
+
+ if (keywords.propertyIsEnumerable(cur)) {
+ if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
+ return "keyword";
+ }
+ return "word";
+ }
+
+ tokenBase.isBase = true;
+
+ function startString(quote, stream, state) {
+ var tripleQuoted = false;
+ if (quote != "/" && stream.eat(quote)) {
+ if (stream.eat(quote)) tripleQuoted = true;
+ else return "string";
+ }
+ function t(stream, state) {
+ var escaped = false, next, end = !tripleQuoted;
+
+ while ((next = stream.next()) != null) {
+ if (next == quote && !escaped) {
+ if (!tripleQuoted) {
+ break;
+ }
+ if (stream.match(quote + quote)) {
+ end = true;
+ break;
+ }
+ }
+
+ if (quote == '"' && next == "$" && !escaped && stream.eat("{")) {
+ state.tokenize.push(tokenBaseUntilBrace());
+ return "string";
+ }
+
+ if (next == "$" && !escaped && !stream.eat(" ")) {
+ state.tokenize.push(tokenBaseUntilSpace());
+ return "string";
+ }
+ escaped = !escaped && next == "\\";
+ }
+ if (multiLineStrings)
+ state.tokenize.push(t);
+ if (end) state.tokenize.pop();
+ return "string";
+ }
+
+ state.tokenize.push(t);
+ return t(stream, state);
+ }
+
+ function tokenBaseUntilBrace() {
+ var depth = 1;
+
+ function t(stream, state) {
+ if (stream.peek() == "}") {
+ depth--;
+ if (depth == 0) {
+ state.tokenize.pop();
+ return state.tokenize[state.tokenize.length - 1](stream, state);
+ }
+ } else if (stream.peek() == "{") {
+ depth++;
+ }
+ return tokenBase(stream, state);
+ }
+
+ t.isBase = true;
+ return t;
+ }
+
+ function tokenBaseUntilSpace() {
+ function t(stream, state) {
+ if (stream.eat(/[\w]/)) {
+ var isWord = stream.eatWhile(/[\w]/);
+ if (isWord) {
+ state.tokenize.pop();
+ return "word";
+ }
+ }
+ state.tokenize.pop();
+ return "string";
+ }
+
+ t.isBase = true;
+ return t;
+ }
+
+ function tokenComment(stream, state) {
+ var maybeEnd = false, ch;
+ while (ch = stream.next()) {
+ if (ch == "/" && maybeEnd) {
+ state.tokenize.pop();
+ break;
+ }
+ maybeEnd = (ch == "*");
+ }
+ return "comment";
+ }
+
+ function expectExpression(last) {
+ return !last || last == "operator" || last == "->" || /[\.\[\{\(,;:]/.test(last) ||
+ last == "newstatement" || last == "keyword" || last == "proplabel";
+ }
+
+ function Context(indented, column, type, align, prev) {
+ this.indented = indented;
+ this.column = column;
+ this.type = type;
+ this.align = align;
+ this.prev = prev;
+ }
+
+ function pushContext(state, col, type) {
+ return state.context = new Context(state.indented, col, type, null, state.context);
+ }
+
+ function popContext(state) {
+ var t = state.context.type;
+ if (t == ")" || t == "]" || t == "}")
+ state.indented = state.context.indented;
+ return state.context = state.context.prev;
+ }
+
+ // Interface
+
+ return {
+ startState: function (basecolumn) {
+ return {
+ tokenize: [tokenBase],
+ context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false),
+ indented: 0,
+ startOfLine: true,
+ lastToken: null
+ };
+ },
+
+ token: function (stream, state) {
+ var ctx = state.context;
+ if (stream.sol()) {
+ if (ctx.align == null) ctx.align = false;
+ state.indented = stream.indentation();
+ state.startOfLine = true;
+ // Automatic semicolon insertion
+ if (ctx.type == "statement" && !expectExpression(state.lastToken)) {
+ popContext(state);
+ ctx = state.context;
+ }
+ }
+ if (stream.eatSpace()) return null;
+ curPunc = null;
+ var style = state.tokenize[state.tokenize.length - 1](stream, state);
+ if (style == "comment") return style;
+ if (ctx.align == null) ctx.align = true;
+ if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
+ // Handle indentation for {x -> \n ... }
+ else if (curPunc == "->" && ctx.type == "statement" && ctx.prev.type == "}") {
+ popContext(state);
+ state.context.align = false;
+ }
+ else if (curPunc == "{") pushContext(state, stream.column(), "}");
+ else if (curPunc == "[") pushContext(state, stream.column(), "]");
+ else if (curPunc == "(") pushContext(state, stream.column(), ")");
+ else if (curPunc == "}") {
+ while (ctx.type == "statement") ctx = popContext(state);
+ if (ctx.type == "}") ctx = popContext(state);
+ while (ctx.type == "statement") ctx = popContext(state);
+ }
+ else if (curPunc == ctx.type) popContext(state);
+ else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
+ pushContext(state, stream.column(), "statement");
+ state.startOfLine = false;
+ state.lastToken = curPunc || style;
+ return style;
+ },
+
+ indent: function (state, textAfter) {
+ if (!state.tokenize[state.tokenize.length - 1].isBase) return 0;
+ var firstChar = textAfter && textAfter.charAt(0), ctx = state.context;
+ if (ctx.type == "statement" && !expectExpression(state.lastToken)) ctx = ctx.prev;
+ var closing = firstChar == ctx.type;
+ if (ctx.type == "statement") {
+ return ctx.indented + (firstChar == "{" ? 0 : config.indentUnit);
+ }
+ else if (ctx.align) return ctx.column + (closing ? 0 : 1);
+ else return ctx.indented + (closing ? 0 : config.indentUnit);
+ },
+
+ closeBrackets: {triples: "'\""},
+ electricChars: "{}"
+ };
+});
+
+CodeMirror.defineMIME("text/x-kotlin", "kotlin");
+
+});