From 0b5d78736fd535bb6ed0bea0bb2815ea9a7639cd Mon Sep 17 00:00:00 2001 From: Breck Date: Mon, 9 Sep 2013 11:46:03 -0700 Subject: [PATCH] Rebased on latest Ace. Added Coffee Fold Mode --- demo/kitchen-sink/doclist.js | 1 + demo/kitchen-sink/docs/space.space | 56 +++++++++++++++++++++++++++ lib/ace/ext/modelist.js | 1 + lib/ace/mode/space.js | 42 ++++++++++++++++++++ lib/ace/mode/space_highlight_rules.js | 56 +++++++++++++++++++++++++++ 5 files changed, 156 insertions(+) create mode 100644 demo/kitchen-sink/docs/space.space create mode 100644 lib/ace/mode/space.js create mode 100644 lib/ace/mode/space_highlight_rules.js diff --git a/demo/kitchen-sink/doclist.js b/demo/kitchen-sink/doclist.js index a5f92fd4..81e06cd7 100644 --- a/demo/kitchen-sink/doclist.js +++ b/demo/kitchen-sink/doclist.js @@ -125,6 +125,7 @@ var docs = { "docs/scss.scss": "SCSS", "docs/sass.sass": "SASS", "docs/sh.sh": "SH", + "docs/space.space": "Space", "docs/stylus.styl": "Stylus", "docs/sql.sql": {name: "SQL", wrapped: true}, "docs/svg.svg": "SVG", diff --git a/demo/kitchen-sink/docs/space.space b/demo/kitchen-sink/docs/space.space new file mode 100644 index 00000000..7bd8ab19 --- /dev/null +++ b/demo/kitchen-sink/docs/space.space @@ -0,0 +1,56 @@ +query + count 10 + created 2011-06-21T08:10:46Z + lang en-US + results + photo + 0 + farm 6 + id 5855620975 + isfamily 0 + isfriend 0 + ispublic 1 + owner 32021554@N04 + secret f1f5e8515d + server 5110 + title 7087 bandit cat + 1 + farm 4 + id 5856170534 + isfamily 0 + isfriend 0 + ispublic 1 + owner 32021554@N04 + secret ff1efb2a6f + server 3217 + title 6975 rusty cat + 2 + farm 6 + id 5856172972 + isfamily 0 + isfriend 0 + ispublic 1 + owner 51249875@N03 + secret 6c6887347c + server 5192 + title watermarked-cats + 3 + farm 6 + id 5856168328 + isfamily 0 + isfriend 0 + ispublic 1 + owner 32021554@N04 + secret 0c1cfdf64c + server 5078 + title 7020 mandy cat + 4 + farm 3 + id 5856171774 + isfamily 0 + isfriend 0 + ispublic 1 + owner 32021554@N04 + secret 7f5a3180ab + server 2696 + title 7448 bobby cat diff --git a/lib/ace/ext/modelist.js b/lib/ace/ext/modelist.js index 5e6551ba..ab8f7569 100644 --- a/lib/ace/ext/modelist.js +++ b/lib/ace/ext/modelist.js @@ -120,6 +120,7 @@ var supportedModes = { Scheme: ["scm|rkt"], SCSS: ["scss"], SH: ["sh|bash"], + Space: ["space"], snippets: ["snippets"], SQL: ["sql"], Stylus: ["styl|stylus"], diff --git a/lib/ace/mode/space.js b/lib/ace/mode/space.js new file mode 100644 index 00000000..0905592b --- /dev/null +++ b/lib/ace/mode/space.js @@ -0,0 +1,42 @@ +define(function(require, exports, module) { +"use strict"; +var oop = require("../lib/oop"); +// defines the parent mode +var TextMode = require("./text").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var FoldMode = require("./folding/coffee").FoldMode; +// defines the language specific highlighters and folding rules +var SpaceHighlightRules = require("./space_highlight_rules").SpaceHighlightRules; +var Mode = function() { + // set everything up + var highlighter = new SpaceHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.foldingRules = new FoldMode(); +}; +oop.inherits(Mode, TextMode); +(function() { + + // todo: code folding, multiline value support. + + + // Extra logic goes here--we won't be covering all of this + /* These are all optional pieces of code! + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + return indent; + }; + this.checkOutdent = function(state, line, input) { + return this.$outdent.checkOutdent(line, input); + }; + this.autoOutdent = function(state, doc, row) { + this.$outdent.autoOutdent(doc, row); + }; + this.createWorker = function(session) { + var worker = new WorkerClient(["ace"], "ace/mode/mynew_worker", "NewWorker"); + worker.attachToDocument(session.getDocument()); + return worker; + }; + */ +}).call(Mode.prototype); +exports.Mode = Mode; +}); diff --git a/lib/ace/mode/space_highlight_rules.js b/lib/ace/mode/space_highlight_rules.js new file mode 100644 index 00000000..4a347b19 --- /dev/null +++ b/lib/ace/mode/space_highlight_rules.js @@ -0,0 +1,56 @@ +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var SpaceHighlightRules = function() { + + // Todo: support multiline values that escape the newline with spaces. + this.$rules = { + "start" : [ + { + token : "empty_line", + regex : / */, + next : "key" + }, + { + token : "empty_line", + regex : /$/, + next : "key" + } + ], + "key" : [ + { + token : "variable", + regex : /\S+/ + }, + { + token : "empty_line", + regex : /$/, + next : "start" + },{ + token : "keyword.operator", + regex : / /, + next : "value" + } + ], + "value" : [ + { + token : "keyword.operator", + regex : /$/, + next : "start" + }, + { + token : "string", + regex : /[^$]/ + } + ] + }; + +}; + +oop.inherits(SpaceHighlightRules, TextHighlightRules); + +exports.SpaceHighlightRules = SpaceHighlightRules; +});