From b204cd72366c343435616445b7aa6e5c66b529c1 Mon Sep 17 00:00:00 2001 From: Adam Jimenez Date: Wed, 29 Oct 2014 17:01:41 +0000 Subject: [PATCH 1/3] use mode delegates in PHP fixes #2197 --- lib/ace/mode/php.js | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/ace/mode/php.js b/lib/ace/mode/php.js index beeefda7..3bb2e6a5 100644 --- a/lib/ace/mode/php.js +++ b/lib/ace/mode/php.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -41,8 +41,11 @@ var WorkerClient = require("../worker/worker_client").WorkerClient; var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var unicode = require("../unicode"); +var HtmlMode = require("./html").Mode; +var JavaScriptMode = require("./javascript").Mode; +var CssMode = require("./css").Mode; -var Mode = function(opts) { +var PhpMode = function(opts) { this.inlinePhp = opts && opts.inline; var HighlightRules = this.inlinePhp ? PhpLangHighlightRules : PhpHighlightRules; this.HighlightRules = HighlightRules; @@ -50,7 +53,18 @@ var Mode = function(opts) { this.$behaviour = new CstyleBehaviour(); this.foldingRules = new CStyleFoldMode(); }; -oop.inherits(Mode, TextMode); +oop.inherits(PhpMode, TextMode); + +var Mode = function() { + HtmlMode.call(this); + this.HighlightRules = PhpHighlightRules; + this.createModeDelegates({ + "js-": JavaScriptMode, + "css-": CssMode, + "php-": PhpMode + }); +}; +oop.inherits(Mode, HtmlMode); (function() { @@ -60,7 +74,7 @@ oop.inherits(Mode, TextMode); + unicode.packages.Nd + unicode.packages.Pc + "\_]+", "g" ); - + this.nonTokenRe = new RegExp("^(?:[^" + unicode.packages.L + unicode.packages.Mn + unicode.packages.Mc @@ -68,7 +82,7 @@ oop.inherits(Mode, TextMode); + unicode.packages.Pc + "\_]|\s])+", "g" ); - + this.lineCommentStart = ["//", "#"]; this.blockComment = {start: "/*", end: "*/"}; @@ -106,17 +120,19 @@ oop.inherits(Mode, TextMode); }; this.checkOutdent = function(state, line, input) { - return this.$outdent.checkOutdent(line, input); + if (this.$outdent) + return this.$outdent.checkOutdent(line, input); }; this.autoOutdent = function(state, doc, row) { - this.$outdent.autoOutdent(doc, row); + if (this.$outdent) + this.$outdent.autoOutdent(doc, row); }; this.createWorker = function(session) { var worker = new WorkerClient(["ace"], "ace/mode/php_worker", "PhpWorker"); worker.attachToDocument(session.getDocument()); - + if (this.inlinePhp) worker.call("setOptions", [{inline: true}]); From 2bd2e3736795387597f28cb7ba017663113e6889 Mon Sep 17 00:00:00 2001 From: Adam Jimenez Date: Thu, 30 Oct 2014 01:52:38 +0000 Subject: [PATCH 2/3] fix php indentation --- lib/ace/mode/php.js | 88 +++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/lib/ace/mode/php.js b/lib/ace/mode/php.js index 3bb2e6a5..101cc3c0 100644 --- a/lib/ace/mode/php.js +++ b/lib/ace/mode/php.js @@ -55,6 +55,51 @@ var PhpMode = function(opts) { }; oop.inherits(PhpMode, TextMode); +(function() { + + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + + var tokenizedLine = this.getTokenizer().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; + } + } else if (state == "doc-start") { + if (endState != "doc-start") { + return ""; + } + var match = line.match(/^\s*(\/?)\*/); + if (match) { + if (match[1]) { + indent += " "; + } + indent += "* "; + } + } + + return indent; + }; + + this.checkOutdent = function(state, line, input) { + return this.$outdent.checkOutdent(line, input); + }; + + this.autoOutdent = function(state, doc, row) { + this.$outdent.autoOutdent(doc, row); + }; + + this.$id = "ace/mode/php-inline"; +}).call(PhpMode.prototype); + var Mode = function() { HtmlMode.call(this); this.HighlightRules = PhpHighlightRules; @@ -86,49 +131,6 @@ oop.inherits(Mode, HtmlMode); this.lineCommentStart = ["//", "#"]; this.blockComment = {start: "/*", end: "*/"}; - this.getNextLineIndent = function(state, line, tab) { - var indent = this.$getIndent(line); - - var tokenizedLine = this.getTokenizer().getLineTokens(line, state); - var tokens = tokenizedLine.tokens; - var endState = tokenizedLine.state; - - - if (tokens.length && tokens[tokens.length-1].type == "comment") { - return indent; - } - - if (state == "php-start") { - var match = line.match(/^.*[\{\(\[\:]\s*$/); - if (match) { - indent += tab; - } - } else if (state == "php-doc-start") { - if (endState != "php-doc-start") { - return ""; - } - var match = line.match(/^\s*(\/?)\*/); - if (match) { - if (match[1]) { - indent += " "; - } - indent += "* "; - } - } - - return indent; - }; - - this.checkOutdent = function(state, line, input) { - if (this.$outdent) - return this.$outdent.checkOutdent(line, input); - }; - - this.autoOutdent = function(state, doc, row) { - if (this.$outdent) - this.$outdent.autoOutdent(doc, row); - }; - this.createWorker = function(session) { var worker = new WorkerClient(["ace"], "ace/mode/php_worker", "PhpWorker"); worker.attachToDocument(session.getDocument()); From 366675a7a74ed341b9313b52e6b12f19aa0be510 Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 31 Oct 2014 15:08:44 +0400 Subject: [PATCH 3/3] fix inline php mode --- lib/ace/mode/php.js | 10 ++++--- lib/ace/mode/php_test.js | 65 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 lib/ace/mode/php_test.js diff --git a/lib/ace/mode/php.js b/lib/ace/mode/php.js index 101cc3c0..a44e79c6 100644 --- a/lib/ace/mode/php.js +++ b/lib/ace/mode/php.js @@ -46,9 +46,7 @@ var JavaScriptMode = require("./javascript").Mode; var CssMode = require("./css").Mode; var PhpMode = function(opts) { - this.inlinePhp = opts && opts.inline; - var HighlightRules = this.inlinePhp ? PhpLangHighlightRules : PhpHighlightRules; - this.HighlightRules = HighlightRules; + this.HighlightRules = PhpLangHighlightRules; this.$outdent = new MatchingBraceOutdent(); this.$behaviour = new CstyleBehaviour(); this.foldingRules = new CStyleFoldMode(); @@ -100,7 +98,11 @@ oop.inherits(PhpMode, TextMode); this.$id = "ace/mode/php-inline"; }).call(PhpMode.prototype); -var Mode = function() { +var Mode = function(opts) { + if (opts && opts.inline) { + PhpMode.call(this); + return; + } HtmlMode.call(this); this.HighlightRules = PhpHighlightRules; this.createModeDelegates({ diff --git a/lib/ace/mode/php_test.js b/lib/ace/mode/php_test.js new file mode 100644 index 00000000..9e86a304 --- /dev/null +++ b/lib/ace/mode/php_test.js @@ -0,0 +1,65 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +if (typeof process !== "undefined") { + require("amd-loader"); +} + +define(function(require, exports, module) { +"use strict"; + +var EditSession = require("../edit_session").EditSession; +var Tokenizer = require("../tokenizer").Tokenizer; +var Mode = require("./php").Mode; +var assert = require("../test/assertions"); + +module.exports = { + "test: inline mode" : function() { + var mode = new Mode(); + var tokenizer = mode.getTokenizer(); + var tokens = tokenizer.getLineTokens("'juhu kinners' ?> html html