diff --git a/.gitignore b/.gitignore index 45220054..a589a0c9 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ node_modules/mime/ node_modules/dryice/ node_modules/uglify-js/ node_modules/.bin/ - +tool/node_modules/ .git-ref npm-debug.log diff --git a/Makefile.dryice.js b/Makefile.dryice.js index aed33736..0ae45a18 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -218,9 +218,9 @@ function buildAce(aceProject, options) { compat: true, modes: [ "css", "html", "javascript", "php", "coldfusion", "python", "lua", "xml", "ruby", "java", "c_cpp", - "coffee", "perl", "csharp", "haxe", "svg", "clojure", "scss", "json", "groovy", + "coffee", "perl", "csharp", "haxe", "liquid", "svg", "clojure", "scss", "json", "groovy", "ocaml", "scala", "textile", "scad", "markdown", "latex", "powershell", "sql", - "text", "pgsql", "sh" + "text", "pgsql", "sh", "xquery" ], themes: [ "chrome", "clouds", "clouds_midnight", "cobalt", "crimson_editor", "dawn", diff --git a/build/demo/kitchen-sink/kitchen-sink-uncompressed.js b/build/demo/kitchen-sink/kitchen-sink-uncompressed.js index c3d6d0b9..0f1e6383 100644 --- a/build/demo/kitchen-sink/kitchen-sink-uncompressed.js +++ b/build/demo/kitchen-sink/kitchen-sink-uncompressed.js @@ -244,7 +244,7 @@ exportAce(ACE_NAMESPACE); * ***** END LICENSE BLOCK ***** */ -define('kitchen-sink/demo', ['require', 'exports', 'module' , 'ace/lib/fixoldbrowsers', 'ace/config', 'ace/lib/event', 'ace/theme/textmate', 'ace/edit_session', 'ace/undomanager', 'ace/keyboard/keybinding/vim', 'ace/keyboard/keybinding/emacs', 'ace/keyboard/hash_handler', 'text!kitchen-sink/docs/plaintext.txt', 'text!kitchen-sink/docs/javascript.js', 'text!kitchen-sink/docs/coffeescript.coffee', 'text!kitchen-sink/docs/json.json', 'text!kitchen-sink/docs/css.css', 'text!kitchen-sink/docs/scss.scss', 'text!kitchen-sink/docs/html.html', 'text!kitchen-sink/docs/xml.xml', 'text!kitchen-sink/docs/svg.svg', 'text!kitchen-sink/docs/php.php', 'text!kitchen-sink/docs/coldfusion.cfm', 'text!kitchen-sink/docs/python.py', 'text!kitchen-sink/docs/ruby.rb', 'text!kitchen-sink/docs/perl.pl', 'text!kitchen-sink/docs/ocaml.ml', 'text!kitchen-sink/docs/lua.lua', 'text!kitchen-sink/docs/java.java', 'text!kitchen-sink/docs/clojure.clj', 'text!kitchen-sink/docs/groovy.groovy', 'text!kitchen-sink/docs/scala.scala', 'text!kitchen-sink/docs/csharp.cs', 'text!kitchen-sink/docs/powershell.ps1', 'text!kitchen-sink/docs/cpp.cpp', 'text!kitchen-sink/docs/Haxe.hx', 'text!kitchen-sink/docs/sh.sh', 'text!kitchen-sink/docs/markdown.md', 'text!kitchen-sink/docs/textile.textile', 'text!kitchen-sink/docs/latex.tex', 'text!kitchen-sink/docs/sql.sql', 'text!kitchen-sink/docs/pgsql.pgsql', 'ace/split'], function(require, exports, module) { +define('kitchen-sink/demo', ['require', 'exports', 'module' , 'ace/lib/fixoldbrowsers', 'ace/config', 'ace/lib/event', 'ace/theme/textmate', 'ace/edit_session', 'ace/undomanager', 'ace/keyboard/keybinding/vim', 'ace/keyboard/keybinding/emacs', 'ace/keyboard/hash_handler', 'text!kitchen-sink/docs/plaintext.txt', 'text!kitchen-sink/docs/javascript.js', 'text!kitchen-sink/docs/coffeescript.coffee', 'text!kitchen-sink/docs/json.json', 'text!kitchen-sink/docs/css.css', 'text!kitchen-sink/docs/scss.scss', 'text!kitchen-sink/docs/html.html', 'text!kitchen-sink/docs/xml.xml', 'text!kitchen-sink/docs/svg.svg', 'text!kitchen-sink/docs/php.php', 'text!kitchen-sink/docs/coldfusion.cfm', 'text!kitchen-sink/docs/python.py', 'text!kitchen-sink/docs/ruby.rb', 'text!kitchen-sink/docs/perl.pl', 'text!kitchen-sink/docs/ocaml.ml', 'text!kitchen-sink/docs/lua.lua', 'text!kitchen-sink/docs/liquid.liquid', 'text!kitchen-sink/docs/java.java', 'text!kitchen-sink/docs/clojure.clj', 'text!kitchen-sink/docs/groovy.groovy', 'text!kitchen-sink/docs/scala.scala', 'text!kitchen-sink/docs/csharp.cs', 'text!kitchen-sink/docs/powershell.ps1', 'text!kitchen-sink/docs/cpp.cpp', 'text!kitchen-sink/docs/Haxe.hx', 'text!kitchen-sink/docs/sh.sh', 'text!kitchen-sink/docs/xquery.xq', 'text!kitchen-sink/docs/markdown.md', 'text!kitchen-sink/docs/textile.textile', 'text!kitchen-sink/docs/latex.tex', 'text!kitchen-sink/docs/sql.sql', 'text!kitchen-sink/docs/pgsql.pgsql', 'ace/split'], function(require, exports, module) { require("ace/lib/fixoldbrowsers"); require("ace/config").init(); @@ -266,7 +266,6 @@ var Doc = function(name, desc, file) { this.name = name; this.desc = desc; this.doc = new EditSession(file); - this.doc.setMode(modesByName[name].mode); this.doc.modeName = name; this.doc.setUndoManager(new UndoManager()); }; @@ -304,6 +303,7 @@ var modes = [ new Mode("json", "JSON", ["json"]), new Mode("latex", "LaTeX", ["tex"]), new Mode("lua", "Lua", ["lua"]), + new Mode("liquid", "Liquid", ["liquid"]), new Mode("markdown", "Markdown", ["md", "markdown"]), new Mode("ocaml", "OCaml", ["ml", "mli"]), new Mode("perl", "Perl", ["pl", "pm"]), @@ -319,7 +319,8 @@ var modes = [ new Mode("text", "Text", ["txt"]), new Mode("textile", "Textile", ["textile"]), new Mode("xml", "XML", ["xml"]), - new Mode("sh", "SH", ["sh"]) + new Mode("sh", "SH", ["sh"]), + new Mode("xquery", "XQuery", ["xq"]) ]; modesByName = {}; @@ -394,6 +395,10 @@ var docs = [ "lua", "Lua", require("text!./docs/lua.lua") ), + new Doc( + "liquid", "Liquid", + require("text!./docs/liquid.liquid") + ), new Doc( "java", "Java", require("text!./docs/java.java") @@ -430,6 +435,10 @@ var docs = [ "sh", "SH", require("text!./docs/sh.sh") ), + new Doc( + "xquery", "XQuery", + require("text!./docs/xquery.xq") + ), new WrappedDoc( "markdown", "Markdown", require("text!./docs/markdown.md") @@ -517,6 +526,12 @@ modes.forEach(function(mode) { bindDropdown("doc", function(value) { var doc = docsByName[value].doc; + + if (!docsByName[value].initialized) { + docsByName[value].initialized = true; + doc.setMode(modesByName[docsByName[value].name].mode); + } + var session = env.split.setSession(doc); session.name = doc.name; @@ -3853,6 +3868,10 @@ var EditSession = function(text, mode) { return callback(_self.$modes[mode]); _self.$modes[mode] = new module.Mode(); + _self._emit("loadmode", { + name: mode, + mode: _self.$modes[mode] + }); callback(_self.$modes[mode]); } @@ -6393,23 +6412,30 @@ var Tokenizer = function(rules, flag) { var ruleRegExps = []; var matchTotal = 0; var mapping = this.matchMappings[key] = {}; - + for ( var i = 0; i < state.length; i++) { + + if (state[i].regex instanceof RegExp) + state[i].regex = state[i].regex.toString().slice(1, -1); + // Count number of matching groups. 2 extra groups from the full match // And the catch-all on the end (used to force a match); var matchcount = new RegExp("(?:(" + state[i].regex + ")|(.))").exec("a").length - 2; - + // Replace any backreferences and offset appropriately. var adjustedregex = state[i].regex.replace(/\\([0-9]+)/g, function (match, digit) { return "\\" + (parseInt(digit, 10) + matchTotal + 1); }); - + + if (matchcount > 1 && state[i].token.length !== matchcount-1) + throw new Error("Matching groups and length of the token array don't match in rule #" + i + " of state " + key); + mapping[matchTotal] = { rule: i, len: matchcount }; matchTotal += matchcount; - + ruleRegExps.push(adjustedregex); } @@ -6425,47 +6451,47 @@ var Tokenizer = function(rules, flag) { var mapping = this.matchMappings[currentState]; var re = this.regExps[currentState]; re.lastIndex = 0; - + var match, tokens = []; - + var lastIndex = 0; - + var token = { type: null, value: "" }; - + while (match = re.exec(line)) { var type = "text"; var rule = null; var value = [match[0]]; for (var i = 0; i < match.length-2; i++) { - if (match[i + 1] !== undefined) { - rule = state[mapping[i].rule]; - - if (mapping[i].len > 1) { - value = match.slice(i+2, i+1+mapping[i].len); - } - - // compute token type - if (typeof rule.token == "function") - type = rule.token.apply(this, value); - else - type = rule.token; + if (match[i + 1] === undefined) + continue; - var next = rule.next; - if (next && next !== currentState) { - currentState = next; - state = this.rules[currentState]; - mapping = this.matchMappings[currentState]; - lastIndex = re.lastIndex; + rule = state[mapping[i].rule]; - re = this.regExps[currentState]; - re.lastIndex = lastIndex; - } - break; + if (mapping[i].len > 1) + value = match.slice(i+2, i+1+mapping[i].len); + + // compute token type + if (typeof rule.token == "function") + type = rule.token.apply(this, value); + else + type = rule.token; + + var next = rule.next; + if (next && next !== currentState) { + currentState = next; + state = this.rules[currentState]; + mapping = this.matchMappings[currentState]; + lastIndex = re.lastIndex; + + re = this.regExps[currentState]; + re.lastIndex = lastIndex; } + break; } if (value[0]) { @@ -6474,13 +6500,15 @@ var Tokenizer = function(rules, flag) { type = [type]; } for (var i = 0; i < value.length; i++) { + if (!value[i]) + continue; + if ((!rule || rule.merge || type[i] === "text") && token.type === type[i]) { token.value += value[i]; } else { - if (token.type) { + if (token.type) tokens.push(token); - } - + token = { type: type[i], value: value[i] @@ -6488,10 +6516,10 @@ var Tokenizer = function(rules, flag) { } } } - + if (lastIndex == line.length) break; - + lastIndex = re.lastIndex; } @@ -7002,6 +7030,7 @@ var Document = function(text) { position = this.$clipPosition(position); + // only detect new lines if the document has no line break yet if (this.getLength() <= 1) this.$detectNewLine(text); @@ -10258,6 +10287,84 @@ define("text!kitchen-sink/docs/lua.lua", [], "--[[--\n" + "print(table.maxn{1,2,[4]=4,[8]=8) -- outputs 8 instead of 2\n" + ""); +define("text!kitchen-sink/docs/liquid.liquid", [], "The following examples can be found in full at http://liquidmarkup.org/\n" + + "\n" + + "Liquid is an extraction from the e-commerce system Shopify.\n" + + "Shopify powers many thousands of e-commerce stores which all call for unique designs.\n" + + "For this we developed Liquid which allows our customers complete design freedom while\n" + + "maintaining the integrity of our servers.\n" + + "\n" + + "Liquid has been in production use since June 2006 and is now used by many other\n" + + "hosted web applications.\n" + + "\n" + + "It was developed for usage in Ruby on Rails web applications and integrates seamlessly\n" + + "as a plugin but it also works excellently as a stand alone library.\n" + + "\n" + + "Here's what it looks like:\n" + + "\n" + + " \n" + + "\n" + + "\n" + + "Some more features include:\n" + + "\n" + + "

Filters

\n" + + "

The word \"tobi\" in uppercase: {{ 'tobi' | upcase }}

\n" + + "

The word \"tobi\" has {{ 'tobi' | size }} letters!

\n" + + "

Change \"Hello world\" to \"Hi world\": {{ 'Hello world' | replace: 'Hello', 'Hi' }}

\n" + + "

The date today is {{ 'now' | date: \"%Y %b %d\" }}

\n" + + "\n" + + "\n" + + "

If

\n" + + "

\n" + + " {% if user.name == 'tobi' or user.name == 'marc' %} \n" + + " hi marc or tobi\n" + + " {% endif %}\n" + + "

\n" + + "\n" + + "\n" + + "

Case

\n" + + "

\n" + + " {% case template %}\n" + + " {% when 'index' %}\n" + + " Welcome\n" + + " {% when 'product' %}\n" + + " {{ product.vendor | link_to_vendor }} / {{ product.title }}\n" + + " {% else %}\n" + + " {{ page_title }}\n" + + " {% endcase %}\n" + + "

\n" + + "\n" + + "\n" + + "

For Loops

\n" + + "

\n" + + " {% for item in array %} \n" + + " {{ item }}\n" + + " {% endfor %}\n" + + "

\n" + + "\n" + + "\n" + + "

Tables

\n" + + "

\n" + + " {% tablerow item in items cols: 3 %}\n" + + " {% if tablerowloop.col_first %}\n" + + " First column: {{ item.variable }}\n" + + " {% else %}\n" + + " Different column: {{ item.variable }}\n" + + " {% endif %}\n" + + " {% endtablerow %}\n" + + "

\n" + + ""); + define("text!kitchen-sink/docs/java.java", [], "public class InfiniteLoop {\n" + "\n" + " /*\n" + @@ -10509,6 +10616,14 @@ define("text!kitchen-sink/docs/sh.sh", [], "#!/bin/sh\n" + "fi\n" + ""); +define("text!kitchen-sink/docs/xquery.xq", [], "xquery version \"1.0\";\n" + + "\n" + + "let $message := \"Hello World!\"\n" + + "return \n" + + " {$message}\n" + + "\n" + + ""); + define("text!kitchen-sink/docs/markdown.md", [], "Ace (Ajax.org Cloud9 Editor)\n" + "============================\n" + "\n" + @@ -11218,7 +11333,7 @@ var Editor = function(renderer, session) { var container = renderer.getContainerElement(); this.container = container; this.renderer = renderer; - + this.textInput = new TextInput(renderer.getTextAreaContainer(), this); this.keyBinding = new KeyBinding(this); @@ -11472,7 +11587,11 @@ var Editor = function(renderer, session) { this.renderer.updateCursor(); if (!this.$blockScrolling) { - this.renderer.scrollCursorIntoView(); + var selection = this.getSelection(); + if (selection.isEmpty()) + this.renderer.scrollCursorIntoView(selection.getCursor()); + else + this.renderer.scrollSelectionIntoView(selection.getSelectionLead(), selection.getSelectionAnchor()); } // move text input over the cursor @@ -11816,7 +11935,7 @@ var Editor = function(renderer, session) { this.$showFoldWidgets = show; this.renderer.updateFull(); }; - + this.getShowFoldWidgets = function() { return this.renderer.$gutterLayer.getShowFoldWidgets(); }; @@ -12033,7 +12152,7 @@ var Editor = function(renderer, session) { range.start.row += linesMoved; range.end.row += linesMoved; selection.setSelectionRange(range, reverse); - } + } else { selection.setSelectionAnchor(rows.last+linesMoved+1, 0); selection.$moveSelection(function() { @@ -12197,13 +12316,13 @@ var Editor = function(renderer, session) { cursor.column -= 2; pos = this.session.findMatchingBracket(cursor); } - + if (pos) { this.clearSelection(); this.moveCursorTo(pos.row, pos.column); } }; - + this.gotoLine = function(lineNumber, column) { this.selection.clearSelection(); this.session.unfold({row: lineNumber - 1, column: column || 0}); @@ -13928,13 +14047,13 @@ exports.commands = [{ }, { name: "backspace", bindKey: bindKey( - "Ctrl-Backspace|Command-Backspace|Option-Backspace|Shift-Backspace|Backspace", + "Command-Backspace|Option-Backspace|Shift-Backspace|Backspace", "Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H" ), exec: function(editor) { editor.remove("left"); } }, { name: "removetolinestart", - bindKey: bindKey("Alt-Backspace", "Option-Backspace"), + bindKey: bindKey("Alt-Backspace", "Command-Backspace"), exec: function(editor) { editor.removeToLineStart(); } }, { name: "removetolineend", @@ -14419,7 +14538,7 @@ var CommandManager = function(platform, commands) { var key = typeof binding == "string" ? binding: binding[this.platform]; this.bindKey(key, command); - } + }; function parseKeys(keys, val, ret) { var key; @@ -14436,10 +14555,10 @@ var CommandManager = function(platform, commands) { return { key: key, hashId: hashId - } + }; } - function splitSafe(s, separator) { + function splitSafe(s) { return (s.toLowerCase() .trim() .split(new RegExp("[\\s ]*\\-[\\s ]*", "g"), 999)); @@ -14453,7 +14572,7 @@ var CommandManager = function(platform, commands) { var ckbr = this.commmandKeyBinding; return ckbr[hashId] && ckbr[hashId][textOrKey.toLowerCase()]; - } + }; this.exec = function(command, editor, args) { if (typeof command === 'string') @@ -14505,7 +14624,7 @@ var CommandManager = function(platform, commands) { this.exec(x, editor); else this.exec(x[0], editor, x[1]); - }, this) + }, this); } finally { this.$inReplay = false; } @@ -14517,9 +14636,9 @@ var CommandManager = function(platform, commands) { x[0] = x[0].name; if (!x[1]) x = x[0]; - return x - }) - } + return x; + }); + }; }).call(CommandManager.prototype); @@ -14588,13 +14707,13 @@ dom.importCssString(editorCss, "ace_editor"); var VirtualRenderer = function(container, theme) { var _self = this; - + this.container = container; // TODO: this breaks rendering in Cloud9 with multiple ace instances // // Imports CSS once per DOM document ('ace_editor' serves as an identifier). // dom.importCssString(editorCss, "ace_editor", container.ownerDocument); - + dom.addCssClass(container, "ace_editor"); this.setTheme(theme); @@ -14612,8 +14731,8 @@ var VirtualRenderer = function(container, theme) { this.scroller.appendChild(this.content); this.$gutterLayer = new GutterLayer(this.$gutter); - this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true)); - + this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true)); + this.$markerBack = new MarkerLayer(this.content); var textLayer = this.$textLayer = new TextLayer(this.content); @@ -14640,7 +14759,7 @@ var VirtualRenderer = function(container, theme) { this.scrollTop = 0; this.scrollLeft = 0; - + event.addListener(this.scroller, "scroll", function() { var scrollLeft = _self.scroller.scrollLeft; _self.scrollLeft = scrollLeft; @@ -14890,7 +15009,7 @@ var VirtualRenderer = function(container, theme) { // this persists in IE9 if (useragent.isIE) return; - + if (this.layerConfig.lastRow === 0) return; @@ -14966,13 +15085,13 @@ var VirtualRenderer = function(container, theme) { // horizontal scrolling if (changes & this.CHANGE_H_SCROLL) { this.scroller.scrollLeft = this.scrollLeft; - + // read the value after writing it since the value might get clipped var scrollLeft = this.scroller.scrollLeft; this.scrollLeft = scrollLeft; this.session.setScrollLeft(scrollLeft); } - + // full if (changes & this.CHANGE_FULL) { this.$textLayer.checkForSizeChanges(); @@ -15185,12 +15304,18 @@ var VirtualRenderer = function(container, theme) { this.$cursorLayer.showCursor(); }; - this.scrollCursorIntoView = function() { + this.scrollSelectionIntoView = function(anchor, lead) { + // first scroll anchor into view then scroll lead into view + this.scrollCursorIntoView(anchor); + this.scrollCursorIntoView(lead); + }; + + this.scrollCursorIntoView = function(cursor) { // the editor is not visible if (this.$size.scrollerHeight === 0) return; - var pos = this.$cursorLayer.getPixelPosition(); + var pos = this.$cursorLayer.getPixelPosition(cursor); var left = pos.left; var top = pos.top; @@ -15379,7 +15504,7 @@ var VirtualRenderer = function(container, theme) { this._loadTheme = function(name, callback) { if (!config.get("packaged")) return callback(); - + var base = name.split("/").pop(); var filename = config.get("themePath") + "/theme-" + base + config.get("suffix"); net.loadScript(filename, callback); @@ -15391,14 +15516,14 @@ var VirtualRenderer = function(container, theme) { this.$themeValue = theme; if (!theme || typeof theme == "string") { var moduleName = theme || "ace/theme/textmate"; - + var module; try { module = require(moduleName); } catch (e) {}; if (module) return afterLoad(module); - + _self._loadTheme(moduleName, function() { require([theme], function(module) { if (_self.$themeValue !== theme) diff --git a/build/demo/kitchen-sink/mode-c_cpp-uncompressed.js b/build/demo/kitchen-sink/mode-c_cpp-uncompressed.js index d01f082c..abd3190b 100644 --- a/build/demo/kitchen-sink/mode-c_cpp-uncompressed.js +++ b/build/demo/kitchen-sink/mode-c_cpp-uncompressed.js @@ -541,12 +541,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -558,7 +558,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -576,7 +576,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -601,12 +601,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -618,7 +618,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -637,14 +637,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -665,7 +666,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -674,19 +675,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -695,7 +696,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -705,7 +706,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-clojure-uncompressed.js b/build/demo/kitchen-sink/mode-clojure-uncompressed.js index 1980ac6a..cb008131 100644 --- a/build/demo/kitchen-sink/mode-clojure-uncompressed.js +++ b/build/demo/kitchen-sink/mode-clojure-uncompressed.js @@ -259,9 +259,9 @@ var ClojureHighlightRules = function() { token : "comment", regex : ";.*$" }, { - token : "comment", // multi line comment - regex : "^\=begin$", - next : "comment" + token : "comment", // multi line comment + regex : "^=begin$", + next : "comment" }, { token : "keyword", //parens regex : "[\\(|\\)]" @@ -314,17 +314,17 @@ var ClojureHighlightRules = function() { regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' }, { token : "string", // symbol - regex : "[:](?:[a-zA-Z]|\d)+" + regex : "[:](?:[a-zA-Z]|\\d)+" }, { - token : "string.regexp", //Regular Expressions - regex : '/#"(?:\.|(\\\")|[^\""\n])*"/g' + token : "string.regexp", //Regular Expressions + regex : '/#"(?:\\.|(?:\\\")|[^\""\n])*"/g' } - + ], "comment" : [ { token : "comment", // closing comment - regex : "^\=end$", + regex : "^=end$", next : "start" }, { token : "comment", // comment spanning whole line diff --git a/build/demo/kitchen-sink/mode-coldfusion-uncompressed.js b/build/demo/kitchen-sink/mode-coldfusion-uncompressed.js index ae110840..b8f08b00 100644 --- a/build/demo/kitchen-sink/mode-coldfusion-uncompressed.js +++ b/build/demo/kitchen-sink/mode-coldfusion-uncompressed.js @@ -528,12 +528,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -545,7 +545,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -563,7 +563,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -588,12 +588,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -605,7 +605,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -624,14 +624,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -652,7 +653,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -661,19 +662,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -682,7 +683,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -692,7 +693,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; @@ -1329,20 +1331,20 @@ var JavaScriptHighlightRules = function() { ); // TODO: Unicode escape sequences - var identifierRe = "[" + unicode.packages.L + "\\$_][" + var identifierRe = "[" + unicode.packages.L + "\\$_][" + unicode.packages.L + unicode.packages.Mn + unicode.packages.Mc + unicode.packages.Nd + unicode.packages.Pc + "\\$_]*\\b"; - + var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex "u[0-9a-fA-F]{4}|" + // unicode "[0-2][0-7]{0,2}|" + // oct "3[0-6][0-7]?|" + // oct - "37[0-7]?|" + // oct + "37[0-7]?|" + // oct "[4-7][0-7]?|" + //oct ".)"; - + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -1350,13 +1352,13 @@ var JavaScriptHighlightRules = function() { "start" : [ { token : "comment", - regex : "\\/\\/.*$" + regex : /\/\/.*$/ }, new DocCommentHighlightRules().getStartRule("doc-start"), { token : "comment", // multi line comment merge : true, - regex : "\\/\\*", + regex : /\/\*/, next : "comment" }, { token : "string", @@ -1368,33 +1370,121 @@ var JavaScriptHighlightRules = function() { next : "qqstring" }, { token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" + regex : /0[xX][0-9a-fA-F]+\b/ }, { token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : ["storage.type", "text", "entity.name.function", "text", "paren.lparen", "variable.parameter", "paren.rparen"], + regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { // match stuff like: Sound.prototype.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: Sound.prototype.play = myfunc + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)" + }, { // match stuff like: Sound.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: play = function() { } + token : [ + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match regular function like: function myFunc(arg) { } + token : [ + "storage.type", + "text", + "entity.name.function", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: foobar: function() { } + token : [ + "entity.name.function", + "text", + "punctuation.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // Attempt to match : function() { } (this is for issues with 'foo': function() { }) + token : [ + "text", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(:)(\\s*)(function)?(\\s*)(\\()([^)]*)(\\))" }, { token : "constant.language.boolean", - regex : "(?:true|false)\\b" + regex : /(?:true|false)\b/ }, { token : "keyword", regex : "(?:" + kwBeforeRe + ")\\b", next : "regex_allowed" }, { token : "support.function", - regex : "\\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\\b(?=\\()" + regex : /\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ }, { token : "support.function.dom", - regex : "\\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\\b(?=\\()" + regex : /\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ }, { - token : "support.function.constant", - regex : "\\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\\b" + token : "support.constant", + regex : /\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/ }, { - token : ["punctuation.operator", "support.function.firebug"], - regex : "(\\.)(warn|info|log|error|time|timeEnd|assert)\\b" - + token : ["storage.type", "punctuation.operator", "support.function.firebug"], + regex : /\b(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/ }, { token : function(value) { if (globals.hasOwnProperty(value)) @@ -1417,29 +1507,29 @@ var JavaScriptHighlightRules = function() { regex : identifierRe }, { token : "keyword.operator", - regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)", + regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/, next : "regex_allowed" }, { token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\;|\\.", + regex : /\?|\:|\,|\;|\./, next : "regex_allowed" }, { token : "paren.lparen", - regex : "[[({]", + regex : /[\[({]/, next : "regex_allowed" }, { token : "paren.rparen", - regex : "[\\])}]" + regex : /[\])}]/ }, { token : "keyword.operator", - regex : "\\/=?", + regex : /\/=?/, next : "regex_allowed" }, { token: "comment", - regex: "^#!.*$" + regex: /^#!.*$/ }, { token : "text", - regex : "\\s+" + regex : /\s+/ } ], // regular expressions are only allowed after certain tokens. This @@ -1464,7 +1554,7 @@ var JavaScriptHighlightRules = function() { }, { // immediately return to the start mode without matching // anything - token: "empty", + token: "empty", regex: "", next: "start" } @@ -1476,10 +1566,10 @@ var JavaScriptHighlightRules = function() { next: "regex" }, { // flag - token: "string.regexp", + token: "string.regexp", regex: "/\\w*", next: "start", - merge: true + merge: true }, { token: "string.regexp", regex: "[^\\\\/\\[]+", @@ -1491,9 +1581,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "regex_character_class": [ @@ -1512,9 +1602,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "comment_regex_allowed" : [ @@ -1568,7 +1658,7 @@ var JavaScriptHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ new DocCommentHighlightRules().getEndRule("start") ]); }; @@ -2231,11 +2321,17 @@ var CssHighlightRules = function() { "purple|red|silver|teal|white|yellow").split("|") ); + var fonts = lang.arrayToMap( + ("arial|century|comic|courier|garamond|georgia|helvetica|impact|lucida|" + + "symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|" + + "serif|monospace").split("|") + ); + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))"; - + var base_ruleset = [ { token : "comment", // multi line comment @@ -2249,8 +2345,11 @@ var CssHighlightRules = function() { token : "string", // single line regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" }, { - token : "constant.numeric", - regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)" + token : ["constant.numeric", "keyword"], + regex : "(" + numRe + ")(em|ex|px|ch|cm|mm|in|pt|pc|deg|rad|dpi|grad|ms|s|hz|khz|%)" + }, { + token : ["constant.numeric"], + regex : "([0-9]+)" }, { token : "constant.numeric", // hex6 color regex : "#[a-f0-9]{6}" @@ -2271,12 +2370,15 @@ var CssHighlightRules = function() { else if (colors.hasOwnProperty(value.toLowerCase())) { return "support.constant.color"; } + else if (fonts.hasOwnProperty(value.toLowerCase())) { + return "support.constant.fonts"; + } else { return "text"; } }, regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*" - } + } ]; var ruleset = lang.copyArray(base_ruleset); diff --git a/build/demo/kitchen-sink/mode-csharp-uncompressed.js b/build/demo/kitchen-sink/mode-csharp-uncompressed.js index 018b34e2..3e83d27d 100644 --- a/build/demo/kitchen-sink/mode-csharp-uncompressed.js +++ b/build/demo/kitchen-sink/mode-csharp-uncompressed.js @@ -391,12 +391,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -408,7 +408,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -426,7 +426,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -451,12 +451,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -468,7 +468,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -487,14 +487,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -515,7 +516,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -524,19 +525,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -545,7 +546,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -555,7 +556,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-css-uncompressed.js b/build/demo/kitchen-sink/mode-css-uncompressed.js index 9d8f5f26..121969b3 100644 --- a/build/demo/kitchen-sink/mode-css-uncompressed.js +++ b/build/demo/kitchen-sink/mode-css-uncompressed.js @@ -215,11 +215,17 @@ var CssHighlightRules = function() { "purple|red|silver|teal|white|yellow").split("|") ); + var fonts = lang.arrayToMap( + ("arial|century|comic|courier|garamond|georgia|helvetica|impact|lucida|" + + "symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|" + + "serif|monospace").split("|") + ); + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))"; - + var base_ruleset = [ { token : "comment", // multi line comment @@ -233,8 +239,11 @@ var CssHighlightRules = function() { token : "string", // single line regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" }, { - token : "constant.numeric", - regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)" + token : ["constant.numeric", "keyword"], + regex : "(" + numRe + ")(em|ex|px|ch|cm|mm|in|pt|pc|deg|rad|dpi|grad|ms|s|hz|khz|%)" + }, { + token : ["constant.numeric"], + regex : "([0-9]+)" }, { token : "constant.numeric", // hex6 color regex : "#[a-f0-9]{6}" @@ -255,12 +264,15 @@ var CssHighlightRules = function() { else if (colors.hasOwnProperty(value.toLowerCase())) { return "support.constant.color"; } + else if (fonts.hasOwnProperty(value.toLowerCase())) { + return "support.constant.fonts"; + } else { return "text"; } }, regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*" - } + } ]; var ruleset = lang.copyArray(base_ruleset); diff --git a/build/demo/kitchen-sink/mode-groovy-uncompressed.js b/build/demo/kitchen-sink/mode-groovy-uncompressed.js index 597f8eec..43d1e8f4 100644 --- a/build/demo/kitchen-sink/mode-groovy-uncompressed.js +++ b/build/demo/kitchen-sink/mode-groovy-uncompressed.js @@ -281,20 +281,20 @@ var JavaScriptHighlightRules = function() { ); // TODO: Unicode escape sequences - var identifierRe = "[" + unicode.packages.L + "\\$_][" + var identifierRe = "[" + unicode.packages.L + "\\$_][" + unicode.packages.L + unicode.packages.Mn + unicode.packages.Mc + unicode.packages.Nd + unicode.packages.Pc + "\\$_]*\\b"; - + var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex "u[0-9a-fA-F]{4}|" + // unicode "[0-2][0-7]{0,2}|" + // oct "3[0-6][0-7]?|" + // oct - "37[0-7]?|" + // oct + "37[0-7]?|" + // oct "[4-7][0-7]?|" + //oct ".)"; - + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -302,13 +302,13 @@ var JavaScriptHighlightRules = function() { "start" : [ { token : "comment", - regex : "\\/\\/.*$" + regex : /\/\/.*$/ }, new DocCommentHighlightRules().getStartRule("doc-start"), { token : "comment", // multi line comment merge : true, - regex : "\\/\\*", + regex : /\/\*/, next : "comment" }, { token : "string", @@ -320,33 +320,121 @@ var JavaScriptHighlightRules = function() { next : "qqstring" }, { token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" + regex : /0[xX][0-9a-fA-F]+\b/ }, { token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : ["storage.type", "text", "entity.name.function", "text", "paren.lparen", "variable.parameter", "paren.rparen"], + regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { // match stuff like: Sound.prototype.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: Sound.prototype.play = myfunc + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)" + }, { // match stuff like: Sound.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: play = function() { } + token : [ + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match regular function like: function myFunc(arg) { } + token : [ + "storage.type", + "text", + "entity.name.function", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: foobar: function() { } + token : [ + "entity.name.function", + "text", + "punctuation.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // Attempt to match : function() { } (this is for issues with 'foo': function() { }) + token : [ + "text", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(:)(\\s*)(function)?(\\s*)(\\()([^)]*)(\\))" }, { token : "constant.language.boolean", - regex : "(?:true|false)\\b" + regex : /(?:true|false)\b/ }, { token : "keyword", regex : "(?:" + kwBeforeRe + ")\\b", next : "regex_allowed" }, { token : "support.function", - regex : "\\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\\b(?=\\()" + regex : /\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ }, { token : "support.function.dom", - regex : "\\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\\b(?=\\()" + regex : /\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ }, { - token : "support.function.constant", - regex : "\\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\\b" + token : "support.constant", + regex : /\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/ }, { - token : ["punctuation.operator", "support.function.firebug"], - regex : "(\\.)(warn|info|log|error|time|timeEnd|assert)\\b" - + token : ["storage.type", "punctuation.operator", "support.function.firebug"], + regex : /\b(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/ }, { token : function(value) { if (globals.hasOwnProperty(value)) @@ -369,29 +457,29 @@ var JavaScriptHighlightRules = function() { regex : identifierRe }, { token : "keyword.operator", - regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)", + regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/, next : "regex_allowed" }, { token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\;|\\.", + regex : /\?|\:|\,|\;|\./, next : "regex_allowed" }, { token : "paren.lparen", - regex : "[[({]", + regex : /[\[({]/, next : "regex_allowed" }, { token : "paren.rparen", - regex : "[\\])}]" + regex : /[\])}]/ }, { token : "keyword.operator", - regex : "\\/=?", + regex : /\/=?/, next : "regex_allowed" }, { token: "comment", - regex: "^#!.*$" + regex: /^#!.*$/ }, { token : "text", - regex : "\\s+" + regex : /\s+/ } ], // regular expressions are only allowed after certain tokens. This @@ -416,7 +504,7 @@ var JavaScriptHighlightRules = function() { }, { // immediately return to the start mode without matching // anything - token: "empty", + token: "empty", regex: "", next: "start" } @@ -428,10 +516,10 @@ var JavaScriptHighlightRules = function() { next: "regex" }, { // flag - token: "string.regexp", + token: "string.regexp", regex: "/\\w*", next: "start", - merge: true + merge: true }, { token: "string.regexp", regex: "[^\\\\/\\[]+", @@ -443,9 +531,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "regex_character_class": [ @@ -464,9 +552,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "comment_regex_allowed" : [ @@ -520,7 +608,7 @@ var JavaScriptHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ new DocCommentHighlightRules().getEndRule("start") ]); }; @@ -926,12 +1014,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -943,7 +1031,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -961,7 +1049,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -986,12 +1074,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -1003,7 +1091,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -1022,14 +1110,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -1050,7 +1139,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -1059,19 +1148,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -1080,7 +1169,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -1090,7 +1179,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-haxe-uncompressed.js b/build/demo/kitchen-sink/mode-haxe-uncompressed.js index ce621745..7efa04c5 100644 --- a/build/demo/kitchen-sink/mode-haxe-uncompressed.js +++ b/build/demo/kitchen-sink/mode-haxe-uncompressed.js @@ -391,12 +391,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -408,7 +408,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -426,7 +426,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -451,12 +451,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -468,7 +468,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -487,14 +487,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -515,7 +516,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -524,19 +525,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -545,7 +546,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -555,7 +556,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-html-uncompressed.js b/build/demo/kitchen-sink/mode-html-uncompressed.js index e7c403b5..6029afad 100644 --- a/build/demo/kitchen-sink/mode-html-uncompressed.js +++ b/build/demo/kitchen-sink/mode-html-uncompressed.js @@ -340,20 +340,20 @@ var JavaScriptHighlightRules = function() { ); // TODO: Unicode escape sequences - var identifierRe = "[" + unicode.packages.L + "\\$_][" + var identifierRe = "[" + unicode.packages.L + "\\$_][" + unicode.packages.L + unicode.packages.Mn + unicode.packages.Mc + unicode.packages.Nd + unicode.packages.Pc + "\\$_]*\\b"; - + var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex "u[0-9a-fA-F]{4}|" + // unicode "[0-2][0-7]{0,2}|" + // oct "3[0-6][0-7]?|" + // oct - "37[0-7]?|" + // oct + "37[0-7]?|" + // oct "[4-7][0-7]?|" + //oct ".)"; - + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -361,13 +361,13 @@ var JavaScriptHighlightRules = function() { "start" : [ { token : "comment", - regex : "\\/\\/.*$" + regex : /\/\/.*$/ }, new DocCommentHighlightRules().getStartRule("doc-start"), { token : "comment", // multi line comment merge : true, - regex : "\\/\\*", + regex : /\/\*/, next : "comment" }, { token : "string", @@ -379,33 +379,121 @@ var JavaScriptHighlightRules = function() { next : "qqstring" }, { token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" + regex : /0[xX][0-9a-fA-F]+\b/ }, { token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : ["storage.type", "text", "entity.name.function", "text", "paren.lparen", "variable.parameter", "paren.rparen"], + regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { // match stuff like: Sound.prototype.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: Sound.prototype.play = myfunc + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)" + }, { // match stuff like: Sound.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: play = function() { } + token : [ + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match regular function like: function myFunc(arg) { } + token : [ + "storage.type", + "text", + "entity.name.function", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: foobar: function() { } + token : [ + "entity.name.function", + "text", + "punctuation.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // Attempt to match : function() { } (this is for issues with 'foo': function() { }) + token : [ + "text", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(:)(\\s*)(function)?(\\s*)(\\()([^)]*)(\\))" }, { token : "constant.language.boolean", - regex : "(?:true|false)\\b" + regex : /(?:true|false)\b/ }, { token : "keyword", regex : "(?:" + kwBeforeRe + ")\\b", next : "regex_allowed" }, { token : "support.function", - regex : "\\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\\b(?=\\()" + regex : /\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ }, { token : "support.function.dom", - regex : "\\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\\b(?=\\()" + regex : /\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ }, { - token : "support.function.constant", - regex : "\\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\\b" + token : "support.constant", + regex : /\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/ }, { - token : ["punctuation.operator", "support.function.firebug"], - regex : "(\\.)(warn|info|log|error|time|timeEnd|assert)\\b" - + token : ["storage.type", "punctuation.operator", "support.function.firebug"], + regex : /\b(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/ }, { token : function(value) { if (globals.hasOwnProperty(value)) @@ -428,29 +516,29 @@ var JavaScriptHighlightRules = function() { regex : identifierRe }, { token : "keyword.operator", - regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)", + regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/, next : "regex_allowed" }, { token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\;|\\.", + regex : /\?|\:|\,|\;|\./, next : "regex_allowed" }, { token : "paren.lparen", - regex : "[[({]", + regex : /[\[({]/, next : "regex_allowed" }, { token : "paren.rparen", - regex : "[\\])}]" + regex : /[\])}]/ }, { token : "keyword.operator", - regex : "\\/=?", + regex : /\/=?/, next : "regex_allowed" }, { token: "comment", - regex: "^#!.*$" + regex: /^#!.*$/ }, { token : "text", - regex : "\\s+" + regex : /\s+/ } ], // regular expressions are only allowed after certain tokens. This @@ -475,7 +563,7 @@ var JavaScriptHighlightRules = function() { }, { // immediately return to the start mode without matching // anything - token: "empty", + token: "empty", regex: "", next: "start" } @@ -487,10 +575,10 @@ var JavaScriptHighlightRules = function() { next: "regex" }, { // flag - token: "string.regexp", + token: "string.regexp", regex: "/\\w*", next: "start", - merge: true + merge: true }, { token: "string.regexp", regex: "[^\\\\/\\[]+", @@ -502,9 +590,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "regex_character_class": [ @@ -523,9 +611,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "comment_regex_allowed" : [ @@ -579,7 +667,7 @@ var JavaScriptHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ new DocCommentHighlightRules().getEndRule("start") ]); }; @@ -985,12 +1073,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -1002,7 +1090,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -1020,7 +1108,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -1045,12 +1133,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -1062,7 +1150,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -1081,14 +1169,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -1109,7 +1198,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -1118,19 +1207,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -1139,7 +1228,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -1149,7 +1238,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; @@ -1577,11 +1667,17 @@ var CssHighlightRules = function() { "purple|red|silver|teal|white|yellow").split("|") ); + var fonts = lang.arrayToMap( + ("arial|century|comic|courier|garamond|georgia|helvetica|impact|lucida|" + + "symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|" + + "serif|monospace").split("|") + ); + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))"; - + var base_ruleset = [ { token : "comment", // multi line comment @@ -1595,8 +1691,11 @@ var CssHighlightRules = function() { token : "string", // single line regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" }, { - token : "constant.numeric", - regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)" + token : ["constant.numeric", "keyword"], + regex : "(" + numRe + ")(em|ex|px|ch|cm|mm|in|pt|pc|deg|rad|dpi|grad|ms|s|hz|khz|%)" + }, { + token : ["constant.numeric"], + regex : "([0-9]+)" }, { token : "constant.numeric", // hex6 color regex : "#[a-f0-9]{6}" @@ -1617,12 +1716,15 @@ var CssHighlightRules = function() { else if (colors.hasOwnProperty(value.toLowerCase())) { return "support.constant.color"; } + else if (fonts.hasOwnProperty(value.toLowerCase())) { + return "support.constant.fonts"; + } else { return "text"; } }, regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*" - } + } ]; var ruleset = lang.copyArray(base_ruleset); diff --git a/build/demo/kitchen-sink/mode-java-uncompressed.js b/build/demo/kitchen-sink/mode-java-uncompressed.js index f57dee09..7f4badf1 100644 --- a/build/demo/kitchen-sink/mode-java-uncompressed.js +++ b/build/demo/kitchen-sink/mode-java-uncompressed.js @@ -282,20 +282,20 @@ var JavaScriptHighlightRules = function() { ); // TODO: Unicode escape sequences - var identifierRe = "[" + unicode.packages.L + "\\$_][" + var identifierRe = "[" + unicode.packages.L + "\\$_][" + unicode.packages.L + unicode.packages.Mn + unicode.packages.Mc + unicode.packages.Nd + unicode.packages.Pc + "\\$_]*\\b"; - + var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex "u[0-9a-fA-F]{4}|" + // unicode "[0-2][0-7]{0,2}|" + // oct "3[0-6][0-7]?|" + // oct - "37[0-7]?|" + // oct + "37[0-7]?|" + // oct "[4-7][0-7]?|" + //oct ".)"; - + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -303,13 +303,13 @@ var JavaScriptHighlightRules = function() { "start" : [ { token : "comment", - regex : "\\/\\/.*$" + regex : /\/\/.*$/ }, new DocCommentHighlightRules().getStartRule("doc-start"), { token : "comment", // multi line comment merge : true, - regex : "\\/\\*", + regex : /\/\*/, next : "comment" }, { token : "string", @@ -321,33 +321,121 @@ var JavaScriptHighlightRules = function() { next : "qqstring" }, { token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" + regex : /0[xX][0-9a-fA-F]+\b/ }, { token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : ["storage.type", "text", "entity.name.function", "text", "paren.lparen", "variable.parameter", "paren.rparen"], + regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { // match stuff like: Sound.prototype.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: Sound.prototype.play = myfunc + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)" + }, { // match stuff like: Sound.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: play = function() { } + token : [ + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match regular function like: function myFunc(arg) { } + token : [ + "storage.type", + "text", + "entity.name.function", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: foobar: function() { } + token : [ + "entity.name.function", + "text", + "punctuation.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // Attempt to match : function() { } (this is for issues with 'foo': function() { }) + token : [ + "text", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(:)(\\s*)(function)?(\\s*)(\\()([^)]*)(\\))" }, { token : "constant.language.boolean", - regex : "(?:true|false)\\b" + regex : /(?:true|false)\b/ }, { token : "keyword", regex : "(?:" + kwBeforeRe + ")\\b", next : "regex_allowed" }, { token : "support.function", - regex : "\\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\\b(?=\\()" + regex : /\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ }, { token : "support.function.dom", - regex : "\\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\\b(?=\\()" + regex : /\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ }, { - token : "support.function.constant", - regex : "\\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\\b" + token : "support.constant", + regex : /\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/ }, { - token : ["punctuation.operator", "support.function.firebug"], - regex : "(\\.)(warn|info|log|error|time|timeEnd|assert)\\b" - + token : ["storage.type", "punctuation.operator", "support.function.firebug"], + regex : /\b(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/ }, { token : function(value) { if (globals.hasOwnProperty(value)) @@ -370,29 +458,29 @@ var JavaScriptHighlightRules = function() { regex : identifierRe }, { token : "keyword.operator", - regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)", + regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/, next : "regex_allowed" }, { token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\;|\\.", + regex : /\?|\:|\,|\;|\./, next : "regex_allowed" }, { token : "paren.lparen", - regex : "[[({]", + regex : /[\[({]/, next : "regex_allowed" }, { token : "paren.rparen", - regex : "[\\])}]" + regex : /[\])}]/ }, { token : "keyword.operator", - regex : "\\/=?", + regex : /\/=?/, next : "regex_allowed" }, { token: "comment", - regex: "^#!.*$" + regex: /^#!.*$/ }, { token : "text", - regex : "\\s+" + regex : /\s+/ } ], // regular expressions are only allowed after certain tokens. This @@ -417,7 +505,7 @@ var JavaScriptHighlightRules = function() { }, { // immediately return to the start mode without matching // anything - token: "empty", + token: "empty", regex: "", next: "start" } @@ -429,10 +517,10 @@ var JavaScriptHighlightRules = function() { next: "regex" }, { // flag - token: "string.regexp", + token: "string.regexp", regex: "/\\w*", next: "start", - merge: true + merge: true }, { token: "string.regexp", regex: "[^\\\\/\\[]+", @@ -444,9 +532,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "regex_character_class": [ @@ -465,9 +553,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "comment_regex_allowed" : [ @@ -521,7 +609,7 @@ var JavaScriptHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ new DocCommentHighlightRules().getEndRule("start") ]); }; @@ -927,12 +1015,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -944,7 +1032,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -962,7 +1050,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -987,12 +1075,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -1004,7 +1092,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -1023,14 +1111,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -1051,7 +1140,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -1060,19 +1149,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -1081,7 +1170,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -1091,7 +1180,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-javascript-uncompressed.js b/build/demo/kitchen-sink/mode-javascript-uncompressed.js index dcf3ffb1..1ca459d8 100644 --- a/build/demo/kitchen-sink/mode-javascript-uncompressed.js +++ b/build/demo/kitchen-sink/mode-javascript-uncompressed.js @@ -257,20 +257,20 @@ var JavaScriptHighlightRules = function() { ); // TODO: Unicode escape sequences - var identifierRe = "[" + unicode.packages.L + "\\$_][" + var identifierRe = "[" + unicode.packages.L + "\\$_][" + unicode.packages.L + unicode.packages.Mn + unicode.packages.Mc + unicode.packages.Nd + unicode.packages.Pc + "\\$_]*\\b"; - + var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex "u[0-9a-fA-F]{4}|" + // unicode "[0-2][0-7]{0,2}|" + // oct "3[0-6][0-7]?|" + // oct - "37[0-7]?|" + // oct + "37[0-7]?|" + // oct "[4-7][0-7]?|" + //oct ".)"; - + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -278,13 +278,13 @@ var JavaScriptHighlightRules = function() { "start" : [ { token : "comment", - regex : "\\/\\/.*$" + regex : /\/\/.*$/ }, new DocCommentHighlightRules().getStartRule("doc-start"), { token : "comment", // multi line comment merge : true, - regex : "\\/\\*", + regex : /\/\*/, next : "comment" }, { token : "string", @@ -296,33 +296,121 @@ var JavaScriptHighlightRules = function() { next : "qqstring" }, { token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" + regex : /0[xX][0-9a-fA-F]+\b/ }, { token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : ["storage.type", "text", "entity.name.function", "text", "paren.lparen", "variable.parameter", "paren.rparen"], + regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { // match stuff like: Sound.prototype.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: Sound.prototype.play = myfunc + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)" + }, { // match stuff like: Sound.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: play = function() { } + token : [ + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match regular function like: function myFunc(arg) { } + token : [ + "storage.type", + "text", + "entity.name.function", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: foobar: function() { } + token : [ + "entity.name.function", + "text", + "punctuation.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // Attempt to match : function() { } (this is for issues with 'foo': function() { }) + token : [ + "text", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(:)(\\s*)(function)?(\\s*)(\\()([^)]*)(\\))" }, { token : "constant.language.boolean", - regex : "(?:true|false)\\b" + regex : /(?:true|false)\b/ }, { token : "keyword", regex : "(?:" + kwBeforeRe + ")\\b", next : "regex_allowed" }, { token : "support.function", - regex : "\\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\\b(?=\\()" + regex : /\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ }, { token : "support.function.dom", - regex : "\\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\\b(?=\\()" + regex : /\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ }, { - token : "support.function.constant", - regex : "\\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\\b" + token : "support.constant", + regex : /\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/ }, { - token : ["punctuation.operator", "support.function.firebug"], - regex : "(\\.)(warn|info|log|error|time|timeEnd|assert)\\b" - + token : ["storage.type", "punctuation.operator", "support.function.firebug"], + regex : /\b(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/ }, { token : function(value) { if (globals.hasOwnProperty(value)) @@ -345,29 +433,29 @@ var JavaScriptHighlightRules = function() { regex : identifierRe }, { token : "keyword.operator", - regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)", + regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/, next : "regex_allowed" }, { token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\;|\\.", + regex : /\?|\:|\,|\;|\./, next : "regex_allowed" }, { token : "paren.lparen", - regex : "[[({]", + regex : /[\[({]/, next : "regex_allowed" }, { token : "paren.rparen", - regex : "[\\])}]" + regex : /[\])}]/ }, { token : "keyword.operator", - regex : "\\/=?", + regex : /\/=?/, next : "regex_allowed" }, { token: "comment", - regex: "^#!.*$" + regex: /^#!.*$/ }, { token : "text", - regex : "\\s+" + regex : /\s+/ } ], // regular expressions are only allowed after certain tokens. This @@ -392,7 +480,7 @@ var JavaScriptHighlightRules = function() { }, { // immediately return to the start mode without matching // anything - token: "empty", + token: "empty", regex: "", next: "start" } @@ -404,10 +492,10 @@ var JavaScriptHighlightRules = function() { next: "regex" }, { // flag - token: "string.regexp", + token: "string.regexp", regex: "/\\w*", next: "start", - merge: true + merge: true }, { token: "string.regexp", regex: "[^\\\\/\\[]+", @@ -419,9 +507,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "regex_character_class": [ @@ -440,9 +528,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "comment_regex_allowed" : [ @@ -496,7 +584,7 @@ var JavaScriptHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ new DocCommentHighlightRules().getEndRule("start") ]); }; @@ -902,12 +990,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -919,7 +1007,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -937,7 +1025,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -962,12 +1050,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -979,7 +1067,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -998,14 +1086,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -1026,7 +1115,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -1035,19 +1124,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -1056,7 +1145,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -1066,7 +1155,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-json-uncompressed.js b/build/demo/kitchen-sink/mode-json-uncompressed.js index e66620ec..a3d4f713 100644 --- a/build/demo/kitchen-sink/mode-json-uncompressed.js +++ b/build/demo/kitchen-sink/mode-json-uncompressed.js @@ -319,12 +319,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -336,7 +336,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -354,7 +354,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -379,12 +379,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -396,7 +396,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -415,14 +415,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -443,7 +444,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -452,19 +453,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -473,7 +474,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -483,7 +484,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-liquid-uncompressed.js b/build/demo/kitchen-sink/mode-liquid-uncompressed.js new file mode 100644 index 00000000..a83ea7f8 --- /dev/null +++ b/build/demo/kitchen-sink/mode-liquid-uncompressed.js @@ -0,0 +1,1368 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabian Jakobs + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define('ace/mode/liquid', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/liquid_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/range'], function(require, exports, module) { + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var LiquidHighlightRules = require("./liquid_highlight_rules").LiquidHighlightRules; +var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; +var Range = require("../range").Range; + +var Mode = function() { + this.$tokenizer = new Tokenizer(new LiquidHighlightRules().getRules()); + this.$outdent = new MatchingBraceOutdent(); +}; +oop.inherits(Mode, TextMode); + +(function() { + + this.toggleCommentLines = function(state, doc, startRow, endRow) { + var outdent = true; + var outentedRows = []; + var re = /^(\s*)#/; + + for (var i=startRow; i<= endRow; i++) { + if (!re.test(doc.getLine(i))) { + outdent = false; + break; + } + } + + if (outdent) { + var deleteRange = new Range(0, 0, 0, 0); + for (var i=startRow; i<= endRow; i++) + { + var line = doc.getLine(i); + var m = line.match(re); + deleteRange.start.row = i; + deleteRange.end.row = i; + deleteRange.end.column = m[0].length; + doc.replace(deleteRange, m[1]); + } + } + else { + doc.indentRows(startRow, endRow, "#"); + } + }; + + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + + var tokenizedLine = this.$tokenizer.getLineTokens(line, state); + var tokens = tokenizedLine.tokens; + var endState = tokenizedLine.state; + + if (tokens.length && tokens[tokens.length-1].type == "comment") { + return indent; + } + + if (state == "start") { + var match = line.match(/^.*[\{\(\[]\s*$/); + if (match) { + indent += tab; + } + } + + 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); + }; + +}).call(Mode.prototype); + +exports.Mode = Mode; +}); +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabian Jakobs + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define('ace/mode/liquid_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/css_highlight_rules', 'ace/mode/javascript_highlight_rules', 'ace/lib/lang', 'ace/mode/xml_util', 'ace/mode/text_highlight_rules'], function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules; +var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules; +var lang = require("../lib/lang"); +var xmlUtil = require("./xml_util"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var LiquidHighlightRules = function() { + + // see: https://developer.mozilla.org/en/Liquid/Reference/Global_Objects + var functions = lang.arrayToMap( + // Standard Filters + ("date|capitalize|downcase|upcase|first|last|join|sort|map|size|escape|" + + "escape_once|strip_html|strip_newlines|newline_to_br|replace|replace_first|" + + "truncate|truncatewords|prepend|append|minus|plus|times|divided_by|split" + ).split("|") + ); + + var keywords = lang.arrayToMap( + // Standard Tags + ("capture|endcapture|case|endcase|when|comment|endcomment|" + + "cycle|for|endfor|in|reversed|if|endif|else|elsif|include|endinclude|unless|endunless|" + + // Commonly used tags + "style|text|image|widget|plugin|marker|endmarker|tablerow|endtablerow").split("|") + ); + + var builtinVariables = lang.arrayToMap( + ['forloop'] + // ("forloop\\.(length|index|index0|rindex|rindex0|first|last)|limit|offset|range" + + // "tablerowloop\\.(length|index|index0|rindex|rindex0|first|last|col|col0|"+ + // "col_first|col_last)").split("|") + ); + + var definitions = lang.arrayToMap(("assign").split("|")); + + // regexp must not have capturing parentheses. Use (?:) instead. + // regexps are ordered -> the first match is used + + this.$rules = { + start : [{ + token : "variable", + regex : "{%", + next : "liquid_start" + }, { + token : "variable", + regex : "{{", + next : "liquid_start" + }, { + token : "meta.tag", + merge : true, + regex : "<\\!\\[CDATA\\[", + next : "cdata" + }, { + token : "xml_pe", + regex : "<\\?.*?\\?>" + }, { + token : "comment", + merge : true, + regex : "<\\!--", + next : "comment" + }, { + token : "meta.tag", + regex : "<(?=\\s*script\\b)", + next : "script" + }, { + token : "meta.tag", + regex : "<(?=\\s*style\\b)", + next : "style" + }, { + token : "meta.tag", // opening tag + regex : "<\\/?", + next : "tag" + }, { + token : "text", + regex : "\\s+" + }, { + token : "text", + regex : "[^<]+" + } ], + + cdata : [ { + token : "text", + regex : "\\]\\]>", + next : "start" + }, { + token : "text", + merge : true, + regex : "\\s+" + }, { + token : "text", + merge : true, + regex : ".+" + } ], + + comment : [ { + token : "comment", + regex : ".*?-->", + next : "start" + }, { + token : "comment", + merge : true, + regex : ".+" + } ] , + + liquid_start : [{ + token: "variable", + regex: "}}", + next: "start" + }, { + token: "variable", + regex: "%}", + next: "start" + }, { + token : "string", // single line + regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' + }, { + token : "string", // single line + regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" + }, { + token : "constant.numeric", // hex + regex : "0[xX][0-9a-fA-F]+\\b" + }, { + token : "constant.numeric", // float + regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + }, { + token : "constant.language.boolean", + regex : "(?:true|false)\\b" + }, { + token : function(value) { + if (functions.hasOwnProperty(value)) + return "support.function"; + else if (keywords.hasOwnProperty(value)) + return "keyword"; + else if (builtinVariables.hasOwnProperty(value)) + return "variable.language"; + else if (definitions.hasOwnProperty(value)) + return "keyword.definition"; + else + return "identifier"; + }, + regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }, { + token : "keyword.operator", + regex : "\/|\\*|\\-|\\+|=|!=|\\?\\:" + }, { + token : "paren.lparen", + regex : /[\[\({]/ + }, { + token : "paren.rparen", + regex : /[\])}]/ + }, { + token : "text", + regex : "\\s+" + }] + }; + + xmlUtil.tag(this.$rules, "tag", "start"); + xmlUtil.tag(this.$rules, "style", "css-start"); + xmlUtil.tag(this.$rules, "script", "js-start"); + + this.embedRules(JavaScriptHighlightRules, "js-", [{ + token: "comment", + regex: "\\/\\/.*(?=<\\/script>)", + next: "tag" + }, { + token: "meta.tag", + regex: "<\\/(?=script)", + next: "tag" + }]); + + this.embedRules(CssHighlightRules, "css-", [{ + token: "meta.tag", + regex: "<\\/(?=style)", + next: "tag" + }]); +}; +oop.inherits(LiquidHighlightRules, TextHighlightRules); + +exports.LiquidHighlightRules = LiquidHighlightRules; +}); +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabian Jakobs + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define('ace/mode/css_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules'], function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var lang = require("../lib/lang"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var CssHighlightRules = function() { + + var properties = lang.arrayToMap( + ("-moz-appearance|-moz-box-sizing|-webkit-box-sizing|-moz-outline-radius|-moz-transform|-webkit-transform|" + + "appearance|azimuth|background-attachment|background-color|background-image|" + + "background-origin|background-position|background-repeat|background|border-bottom-color|" + + "border-bottom-style|border-bottom-width|border-bottom|border-collapse|" + + "border-color|border-left-color|border-left-style|border-left-width|" + + "border-left|border-right-color|border-right-style|border-right-width|" + + "border-right|border-spacing|border-style|border-top-color|" + + "border-top-style|border-top-width|border-top|border-width|border|" + + "bottom|box-sizing|caption-side|clear|clip|color|content|counter-increment|" + + "counter-reset|cue-after|cue-before|cue|cursor|direction|display|" + + "elevation|empty-cells|float|font-family|font-size-adjust|font-size|" + + "font-stretch|font-style|font-variant|font-weight|font|height|left|" + + "letter-spacing|line-height|list-style-image|list-style-position|" + + "list-style-type|list-style|margin-bottom|margin-left|margin-right|" + + "margin-top|marker-offset|margin|marks|max-height|max-width|min-height|" + + "min-width|-moz-border-radius|opacity|orphans|outline-color|outline-offset|outline-radius|" + + "outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|" + + "padding-left|padding-right|padding-top|padding|page-break-after|" + + "page-break-before|page-break-inside|page|pause-after|pause-before|" + + "pause|pitch-range|pitch|play-during|pointer-events|position|quotes|resize|richness|right|" + + "size|speak-header|speak-numeral|speak-punctuation|speech-rate|speak|" + + "stress|table-layout|text-align|text-decoration|text-indent|" + + "text-shadow|text-transform|top|transform|unicode-bidi|vertical-align|" + + "visibility|voice-family|volume|white-space|widows|width|word-spacing|" + + "z-index").split("|") + ); + + var functions = lang.arrayToMap( + ("rgb|rgba|url|attr|counter|counters").split("|") + ); + + var constants = lang.arrayToMap( + ("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|" + + "block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|" + + "char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|" + + "decimal-leading-zero|decimal|default|disabled|disc|" + + "distribute-all-lines|distribute-letter|distribute-space|" + + "distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|" + + "hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|" + + "ideograph-alpha|ideograph-numeric|ideograph-parenthesis|" + + "ideograph-space|inactive|inherit|inline-block|inline|inset|inside|" + + "inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|" + + "keep-all|left|lighter|line-edge|line-through|line|list-item|loose|" + + "lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|" + + "medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|" + + "nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|" + + "overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|" + + "ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|" + + "solid|square|static|strict|super|sw-resize|table-footer-group|" + + "table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|" + + "transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|" + + "vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|" + + "zero").split("|") + ); + + var colors = lang.arrayToMap( + ("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|" + + "purple|red|silver|teal|white|yellow").split("|") + ); + + var fonts = lang.arrayToMap( + ("arial|century|comic|courier|garamond|georgia|helvetica|impact|lucida|" + + "symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|" + + "serif|monospace").split("|") + ); + + // regexp must not have capturing parentheses. Use (?:) instead. + // regexps are ordered -> the first match is used + + var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))"; + + var base_ruleset = [ + { + token : "comment", // multi line comment + merge : true, + regex : "\\/\\*", + next : "ruleset_comment" + },{ + token : "string", // single line + regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' + }, { + token : "string", // single line + regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" + }, { + token : ["constant.numeric", "keyword"], + regex : "(" + numRe + ")(em|ex|px|ch|cm|mm|in|pt|pc|deg|rad|dpi|grad|ms|s|hz|khz|%)" + }, { + token : ["constant.numeric"], + regex : "([0-9]+)" + }, { + token : "constant.numeric", // hex6 color + regex : "#[a-f0-9]{6}" + }, { + token : "constant.numeric", // hex3 color + regex : "#[a-f0-9]{3}" + }, { + token : function(value) { + if (properties.hasOwnProperty(value.toLowerCase())) { + return "support.type"; + } + else if (functions.hasOwnProperty(value.toLowerCase())) { + return "support.function"; + } + else if (constants.hasOwnProperty(value.toLowerCase())) { + return "support.constant"; + } + else if (colors.hasOwnProperty(value.toLowerCase())) { + return "support.constant.color"; + } + else if (fonts.hasOwnProperty(value.toLowerCase())) { + return "support.constant.fonts"; + } + else { + return "text"; + } + }, + regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*" + } + ]; + + var ruleset = lang.copyArray(base_ruleset); + ruleset.unshift({ + token : "paren.rparen", + regex : "\\}", + next: "start" + }); + + var media_ruleset = lang.copyArray( base_ruleset ); + media_ruleset.unshift({ + token : "paren.rparen", + regex : "\\}", + next: "media" + }); + + var base_comment = [{ + token : "comment", // comment spanning whole line + merge : true, + regex : ".+" + }]; + + var comment = lang.copyArray(base_comment); + comment.unshift({ + token : "comment", // closing comment + regex : ".*?\\*\\/", + next : "start" + }); + + var media_comment = lang.copyArray(base_comment); + media_comment.unshift({ + token : "comment", // closing comment + regex : ".*?\\*\\/", + next : "media" + }); + + var ruleset_comment = lang.copyArray(base_comment); + ruleset_comment.unshift({ + token : "comment", // closing comment + regex : ".*?\\*\\/", + next : "ruleset" + }); + + this.$rules = { + "start" : [{ + token : "comment", // multi line comment + merge : true, + regex : "\\/\\*", + next : "comment" + }, { + token: "paren.lparen", + regex: "\\{", + next: "ruleset" + }, { + token: "string", + regex: "@.*?{", + next: "media" + },{ + token: "keyword", + regex: "#[a-z0-9-_]+" + },{ + token: "variable", + regex: "\\.[a-z0-9-_]+" + },{ + token: "string", + regex: ":[a-z0-9-_]+" + },{ + token: "constant", + regex: "[a-z0-9-_]+" + }], + + "media" : [ { + token : "comment", // multi line comment + merge : true, + regex : "\\/\\*", + next : "media_comment" + }, { + token: "paren.lparen", + regex: "\\{", + next: "media_ruleset" + },{ + token: "string", + regex: "\\}", + next: "start" + },{ + token: "keyword", + regex: "#[a-z0-9-_]+" + },{ + token: "variable", + regex: "\\.[a-z0-9-_]+" + },{ + token: "string", + regex: ":[a-z0-9-_]+" + },{ + token: "constant", + regex: "[a-z0-9-_]+" + }], + + "comment" : comment, + + "ruleset" : ruleset, + "ruleset_comment" : ruleset_comment, + + "media_ruleset" : media_ruleset, + "media_comment" : media_comment + }; +}; + +oop.inherits(CssHighlightRules, TextHighlightRules); + +exports.CssHighlightRules = CssHighlightRules; + +}); +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabian Jakobs + * Mihai Sucan + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define('ace/mode/javascript_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/unicode', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var lang = require("../lib/lang"); +var unicode = require("../unicode"); +var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var JavaScriptHighlightRules = function() { + + // see: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects + var globals = lang.arrayToMap( + // Constructors + ("Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" + + // E4X + "Namespace|QName|XML|XMLList|" + + "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" + + "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" + + // Errors + "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" + + "SyntaxError|TypeError|URIError|" + + // Non-constructor functions + "decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + + "isNaN|parseFloat|parseInt|" + + // Other + "JSON|Math|" + + // Pseudo + "this|arguments|prototype|window|document" + ).split("|") + ); + + var keywords = lang.arrayToMap( + ("break|case|catch|continue|default|delete|do|else|finally|for|function|" + + "if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|" + + "const|yield|import|get|set").split("|") + ); + + // keywords which can be followed by regular expressions + var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield"; + + var deprecated = lang.arrayToMap( + ("__parent__|__count__|escape|unescape|with|__proto__").split("|") + ); + + var definitions = lang.arrayToMap(("const|let|var|function").split("|")); + + var buildinConstants = lang.arrayToMap( + ("null|Infinity|NaN|undefined").split("|") + ); + + var futureReserved = lang.arrayToMap( + ("class|enum|extends|super|export|implements|private|" + + "public|interface|package|protected|static").split("|") + ); + + // TODO: Unicode escape sequences + var identifierRe = "[" + unicode.packages.L + "\\$_][" + + unicode.packages.L + + unicode.packages.Mn + unicode.packages.Mc + + unicode.packages.Nd + + unicode.packages.Pc + "\\$_]*\\b"; + + var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex + "u[0-9a-fA-F]{4}|" + // unicode + "[0-2][0-7]{0,2}|" + // oct + "3[0-6][0-7]?|" + // oct + "37[0-7]?|" + // oct + "[4-7][0-7]?|" + //oct + ".)"; + + // regexp must not have capturing parentheses. Use (?:) instead. + // regexps are ordered -> the first match is used + + this.$rules = { + "start" : [ + { + token : "comment", + regex : /\/\/.*$/ + }, + new DocCommentHighlightRules().getStartRule("doc-start"), + { + token : "comment", // multi line comment + merge : true, + regex : /\/\*/, + next : "comment" + }, { + token : "string", + regex : "'", + next : "qstring" + }, { + token : "string", + regex : '"', + next : "qqstring" + }, { + token : "constant.numeric", // hex + regex : /0[xX][0-9a-fA-F]+\b/ + }, { + token : "constant.numeric", // float + regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { // match stuff like: Sound.prototype.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: Sound.prototype.play = myfunc + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)" + }, { // match stuff like: Sound.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: play = function() { } + token : [ + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match regular function like: function myFunc(arg) { } + token : [ + "storage.type", + "text", + "entity.name.function", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: foobar: function() { } + token : [ + "entity.name.function", + "text", + "punctuation.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // Attempt to match : function() { } (this is for issues with 'foo': function() { }) + token : [ + "text", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(:)(\\s*)(function)?(\\s*)(\\()([^)]*)(\\))" + }, { + token : "constant.language.boolean", + regex : /(?:true|false)\b/ + }, { + token : "keyword", + regex : "(?:" + kwBeforeRe + ")\\b", + next : "regex_allowed" + }, { + token : "support.function", + regex : /\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ + }, { + token : "support.function.dom", + regex : /\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ + }, { + token : "support.constant", + regex : /\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/ + }, { + token : ["storage.type", "punctuation.operator", "support.function.firebug"], + regex : /\b(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/ + }, { + token : function(value) { + if (globals.hasOwnProperty(value)) + return "variable.language"; + else if (deprecated.hasOwnProperty(value)) + return "invalid.deprecated"; + else if (definitions.hasOwnProperty(value)) + return "storage.type"; + else if (keywords.hasOwnProperty(value)) + return "keyword"; + else if (buildinConstants.hasOwnProperty(value)) + return "constant.language"; + else if (futureReserved.hasOwnProperty(value)) + return "invalid.illegal"; + else if (value == "debugger") + return "invalid.deprecated"; + else + return "identifier"; + }, + regex : identifierRe + }, { + token : "keyword.operator", + regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/, + next : "regex_allowed" + }, { + token : "punctuation.operator", + regex : /\?|\:|\,|\;|\./, + next : "regex_allowed" + }, { + token : "paren.lparen", + regex : /[\[({]/, + next : "regex_allowed" + }, { + token : "paren.rparen", + regex : /[\])}]/ + }, { + token : "keyword.operator", + regex : /\/=?/, + next : "regex_allowed" + }, { + token: "comment", + regex: /^#!.*$/ + }, { + token : "text", + regex : /\s+/ + } + ], + // regular expressions are only allowed after certain tokens. This + // makes sure we don't mix up regexps with the divison operator + "regex_allowed": [ + { + token : "comment", // multi line comment + merge : true, + regex : "\\/\\*", + next : "comment_regex_allowed" + }, { + token : "comment", + regex : "\\/\\/.*$" + }, { + token: "string.regexp", + regex: "\\/", + next: "regex", + merge: true + }, { + token : "text", + regex : "\\s+" + }, { + // immediately return to the start mode without matching + // anything + token: "empty", + regex: "", + next: "start" + } + ], + "regex": [ + { + token: "regexp.keyword.operator", + regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)", + next: "regex" + }, { + // flag + token: "string.regexp", + regex: "/\\w*", + next: "start", + merge: true + }, { + token: "string.regexp", + regex: "[^\\\\/\\[]+", + next: "regex", + merge: true + }, { + token: "string.regexp.charachterclass", + regex: "\\[", + next: "regex_character_class", + merge: true + }, { + token: "empty", + regex: "", + next: "start" + } + ], + "regex_character_class": [ + { + token: "regexp.keyword.operator", + regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)", + next: "regex_character_class" + }, { + token: "string.regexp.charachterclass", + regex: "]", + next: "regex", + merge: true + }, { + token: "string.regexp.charachterclass", + regex: "[^\\\\\\]]+", + next: "regex_character_class", + merge: true + }, { + token: "empty", + regex: "", + next: "start" + } + ], + "comment_regex_allowed" : [ + { + token : "comment", // closing comment + regex : ".*?\\*\\/", + merge : true, + next : "regex_allowed" + }, { + token : "comment", // comment spanning whole line + merge : true, + regex : ".+" + } + ], + "comment" : [ + { + token : "comment", // closing comment + regex : ".*?\\*\\/", + merge : true, + next : "start" + }, { + token : "comment", // comment spanning whole line + merge : true, + regex : ".+" + } + ], + "qqstring" : [ + { + token : "constant.language.escape", + regex : escapedRe + }, { + token : "string", + regex : '[^"\\\\]+' + }, { + token : "string", + regex : '"', + next : "start" + } + ], + "qstring" : [ + { + token : "constant.language.escape", + regex : escapedRe + }, { + token : "string", + regex : "[^'\\\\]+" + }, { + token : "string", + regex : "'", + next : "start" + } + ] + }; + + this.embedRules(DocCommentHighlightRules, "doc-", + [ new DocCommentHighlightRules().getEndRule("start") ]); +}; + +oop.inherits(JavaScriptHighlightRules, TextHighlightRules); + +exports.JavaScriptHighlightRules = JavaScriptHighlightRules; +}); +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabian Jakobs + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var DocCommentHighlightRules = function() { + + this.$rules = { + "start" : [ { + token : "comment.doc.tag", + regex : "@[\\w\\d_]+" // TODO: fix email addresses + }, { + token : "comment.doc", + merge : true, + regex : "\\s+" + }, { + token : "comment.doc", + merge : true, + regex : "TODO" + }, { + token : "comment.doc", + merge : true, + regex : "[^@\\*]+" + }, { + token : "comment.doc", + merge : true, + regex : "." + }] + }; +}; + +oop.inherits(DocCommentHighlightRules, TextHighlightRules); + +(function() { + + this.getStartRule = function(start) { + return { + token : "comment.doc", // doc comment + merge : true, + regex : "\\/\\*(?=\\*)", + next : start + }; + }; + + this.getEndRule = function (start) { + return { + token : "comment.doc", // closing comment + merge : true, + regex : "\\*\\/", + next : start + }; + }; + +}).call(DocCommentHighlightRules.prototype); + +exports.DocCommentHighlightRules = DocCommentHighlightRules; + +}); +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabian Jakobs + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define('ace/mode/xml_util', ['require', 'exports', 'module' , 'ace/lib/lang'], function(require, exports, module) { +"use strict"; + +var lang = require("../lib/lang"); + +var formTags = lang.arrayToMap( + ("button|form|input|label|select|textarea").split("|") +); + +var tableTags = lang.arrayToMap( + ("table|tbody|td|tfoot|th|tr").split("|") +); + +function string(state) { + return [{ + token : "string", + regex : '".*?"' + }, { + token : "string", // multi line string start + merge : true, + regex : '["].*', + next : state + "_qqstring" + }, { + token : "string", + regex : "'.*?'" + }, { + token : "string", // multi line string start + merge : true, + regex : "['].*", + next : state + "_qstring" + }]; +} + +function multiLineString(quote, state) { + return [{ + token : "string", + merge : true, + regex : ".*?" + quote, + next : state + }, { + token : "string", + merge : true, + regex : '.+' + }]; +} + +exports.tag = function(states, name, nextState) { + states[name] = [{ + token : "text", + regex : "\\s+" + }, { + //token : "meta.tag", + + token : function(value) { + if ( value==='a' ) { + return "meta.tag.anchor"; + } + else if ( value==='img' ) { + return "meta.tag.image"; + } + else if ( value==='script' ) { + return "meta.tag.script"; + } + else if ( value==='style' ) { + return "meta.tag.style"; + } + else if (formTags.hasOwnProperty(value.toLowerCase())) { + return "meta.tag.form"; + } + else if (tableTags.hasOwnProperty(value.toLowerCase())) { + return "meta.tag.table"; + } + else { + return "meta.tag"; + } + }, + merge : true, + regex : "[-_a-zA-Z0-9:!]+", + next : name + "_embed_attribute_list" + }, { + token: "empty", + regex: "", + next : name + "_embed_attribute_list" + }]; + + states[name + "_qstring"] = multiLineString("'", name + "_embed_attribute_list"); + states[name + "_qqstring"] = multiLineString("\"", name + "_embed_attribute_list"); + + states[name + "_embed_attribute_list"] = [{ + token : "meta.tag", + merge : true, + regex : "\/?>", + next : nextState + }, { + token : "keyword.operator", + regex : "=" + }, { + token : "entity.other.attribute-name", + regex : "[-_a-zA-Z0-9:]+" + }, { + token : "constant.numeric", // float + regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + }, { + token : "text", + regex : "\\s+" + }].concat(string(name)); +}; + +}); +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabian Jakobs + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) { +"use strict"; + +var Range = require("../range").Range; + +var MatchingBraceOutdent = function() {}; + +(function() { + + this.checkOutdent = function(line, input) { + if (! /^\s+$/.test(line)) + return false; + + return /^\s*\}/.test(input); + }; + + this.autoOutdent = function(doc, row) { + var line = doc.getLine(row); + var match = line.match(/^(\s*\})/); + + if (!match) return 0; + + var column = match[1].length; + var openBracePos = doc.findMatchingBracket({row: row, column: column}); + + if (!openBracePos || openBracePos.row == row) return 0; + + var indent = this.$getIndent(doc.getLine(openBracePos.row)); + doc.replace(new Range(row, 0, row, column-1), indent); + }; + + this.$getIndent = function(line) { + var match = line.match(/^(\s+)/); + if (match) { + return match[1]; + } + + return ""; + }; + +}).call(MatchingBraceOutdent.prototype); + +exports.MatchingBraceOutdent = MatchingBraceOutdent; +}); diff --git a/build/demo/kitchen-sink/mode-markdown-uncompressed.js b/build/demo/kitchen-sink/mode-markdown-uncompressed.js index da75c07a..426803ff 100644 --- a/build/demo/kitchen-sink/mode-markdown-uncompressed.js +++ b/build/demo/kitchen-sink/mode-markdown-uncompressed.js @@ -337,20 +337,20 @@ var JavaScriptHighlightRules = function() { ); // TODO: Unicode escape sequences - var identifierRe = "[" + unicode.packages.L + "\\$_][" + var identifierRe = "[" + unicode.packages.L + "\\$_][" + unicode.packages.L + unicode.packages.Mn + unicode.packages.Mc + unicode.packages.Nd + unicode.packages.Pc + "\\$_]*\\b"; - + var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex "u[0-9a-fA-F]{4}|" + // unicode "[0-2][0-7]{0,2}|" + // oct "3[0-6][0-7]?|" + // oct - "37[0-7]?|" + // oct + "37[0-7]?|" + // oct "[4-7][0-7]?|" + //oct ".)"; - + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -358,13 +358,13 @@ var JavaScriptHighlightRules = function() { "start" : [ { token : "comment", - regex : "\\/\\/.*$" + regex : /\/\/.*$/ }, new DocCommentHighlightRules().getStartRule("doc-start"), { token : "comment", // multi line comment merge : true, - regex : "\\/\\*", + regex : /\/\*/, next : "comment" }, { token : "string", @@ -376,33 +376,121 @@ var JavaScriptHighlightRules = function() { next : "qqstring" }, { token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" + regex : /0[xX][0-9a-fA-F]+\b/ }, { token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : ["storage.type", "text", "entity.name.function", "text", "paren.lparen", "variable.parameter", "paren.rparen"], + regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { // match stuff like: Sound.prototype.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: Sound.prototype.play = myfunc + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)" + }, { // match stuff like: Sound.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: play = function() { } + token : [ + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match regular function like: function myFunc(arg) { } + token : [ + "storage.type", + "text", + "entity.name.function", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: foobar: function() { } + token : [ + "entity.name.function", + "text", + "punctuation.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // Attempt to match : function() { } (this is for issues with 'foo': function() { }) + token : [ + "text", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(:)(\\s*)(function)?(\\s*)(\\()([^)]*)(\\))" }, { token : "constant.language.boolean", - regex : "(?:true|false)\\b" + regex : /(?:true|false)\b/ }, { token : "keyword", regex : "(?:" + kwBeforeRe + ")\\b", next : "regex_allowed" }, { token : "support.function", - regex : "\\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\\b(?=\\()" + regex : /\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ }, { token : "support.function.dom", - regex : "\\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\\b(?=\\()" + regex : /\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ }, { - token : "support.function.constant", - regex : "\\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\\b" + token : "support.constant", + regex : /\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/ }, { - token : ["punctuation.operator", "support.function.firebug"], - regex : "(\\.)(warn|info|log|error|time|timeEnd|assert)\\b" - + token : ["storage.type", "punctuation.operator", "support.function.firebug"], + regex : /\b(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/ }, { token : function(value) { if (globals.hasOwnProperty(value)) @@ -425,29 +513,29 @@ var JavaScriptHighlightRules = function() { regex : identifierRe }, { token : "keyword.operator", - regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)", + regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/, next : "regex_allowed" }, { token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\;|\\.", + regex : /\?|\:|\,|\;|\./, next : "regex_allowed" }, { token : "paren.lparen", - regex : "[[({]", + regex : /[\[({]/, next : "regex_allowed" }, { token : "paren.rparen", - regex : "[\\])}]" + regex : /[\])}]/ }, { token : "keyword.operator", - regex : "\\/=?", + regex : /\/=?/, next : "regex_allowed" }, { token: "comment", - regex: "^#!.*$" + regex: /^#!.*$/ }, { token : "text", - regex : "\\s+" + regex : /\s+/ } ], // regular expressions are only allowed after certain tokens. This @@ -472,7 +560,7 @@ var JavaScriptHighlightRules = function() { }, { // immediately return to the start mode without matching // anything - token: "empty", + token: "empty", regex: "", next: "start" } @@ -484,10 +572,10 @@ var JavaScriptHighlightRules = function() { next: "regex" }, { // flag - token: "string.regexp", + token: "string.regexp", regex: "/\\w*", next: "start", - merge: true + merge: true }, { token: "string.regexp", regex: "[^\\\\/\\[]+", @@ -499,9 +587,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "regex_character_class": [ @@ -520,9 +608,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "comment_regex_allowed" : [ @@ -576,7 +664,7 @@ var JavaScriptHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ new DocCommentHighlightRules().getEndRule("start") ]); }; @@ -982,12 +1070,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -999,7 +1087,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -1017,7 +1105,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -1042,12 +1130,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -1059,7 +1147,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -1078,14 +1166,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -1106,7 +1195,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -1115,19 +1204,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -1136,7 +1225,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -1146,7 +1235,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; @@ -2323,11 +2413,17 @@ var CssHighlightRules = function() { "purple|red|silver|teal|white|yellow").split("|") ); + var fonts = lang.arrayToMap( + ("arial|century|comic|courier|garamond|georgia|helvetica|impact|lucida|" + + "symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|" + + "serif|monospace").split("|") + ); + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))"; - + var base_ruleset = [ { token : "comment", // multi line comment @@ -2341,8 +2437,11 @@ var CssHighlightRules = function() { token : "string", // single line regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" }, { - token : "constant.numeric", - regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)" + token : ["constant.numeric", "keyword"], + regex : "(" + numRe + ")(em|ex|px|ch|cm|mm|in|pt|pc|deg|rad|dpi|grad|ms|s|hz|khz|%)" + }, { + token : ["constant.numeric"], + regex : "([0-9]+)" }, { token : "constant.numeric", // hex6 color regex : "#[a-f0-9]{6}" @@ -2363,12 +2462,15 @@ var CssHighlightRules = function() { else if (colors.hasOwnProperty(value.toLowerCase())) { return "support.constant.color"; } + else if (fonts.hasOwnProperty(value.toLowerCase())) { + return "support.constant.fonts"; + } else { return "text"; } }, regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*" - } + } ]; var ruleset = lang.copyArray(base_ruleset); @@ -2854,7 +2956,7 @@ var MarkdownHighlightRules = function() { token : "empty_line", regex : '^$' }, { // code span ` - token : "support.function", + token : ["support.function", "support.function", "support.function"], regex : "(`+)([^\\r]*?[^`])(\\1)" }, { // code block token : "support.function", @@ -2884,7 +2986,7 @@ var MarkdownHighlightRules = function() { next : "blockquote" }, { // reference token : ["text", "constant", "text", "url", "string", "text"], - regex : "^([ ]{0,3}\\[)([^\\]]+)(\\]:\\s*)([^ ]+)(\\s*(?:[\"][^\"]+[\"])?\\s*)$" + regex : "^([ ]{0,3}\\[)([^\\]]+)(\\]:\\s*)([^ ]+)(\\s*(?:[\"][^\"]+[\"])?(\\s*))$" }, { // link by reference token : ["text", "string", "text", "constant", "text"], regex : "(\\[)((?:[[^\\]]*\\]|[^\\[\\]])*)(\\][ ]?(?:\\n[ ]*)?\\[)(.*?)(\\])" @@ -2910,10 +3012,10 @@ var MarkdownHighlightRules = function() { regex : "^\\s{0,3}(?:[*+-]|\\d+\\.)\\s+", next : "listblock" }, { // strong ** __ - token : "string", + token : ["string", "string", "string"], regex : "([*]{2}|[_]{2}(?=\\S))([^\\r]*?\\S[*_]*)(\\1)" }, { // emphasis * _ - token : "string", + token : ["string", "string", "string"], regex : "([*]|[_](?=\\S))([^\\r]*?\\S[*_]*)(\\1)" }, { // token : ["text", "url", "text"], diff --git a/build/demo/kitchen-sink/mode-php-uncompressed.js b/build/demo/kitchen-sink/mode-php-uncompressed.js index 103b9f89..3b0c2f8d 100644 --- a/build/demo/kitchen-sink/mode-php-uncompressed.js +++ b/build/demo/kitchen-sink/mode-php-uncompressed.js @@ -1071,14 +1071,14 @@ var PhpHighlightRules = function() { regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' }, { token : "string", // multi line string start - regex : '["].*\\\\$', + regex : '["][\\s\\S]*', next : "qqstring" }, { token : "string", // single line regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" }, { token : "string", // multi line string start - regex : "['].*\\\\$", + regex : "['][\\s\\S]+", next : "qstring" }, { token : "constant.numeric", // hex @@ -1160,21 +1160,21 @@ var PhpHighlightRules = function() { "qqstring" : [ { token : "string", - regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"', + regex : '"', next : "start" }, { token : "string", - regex : '.+' + regex : '[^"]+' } ], "qstring" : [ { token : "string", - regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'", + regex : "'", next : "start" }, { token : "string", - regex : '.+' + regex : "[^']+" } ], "htmlcomment" : [ @@ -1213,7 +1213,7 @@ var PhpHighlightRules = function() { next : "htmltag" }, { token : "meta.tag", - regex : ">", + regex : ">" }, { token : 'text', regex : "(?:media|type|href)" @@ -1223,7 +1223,7 @@ var PhpHighlightRules = function() { }, { token : "paren.lparen", regex : "\{", - next : "cssdeclaration", + next : "cssdeclaration" }, { token : "keyword", regex : "#[A-Za-z0-9\-\_\.]+" @@ -1265,7 +1265,7 @@ var PhpHighlightRules = function() { regex : ";", next : "cssdeclaration" } - ], + ] }; this.embedRules(DocCommentHighlightRules, "doc-", @@ -1507,12 +1507,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -1524,7 +1524,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -1542,7 +1542,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -1567,12 +1567,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -1584,7 +1584,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -1603,14 +1603,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -1631,7 +1632,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -1640,19 +1641,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -1661,7 +1662,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -1671,7 +1672,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-powershell-uncompressed.js b/build/demo/kitchen-sink/mode-powershell-uncompressed.js index a68095e0..e6f9deea 100644 --- a/build/demo/kitchen-sink/mode-powershell-uncompressed.js +++ b/build/demo/kitchen-sink/mode-powershell-uncompressed.js @@ -329,12 +329,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -346,7 +346,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -364,7 +364,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -389,12 +389,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -406,7 +406,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -425,14 +425,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -453,7 +454,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -462,19 +463,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -483,7 +484,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -493,7 +494,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-scad-uncompressed.js b/build/demo/kitchen-sink/mode-scad-uncompressed.js index 8e4b4644..c944ed17 100644 --- a/build/demo/kitchen-sink/mode-scad-uncompressed.js +++ b/build/demo/kitchen-sink/mode-scad-uncompressed.js @@ -529,12 +529,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -546,7 +546,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -564,7 +564,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -589,12 +589,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -606,7 +606,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -625,14 +625,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -653,7 +654,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -662,19 +663,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -683,7 +684,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -693,7 +694,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-scala-uncompressed.js b/build/demo/kitchen-sink/mode-scala-uncompressed.js index b78072fc..2aafee08 100644 --- a/build/demo/kitchen-sink/mode-scala-uncompressed.js +++ b/build/demo/kitchen-sink/mode-scala-uncompressed.js @@ -282,20 +282,20 @@ var JavaScriptHighlightRules = function() { ); // TODO: Unicode escape sequences - var identifierRe = "[" + unicode.packages.L + "\\$_][" + var identifierRe = "[" + unicode.packages.L + "\\$_][" + unicode.packages.L + unicode.packages.Mn + unicode.packages.Mc + unicode.packages.Nd + unicode.packages.Pc + "\\$_]*\\b"; - + var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex "u[0-9a-fA-F]{4}|" + // unicode "[0-2][0-7]{0,2}|" + // oct "3[0-6][0-7]?|" + // oct - "37[0-7]?|" + // oct + "37[0-7]?|" + // oct "[4-7][0-7]?|" + //oct ".)"; - + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -303,13 +303,13 @@ var JavaScriptHighlightRules = function() { "start" : [ { token : "comment", - regex : "\\/\\/.*$" + regex : /\/\/.*$/ }, new DocCommentHighlightRules().getStartRule("doc-start"), { token : "comment", // multi line comment merge : true, - regex : "\\/\\*", + regex : /\/\*/, next : "comment" }, { token : "string", @@ -321,33 +321,121 @@ var JavaScriptHighlightRules = function() { next : "qqstring" }, { token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" + regex : /0[xX][0-9a-fA-F]+\b/ }, { token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : ["storage.type", "text", "entity.name.function", "text", "paren.lparen", "variable.parameter", "paren.rparen"], + regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { // match stuff like: Sound.prototype.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: Sound.prototype.play = myfunc + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)" + }, { // match stuff like: Sound.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: play = function() { } + token : [ + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match regular function like: function myFunc(arg) { } + token : [ + "storage.type", + "text", + "entity.name.function", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: foobar: function() { } + token : [ + "entity.name.function", + "text", + "punctuation.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // Attempt to match : function() { } (this is for issues with 'foo': function() { }) + token : [ + "text", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(:)(\\s*)(function)?(\\s*)(\\()([^)]*)(\\))" }, { token : "constant.language.boolean", - regex : "(?:true|false)\\b" + regex : /(?:true|false)\b/ }, { token : "keyword", regex : "(?:" + kwBeforeRe + ")\\b", next : "regex_allowed" }, { token : "support.function", - regex : "\\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\\b(?=\\()" + regex : /\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ }, { token : "support.function.dom", - regex : "\\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\\b(?=\\()" + regex : /\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ }, { - token : "support.function.constant", - regex : "\\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\\b" + token : "support.constant", + regex : /\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/ }, { - token : ["punctuation.operator", "support.function.firebug"], - regex : "(\\.)(warn|info|log|error|time|timeEnd|assert)\\b" - + token : ["storage.type", "punctuation.operator", "support.function.firebug"], + regex : /\b(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/ }, { token : function(value) { if (globals.hasOwnProperty(value)) @@ -370,29 +458,29 @@ var JavaScriptHighlightRules = function() { regex : identifierRe }, { token : "keyword.operator", - regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)", + regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/, next : "regex_allowed" }, { token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\;|\\.", + regex : /\?|\:|\,|\;|\./, next : "regex_allowed" }, { token : "paren.lparen", - regex : "[[({]", + regex : /[\[({]/, next : "regex_allowed" }, { token : "paren.rparen", - regex : "[\\])}]" + regex : /[\])}]/ }, { token : "keyword.operator", - regex : "\\/=?", + regex : /\/=?/, next : "regex_allowed" }, { token: "comment", - regex: "^#!.*$" + regex: /^#!.*$/ }, { token : "text", - regex : "\\s+" + regex : /\s+/ } ], // regular expressions are only allowed after certain tokens. This @@ -417,7 +505,7 @@ var JavaScriptHighlightRules = function() { }, { // immediately return to the start mode without matching // anything - token: "empty", + token: "empty", regex: "", next: "start" } @@ -429,10 +517,10 @@ var JavaScriptHighlightRules = function() { next: "regex" }, { // flag - token: "string.regexp", + token: "string.regexp", regex: "/\\w*", next: "start", - merge: true + merge: true }, { token: "string.regexp", regex: "[^\\\\/\\[]+", @@ -444,9 +532,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "regex_character_class": [ @@ -465,9 +553,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "comment_regex_allowed" : [ @@ -521,7 +609,7 @@ var JavaScriptHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ new DocCommentHighlightRules().getEndRule("start") ]); }; @@ -927,12 +1015,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -944,7 +1032,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -962,7 +1050,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -987,12 +1075,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -1004,7 +1092,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -1023,14 +1111,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -1051,7 +1140,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -1060,19 +1149,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -1081,7 +1170,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -1091,7 +1180,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-sh-uncompressed.js b/build/demo/kitchen-sink/mode-sh-uncompressed.js index 4f69ec4d..c341067e 100644 --- a/build/demo/kitchen-sink/mode-sh-uncompressed.js +++ b/build/demo/kitchen-sink/mode-sh-uncompressed.js @@ -202,11 +202,6 @@ var ShHighlightRules = function() { ).split('|') ); - var builtinVariables = lang.arrayToMap( - // TODO - ('$?|$$|$!|$SHLVL').split('|') - ); - var integer = "(?:(?:[1-9]\\d*)|(?:0))"; // var integer = "(?:" + decimalInteger + ")"; @@ -215,6 +210,14 @@ var ShHighlightRules = function() { var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))"; var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + ")"; var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")"; + var fileDescriptor = "(?:&" + intPart + ")"; + + var variableName = "[a-zA-Z][a-zA-Z0-9_]*"; + var variable = "(?:(?:\\$" + variableName + ")|(?:" + variableName + "=))"; + + var builtinVariable = "(?:\\$(?:SHLVL|\\$|\\!|\\?))"; + + var func = "(?:" + variableName + "\\s*\\(\\))"; this.$rules = { "start" : [ { @@ -223,6 +226,18 @@ var ShHighlightRules = function() { }, { token : "string", // " string regex : '"(?:[^\\\\]|\\\\.)*?"' + }, { + token : "variable.language", + regex : builtinVariable + }, { + token : "variable", + regex : variable + }, { + token : "support.function", + regex : func, + }, { + token : "support.function", + regex : fileDescriptor }, { token : "string", // ' string regex : "'(?:[^\\\\]|\\\\.)*?'" @@ -238,8 +253,6 @@ var ShHighlightRules = function() { return "keyword"; else if (languageConstructs.hasOwnProperty(value)) return "constant.language"; - else if (builtinVariables.hasOwnProperty(value)) - return "support.function"; else if (value == "debugger") return "invalid.deprecated"; else diff --git a/build/demo/kitchen-sink/mode-svg-uncompressed.js b/build/demo/kitchen-sink/mode-svg-uncompressed.js index 1eaaee78..2777c22e 100644 --- a/build/demo/kitchen-sink/mode-svg-uncompressed.js +++ b/build/demo/kitchen-sink/mode-svg-uncompressed.js @@ -535,12 +535,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -552,7 +552,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -570,7 +570,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -595,12 +595,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -612,7 +612,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -631,14 +631,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -659,7 +660,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -668,19 +669,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -689,7 +690,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -699,7 +700,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; @@ -1336,20 +1338,20 @@ var JavaScriptHighlightRules = function() { ); // TODO: Unicode escape sequences - var identifierRe = "[" + unicode.packages.L + "\\$_][" + var identifierRe = "[" + unicode.packages.L + "\\$_][" + unicode.packages.L + unicode.packages.Mn + unicode.packages.Mc + unicode.packages.Nd + unicode.packages.Pc + "\\$_]*\\b"; - + var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex "u[0-9a-fA-F]{4}|" + // unicode "[0-2][0-7]{0,2}|" + // oct "3[0-6][0-7]?|" + // oct - "37[0-7]?|" + // oct + "37[0-7]?|" + // oct "[4-7][0-7]?|" + //oct ".)"; - + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -1357,13 +1359,13 @@ var JavaScriptHighlightRules = function() { "start" : [ { token : "comment", - regex : "\\/\\/.*$" + regex : /\/\/.*$/ }, new DocCommentHighlightRules().getStartRule("doc-start"), { token : "comment", // multi line comment merge : true, - regex : "\\/\\*", + regex : /\/\*/, next : "comment" }, { token : "string", @@ -1375,33 +1377,121 @@ var JavaScriptHighlightRules = function() { next : "qqstring" }, { token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" + regex : /0[xX][0-9a-fA-F]+\b/ }, { token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : ["storage.type", "text", "entity.name.function", "text", "paren.lparen", "variable.parameter", "paren.rparen"], + regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/ + }, { // match stuff like: Sound.prototype.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: Sound.prototype.play = myfunc + token : [ + "storage.type", + "punctuation.operator", + "support.function", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text" + ], + regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)" + }, { // match stuff like: Sound.play = function() { } + token : [ + "storage.type", + "punctuation.operator", + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: play = function() { } + token : [ + "entity.name.function", + "text", + "keyword.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // match regular function like: function myFunc(arg) { } + token : [ + "storage.type", + "text", + "entity.name.function", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()(.*?)(\\))" + }, { // match stuff like: foobar: function() { } + token : [ + "entity.name.function", + "text", + "punctuation.operator", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()(.*?)(\\))" + }, { // Attempt to match : function() { } (this is for issues with 'foo': function() { }) + token : [ + "text", + "text", + "storage.type", + "text", + "paren.lparen", + "variable.parameter", + "paren.rparen" + ], + regex : "(:)(\\s*)(function)?(\\s*)(\\()([^)]*)(\\))" }, { token : "constant.language.boolean", - regex : "(?:true|false)\\b" + regex : /(?:true|false)\b/ }, { token : "keyword", regex : "(?:" + kwBeforeRe + ")\\b", next : "regex_allowed" }, { token : "support.function", - regex : "\\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\\b(?=\\()" + regex : /\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ }, { token : "support.function.dom", - regex : "\\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\\b(?=\\()" + regex : /\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ }, { - token : "support.function.constant", - regex : "\\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\\b" + token : "support.constant", + regex : /\b(?:s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/ }, { - token : ["punctuation.operator", "support.function.firebug"], - regex : "(\\.)(warn|info|log|error|time|timeEnd|assert)\\b" - + token : ["storage.type", "punctuation.operator", "support.function.firebug"], + regex : /\b(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/ }, { token : function(value) { if (globals.hasOwnProperty(value)) @@ -1424,29 +1514,29 @@ var JavaScriptHighlightRules = function() { regex : identifierRe }, { token : "keyword.operator", - regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)", + regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/, next : "regex_allowed" }, { token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\;|\\.", + regex : /\?|\:|\,|\;|\./, next : "regex_allowed" }, { token : "paren.lparen", - regex : "[[({]", + regex : /[\[({]/, next : "regex_allowed" }, { token : "paren.rparen", - regex : "[\\])}]" + regex : /[\])}]/ }, { token : "keyword.operator", - regex : "\\/=?", + regex : /\/=?/, next : "regex_allowed" }, { token: "comment", - regex: "^#!.*$" + regex: /^#!.*$/ }, { token : "text", - regex : "\\s+" + regex : /\s+/ } ], // regular expressions are only allowed after certain tokens. This @@ -1471,7 +1561,7 @@ var JavaScriptHighlightRules = function() { }, { // immediately return to the start mode without matching // anything - token: "empty", + token: "empty", regex: "", next: "start" } @@ -1483,10 +1573,10 @@ var JavaScriptHighlightRules = function() { next: "regex" }, { // flag - token: "string.regexp", + token: "string.regexp", regex: "/\\w*", next: "start", - merge: true + merge: true }, { token: "string.regexp", regex: "[^\\\\/\\[]+", @@ -1498,9 +1588,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "regex_character_class": [ @@ -1519,9 +1609,9 @@ var JavaScriptHighlightRules = function() { next: "regex_character_class", merge: true }, { - token: "empty", + token: "empty", regex: "", - next: "start" + next: "start" } ], "comment_regex_allowed" : [ @@ -1575,7 +1665,7 @@ var JavaScriptHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ new DocCommentHighlightRules().getEndRule("start") ]); }; diff --git a/build/demo/kitchen-sink/mode-xml-uncompressed.js b/build/demo/kitchen-sink/mode-xml-uncompressed.js index 980707e5..c4e9480b 100644 --- a/build/demo/kitchen-sink/mode-xml-uncompressed.js +++ b/build/demo/kitchen-sink/mode-xml-uncompressed.js @@ -457,12 +457,12 @@ var CstyleBehaviour = function () { return { text: '{' + selected + '}', selection: false - } + }; } else { return { text: '{}', selection: [1, 1] - } + }; } } else if (text == '}') { var cursor = editor.getCursorPosition(); @@ -474,7 +474,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } else if (text == "\n") { @@ -492,7 +492,7 @@ var CstyleBehaviour = function () { return { text: '\n' + indent + '\n' + next_indent, selection: [1, indent.length, 1, indent.length] - } + }; } } }); @@ -517,12 +517,12 @@ var CstyleBehaviour = function () { return { text: '(' + selected + ')', selection: false - } + }; } else { return { text: '()', selection: [1, 1] - } + }; } } else if (text == ')') { var cursor = editor.getCursorPosition(); @@ -534,7 +534,7 @@ var CstyleBehaviour = function () { return { text: '', selection: [1, 1] - } + }; } } } @@ -553,14 +553,15 @@ var CstyleBehaviour = function () { }); this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"') { + if (text == '"' || text == "'") { + var quote = text; var selection = editor.getSelectionRange(); var selected = session.doc.getTextRange(selection); if (selected !== "") { return { - text: '"' + selected + '"', + text: quote + selected + quote, selection: false - } + }; } else { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); @@ -581,7 +582,7 @@ var CstyleBehaviour = function () { if (token.type == "string") { quotepos = -1; } else if (quotepos < 0) { - quotepos = token.value.indexOf('"'); + quotepos = token.value.indexOf(quote); } if ((token.value.length + col) > selection.start.column) { break; @@ -590,19 +591,19 @@ var CstyleBehaviour = function () { } // Try and be smart about when we auto insert. - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) { + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return { - text: '""', + text: quote + quote, selection: [1,1] - } + }; } else if (token && token.type === "string") { // Ignore input and move right one if we're typing over the closing quote. var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '"') { + if (rightChar == quote) { return { text: '', selection: [1, 1] - } + }; } } } @@ -611,7 +612,7 @@ var CstyleBehaviour = function () { this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '"') { + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { var line = session.doc.getLine(range.start.row); var rightChar = line.substring(range.start.column + 1, range.start.column + 2); if (rightChar == '"') { @@ -621,7 +622,8 @@ var CstyleBehaviour = function () { } }); -} +}; + oop.inherits(CstyleBehaviour, Behaviour); exports.CstyleBehaviour = CstyleBehaviour; diff --git a/build/demo/kitchen-sink/mode-xquery-uncompressed.js b/build/demo/kitchen-sink/mode-xquery-uncompressed.js new file mode 100644 index 00000000..69effad6 --- /dev/null +++ b/build/demo/kitchen-sink/mode-xquery-uncompressed.js @@ -0,0 +1,540 @@ +/* + * eXide - web-based XQuery IDE + * + * Copyright (C) 2011 Wolfgang Meier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +define('ace/mode/xquery', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/xquery_highlight_rules', 'ace/mode/behaviour/xquery', 'ace/range'], function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var XQueryHighlightRules = require("./xquery_highlight_rules").XQueryHighlightRules; +var XQueryBehaviour = require("./behaviour/xquery").XQueryBehaviour; +var Range = require("../range").Range; + +var Mode = function(parent) { + this.$tokenizer = new Tokenizer(new XQueryHighlightRules().getRules()); + this.$behaviour = new XQueryBehaviour(parent); +}; + +oop.inherits(Mode, TextMode); + +(function() { + + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + var match = line.match(/\s*(?:then|else|return|[{\(]|<\w+>)\s*$/); + if (match) + indent += tab; + return indent; + }; + + this.checkOutdent = function(state, line, input) { + if (! /^\s+$/.test(line)) + return false; + + return /^\s*[\}\)]/.test(input); + }; + + this.autoOutdent = function(state, doc, row) { + var line = doc.getLine(row); + var match = line.match(/^(\s*[\}\)])/); + + if (!match) return 0; + + var column = match[1].length; + var openBracePos = doc.findMatchingBracket({row: row, column: column}); + + if (!openBracePos || openBracePos.row == row) return 0; + + var indent = this.$getIndent(doc.getLine(openBracePos.row)); + doc.replace(new Range(row, 0, row, column-1), indent); + }; + + this.$getIndent = function(line) { + var match = line.match(/^(\s+)/); + if (match) { + return match[1]; + } + + return ""; + }; + + this.toggleCommentLines = function(state, doc, startRow, endRow) { + var i, line; + var outdent = true; + var re = /^\s*\(:(.*):\)/; + + for (i=startRow; i<= endRow; i++) { + if (!re.test(doc.getLine(i))) { + outdent = false; + break; + } + } + + var range = new Range(0, 0, 0, 0); + for (i=startRow; i<= endRow; i++) { + line = doc.getLine(i); + range.start.row = i; + range.end.row = i; + range.end.column = line.length; + + doc.replace(range, outdent ? line.match(re)[1] : "(:" + line + ":)"); + } + }; +}).call(Mode.prototype); + +exports.Mode = Mode; +}); +/* + * eXide - web-based XQuery IDE + * + * Copyright (C) 2011 Wolfgang Meier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +define('ace/mode/xquery_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules'], function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var lang = require("../lib/lang"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var XQueryHighlightRules = function() { + + var keywords = lang.arrayToMap( + ("return|for|let|where|order|by|declare|function|variable|xquery|version|option|namespace|import|module|when|encoding|" + + "switch|default|try|catch|group|tumbling|sliding|window|start|end|at|only|" + + "using|stemming|" + + "while|" + + "external|" + + "if|then|else|as|and|or|typeswitch|case|ascending|descending|empty|in|count|updating|insert|delete|replace|value|node|attribute|text|element|into|of|with|contains").split("|") + ); + + // regexp must not have capturing parentheses + // regexps are ordered -> the first match is used + + this.$rules = { + start : [ { + token : "text", + regex : "<\\!\\[CDATA\\[", + next : "cdata" + }, { + token : "xml_pe", + regex : "<\\?.*?\\?>" + }, { + token : "comment", + regex : "<\\!--", + next : "comment" + }, { + token : "comment", + regex : "\\(:", + next : "comment" + }, { + token : "text", // opening tag + regex : "<\\/?", + next : "tag" + }, { + token : "constant", // number + regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + }, { + token : "variable", // variable + regex : "\\$[a-zA-Z_][a-zA-Z0-9_\\-:]*\\b" + }, { + token: "string", + regex : '".*?"' + }, { + token: "string", + regex : "'.*?'" + }, { + token : "text", + regex : "\\s+" + }, { + token: "support.function", + regex: "\\w[\\w+_\\-:]+(?=\\()" + }, { + token : function(value) { + if (keywords[value]) + return "keyword"; + else + return "identifier"; + }, + regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }, { + token: "keyword.operator", + regex: "\\*|=|<|>|\\-|\\+|and|or|eq|ne|lt|gt" + }, { + token: "lparen", + regex: "[[({]" + }, { + token: "rparen", + regex: "[\\])}]" + } ], + + tag : [ { + token : "text", + regex : ">", + next : "start" + }, { + token : "meta.tag", + regex : "[-_a-zA-Z0-9:]+" + }, { + token : "text", + regex : "\\s+" + }, { + token : "string", + regex : '".*?"' + }, { + token : "string", + regex : "'.*?'" + } ], + + cdata : [ { + token : "text", + regex : "\\]\\]>", + next : "start" + }, { + token : "text", + regex : "\\s+" + }, { + token : "text", + regex : "(?:[^\\]]|\\](?!\\]>))+" + } ], + + comment : [ { + token : "comment", + regex : ".*?-->", + next : "start" + }, { + token: "comment", + regex : ".*:\\)", + next : "start" + }, { + token : "comment", + regex : ".+" + } ] + }; +}; + +oop.inherits(XQueryHighlightRules, TextHighlightRules); + +exports.XQueryHighlightRules = XQueryHighlightRules; +}); +/* +* eXide - web-based XQuery IDE +* +* Copyright (C) 2011 Wolfgang Meier +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ +define('ace/mode/behaviour/xquery', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/mode/behaviour/cstyle'], function(require, exports, module) { +"use strict"; + + var oop = require("../../lib/oop"); + var Behaviour = require('../behaviour').Behaviour; + var CstyleBehaviour = require('./cstyle').CstyleBehaviour; + + var XQueryBehaviour = function (parent) { + + this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour + this.parent = parent; + + this.add("brackets", "insertion", function (state, action, editor, session, text) { + if (text == "\n") { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + var rightChars = line.substring(cursor.column, cursor.column + 2); + if (rightChars == ' 0 && line.charAt(cursor.column - 1) == "<") { + line = line.substring(0, cursor.column) + "/" + line.substring(cursor.column); + var lines = session.doc.getAllLines(); + lines[cursor.row] = line; + // call mode helper to close the tag if possible + parent.exec("closeTag", lines.join(session.doc.getNewLineCharacter()), cursor.row); + } + } + return false; + }); + } + oop.inherits(XQueryBehaviour, Behaviour); + + exports.XQueryBehaviour = XQueryBehaviour; +}); +/* vim:ts=4:sts=4:sw=4: + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Chris Spencer + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour'], function(require, exports, module) { +"use strict"; + +var oop = require("../../lib/oop"); +var Behaviour = require('../behaviour').Behaviour; + +var CstyleBehaviour = function () { + + this.add("braces", "insertion", function (state, action, editor, session, text) { + if (text == '{') { + var selection = editor.getSelectionRange(); + var selected = session.doc.getTextRange(selection); + if (selected !== "") { + return { + text: '{' + selected + '}', + selection: false + }; + } else { + return { + text: '{}', + selection: [1, 1] + }; + } + } else if (text == '}') { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + var rightChar = line.substring(cursor.column, cursor.column + 1); + if (rightChar == '}') { + var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row}); + if (matching !== null) { + return { + text: '', + selection: [1, 1] + }; + } + } + } else if (text == "\n") { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + var rightChar = line.substring(cursor.column, cursor.column + 1); + if (rightChar == '}') { + var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column + 1}); + if (!openBracePos) + return null; + + var indent = this.getNextLineIndent(state, line.substring(0, line.length - 1), session.getTabString()); + var next_indent = this.$getIndent(session.doc.getLine(openBracePos.row)); + + return { + text: '\n' + indent + '\n' + next_indent, + selection: [1, indent.length, 1, indent.length] + }; + } + } + }); + + this.add("braces", "deletion", function (state, action, editor, session, range) { + var selected = session.doc.getTextRange(range); + if (!range.isMultiLine() && selected == '{') { + var line = session.doc.getLine(range.start.row); + var rightChar = line.substring(range.end.column, range.end.column + 1); + if (rightChar == '}') { + range.end.column++; + return range; + } + } + }); + + this.add("parens", "insertion", function (state, action, editor, session, text) { + if (text == '(') { + var selection = editor.getSelectionRange(); + var selected = session.doc.getTextRange(selection); + if (selected !== "") { + return { + text: '(' + selected + ')', + selection: false + }; + } else { + return { + text: '()', + selection: [1, 1] + }; + } + } else if (text == ')') { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + var rightChar = line.substring(cursor.column, cursor.column + 1); + if (rightChar == ')') { + var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row}); + if (matching !== null) { + return { + text: '', + selection: [1, 1] + }; + } + } + } + }); + + this.add("parens", "deletion", function (state, action, editor, session, range) { + var selected = session.doc.getTextRange(range); + if (!range.isMultiLine() && selected == '(') { + var line = session.doc.getLine(range.start.row); + var rightChar = line.substring(range.start.column + 1, range.start.column + 2); + if (rightChar == ')') { + range.end.column++; + return range; + } + } + }); + + this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { + if (text == '"' || text == "'") { + var quote = text; + var selection = editor.getSelectionRange(); + var selected = session.doc.getTextRange(selection); + if (selected !== "") { + return { + text: quote + selected + quote, + selection: false + }; + } else { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + var leftChar = line.substring(cursor.column-1, cursor.column); + + // We're escaped. + if (leftChar == '\\') { + return null; + } + + // Find what token we're inside. + var tokens = session.getTokens(selection.start.row, selection.start.row)[0].tokens; + var col = 0, token; + var quotepos = -1; // Track whether we're inside an open quote. + + for (var x = 0; x < tokens.length; x++) { + token = tokens[x]; + if (token.type == "string") { + quotepos = -1; + } else if (quotepos < 0) { + quotepos = token.value.indexOf(quote); + } + if ((token.value.length + col) > selection.start.column) { + break; + } + col += tokens[x].value.length; + } + + // Try and be smart about when we auto insert. + if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { + return { + text: quote + quote, + selection: [1,1] + }; + } else if (token && token.type === "string") { + // Ignore input and move right one if we're typing over the closing quote. + var rightChar = line.substring(cursor.column, cursor.column + 1); + if (rightChar == quote) { + return { + text: '', + selection: [1, 1] + }; + } + } + } + } + }); + + this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { + var selected = session.doc.getTextRange(range); + if (!range.isMultiLine() && (selected == '"' || selected == "'")) { + var line = session.doc.getLine(range.start.row); + var rightChar = line.substring(range.start.column + 1, range.start.column + 2); + if (rightChar == '"') { + range.end.column++; + return range; + } + } + }); + +}; + +oop.inherits(CstyleBehaviour, Behaviour); + +exports.CstyleBehaviour = CstyleBehaviour; +}); \ No newline at end of file diff --git a/build/demo/kitchen-sink/theme-chrome-uncompressed.js b/build/demo/kitchen-sink/theme-chrome-uncompressed.js index 1caa9483..57700c4b 100644 --- a/build/demo/kitchen-sink/theme-chrome-uncompressed.js +++ b/build/demo/kitchen-sink/theme-chrome-uncompressed.js @@ -47,7 +47,6 @@ exports.cssText = ".ace-chrome .ace_editor {\ }\ \ .ace-chrome .ace_gutter {\ - width: 50px;\ background: #e8e8e8;\ color: #333;\ overflow : hidden;\ @@ -58,10 +57,6 @@ exports.cssText = ".ace-chrome .ace_editor {\ text-align: right;\ }\ \ -.ace-chrome .ace_gutter-layer .ace_gutter-cell {\ - padding-right: 6px;\ -}\ -\ .ace-chrome .ace_print_margin {\ width: 1px;\ background: #e8e8e8;\ diff --git a/build/demo/kitchen-sink/theme-clouds-uncompressed.js b/build/demo/kitchen-sink/theme-clouds-uncompressed.js index 379be9b8..b6ca3c47 100644 --- a/build/demo/kitchen-sink/theme-clouds-uncompressed.js +++ b/build/demo/kitchen-sink/theme-clouds-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: #BFBFBF;\ }\ \ -.ace-clouds .ace_keyword {\ +.ace-clouds .ace_keyword, .ace-clouds .ace_meta {\ color:#AF956F;\ }\ \ diff --git a/build/demo/kitchen-sink/theme-clouds_midnight-uncompressed.js b/build/demo/kitchen-sink/theme-clouds_midnight-uncompressed.js index e6526e77..3ab4825e 100644 --- a/build/demo/kitchen-sink/theme-clouds_midnight-uncompressed.js +++ b/build/demo/kitchen-sink/theme-clouds_midnight-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: #BFBFBF;\ }\ \ -.ace-clouds-midnight .ace_keyword {\ +.ace-clouds-midnight .ace_keyword, .ace-clouds-midnight .ace_meta {\ color:#927C5D;\ }\ \ diff --git a/build/demo/kitchen-sink/theme-cobalt-uncompressed.js b/build/demo/kitchen-sink/theme-cobalt-uncompressed.js index 487e4703..71f0428a 100644 --- a/build/demo/kitchen-sink/theme-cobalt-uncompressed.js +++ b/build/demo/kitchen-sink/theme-cobalt-uncompressed.js @@ -101,11 +101,11 @@ exports.cssText = "\ color: rgba(255, 255, 255, 0.15);\ }\ \ -.ace-cobalt .ace_keyword {\ +.ace-cobalt .ace_keyword, .ace-cobalt .ace_meta {\ color:#FF9D00;\ }\ \ -.ace-cobalt .ace_constant {\ +.ace-cobalt .ace_constant, .ace-cobalt .ace_constant.ace_other {\ color:#FF628C;\ }\ \ @@ -118,6 +118,10 @@ background-color:#800F00;\ color:#80FFBB;\ }\ \ +.ace-cobalt .ace_support.ace_constant {\ + color:#EB939A;\ +}\ +\ .ace-cobalt .ace_fold {\ background-color: #FF9D00;\ border-color: #FFFFFF;\ diff --git a/build/demo/kitchen-sink/theme-dawn-uncompressed.js b/build/demo/kitchen-sink/theme-dawn-uncompressed.js index 6e6dfeca..1ff79c9e 100644 --- a/build/demo/kitchen-sink/theme-dawn-uncompressed.js +++ b/build/demo/kitchen-sink/theme-dawn-uncompressed.js @@ -101,11 +101,11 @@ exports.cssText = "\ color: rgba(75, 75, 126, 0.50);\ }\ \ -.ace-dawn .ace_keyword {\ +.ace-dawn .ace_keyword, .ace-dawn .ace_meta {\ color:#794938;\ }\ \ -.ace-dawn .ace_constant {\ +.ace-dawn .ace_constant, .ace-dawn .ace_constant.ace_other {\ color:#811F24;\ }\ \ @@ -126,6 +126,10 @@ color:#B52A1D;\ color:#691C97;\ }\ \ +.ace-dawn .ace_support.ace_constant {\ + color:#B4371F;\ +}\ +\ .ace-dawn .ace_fold {\ background-color: #794938;\ border-color: #080808;\ diff --git a/build/demo/kitchen-sink/theme-idle_fingers-uncompressed.js b/build/demo/kitchen-sink/theme-idle_fingers-uncompressed.js index ebb1c41a..35d6227d 100644 --- a/build/demo/kitchen-sink/theme-idle_fingers-uncompressed.js +++ b/build/demo/kitchen-sink/theme-idle_fingers-uncompressed.js @@ -101,11 +101,11 @@ exports.cssText = "\ color: #404040;\ }\ \ -.ace-idle-fingers .ace_keyword {\ +.ace-idle-fingers .ace_keyword, .ace-idle-fingers .ace_meta {\ color:#CC7833;\ }\ \ -.ace-idle-fingers .ace_constant {\ +.ace-idle-fingers .ace_constant, .ace-idle-fingers .ace_constant.ace_other {\ color:#6C99BB;\ }\ \ @@ -114,6 +114,10 @@ exports.cssText = "\ background-color:#FF0000;\ }\ \ +.ace-idle-fingers .ace_support.ace_constant {\ + color:#6C99BB;\ +}\ +\ .ace-idle-fingers .ace_fold {\ background-color: #CC7833;\ border-color: #FFFFFF;\ diff --git a/build/demo/kitchen-sink/theme-kr_theme-uncompressed.js b/build/demo/kitchen-sink/theme-kr_theme-uncompressed.js index 7d5f1e10..2742b72f 100644 --- a/build/demo/kitchen-sink/theme-kr_theme-uncompressed.js +++ b/build/demo/kitchen-sink/theme-kr_theme-uncompressed.js @@ -101,11 +101,11 @@ exports.cssText = "\ color: rgba(255, 177, 111, 0.32);\ }\ \ -.ace-kr-theme .ace_keyword {\ +.ace-kr-theme .ace_keyword, .ace-kr-theme .ace_meta {\ color:#949C8B;\ }\ \ -.ace-kr-theme .ace_constant {\ +.ace-kr-theme .ace_constant, .ace-kr-theme .ace_constant.ace_other {\ color:rgba(210, 117, 24, 0.76);\ }\ \ @@ -118,6 +118,10 @@ background-color:#A41300;\ color:#9FC28A;\ }\ \ +.ace-kr-theme .ace_support.ace_constant {\ + color:#C27E66;\ +}\ +\ .ace-kr-theme .ace_fold {\ background-color: #949C8B;\ border-color: #FCFFE0;\ diff --git a/build/demo/kitchen-sink/theme-merbivore-uncompressed.js b/build/demo/kitchen-sink/theme-merbivore-uncompressed.js index f16811af..09507c6c 100644 --- a/build/demo/kitchen-sink/theme-merbivore-uncompressed.js +++ b/build/demo/kitchen-sink/theme-merbivore-uncompressed.js @@ -101,11 +101,11 @@ exports.cssText = "\ color: #404040;\ }\ \ -.ace-merbivore .ace_keyword {\ +.ace-merbivore .ace_keyword, .ace-merbivore .ace_meta {\ color:#FC6F09;\ }\ \ -.ace-merbivore .ace_constant {\ +.ace-merbivore .ace_constant, .ace-merbivore .ace_constant.ace_other {\ color:#1EDAFB;\ }\ \ @@ -126,6 +126,10 @@ exports.cssText = "\ background-color:#990000;\ }\ \ +.ace-merbivore .ace_support.ace_constant {\ + color:#8DFF0A;\ +}\ +\ .ace-merbivore .ace_fold {\ background-color: #FC6F09;\ border-color: #E6E1DC;\ diff --git a/build/demo/kitchen-sink/theme-merbivore_soft-uncompressed.js b/build/demo/kitchen-sink/theme-merbivore_soft-uncompressed.js index 434d5338..25a00bc1 100644 --- a/build/demo/kitchen-sink/theme-merbivore_soft-uncompressed.js +++ b/build/demo/kitchen-sink/theme-merbivore_soft-uncompressed.js @@ -101,11 +101,11 @@ exports.cssText = "\ color: #404040;\ }\ \ -.ace-merbivore-soft .ace_keyword {\ +.ace-merbivore-soft .ace_keyword, .ace-merbivore-soft .ace_meta {\ color:#FC803A;\ }\ \ -.ace-merbivore-soft .ace_constant {\ +.ace-merbivore-soft .ace_constant, .ace-merbivore-soft .ace_constant.ace_other {\ color:#68C1D8;\ }\ \ @@ -131,6 +131,10 @@ background-color:#FE3838;\ background-color:#FE3838;\ }\ \ +.ace-merbivore-soft .ace_support.ace_constant {\ + color:#8EC65F;\ +}\ +\ .ace-merbivore-soft .ace_fold {\ background-color: #FC803A;\ border-color: #E6E1DC;\ diff --git a/build/demo/kitchen-sink/theme-mono_industrial-uncompressed.js b/build/demo/kitchen-sink/theme-mono_industrial-uncompressed.js index d33da534..e53cb214 100644 --- a/build/demo/kitchen-sink/theme-mono_industrial-uncompressed.js +++ b/build/demo/kitchen-sink/theme-mono_industrial-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: rgba(102, 108, 104, 0.50);\ }\ \ -.ace-mono-industrial .ace_keyword {\ +.ace-mono-industrial .ace_keyword, .ace-mono-industrial .ace_meta {\ color:#A39E64;\ }\ \ @@ -109,7 +109,7 @@ exports.cssText = "\ color:#A8B3AB;\ }\ \ -.ace-mono-industrial .ace_constant {\ +.ace-mono-industrial .ace_constant, .ace-mono-industrial .ace_constant.ace_other {\ color:#E98800;\ }\ \ @@ -122,6 +122,10 @@ exports.cssText = "\ background-color:rgba(153, 0, 0, 0.68);\ }\ \ +.ace-mono-industrial .ace_support.ace_constant {\ + color:#C87500;\ +}\ +\ .ace-mono-industrial .ace_fold {\ background-color: #A8B3AB;\ border-color: #FFFFFF;\ @@ -135,6 +139,10 @@ background-color:rgba(153, 0, 0, 0.68);\ color:#C23B00;\ }\ \ +.ace-mono-industrial .ace_variable {\ + color:#A8B3AB;\ +}\ +\ .ace-mono-industrial .ace_variable.ace_parameter {\ color:#648BD2;\ }\ diff --git a/build/demo/kitchen-sink/theme-monokai-uncompressed.js b/build/demo/kitchen-sink/theme-monokai-uncompressed.js index bf5015d1..1d4d3727 100644 --- a/build/demo/kitchen-sink/theme-monokai-uncompressed.js +++ b/build/demo/kitchen-sink/theme-monokai-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: #49483E;\ }\ \ -.ace-monokai .ace_keyword {\ +.ace-monokai .ace_keyword, .ace-monokai .ace_meta {\ color:#F92672;\ }\ \ @@ -113,6 +113,10 @@ exports.cssText = "\ color:#AE81FF;\ }\ \ +.ace-monokai .ace_constant.ace_other {\ + color:#AE81FF;\ +}\ +\ .ace-monokai .ace_invalid {\ color:#F8F8F0;\ background-color:#F92672;\ @@ -123,6 +127,10 @@ background-color:#F92672;\ background-color:#AE81FF;\ }\ \ +.ace-monokai .ace_support.ace_constant {\ + color:#66D9EF;\ +}\ +\ .ace-monokai .ace_fold {\ background-color: #A6E22E;\ border-color: #F8F8F2;\ @@ -136,11 +144,15 @@ background-color:#AE81FF;\ color:#F92672;\ }\ \ -.ace-monokai .ace_storage.ace_type {\ +.ace-monokai .ace_storage.ace_type, .ace-monokai .ace_support.ace_type{\ font-style:italic;\ color:#66D9EF;\ }\ \ +.ace-monokai .ace_variable {\ + color:#A6E22E;\ +}\ +\ .ace-monokai .ace_variable.ace_parameter {\ font-style:italic;\ color:#FD971F;\ diff --git a/build/demo/kitchen-sink/theme-pastel_on_dark-uncompressed.js b/build/demo/kitchen-sink/theme-pastel_on_dark-uncompressed.js index 309f93e3..69689e16 100644 --- a/build/demo/kitchen-sink/theme-pastel_on_dark-uncompressed.js +++ b/build/demo/kitchen-sink/theme-pastel_on_dark-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: rgba(255, 255, 255, 0.25);\ }\ \ -.ace-pastel-on-dark .ace_keyword {\ +.ace-pastel-on-dark .ace_keyword, .ace-pastel-on-dark .ace_meta {\ color:#757aD8;\ }\ \ @@ -109,7 +109,7 @@ exports.cssText = "\ color:#797878;\ }\ \ -.ace-pastel-on-dark .ace_constant {\ +.ace-pastel-on-dark .ace_constant, .ace-pastel-on-dark .ace_constant.ace_other {\ color:#4FB7C5;\ }\ \ diff --git a/build/demo/kitchen-sink/theme-solarized_dark-uncompressed.js b/build/demo/kitchen-sink/theme-solarized_dark-uncompressed.js index cf19f9d8..3b2b6e1b 100644 --- a/build/demo/kitchen-sink/theme-solarized_dark-uncompressed.js +++ b/build/demo/kitchen-sink/theme-solarized_dark-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: rgba(147, 161, 161, 0.50);\ }\ \ -.ace-solarized-dark .ace_keyword {\ +.ace-solarized-dark .ace_keyword, .ace-solarized-dark .ace_meta {\ color:#859900;\ }\ \ @@ -113,6 +113,10 @@ exports.cssText = "\ color:#D33682;\ }\ \ +.ace-solarized-dark .ace_constant.ace_other {\ + color:#CB4B16;\ +}\ +\ .ace-solarized-dark .ace_fold {\ background-color: #268BD2;\ border-color: #93A1A1;\ @@ -126,6 +130,10 @@ exports.cssText = "\ color:#93A1A1;\ }\ \ +.ace-solarized-dark .ace_variable {\ + color:#268BD2;\ +}\ +\ .ace-solarized-dark .ace_string {\ color:#2AA198;\ }\ diff --git a/build/demo/kitchen-sink/theme-solarized_light-uncompressed.js b/build/demo/kitchen-sink/theme-solarized_light-uncompressed.js index 8402abe5..771f3ea7 100644 --- a/build/demo/kitchen-sink/theme-solarized_light-uncompressed.js +++ b/build/demo/kitchen-sink/theme-solarized_light-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: rgba(147, 161, 161, 0.50);\ }\ \ -.ace-solarized-light .ace_keyword {\ +.ace-solarized-light .ace_keyword, .ace-solarized-light .ace_meta {\ color:#859900;\ }\ \ @@ -113,6 +113,10 @@ exports.cssText = "\ color:#D33682;\ }\ \ +.ace-solarized-light .ace_constant.ace_other {\ + color:#CB4B16;\ +}\ +\ .ace-solarized-light .ace_fold {\ background-color: #268BD2;\ border-color: #586E75;\ @@ -126,6 +130,10 @@ exports.cssText = "\ color:#073642;\ }\ \ +.ace-solarized-light .ace_variable {\ + color:#268BD2;\ +}\ +\ .ace-solarized-light .ace_string {\ color:#2AA198;\ }\ diff --git a/build/demo/kitchen-sink/theme-tomorrow-uncompressed.js b/build/demo/kitchen-sink/theme-tomorrow-uncompressed.js index 3dbada6f..1eb9fbd9 100644 --- a/build/demo/kitchen-sink/theme-tomorrow-uncompressed.js +++ b/build/demo/kitchen-sink/theme-tomorrow-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: #D1D1D1;\ }\ \ -.ace-tomorrow .ace_keyword {\ +.ace-tomorrow .ace_keyword, .ace-tomorrow .ace_meta {\ color:#8959A8;\ }\ \ @@ -117,6 +117,10 @@ exports.cssText = "\ color:#F5871F;\ }\ \ +.ace-tomorrow .ace_constant.ace_other {\ + color:#666969;\ +}\ +\ .ace-tomorrow .ace_invalid {\ color:#FFFFFF;\ background-color:#C82829;\ @@ -127,6 +131,10 @@ background-color:#C82829;\ background-color:#8959A8;\ }\ \ +.ace-tomorrow .ace_support.ace_constant {\ + color:#F5871F;\ +}\ +\ .ace-tomorrow .ace_fold {\ background-color: #4271AE;\ border-color: #4D4D4C;\ @@ -140,10 +148,14 @@ background-color:#8959A8;\ color:#8959A8;\ }\ \ -.ace-tomorrow .ace_storage.ace_type {\ +.ace-tomorrow .ace_storage.ace_type, .ace-tomorrow .ace_support.ace_type{\ color:#8959A8;\ }\ \ +.ace-tomorrow .ace_variable {\ + color:#4271AE;\ +}\ +\ .ace-tomorrow .ace_variable.ace_parameter {\ color:#F5871F;\ }\ diff --git a/build/demo/kitchen-sink/theme-tomorrow_night-uncompressed.js b/build/demo/kitchen-sink/theme-tomorrow_night-uncompressed.js index 4b93b52e..34e64693 100644 --- a/build/demo/kitchen-sink/theme-tomorrow_night-uncompressed.js +++ b/build/demo/kitchen-sink/theme-tomorrow_night-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: #4B4E55;\ }\ \ -.ace-tomorrow-night .ace_keyword {\ +.ace-tomorrow-night .ace_keyword, .ace-tomorrow-night .ace_meta {\ color:#B294BB;\ }\ \ @@ -117,6 +117,10 @@ exports.cssText = "\ color:#DE935F;\ }\ \ +.ace-tomorrow-night .ace_constant.ace_other {\ + color:#CED1CF;\ +}\ +\ .ace-tomorrow-night .ace_invalid {\ color:#CED2CF;\ background-color:#DF5F5F;\ @@ -127,6 +131,10 @@ background-color:#DF5F5F;\ background-color:#B798BF;\ }\ \ +.ace-tomorrow-night .ace_support.ace_constant {\ + color:#DE935F;\ +}\ +\ .ace-tomorrow-night .ace_fold {\ background-color: #81A2BE;\ border-color: #C5C8C6;\ @@ -140,10 +148,14 @@ background-color:#B798BF;\ color:#B294BB;\ }\ \ -.ace-tomorrow-night .ace_storage.ace_type {\ +.ace-tomorrow-night .ace_storage.ace_type, .ace-tomorrow-night .ace_support.ace_type{\ color:#B294BB;\ }\ \ +.ace-tomorrow-night .ace_variable {\ + color:#81A2BE;\ +}\ +\ .ace-tomorrow-night .ace_variable.ace_parameter {\ color:#DE935F;\ }\ diff --git a/build/demo/kitchen-sink/theme-tomorrow_night_blue-uncompressed.js b/build/demo/kitchen-sink/theme-tomorrow_night_blue-uncompressed.js index 50378cc9..4d8ad6b2 100644 --- a/build/demo/kitchen-sink/theme-tomorrow_night_blue-uncompressed.js +++ b/build/demo/kitchen-sink/theme-tomorrow_night_blue-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: #404F7D;\ }\ \ -.ace-tomorrow-night-blue .ace_keyword {\ +.ace-tomorrow-night-blue .ace_keyword, .ace-tomorrow-night-blue .ace_meta {\ color:#EBBBFF;\ }\ \ @@ -117,6 +117,10 @@ exports.cssText = "\ color:#FFC58F;\ }\ \ +.ace-tomorrow-night-blue .ace_constant.ace_other {\ + color:#FFFFFF;\ +}\ +\ .ace-tomorrow-night-blue .ace_invalid {\ color:#FFFFFF;\ background-color:#F99DA5;\ @@ -127,6 +131,10 @@ background-color:#F99DA5;\ background-color:#EBBBFF;\ }\ \ +.ace-tomorrow-night-blue .ace_support.ace_constant {\ + color:#FFC58F;\ +}\ +\ .ace-tomorrow-night-blue .ace_fold {\ background-color: #BBDAFF;\ border-color: #FFFFFF;\ @@ -140,10 +148,14 @@ background-color:#EBBBFF;\ color:#EBBBFF;\ }\ \ -.ace-tomorrow-night-blue .ace_storage.ace_type {\ +.ace-tomorrow-night-blue .ace_storage.ace_type, .ace-tomorrow-night-blue .ace_support.ace_type{\ color:#EBBBFF;\ }\ \ +.ace-tomorrow-night-blue .ace_variable {\ + color:#BBDAFF;\ +}\ +\ .ace-tomorrow-night-blue .ace_variable.ace_parameter {\ color:#FFC58F;\ }\ diff --git a/build/demo/kitchen-sink/theme-tomorrow_night_bright-uncompressed.js b/build/demo/kitchen-sink/theme-tomorrow_night_bright-uncompressed.js index 4e06a32a..667e7e43 100644 --- a/build/demo/kitchen-sink/theme-tomorrow_night_bright-uncompressed.js +++ b/build/demo/kitchen-sink/theme-tomorrow_night_bright-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: #343434;\ }\ \ -.ace-tomorrow-night-bright .ace_keyword {\ +.ace-tomorrow-night-bright .ace_keyword, .ace-tomorrow-night-bright .ace_meta {\ color:#C397D8;\ }\ \ @@ -117,6 +117,10 @@ exports.cssText = "\ color:#E78C45;\ }\ \ +.ace-tomorrow-night-bright .ace_constant.ace_other {\ + color:#EEEEEE;\ +}\ +\ .ace-tomorrow-night-bright .ace_invalid {\ color:#CED2CF;\ background-color:#DF5F5F;\ @@ -127,6 +131,10 @@ background-color:#DF5F5F;\ background-color:#B798BF;\ }\ \ +.ace-tomorrow-night-bright .ace_support.ace_constant {\ + color:#E78C45;\ +}\ +\ .ace-tomorrow-night-bright .ace_fold {\ background-color: #7AA6DA;\ border-color: #DEDEDE;\ @@ -140,10 +148,14 @@ background-color:#B798BF;\ color:#C397D8;\ }\ \ -.ace-tomorrow-night-bright .ace_storage.ace_type {\ +.ace-tomorrow-night-bright .ace_storage.ace_type, .ace-tomorrow-night-bright .ace_support.ace_type{\ color:#C397D8;\ }\ \ +.ace-tomorrow-night-bright .ace_variable {\ + color:#7AA6DA;\ +}\ +\ .ace-tomorrow-night-bright .ace_variable.ace_parameter {\ color:#E78C45;\ }\ diff --git a/build/demo/kitchen-sink/theme-tomorrow_night_eighties-uncompressed.js b/build/demo/kitchen-sink/theme-tomorrow_night_eighties-uncompressed.js index a104465c..61eb414e 100644 --- a/build/demo/kitchen-sink/theme-tomorrow_night_eighties-uncompressed.js +++ b/build/demo/kitchen-sink/theme-tomorrow_night_eighties-uncompressed.js @@ -101,7 +101,7 @@ exports.cssText = "\ color: #6A6A6A;\ }\ \ -.ace-tomorrow-night-eighties .ace_keyword {\ +.ace-tomorrow-night-eighties .ace_keyword, .ace-tomorrow-night-eighties .ace_meta {\ color:#CC99CC;\ }\ \ @@ -117,6 +117,10 @@ exports.cssText = "\ color:#F99157;\ }\ \ +.ace-tomorrow-night-eighties .ace_constant.ace_other {\ + color:#CCCCCC;\ +}\ +\ .ace-tomorrow-night-eighties .ace_invalid {\ color:#CDCDCD;\ background-color:#F2777A;\ @@ -127,6 +131,10 @@ background-color:#F2777A;\ background-color:#CC99CC;\ }\ \ +.ace-tomorrow-night-eighties .ace_support.ace_constant {\ + color:#F99157;\ +}\ +\ .ace-tomorrow-night-eighties .ace_fold {\ background-color: #6699CC;\ border-color: #CCCCCC;\ @@ -140,10 +148,14 @@ background-color:#CC99CC;\ color:#CC99CC;\ }\ \ -.ace-tomorrow-night-eighties .ace_storage.ace_type {\ +.ace-tomorrow-night-eighties .ace_storage.ace_type, .ace-tomorrow-night-eighties .ace_support.ace_type{\ color:#CC99CC;\ }\ \ +.ace-tomorrow-night-eighties .ace_variable {\ + color:#6699CC;\ +}\ +\ .ace-tomorrow-night-eighties .ace_variable.ace_parameter {\ color:#F99157;\ }\ diff --git a/build/demo/kitchen-sink/theme-twilight-uncompressed.js b/build/demo/kitchen-sink/theme-twilight-uncompressed.js index bbe54891..4bd4604f 100644 --- a/build/demo/kitchen-sink/theme-twilight-uncompressed.js +++ b/build/demo/kitchen-sink/theme-twilight-uncompressed.js @@ -101,11 +101,11 @@ exports.cssText = "\ color: rgba(255, 255, 255, 0.25);\ }\ \ -.ace-twilight .ace_keyword {\ +.ace-twilight .ace_keyword, .ace-twilight .ace_meta {\ color:#CDA869;\ }\ \ -.ace-twilight .ace_constant {\ +.ace-twilight .ace_constant, .ace-twilight .ace_constant.ace_other {\ color:#CF6A4C;\ }\ \ @@ -124,6 +124,10 @@ color:#D2A8A1;\ color:#9B859D;\ }\ \ +.ace-twilight .ace_support.ace_constant {\ + color:#CF6A4C;\ +}\ +\ .ace-twilight .ace_fold {\ background-color: #AC885B;\ border-color: #F8F8F8;\ @@ -137,6 +141,10 @@ color:#D2A8A1;\ color:#F9EE98;\ }\ \ +.ace-twilight .ace_variable {\ + color:#AC885B;\ +}\ +\ .ace-twilight .ace_string {\ color:#8F9D6A;\ }\ diff --git a/build/demo/kitchen-sink/theme-vibrant_ink-uncompressed.js b/build/demo/kitchen-sink/theme-vibrant_ink-uncompressed.js index b047ca83..b3558677 100644 --- a/build/demo/kitchen-sink/theme-vibrant_ink-uncompressed.js +++ b/build/demo/kitchen-sink/theme-vibrant_ink-uncompressed.js @@ -101,11 +101,11 @@ exports.cssText = "\ color: #404040;\ }\ \ -.ace-vibrant-ink .ace_keyword {\ +.ace-vibrant-ink .ace_keyword, .ace-vibrant-ink .ace_meta {\ color:#FF6600;\ }\ \ -.ace-vibrant-ink .ace_constant {\ +.ace-vibrant-ink .ace_constant, .ace-vibrant-ink .ace_constant.ace_other {\ color:#339999;\ }\ \ @@ -132,6 +132,10 @@ background-color:#000000;\ color:#FFCC00;\ }\ \ +.ace-vibrant-ink .ace_variable {\ + color:#FFCC00;\ +}\ +\ .ace-vibrant-ink .ace_variable.ace_parameter {\ font-style:italic;\ }\ diff --git a/build/demo/kitchen-sink/worker-coffee.js b/build/demo/kitchen-sink/worker-coffee.js index b6afb95f..4223df24 100644 --- a/build/demo/kitchen-sink/worker-coffee.js +++ b/build/demo/kitchen-sink/worker-coffee.js @@ -1816,6 +1816,7 @@ var Document = function(text) { position = this.$clipPosition(position); + // only detect new lines if the document has no line break yet if (this.getLength() <= 1) this.$detectNewLine(text); diff --git a/build/demo/kitchen-sink/worker-css.js b/build/demo/kitchen-sink/worker-css.js index 0c2a4a41..de73a94d 100644 --- a/build/demo/kitchen-sink/worker-css.js +++ b/build/demo/kitchen-sink/worker-css.js @@ -1790,6 +1790,7 @@ var Document = function(text) { position = this.$clipPosition(position); + // only detect new lines if the document has no line break yet if (this.getLength() <= 1) this.$detectNewLine(text); diff --git a/build/demo/kitchen-sink/worker-javascript.js b/build/demo/kitchen-sink/worker-javascript.js index 2e7a3f72..e04b239f 100644 --- a/build/demo/kitchen-sink/worker-javascript.js +++ b/build/demo/kitchen-sink/worker-javascript.js @@ -1540,12 +1540,13 @@ exports.implement = function(proto, mixin) { * * ***** END LICENSE BLOCK ***** */ -define('ace/mode/javascript_worker', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/worker/mirror', 'ace/worker/jshint', 'ace/narcissus/jsparse'], function(require, exports, module) { +define('ace/mode/javascript_worker', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/worker/mirror', 'ace/worker/jshint', 'ace/narcissus/parser'], function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); var Mirror = require("../worker/mirror").Mirror; var lint = require("../worker/jshint").JSHINT; +var parser = require("../narcissus/parser"); var JavaScriptWorker = exports.JavaScriptWorker = function(sender) { Mirror.call(this, sender); @@ -1561,7 +1562,6 @@ oop.inherits(JavaScriptWorker, Mirror); value = value.replace(/^#!.*\n/, "\n"); // var start = new Date(); - var parser = require("../narcissus/jsparse"); try { parser.parse(value); } catch(e) { @@ -1812,6 +1812,7 @@ var Document = function(text) { position = this.$clipPosition(position); + // only detect new lines if the document has no line break yet if (this.getLength() <= 1) this.$detectNewLine(text); @@ -7218,598 +7219,648 @@ if (typeof exports === 'object' && exports) * Parser. */ -define('ace/narcissus/jsparse', ['require', 'exports', 'module' , 'ace/narcissus/jslex', 'ace/narcissus/jsdefs'], function(require, exports, module) { +define('ace/narcissus/parser', ['require', 'exports', 'module' , 'ace/narcissus/lexer', 'ace/narcissus/definitions', 'ace/narcissus/options'], function(require, exports, module) { - var lexer = require("./jslex"); - var definitions = require("./jsdefs"); +var lexer = require('./lexer'); +var definitions = require('./definitions'); +var options = require('./options'); +var Tokenizer = lexer.Tokenizer; - const StringMap = definitions.StringMap; - const Stack = definitions.Stack; +var Dict = definitions.Dict; +var Stack = definitions.Stack; - // Set constants in the local scope. - eval(definitions.consts); +// Set constants in the local scope. +eval(definitions.consts); - // Banned statement types by language version. - const blackLists = { 160: {}, 185: {}, harmony: {} }; - blackLists[160][IMPORT] = true; - blackLists[160][EXPORT] = true; - blackLists[160][LET] = true; - blackLists[160][MODULE] = true; - blackLists[160][YIELD] = true; - blackLists[185][IMPORT] = true; - blackLists[185][EXPORT] = true; - blackLists[185][MODULE] = true; - blackLists.harmony[WITH] = true; - - /* - * pushDestructuringVarDecls :: (node, hoisting node) -> void - * - * Recursively add all destructured declarations to varDecls. - */ - function pushDestructuringVarDecls(n, s) { - for (var i in n) { - var sub = n[i]; - if (sub.type === IDENTIFIER) { - s.varDecls.push(sub); - } else { - pushDestructuringVarDecls(sub, s); - } - } - } - - function StaticContext(parentScript, parentBlock, inModule, inFunction) { - this.parentScript = parentScript; - this.parentBlock = parentBlock || parentScript; - this.inModule = inModule || false; - this.inFunction = inFunction || false; - this.inForLoopInit = false; - this.topLevel = true; - this.allLabels = new Stack(); - this.currentLabels = new Stack(); - this.labeledTargets = new Stack(); - this.defaultLoopTarget = null; - this.defaultTarget = null; - this.blackList = blackLists[Narcissus.options.version]; - Narcissus.options.ecma3OnlyMode && (this.ecma3OnlyMode = true); - Narcissus.options.parenFreeMode && (this.parenFreeMode = true); - } - - StaticContext.prototype = { - ecma3OnlyMode: false, - parenFreeMode: false, - // non-destructive update via prototype extension - update: function(ext) { - var desc = {}; - for (var key in ext) { - desc[key] = { - value: ext[key], - writable: true, - enumerable: true, - configurable: true - } - } - return Object.create(this, desc); - }, - pushLabel: function(label) { - return this.update({ currentLabels: this.currentLabels.push(label), - allLabels: this.allLabels.push(label) }); - }, - pushTarget: function(target) { - var isDefaultLoopTarget = target.isLoop; - var isDefaultTarget = isDefaultLoopTarget || target.type === SWITCH; - - if (this.currentLabels.isEmpty()) { - if (isDefaultLoopTarget) this.update({ defaultLoopTarget: target }); - if (isDefaultTarget) this.update({ defaultTarget: target }); - return this; - } - - target.labels = new StringMap(); - this.currentLabels.forEach(function(label) { - target.labels.set(label, true); - }); - return this.update({ currentLabels: new Stack(), - labeledTargets: this.labeledTargets.push(target), - defaultLoopTarget: isDefaultLoopTarget - ? target - : this.defaultLoopTarget, - defaultTarget: isDefaultTarget - ? target - : this.defaultTarget }); - }, - nest: function() { - return this.topLevel ? this.update({ topLevel: false }) : this; - }, - allow: function(type) { - switch (type) { - case EXPORT: - if (!this.inModule || this.inFunction || !this.topLevel) - return false; - // FALL THROUGH - - case IMPORT: - return !this.inFunction && this.topLevel; - - case MODULE: - return !this.inFunction && this.topLevel; - - default: - return true; - } - } - }; - - /* - * Script :: (tokenizer, boolean, boolean) -> node - * - * Parses the toplevel and module/function bodies. - */ - function Script(t, inModule, inFunction) { - var n = new Node(t, scriptInit()); - Statements(t, new StaticContext(n, n, inModule, inFunction), n); - return n; - } - - // We extend Array slightly with a top-of-stack method. - definitions.defineProperty(Array.prototype, "top", - function() { - return this.length && this[this.length-1]; - }, false, false, true); - - /* - * Node :: (tokenizer, optional init object) -> node - */ - function Node(t, init) { - var token = t.token; - if (token) { - // If init.type exists it will override token.type. - this.type = token.type; - this.value = token.value; - this.lineno = token.lineno; - - // Start and end are file positions for error handling. - this.start = token.start; - this.end = token.end; +/* + * pushDestructuringVarDecls :: (node, hoisting node) -> void + * + * Recursively add all destructured declarations to varDecls. + */ +function pushDestructuringVarDecls(n, s) { + for (var i in n) { + var sub = n[i]; + if (sub.type === IDENTIFIER) { + s.varDecls.push(sub); } else { - this.lineno = t.lineno; - } - - // Node uses a tokenizer for debugging (getSource, filename getter). - this.tokenizer = t; - this.children = []; - - for (var prop in init) - this[prop] = init[prop]; - } - - /* - * SyntheticNode :: (tokenizer, optional init object) -> node - */ - function SyntheticNode(t, init) { - // print("SYNTHETIC NODE"); - // if (init.type === COMMA) { - // print("SYNTHETIC COMMA"); - // print(init); - // } - this.tokenizer = t; - this.children = []; - for (var prop in init) - this[prop] = init[prop]; - this.synthetic = true; - } - - var Np = Node.prototype = SyntheticNode.prototype = {}; - Np.constructor = Node; - - const TO_SOURCE_SKIP = { - type: true, - value: true, - lineno: true, - start: true, - end: true, - tokenizer: true, - assignOp: true - }; - function unevalableConst(code) { - var token = definitions.tokens[code]; - var constName = definitions.opTypeNames.hasOwnProperty(token) - ? definitions.opTypeNames[token] - : token in definitions.keywords - ? token.toUpperCase() - : token; - return { toSource: function() { return constName } }; - } - Np.toSource = function toSource() { - var mock = {}; - var self = this; - mock.type = unevalableConst(this.type); - if ("value" in this) - mock.value = this.value; - if ("lineno" in this) - mock.lineno = this.lineno; - if ("start" in this) - mock.start = this.start; - if ("end" in this) - mock.end = this.end; - if (this.assignOp) - mock.assignOp = unevalableConst(this.assignOp); - for (var key in this) { - if (this.hasOwnProperty(key) && !(key in TO_SOURCE_SKIP)) - mock[key] = this[key]; - } - return mock.toSource(); - }; - - // Always use push to add operands to an expression, to update start and end. - Np.push = function (kid) { - // kid can be null e.g. [1, , 2]. - if (kid !== null) { - if (kid.start < this.start) - this.start = kid.start; - if (this.end < kid.end) - this.end = kid.end; - } - return this.children.push(kid); - } - - Node.indentLevel = 0; - - function tokenString(tt) { - var t = definitions.tokens[tt]; - return /^\W/.test(t) ? definitions.opTypeNames[t] : t.toUpperCase(); - } - - Np.toString = function () { - var a = []; - for (var i in this) { - if (this.hasOwnProperty(i) && i !== 'type' && i !== 'target') - a.push({id: i, value: this[i]}); - } - a.sort(function (a,b) { return (a.id < b.id) ? -1 : 1; }); - const INDENTATION = " "; - var n = ++Node.indentLevel; - var s = "{\n" + INDENTATION.repeat(n) + "type: " + tokenString(this.type); - for (i = 0; i < a.length; i++) - s += ",\n" + INDENTATION.repeat(n) + a[i].id + ": " + a[i].value; - n = --Node.indentLevel; - s += "\n" + INDENTATION.repeat(n) + "}"; - return s; - } - - Np.getSource = function () { - return this.tokenizer.source.slice(this.start, this.end); - }; - - /* - * Helper init objects for common nodes. - */ - - const LOOP_INIT = { isLoop: true }; - - function blockInit() { - return { type: BLOCK, varDecls: [] }; - } - - function scriptInit() { - return { type: SCRIPT, - funDecls: [], - varDecls: [], - modDefns: new StringMap(), - modAssns: new StringMap(), - modDecls: new StringMap(), - modLoads: new StringMap(), - impDecls: [], - expDecls: [], - exports: new StringMap(), - hasEmptyReturn: false, - hasReturnWithValue: false, - isGenerator: false }; - } - - definitions.defineGetter(Np, "filename", - function() { - return this.tokenizer.filename; - }); - - definitions.defineGetter(Np, "length", - function() { - throw new Error("Node.prototype.length is gone; " + - "use n.children.length instead"); - }); - - definitions.defineProperty(String.prototype, "repeat", - function(n) { - var s = "", t = this + s; - while (--n >= 0) - s += t; - return s; - }, false, false, true); - - function MaybeLeftParen(t, x) { - if (x.parenFreeMode) - return t.match(LEFT_PAREN) ? LEFT_PAREN : END; - return t.mustMatch(LEFT_PAREN).type; - } - - function MaybeRightParen(t, p) { - if (p === LEFT_PAREN) - t.mustMatch(RIGHT_PAREN); - } - - /* - * Statements :: (tokenizer, compiler context, node) -> void - * - * Parses a sequence of Statements. - */ - function Statements(t, x, n) { - try { - while (!t.done && t.peek(true) !== RIGHT_CURLY) - n.push(Statement(t, x)); - } catch (e) { - if (t.done) - t.unexpectedEOF = true; - throw e; + pushDestructuringVarDecls(sub, s); } } +} - function Block(t, x) { - t.mustMatch(LEFT_CURLY); - var n = new Node(t, blockInit()); - Statements(t, x.update({ parentBlock: n }).pushTarget(n), n); - t.mustMatch(RIGHT_CURLY); - return n; - } +function Parser(tokenizer) { + tokenizer.parser = this; + this.t = tokenizer; + this.x = null; + this.unexpectedEOF = false; + options.mozillaMode && (this.mozillaMode = true); + options.parenFreeMode && (this.parenFreeMode = true); +} - const DECLARED_FORM = 0, EXPRESSED_FORM = 1, STATEMENT_FORM = 2; +function StaticContext(parentScript, parentBlock, inModule, inFunction, strictMode) { + this.parentScript = parentScript; + this.parentBlock = parentBlock || parentScript; + this.inModule = inModule || false; + this.inFunction = inFunction || false; + this.inForLoopInit = false; + this.topLevel = true; + this.allLabels = new Stack(); + this.currentLabels = new Stack(); + this.labeledTargets = new Stack(); + this.defaultLoopTarget = null; + this.defaultTarget = null; + this.strictMode = strictMode; +} - /* - * Export :: (binding node, boolean) -> Export - * - * Static semantic representation of a module export. - */ - function Export(node, isDefinition) { - this.node = node; // the AST node declaring this individual export - this.isDefinition = isDefinition; // is the node an 'export'-annotated definition? - this.resolved = null; // resolved pointer to the target of this export - } - - /* - * registerExport :: (StringMap, EXPORT node) -> void - */ - function registerExport(exports, decl) { - function register(name, exp) { - if (exports.has(name)) - throw new SyntaxError("multiple exports of " + name); - exports.set(name, exp); - } - - switch (decl.type) { - case MODULE: - case FUNCTION: - register(decl.name, new Export(decl, true)); - break; - - case VAR: - for (var i = 0; i < decl.children.length; i++) - register(decl.children[i].name, new Export(decl.children[i], true)); - break; - - case LET: - case CONST: - throw new Error("NYI: " + definitions.tokens[decl.type]); - - case EXPORT: - for (var i = 0; i < decl.pathList.length; i++) { - var path = decl.pathList[i]; - switch (path.type) { - case OBJECT_INIT: - for (var j = 0; j < path.children.length; j++) { - // init :: IDENTIFIER | PROPERTY_INIT - var init = path.children[j]; - if (init.type === IDENTIFIER) - register(init.value, new Export(init, false)); - else - register(init.children[0].value, new Export(init.children[1], false)); - } - break; - - case DOT: - register(path.children[1].value, new Export(path, false)); - break; - - case IDENTIFIER: - register(path.value, new Export(path, false)); - break; - - default: - throw new Error("unexpected export path: " + definitions.tokens[path.type]); - } +StaticContext.prototype = { + // non-destructive update via prototype extension + update: function(ext) { + var desc = {}; + for (var key in ext) { + desc[key] = { + value: ext[key], + writable: true, + enumerable: true, + configurable: true } - break; - - default: - throw new Error("unexpected export decl: " + definitions.tokens[exp.type]); } - } + return Object.create(this, desc); + }, + pushLabel: function(label) { + return this.update({ currentLabels: this.currentLabels.push(label), + allLabels: this.allLabels.push(label) }); + }, + pushTarget: function(target) { + var isDefaultLoopTarget = target.isLoop; + var isDefaultTarget = isDefaultLoopTarget || target.type === SWITCH; - /* - * Module :: (node) -> Module - * - * Static semantic representation of a module. - */ - function Module(node) { - var exports = node.body.exports; - var modDefns = node.body.modDefns; + if (this.currentLabels.isEmpty()) { + if (isDefaultLoopTarget) this.update({ defaultLoopTarget: target }); + if (isDefaultTarget) this.update({ defaultTarget: target }); + return this; + } - var exportedModules = new StringMap(); - - exports.forEach(function(name, exp) { - var node = exp.node; - if (node.type === MODULE) { - exportedModules.set(name, node); - } else if (!exp.isDefinition && node.type === IDENTIFIER && modDefns.has(node.value)) { - var mod = modDefns.get(node.value); - exportedModules.set(name, mod); - } + target.labels = new Dict(); + this.currentLabels.forEach(function(label) { + target.labels.set(label, true); }); + return this.update({ currentLabels: new Stack(), + labeledTargets: this.labeledTargets.push(target), + defaultLoopTarget: isDefaultLoopTarget + ? target + : this.defaultLoopTarget, + defaultTarget: isDefaultTarget + ? target + : this.defaultTarget }); + }, + nest: function() { + return this.topLevel ? this.update({ topLevel: false }) : this; + }, + canImport: function() { + return this.topLevel && !this.inFunction; + }, + canExport: function() { + return this.inModule && this.topLevel && !this.inFunction; + }, + banWith: function() { + return this.strictMode || this.inModule; + }, + modulesAllowed: function() { + return this.topLevel && !this.inFunction; + } +}; - this.node = node; - this.exports = exports; - this.exportedModules = exportedModules; +var Pp = Parser.prototype; + +Pp.mozillaMode = false; + +Pp.parenFreeMode = false; + +Pp.withContext = function(x, f) { + var x0 = this.x; + this.x = x; + var result = f.call(this); + // NB: we don't bother with finally, since exceptions trash the parser + this.x = x0; + return result; +}; + +Pp.newNode = function newNode(opts) { + return new Node(this.t, opts); +}; + +Pp.fail = function fail(msg) { + throw this.t.newSyntaxError(msg); +}; + +Pp.match = function match(tt, scanOperand, keywordIsName) { + return this.t.match(tt, scanOperand, keywordIsName); +}; + +Pp.mustMatch = function mustMatch(tt, keywordIsName) { + return this.t.mustMatch(tt, keywordIsName); +}; + +Pp.peek = function peek(scanOperand) { + return this.t.peek(scanOperand); +}; + +Pp.peekOnSameLine = function peekOnSameLine(scanOperand) { + return this.t.peekOnSameLine(scanOperand); +}; + +Pp.done = function done() { + return this.t.done; +}; + +/* + * Script :: (boolean, boolean, boolean) -> node + * + * Parses the toplevel and module/function bodies. + */ +Pp.Script = function Script(inModule, inFunction, expectEnd) { + var node = this.newNode(scriptInit()); + var x2 = new StaticContext(node, node, inModule, inFunction); + this.withContext(x2, function() { + this.Statements(node, true); + }); + if (expectEnd && !this.done()) + this.fail("expected end of input"); + return node; +}; + +/* + * Pragma :: (expression statement node) -> boolean + * + * Checks whether a node is a pragma and annotates it. + */ +function Pragma(n) { + if (n.type === SEMICOLON) { + var e = n.expression; + if (e.type === STRING && e.value === "use strict") { + n.pragma = "strict"; + return true; + } + } + return false; +} + +/* + * Node :: (tokenizer, optional init object) -> node + */ +function Node(t, init) { + var token = t.token; + if (token) { + // If init.type exists it will override token.type. + this.type = token.type; + this.value = token.value; + this.lineno = token.lineno; + + // Start and end are file positions for error handling. + this.start = token.start; + this.end = token.end; + } else { + this.lineno = t.lineno; } - /* - * Statement :: (tokenizer, compiler context) -> node - * - * Parses a Statement. - */ - function Statement(t, x) { - var i, label, n, n2, p, c, ss, tt = t.get(true), tt2, x2, x3; + this.filename = t.filename; + this.children = []; - var comments = t.blockComments; + for (var prop in init) + this[prop] = init[prop]; +} - if (x.blackList[tt]) - throw t.newSyntaxError(definitions.tokens[tt] + " statements only allowed in Harmony"); - if (!x.allow(tt)) - throw t.newSyntaxError(definitions.tokens[tt] + " statement in illegal context"); +/* + * SyntheticNode :: (optional init object) -> node + */ +function SyntheticNode(init) { + this.children = []; + for (var prop in init) + this[prop] = init[prop]; + this.synthetic = true; +} - // Cases for statements ending in a right curly return early, avoiding the - // common semicolon insertion magic after this switch. - switch (tt) { - case IMPORT: - n = new Node(t); - n.pathList = ImportPathList(t, x); - x.parentScript.impDecls.push(n); - break; +var Np = Node.prototype = SyntheticNode.prototype = {}; +Np.constructor = Node; - case EXPORT: - switch (t.peek()) { - case MODULE: - case FUNCTION: - case LET: - case VAR: - case CONST: - n = Statement(t, x); - n.blockComments = comments; - n.exported = true; - x.parentScript.expDecls.push(n); - registerExport(x.parentScript.exports, n); - return n; +var TO_SOURCE_SKIP = { + type: true, + value: true, + lineno: true, + start: true, + end: true, + tokenizer: true, + assignOp: true +}; +function unevalableConst(code) { + var token = definitions.tokens[code]; + var constName = definitions.opTypeNames.hasOwnProperty(token) + ? definitions.opTypeNames[token] + : token in definitions.keywords + ? token.toUpperCase() + : token; + return { toSource: function() { return constName } }; +} +Np.toSource = function toSource() { + var mock = {}; + var self = this; + mock.type = unevalableConst(this.type); + // avoid infinite recursion in case of back-links + if (this.generatingSource) + return mock.toSource(); + this.generatingSource = true; + if ("value" in this) + mock.value = this.value; + if ("lineno" in this) + mock.lineno = this.lineno; + if ("start" in this) + mock.start = this.start; + if ("end" in this) + mock.end = this.end; + if (this.assignOp) + mock.assignOp = unevalableConst(this.assignOp); + for (var key in this) { + if (this.hasOwnProperty(key) && !(key in TO_SOURCE_SKIP)) + mock[key] = this[key]; + } + try { + return mock.toSource(); + } finally { + delete this.generatingSource; + } +}; + +// Always use push to add operands to an expression, to update start and end. +Np.push = function (kid) { + // kid can be null e.g. [1, , 2]. + if (kid !== null) { + if (kid.start < this.start) + this.start = kid.start; + if (this.end < kid.end) + this.end = kid.end; + } + return this.children.push(kid); +} + +Node.indentLevel = 0; + +function tokenString(tt) { + var t = definitions.tokens[tt]; + return /^\W/.test(t) ? definitions.opTypeNames[t] : t.toUpperCase(); +} + +Np.toString = function () { + var a = []; + for (var i in this) { + if (this.hasOwnProperty(i) && i !== 'type' && i !== 'target') + a.push({id: i, value: this[i]}); + } + a.sort(function (a,b) { return (a.id < b.id) ? -1 : 1; }); + var INDENTATION = " "; + var n = ++Node.indentLevel; + var s = "{\n" + INDENTATION.repeat(n) + "type: " + tokenString(this.type); + for (i = 0; i < a.length; i++) + s += ",\n" + INDENTATION.repeat(n) + a[i].id + ": " + a[i].value; + n = --Node.indentLevel; + s += "\n" + INDENTATION.repeat(n) + "}"; + return s; +} + +Np.synth = function(init) { + var node = new SyntheticNode(init); + node.filename = this.filename; + node.lineno = this.lineno; + node.start = this.start; + node.end = this.end; + return node; +}; + +/* + * Helper init objects for common nodes. + */ + +var LOOP_INIT = { isLoop: true }; + +function blockInit() { + return { type: BLOCK, varDecls: [] }; +} + +function scriptInit() { + return { type: SCRIPT, + funDecls: [], + varDecls: [], + modDefns: new Dict(), + modAssns: new Dict(), + modDecls: new Dict(), + modLoads: new Dict(), + impDecls: [], + expDecls: [], + exports: new Dict(), + hasEmptyReturn: false, + hasReturnWithValue: false, + hasYield: false }; +} + +definitions.defineGetter(Np, "length", + function() { + throw new Error("Node.prototype.length is gone; " + + "use n.children.length instead"); + }); + +definitions.defineProperty(String.prototype, "repeat", + function(n) { + var s = "", t = this + s; + while (--n >= 0) + s += t; + return s; + }, false, false, true); + +Pp.MaybeLeftParen = function MaybeLeftParen() { + if (this.parenFreeMode) + return this.match(LEFT_PAREN) ? LEFT_PAREN : END; + return this.mustMatch(LEFT_PAREN).type; +}; + +Pp.MaybeRightParen = function MaybeRightParen(p) { + if (p === LEFT_PAREN) + this.mustMatch(RIGHT_PAREN); +} + +/* + * Statements :: (node[, boolean]) -> void + * + * Parses a sequence of Statements. + */ +Pp.Statements = function Statements(n, topLevel) { + var prologue = !!topLevel; + try { + while (!this.done() && this.peek(true) !== RIGHT_CURLY) { + var n2 = this.Statement(); + n.push(n2); + if (prologue && Pragma(n2)) { + this.x.strictMode = true; + n.strict = true; + } else { + prologue = false; + } + } + } catch (e) { + try { + if (this.done()) + this.unexpectedEOF = true; + } catch(e) {} + throw e; + } +} + +Pp.Block = function Block() { + this.mustMatch(LEFT_CURLY); + var n = this.newNode(blockInit()); + var x2 = this.x.update({ parentBlock: n }).pushTarget(n); + this.withContext(x2, function() { + this.Statements(n); + }); + this.mustMatch(RIGHT_CURLY); + return n; +} + +var DECLARED_FORM = 0, EXPRESSED_FORM = 1, STATEMENT_FORM = 2; + +/* + * Export :: (binding node, boolean) -> Export + * + * Static semantic representation of a module export. + */ +function Export(node, isDefinition) { + this.node = node; // the AST node declaring this individual export + this.isDefinition = isDefinition; // is the node an 'export'-annotated definition? + this.resolved = null; // resolved pointer to the target of this export +} + +/* + * registerExport :: (Dict, EXPORT node) -> void + */ +function registerExport(exports, decl) { + function register(name, exp) { + if (exports.has(name)) + throw new SyntaxError("multiple exports of " + name); + exports.set(name, exp); + } + + switch (decl.type) { + case MODULE: + case FUNCTION: + register(decl.name, new Export(decl, true)); + break; + + case VAR: + for (var i = 0; i < decl.children.length; i++) + register(decl.children[i].name, new Export(decl.children[i], true)); + break; + + case LET: + case CONST: + throw new Error("NYI: " + definitions.tokens[decl.type]); + + case EXPORT: + for (var i = 0; i < decl.pathList.length; i++) { + var path = decl.pathList[i]; + switch (path.type) { + case OBJECT_INIT: + for (var j = 0; j < path.children.length; j++) { + // init :: IDENTIFIER | PROPERTY_INIT + var init = path.children[j]; + if (init.type === IDENTIFIER) + register(init.value, new Export(init, false)); + else + register(init.children[0].value, new Export(init.children[1], false)); + } + break; + + case DOT: + register(path.children[1].value, new Export(path, false)); + break; + + case IDENTIFIER: + register(path.value, new Export(path, false)); + break; default: - n = new Node(t); - n.pathList = ExportPathList(t, x); - break; + throw new Error("unexpected export path: " + definitions.tokens[path.type]); } - x.parentScript.expDecls.push(n); - registerExport(x.parentScript.exports, n); - break; + } + break; + default: + throw new Error("unexpected export decl: " + definitions.tokens[exp.type]); + } +} + +/* + * Module :: (node) -> Module + * + * Static semantic representation of a module. + */ +function Module(node) { + var exports = node.body.exports; + var modDefns = node.body.modDefns; + + var exportedModules = new Dict(); + + exports.forEach(function(name, exp) { + var node = exp.node; + if (node.type === MODULE) { + exportedModules.set(name, node); + } else if (!exp.isDefinition && node.type === IDENTIFIER && modDefns.has(node.value)) { + var mod = modDefns.get(node.value); + exportedModules.set(name, mod); + } + }); + + this.node = node; + this.exports = exports; + this.exportedModules = exportedModules; +} + +/* + * Statement :: () -> node + * + * Parses a Statement. + */ +Pp.Statement = function Statement() { + var i, label, n, n2, p, c, ss, tt = this.t.get(true), tt2, x0, x2, x3; + + var comments = this.t.blockComments; + + // Cases for statements ending in a right curly return early, avoiding the + // common semicolon insertion magic after this switch. + switch (tt) { + case IMPORT: + if (!this.x.canImport()) + this.fail("illegal context for import statement"); + n = this.newNode(); + n.pathList = this.ImportPathList(); + this.x.parentScript.impDecls.push(n); + break; + + case EXPORT: + if (!this.x.canExport()) + this.fail("export statement not in module top level"); + switch (this.peek()) { case MODULE: - n = new Node(t); - n.blockComments = comments; - t.mustMatch(IDENTIFIER); - label = t.token.value; - - if (t.match(LEFT_CURLY)) { - n.name = label; - n.body = Script(t, true, false); - n.module = new Module(n); - t.mustMatch(RIGHT_CURLY); - x.parentScript.modDefns.set(n.name, n); - return n; - } - - t.unget(); - ModuleVariables(t, x, n); - return n; - case FUNCTION: - // DECLARED_FORM extends funDecls of x, STATEMENT_FORM doesn't. - return FunctionDefinition(t, x, true, x.topLevel ? DECLARED_FORM : STATEMENT_FORM, comments); - - case LEFT_CURLY: - n = new Node(t, blockInit()); - Statements(t, x.update({ parentBlock: n }).pushTarget(n).nest(), n); - t.mustMatch(RIGHT_CURLY); + case LET: + case VAR: + case CONST: + n = this.Statement(); + n.blockComments = comments; + n.exported = true; + this.x.parentScript.expDecls.push(n); + registerExport(this.x.parentScript.exports, n); return n; + } + n = this.newNode(); + n.pathList = this.ExportPathList(); + this.x.parentScript.expDecls.push(n); + registerExport(this.x.parentScript.exports, n); + break; - case IF: - n = new Node(t); - n.condition = HeadExpression(t, x); - x2 = x.pushTarget(n).nest(); - n.thenPart = Statement(t, x2); - n.elsePart = t.match(ELSE, true) ? Statement(t, x2) : null; - return n; + case FUNCTION: + // DECLARED_FORM extends funDecls of x, STATEMENT_FORM doesn't. + return this.FunctionDefinition(true, this.x.topLevel ? DECLARED_FORM : STATEMENT_FORM, comments); - case SWITCH: - // This allows CASEs after a DEFAULT, which is in the standard. - n = new Node(t, { cases: [], defaultIndex: -1 }); - n.discriminant = HeadExpression(t, x); - x2 = x.pushTarget(n).nest(); - t.mustMatch(LEFT_CURLY); - while ((tt = t.get()) !== RIGHT_CURLY) { + case LEFT_CURLY: + n = this.newNode(blockInit()); + x2 = this.x.update({ parentBlock: n }).pushTarget(n).nest(); + this.withContext(x2, function() { + this.Statements(n); + }); + this.mustMatch(RIGHT_CURLY); + return n; + + case IF: + n = this.newNode(); + n.condition = this.HeadExpression(); + x2 = this.x.pushTarget(n).nest(); + this.withContext(x2, function() { + n.thenPart = this.Statement(); + n.elsePart = this.match(ELSE, true) ? this.Statement() : null; + }); + return n; + + case SWITCH: + // This allows CASEs after a DEFAULT, which is in the standard. + n = this.newNode({ cases: [], defaultIndex: -1 }); + n.discriminant = this.HeadExpression(); + x2 = this.x.pushTarget(n).nest(); + this.withContext(x2, function() { + this.mustMatch(LEFT_CURLY); + while ((tt = this.t.get()) !== RIGHT_CURLY) { switch (tt) { case DEFAULT: if (n.defaultIndex >= 0) - throw t.newSyntaxError("More than one switch default"); + this.fail("More than one switch default"); // FALL THROUGH case CASE: - n2 = new Node(t); + n2 = this.newNode(); if (tt === DEFAULT) n.defaultIndex = n.cases.length; else - n2.caseLabel = Expression(t, x2, COLON); + n2.caseLabel = this.Expression(COLON); break; default: - throw t.newSyntaxError("Invalid switch case"); + this.fail("Invalid switch case"); } - t.mustMatch(COLON); - n2.statements = new Node(t, blockInit()); - while ((tt=t.peek(true)) !== CASE && tt !== DEFAULT && - tt !== RIGHT_CURLY) - n2.statements.push(Statement(t, x2)); + this.mustMatch(COLON); + n2.statements = this.newNode(blockInit()); + while ((tt=this.peek(true)) !== CASE && tt !== DEFAULT && + tt !== RIGHT_CURLY) + n2.statements.push(this.Statement()); n.cases.push(n2); } - return n; + }); + return n; - case FOR: - n = new Node(t, LOOP_INIT); - n.blockComments = comments; - if (t.match(IDENTIFIER)) { - if (t.token.value === "each") - n.isEach = true; - else - t.unget(); - } - if (!x.parenFreeMode) - t.mustMatch(LEFT_PAREN); - x2 = x.pushTarget(n).nest(); - x3 = x.update({ inForLoopInit: true }); - n2 = null; - if ((tt = t.peek(true)) !== SEMICOLON) { + case FOR: + n = this.newNode(LOOP_INIT); + n.blockComments = comments; + if (this.match(IDENTIFIER)) { + if (this.t.token.value === "each") + n.isEach = true; + else + this.t.unget(); + } + if (!this.parenFreeMode) + this.mustMatch(LEFT_PAREN); + x2 = this.x.pushTarget(n).nest(); + x3 = this.x.update({ inForLoopInit: true }); + n2 = null; + if ((tt = this.peek(true)) !== SEMICOLON) { + this.withContext(x3, function() { if (tt === VAR || tt === CONST) { - t.get(); - n2 = Variables(t, x3); + this.t.get(); + n2 = this.Variables(); } else if (tt === LET) { - t.get(); - if (t.peek() === LEFT_PAREN) { - n2 = LetBlock(t, x3, false); + this.t.get(); + if (this.peek() === LEFT_PAREN) { + n2 = this.LetBlock(false); } else { // Let in for head, we need to add an implicit block // around the rest of the for. - x3.parentBlock = n; + this.x.parentBlock = n; n.varDecls = []; - n2 = Variables(t, x3); + n2 = this.Variables(); } } else { - n2 = Expression(t, x3); + n2 = this.Expression(); } - } - if (n2 && t.match(IN)) { - n.type = FOR_IN; - n.object = Expression(t, x3); + }); + } + if (n2 && this.match(IN)) { + n.type = FOR_IN; + this.withContext(x3, function() { + n.object = this.Expression(); if (n2.type === VAR || n2.type === LET) { c = n2.children; @@ -7817,8 +7868,9 @@ define('ace/narcissus/jsparse', ['require', 'exports', 'module' , 'ace/narcissus // there must be only one destructuring or only one // decl. if (c.length !== 1 && n2.destructurings.length !== 1) { + // FIXME: this.fail ? throw new SyntaxError("Invalid for..in left-hand side", - t.filename, n2.lineno); + this.filename, n2.lineno); } if (n2.destructurings.length > 0) { n.iterator = n2.destructurings[0]; @@ -7828,1252 +7880,1364 @@ define('ace/narcissus/jsparse', ['require', 'exports', 'module' , 'ace/narcissus n.varDecl = n2; } else { if (n2.type === ARRAY_INIT || n2.type === OBJECT_INIT) { - n2.destructuredNames = checkDestructuring(t, x3, n2); + n2.destructuredNames = this.checkDestructuring(n2); } n.iterator = n2; } - } else { - x3.inForLoopInit = false; - n.setup = n2; - t.mustMatch(SEMICOLON); - if (n.isEach) - throw t.newSyntaxError("Invalid for each..in loop"); - n.condition = (t.peek(true) === SEMICOLON) - ? null - : Expression(t, x3); - t.mustMatch(SEMICOLON); - tt2 = t.peek(true); - n.update = (x.parenFreeMode + }); + } else { + x3.inForLoopInit = false; + n.setup = n2; + this.mustMatch(SEMICOLON); + if (n.isEach) + this.fail("Invalid for each..in loop"); + this.withContext(x3, function() { + n.condition = (this.peek(true) === SEMICOLON) + ? null + : this.Expression(); + this.mustMatch(SEMICOLON); + tt2 = this.peek(true); + n.update = (this.parenFreeMode ? tt2 === LEFT_CURLY || definitions.isStatementStartCode[tt2] : tt2 === RIGHT_PAREN) - ? null - : Expression(t, x3); + ? null + : this.Expression(); + }); + } + if (!this.parenFreeMode) + this.mustMatch(RIGHT_PAREN); + this.withContext(x2, function() { + n.body = this.Statement(); + }); + return n; + + case WHILE: + n = this.newNode({ isLoop: true }); + n.blockComments = comments; + n.condition = this.HeadExpression(); + x2 = this.x.pushTarget(n).nest(); + this.withContext(x2, function() { + n.body = this.Statement(); + }); + return n; + + case DO: + n = this.newNode({ isLoop: true }); + n.blockComments = comments; + x2 = this.x.pushTarget(n).next(); + this.withContext(x2, function() { + n.body = this.Statement(); + }); + this.mustMatch(WHILE); + n.condition = this.HeadExpression(); + //