Add XQuery tag completion.
This commit is contained in:
parent
c1ea00244d
commit
cbcec10164
3 changed files with 77 additions and 56 deletions
|
|
@ -1,66 +1,87 @@
|
||||||
/*
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
* eXide - web-based XQuery IDE
|
* Distributed under the BSD license:
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 Wolfgang Meier
|
* Copyright (c) 2010, Ajax.org B.V.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* it under the terms of the GNU General Public License as published by
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* * Redistributions of source code must retain the above copyright
|
||||||
* (at your option) any later version.
|
* 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 program is distributed in the hope that it will be useful,
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* GNU General Public License for more details.
|
* 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.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* ***** END LICENSE BLOCK ***** */
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var oop = require("../../lib/oop");
|
var oop = require("../../lib/oop");
|
||||||
var Behaviour = require('../behaviour').Behaviour;
|
var Behaviour = require('../behaviour').Behaviour;
|
||||||
var CstyleBehaviour = require('./cstyle').CstyleBehaviour;
|
var CstyleBehaviour = require('./cstyle').CstyleBehaviour;
|
||||||
|
var XmlBehaviour = require("../behaviour/xml").XmlBehaviour;
|
||||||
|
var TokenIterator = require("../../token_iterator").TokenIterator;
|
||||||
|
|
||||||
var XQueryBehaviour = function (parent) {
|
function hasType(token, type) {
|
||||||
|
var hasType = true;
|
||||||
|
var typeList = token.type.split('.');
|
||||||
|
var needleList = type.split('.');
|
||||||
|
needleList.forEach(function(needle){
|
||||||
|
if (typeList.indexOf(needle) == -1) {
|
||||||
|
hasType = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return hasType;
|
||||||
|
}
|
||||||
|
|
||||||
|
var XQueryBehaviour = function () {
|
||||||
|
|
||||||
this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour
|
this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour
|
||||||
this.parent = parent;
|
this.inherit(XmlBehaviour); // Get xml behaviour
|
||||||
|
|
||||||
// this.add("brackets", "insertion", function (state, action, editor, session, text) {
|
this.add("autoclosing", "insertion", function (state, action, editor, session, text) {
|
||||||
// if (text == "\n") {
|
if (text == '>') {
|
||||||
// var cursor = editor.getCursorPosition();
|
var position = editor.getCursorPosition();
|
||||||
// var line = session.doc.getLine(cursor.row);
|
var iterator = new TokenIterator(session, position.row, position.column);
|
||||||
// var rightChars = line.substring(cursor.column, cursor.column + 2);
|
var token = iterator.getCurrentToken();
|
||||||
// if (rightChars == '</') {
|
var atCursor = false;
|
||||||
// var indent = this.$getIndent(session.doc.getLine(cursor.row)) + session.getTabString();
|
if (!token || !hasType(token, 'meta.tag') && !(hasType(token, 'text') && token.value.match('/'))){
|
||||||
// var next_indent = this.$getIndent(session.doc.getLine(cursor.row));
|
do {
|
||||||
//
|
token = iterator.stepBackward();
|
||||||
// return {
|
} while (token && (hasType(token, 'string') || hasType(token, 'keyword.operator') || hasType(token, 'entity.attribute-name') || hasType(token, 'text')));
|
||||||
// text: '\n' + indent + '\n' + next_indent,
|
} else {
|
||||||
// selection: [1, indent.length, 1, indent.length]
|
atCursor = true;
|
||||||
// }
|
}
|
||||||
// }
|
if (!token || !hasType(token, 'meta.tag') || iterator.stepBackward().value.match('/')) {
|
||||||
// }
|
return
|
||||||
// return false;
|
}
|
||||||
// });
|
var tag = token.value.substring(1);
|
||||||
|
if (atCursor){
|
||||||
|
var tag = tag.substring(0, position.column - token.start);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
text: '>' + '</' + tag + '>',
|
||||||
|
selection: [1, 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Check for open tag if user enters / and auto-close it.
|
|
||||||
// this.add("slash", "insertion", function (state, action, editor, session, text) {
|
|
||||||
// if (text == "/") {
|
|
||||||
// var cursor = editor.getCursorPosition();
|
|
||||||
// var line = session.doc.getLine(cursor.row);
|
|
||||||
// if (cursor.column > 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);
|
oop.inherits(XQueryBehaviour, Behaviour);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,13 +35,13 @@ var oop = require("../lib/oop");
|
||||||
var TextMode = require("./text").Mode;
|
var TextMode = require("./text").Mode;
|
||||||
var XQueryLexer = require("./xquery/XQueryLexer").XQueryLexer;
|
var XQueryLexer = require("./xquery/XQueryLexer").XQueryLexer;
|
||||||
var Range = require("../range").Range;
|
var Range = require("../range").Range;
|
||||||
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
var XQueryBehaviour = require("./behaviour/xquery").XQueryBehaviour;
|
||||||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||||
|
|
||||||
|
|
||||||
var Mode = function(parent) {
|
var Mode = function(parent) {
|
||||||
this.$tokenizer = new XQueryLexer();
|
this.$tokenizer = new XQueryLexer();
|
||||||
this.$behaviour = new CstyleBehaviour(parent);
|
this.$behaviour = new XQueryBehaviour();
|
||||||
this.foldingRules = new CStyleFoldMode();
|
this.foldingRules = new CStyleFoldMode();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,11 +111,11 @@ define(function(require, exports, module){
|
||||||
].concat(ncnames),
|
].concat(ncnames),
|
||||||
StartTag: [
|
StartTag: [
|
||||||
{ name: "'>'", token: "meta.tag", next: function(stack){ stack.push("TagContent"); } },
|
{ name: "'>'", token: "meta.tag", next: function(stack){ stack.push("TagContent"); } },
|
||||||
{ name: "QName", token: "meta.tag" },
|
{ name: "QName", token: "entity.other.attribute-name" },
|
||||||
{ name: "'='", token: "text" },
|
{ name: "'='", token: "text" },
|
||||||
{ name: "''''", token: "string", next: function(stack){ stack.push("AposAttr"); } },
|
{ name: "''''", token: "string", next: function(stack){ stack.push("AposAttr"); } },
|
||||||
{ name: "'\"'", token: "string", next: function(stack){ stack.push("QuotAttr"); } },
|
{ name: "'\"'", token: "string", next: function(stack){ stack.push("QuotAttr"); } },
|
||||||
{ name: "'/>'", token: "meta.tag", next: function(stack){ stack.pop(); } }
|
{ name: "'/>'", token: "meta.tag.r", next: function(stack){ stack.pop(); } }
|
||||||
],
|
],
|
||||||
TagContent: [
|
TagContent: [
|
||||||
{ name: "ElementContentChar", token: "text" },
|
{ name: "ElementContentChar", token: "text" },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue