You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4736 lines
395 KiB
JavaScript

ace.define("ace/mode/xquery/xquery_lexer",["require","exports","module"], function(require, exports, module) {
module.exports = (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({
1:[function(_dereq_,module,exports){
var XQueryTokenizer = exports.XQueryTokenizer = function XQueryTokenizer(string, parsingEventHandler)
{
init(string, parsingEventHandler);
var self = this;
this.ParseException = function(b, e, s, o, x)
{
var
begin = b,
end = e,
state = s,
offending = o,
expected = x;
this.getBegin = function() {return begin;};
this.getEnd = function() {return end;};
this.getState = function() {return state;};
this.getExpected = function() {return expected;};
this.getOffending = function() {return offending;};
this.getMessage = function()
{
return offending < 0 ? "lexical analysis failed" : "syntax error";
};
};
function init(string, parsingEventHandler)
{
eventHandler = parsingEventHandler;
input = string;
size = string.length;
reset(0, 0, 0);
}
this.getInput = function()
{
return input;
};
function reset(l, b, e)
{
b0 = b; e0 = b;
l1 = l; b1 = b; e1 = e;
end = e;
eventHandler.reset(input);
}
this.getOffendingToken = function(e)
{
var o = e.getOffending();
return o >= 0 ? XQueryTokenizer.TOKEN[o] : null;
};
this.getExpectedTokenSet = function(e)
{
var expected;
if (e.getExpected() < 0)
{
expected = XQueryTokenizer.getTokenSet(- e.getState());
}
else
{
expected = [XQueryTokenizer.TOKEN[e.getExpected()]];
}
return expected;
};
this.getErrorMessage = function(e)
{
var tokenSet = this.getExpectedTokenSet(e);
var found = this.getOffendingToken(e);
var prefix = input.substring(0, e.getBegin());
var lines = prefix.split("\n");
var line = lines.length;
var column = lines[line - 1].length + 1;
var size = e.getEnd() - e.getBegin();
return e.getMessage()
+ (found == null ? "" : ", found " + found)
+ "\nwhile expecting "
+ (tokenSet.length == 1 ? tokenSet[0] : ("[" + tokenSet.join(", ") + "]"))
+ "\n"
+ (size == 0 || found != null ? "" : "after successfully scanning " + size + " characters beginning ")
+ "at line " + line + ", column " + column + ":\n..."
+ input.substring(e.getBegin(), Math.min(input.length, e.getBegin() + 64))
+ "...";
};
this.parse_start = function()
{
eventHandler.startNonterminal("start", e0);
lookahead1W(14); // ModuleDecl | Annotation | OptionDecl | Operator | Variable | Tag | AttrTest |
switch (l1)
{
case 55: // '<![CDATA['
shift(55); // '<![CDATA['
break;
case 54: // '<!--'
shift(54); // '<!--'
break;
case 56: // '<?'
shift(56); // '<?'
break;
case 40: // '(#'
shift(40); // '(#'
break;
case 42: // '(:~'
shift(42); // '(:~'
break;
case 41: // '(:'
shift(41); // '(:'
break;
case 35: // '"'
shift(35); // '"'
break;
case 38: // "'"
shift(38); // "'"
break;
case 274: // '}'
shift(274); // '}'
break;
case 271: // '{'
shift(271); // '{'
break;
case 39: // '('
shift(39); // '('
break;
case 43: // ')'
shift(43); // ')'
break;
case 49: // '/'
shift(49); // '/'
break;
case 62: // '['
shift(62); // '['
break;
case 63: // ']'
shift(63); // ']'
break;
case 46: // ','
shift(46); // ','
break;
case 48: // '.'
shift(48); // '.'
break;
case 53: // ';'
shift(53); // ';'
break;
case 51: // ':'
shift(51); // ':'
break;
case 34: // '!'
shift(34); // '!'
break;
case 273: // '|'
shift(273); // '|'
break;
case 2: // Annotation
shift(2); // Annotation
break;
case 1: // ModuleDecl
shift(1); // ModuleDecl
break;
case 3: // OptionDecl
shift(3); // OptionDecl
break;
case 12: // AttrTest
shift(12); // AttrTest
break;
case 13: // Wildcard
shift(13); // Wildcard
break;
case 15: // IntegerLiteral
shift(15); // IntegerLiteral
break;
case 16: // DecimalLiteral
shift(16); // DecimalLiteral
break;
case 17: // DoubleLiteral
shift(17); // DoubleLiteral
break;
case 5: // Variable
shift(5); // Variable
break;
case 6: // Tag
shift(6); // Tag
break;
case 4: // Operator
shift(4); // Operator
break;
case 33: // EOF
shift(33); // EOF
break;
default:
parse_EQName();
}
eventHandler.endNonterminal("start", e0);
};
this.parse_StartTag = function()
{
eventHandler.startNonterminal("StartTag", e0);
lookahead1W(8); // QName | S^WS | EOF | '"' | "'" | '/>' | '=' | '>'
switch (l1)
{
case 58: // '>'
shift(58); // '>'
break;
case 50: // '/>'
shift(50); // '/>'
break;
case 27: // QName
shift(27); // QName
break;
case 57: // '='
shift(57); // '='
break;
case 35: // '"'
shift(35); // '"'
break;
case 38: // "'"
shift(38); // "'"
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("StartTag", e0);
};
this.parse_TagContent = function()
{
eventHandler.startNonterminal("TagContent", e0);
lookahead1(11); // Tag | EndTag | PredefinedEntityRef | ElementContentChar | CharRef | EOF |
switch (l1)
{
case 23: // ElementContentChar
shift(23); // ElementContentChar
break;
case 6: // Tag
shift(6); // Tag
break;
case 7: // EndTag
shift(7); // EndTag
break;
case 55: // '<![CDATA['
shift(55); // '<![CDATA['
break;
case 54: // '<!--'
shift(54); // '<!--'
break;
case 18: // PredefinedEntityRef
shift(18); // PredefinedEntityRef
break;
case 29: // CharRef
shift(29); // CharRef
break;
case 272: // '{{'
shift(272); // '{{'
break;
case 275: // '}}'
shift(275); // '}}'
break;
case 271: // '{'
shift(271); // '{'
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("TagContent", e0);
};
this.parse_AposAttr = function()
{
eventHandler.startNonterminal("AposAttr", e0);
lookahead1(10); // PredefinedEntityRef | EscapeApos | AposAttrContentChar | CharRef | EOF | "'" |
switch (l1)
{
case 20: // EscapeApos
shift(20); // EscapeApos
break;
case 25: // AposAttrContentChar
shift(25); // AposAttrContentChar
break;
case 18: // PredefinedEntityRef
shift(18); // PredefinedEntityRef
break;
case 29: // CharRef
shift(29); // CharRef
break;
case 272: // '{{'
shift(272); // '{{'
break;
case 275: // '}}'
shift(275); // '}}'
break;
case 271: // '{'
shift(271); // '{'
break;
case 38: // "'"
shift(38); // "'"
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("AposAttr", e0);
};
this.parse_QuotAttr = function()
{
eventHandler.startNonterminal("QuotAttr", e0);
lookahead1(9); // PredefinedEntityRef | EscapeQuot | QuotAttrContentChar | CharRef | EOF | '"' |
switch (l1)
{
case 19: // EscapeQuot
shift(19); // EscapeQuot
break;
case 24: // QuotAttrContentChar
shift(24); // QuotAttrContentChar
break;
case 18: // PredefinedEntityRef
shift(18); // PredefinedEntityRef
break;
case 29: // CharRef
shift(29); // CharRef
break;
case 272: // '{{'
shift(272); // '{{'
break;
case 275: // '}}'
shift(275); // '}}'
break;
case 271: // '{'
shift(271); // '{'
break;
case 35: // '"'
shift(35); // '"'
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("QuotAttr", e0);
};
this.parse_CData = function()
{
eventHandler.startNonterminal("CData", e0);
lookahead1(1); // CDataSectionContents | EOF | ']]>'
switch (l1)
{
case 11: // CDataSectionContents
shift(11); // CDataSectionContents
break;
case 64: // ']]>'
shift(64); // ']]>'
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("CData", e0);
};
this.parse_XMLComment = function()
{
eventHandler.startNonterminal("XMLComment", e0);
lookahead1(0); // DirCommentContents | EOF | '-->'
switch (l1)
{
case 9: // DirCommentContents
shift(9); // DirCommentContents
break;
case 47: // '-->'
shift(47); // '-->'
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("XMLComment", e0);
};
this.parse_PI = function()
{
eventHandler.startNonterminal("PI", e0);
lookahead1(3); // DirPIContents | EOF | '?' | '?>'
switch (l1)
{
case 10: // DirPIContents
shift(10); // DirPIContents
break;
case 59: // '?'
shift(59); // '?'
break;
case 60: // '?>'
shift(60); // '?>'
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("PI", e0);
};
this.parse_Pragma = function()
{
eventHandler.startNonterminal("Pragma", e0);
lookahead1(2); // PragmaContents | EOF | '#' | '#)'
switch (l1)
{
case 8: // PragmaContents
shift(8); // PragmaContents
break;
case 36: // '#'
shift(36); // '#'
break;
case 37: // '#)'
shift(37); // '#)'
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("Pragma", e0);
};
this.parse_Comment = function()
{
eventHandler.startNonterminal("Comment", e0);
lookahead1(4); // CommentContents | EOF | '(:' | ':)'
switch (l1)
{
case 52: // ':)'
shift(52); // ':)'
break;
case 41: // '(:'
shift(41); // '(:'
break;
case 30: // CommentContents
shift(30); // CommentContents
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("Comment", e0);
};
this.parse_CommentDoc = function()
{
eventHandler.startNonterminal("CommentDoc", e0);
lookahead1(5); // DocTag | DocCommentContents | EOF | '(:' | ':)'
switch (l1)
{
case 31: // DocTag
shift(31); // DocTag
break;
case 32: // DocCommentContents
shift(32); // DocCommentContents
break;
case 52: // ':)'
shift(52); // ':)'
break;
case 41: // '(:'
shift(41); // '(:'
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("CommentDoc", e0);
};
this.parse_QuotString = function()
{
eventHandler.startNonterminal("QuotString", e0);
lookahead1(6); // PredefinedEntityRef | EscapeQuot | QuotChar | CharRef | EOF | '"'
switch (l1)
{
case 18: // PredefinedEntityRef
shift(18); // PredefinedEntityRef
break;
case 29: // CharRef
shift(29); // CharRef
break;
case 19: // EscapeQuot
shift(19); // EscapeQuot
break;
case 21: // QuotChar
shift(21); // QuotChar
break;
case 35: // '"'
shift(35); // '"'
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("QuotString", e0);
};
this.parse_AposString = function()
{
eventHandler.startNonterminal("AposString", e0);
lookahead1(7); // PredefinedEntityRef | EscapeApos | AposChar | CharRef | EOF | "'"
switch (l1)
{
case 18: // PredefinedEntityRef
shift(18); // PredefinedEntityRef
break;
case 29: // CharRef
shift(29); // CharRef
break;
case 20: // EscapeApos
shift(20); // EscapeApos
break;
case 22: // AposChar
shift(22); // AposChar
break;
case 38: // "'"
shift(38); // "'"
break;
default:
shift(33); // EOF
}
eventHandler.endNonterminal("AposString", e0);
};
this.parse_Prefix = function()
{
eventHandler.startNonterminal("Prefix", e0);
lookahead1W(13); // NCName^Token | S^WS | 'after' | 'allowing' | 'ancestor' | 'ancestor-or-self' |
whitespace();
parse_NCName();
eventHandler.endNonterminal("Prefix", e0);
};
this.parse__EQName = function()
{
eventHandler.startNonterminal("_EQName", e0);
lookahead1W(12); // EQName^Token | S^WS | 'after' | 'allowing' | 'ancestor' | 'ancestor-or-self' |
whitespace();
parse_EQName();
eventHandler.endNonterminal("_EQName", e0);
};
function parse_EQName()
{
eventHandler.startNonterminal("EQName", e0);
switch (l1)
{
case 77: // 'attribute'
shift(77); // 'attribute'
break;
case 91: // 'comment'
shift(91); // 'comment'
break;
case 115: // 'document-node'
shift(115); // 'document-node'
break;
case 116: // 'element'
shift(116); // 'element'
break;
case 119: // 'empty-sequence'
shift(119); // 'empty-sequence'
break;
case 140: // 'function'
shift(140); // 'function'
break;
case 147: // 'if'
shift(147); // 'if'
break;
case 160: // 'item'
shift(160); // 'item'
break;
case 180: // 'namespace-node'
shift(180); // 'namespace-node'
break;
case 186: // 'node'
shift(186); // 'node'
break;
case 211: // 'processing-instruction'
shift(211); // 'processing-instruction'
break;
case 221: // 'schema-attribute'
shift(221); // 'schema-attribute'
break;
case 222: // 'schema-element'
shift(222); // 'schema-element'
break;
case 238: // 'switch'
shift(238); // 'switch'
break;
case 239: // 'text'
shift(239); // 'text'
break;
case 248: // 'typeswitch'
shift(248); // 'typeswitch'
break;
default:
parse_FunctionName();
}
eventHandler.endNonterminal("EQName", e0);
}
function parse_FunctionName()
{
eventHandler.startNonterminal("FunctionName", e0);
switch (l1)
{
case 14: // EQName^Token
shift(14); // EQName^Token
break;
case 65: // 'after'
shift(65); // 'after'
break;
case 68: // 'ancestor'
shift(68); // 'ancestor'
break;
case 69: // 'ancestor-or-self'
shift(69); // 'ancestor-or-self'
break;
case 70: // 'and'
shift(70); // 'and'
break;
case 74: // 'as'
shift(74); // 'as'
break;
case 75: // 'ascending'
shift(75); // 'ascending'
break;
case 79: // 'before'
shift(79); // 'before'
break;
case 83: // 'case'
shift(83); // 'case'
break;
case 84: // 'cast'
shift(84); // 'cast'
break;
case 85: // 'castable'
shift(85); // 'castable'
break;
case 88: // 'child'
shift(88); // 'child'
break;
case 89: // 'collation'
shift(89); // 'collation'
break;
case 98: // 'copy'
shift(98); // 'copy'
break;
case 100: // 'count'
shift(100); // 'count'
break;
case 103: // 'declare'
shift(103); // 'declare'
break;
case 104: // 'default'
shift(104); // 'default'
break;
case 105: // 'delete'
shift(105); // 'delete'
break;
case 106: // 'descendant'
shift(106); // 'descendant'
break;
case 107: // 'descendant-or-self'
shift(107); // 'descendant-or-self'
break;
case 108: // 'descending'
shift(108); // 'descending'
break;
case 113: // 'div'
shift(113); // 'div'
break;
case 114: // 'document'
shift(114); // 'document'
break;
case 117: // 'else'
shift(117); // 'else'
break;
case 118: // 'empty'
shift(118); // 'empty'
break;
case 121: // 'end'
shift(121); // 'end'
break;
case 123: // 'eq'
shift(123); // 'eq'
break;
case 124: // 'every'
shift(124); // 'every'
break;
case 126: // 'except'
shift(126); // 'except'
break;
case 129: // 'first'
shift(129); // 'first'
break;
case 130: // 'following'
shift(130); // 'following'
break;
case 131: // 'following-sibling'
shift(131); // 'following-sibling'
break;
case 132: // 'for'
shift(132); // 'for'
break;
case 141: // 'ge'
shift(141); // 'ge'
break;
case 143: // 'group'
shift(143); // 'group'
break;
case 145: // 'gt'
shift(145); // 'gt'
break;
case 146: // 'idiv'
shift(146); // 'idiv'
break;
case 148: // 'import'
shift(148); // 'import'
break;
case 154: // 'insert'
shift(154); // 'insert'
break;
case 155: // 'instance'
shift(155); // 'instance'
break;
case 157: // 'intersect'
shift(157); // 'intersect'
break;
case 158: // 'into'
shift(158); // 'into'
break;
case 159: // 'is'
shift(159); // 'is'
break;
case 165: // 'last'
shift(165); // 'last'
break;
case 167: // 'le'
shift(167); // 'le'
break;
case 169: // 'let'
shift(169); // 'let'
break;
case 173: // 'lt'
shift(173); // 'lt'
break;
case 175: // 'mod'
shift(175); // 'mod'
break;
case 176: // 'modify'
shift(176); // 'modify'
break;
case 177: // 'module'
shift(177); // 'module'
break;
case 179: // 'namespace'
shift(179); // 'namespace'
break;
case 181: // 'ne'
shift(181); // 'ne'
break;
case 193: // 'only'
shift(193); // 'only'
break;
case 195: // 'or'
shift(195); // 'or'
break;
case 196: // 'order'
shift(196); // 'order'
break;
case 197: // 'ordered'
shift(197); // 'ordered'
break;
case 201: // 'parent'
shift(201); // 'parent'
break;
case 207: // 'preceding'
shift(207); // 'preceding'
break;
case 208: // 'preceding-sibling'
shift(208); // 'preceding-sibling'
break;
case 213: // 'rename'
shift(213); // 'rename'
break;
case 214: // 'replace'
shift(214); // 'replace'
break;
case 215: // 'return'
shift(215); // 'return'
break;
case 219: // 'satisfies'
shift(219); // 'satisfies'
break;
case 224: // 'self'
shift(224); // 'self'
break;
case 230: // 'some'
shift(230); // 'some'
break;
case 231: // 'stable'
shift(231); // 'stable'
break;
case 232: // 'start'
shift(232); // 'start'
break;
case 243: // 'to'
shift(243); // 'to'
break;
case 244: // 'treat'
shift(244); // 'treat'
break;
case 245: // 'try'
shift(245); // 'try'
break;
case 249: // 'union'
shift(249); // 'union'
break;
case 251: // 'unordered'
shift(251); // 'unordered'
break;
case 255: // 'validate'
shift(255); // 'validate'
break;
case 261: // 'where'
shift(261); // 'where'
break;
case 265: // 'with'
shift(265); // 'with'
break;
case 269: // 'xquery'
shift(269); // 'xquery'
break;
case 67: // 'allowing'
shift(67); // 'allowing'
break;
case 76: // 'at'
shift(76); // 'at'
break;
case 78: // 'base-uri'
shift(78); // 'base-uri'
break;
case 80: // 'boundary-space'
shift(80); // 'boundary-space'
break;
case 81: // 'break'
shift(81); // 'break'
break;
case 86: // 'catch'
shift(86); // 'catch'
break;
case 93: // 'construction'
shift(93); // 'construction'
break;
case 96: // 'context'
shift(96); // 'context'
break;
case 97: // 'continue'
shift(97); // 'continue'
break;
case 99: // 'copy-namespaces'
shift(99); // 'copy-namespaces'
break;
case 101: // 'decimal-format'
shift(101); // 'decimal-format'
break;
case 120: // 'encoding'
shift(120); // 'encoding'
break;
case 127: // 'exit'
shift(127); // 'exit'
break;
case 128: // 'external'
shift(128); // 'external'
break;
case 136: // 'ft-option'
shift(136); // 'ft-option'
break;
case 149: // 'in'
shift(149); // 'in'
break;
case 150: // 'index'
shift(150); // 'index'
break;
case 156: // 'integrity'
shift(156); // 'integrity'
break;
case 166: // 'lax'
shift(166); // 'lax'
break;
case 187: // 'nodes'
shift(187); // 'nodes'
break;
case 194: // 'option'
shift(194); // 'option'
break;
case 198: // 'ordering'
shift(198); // 'ordering'
break;
case 217: // 'revalidation'
shift(217); // 'revalidation'
break;
case 220: // 'schema'
shift(220); // 'schema'
break;
case 223: // 'score'
shift(223); // 'score'
break;
case 229: // 'sliding'
shift(229); // 'sliding'
break;
case 235: // 'strict'
shift(235); // 'strict'
break;
case 246: // 'tumbling'
shift(246); // 'tumbling'
break;
case 247: // 'type'
shift(247); // 'type'
break;
case 252: // 'updating'
shift(252); // 'updating'
break;
case 256: // 'value'
shift(256); // 'value'
break;
case 257: // 'variable'
shift(257); // 'variable'
break;
case 258: // 'version'
shift(258); // 'version'
break;
case 262: // 'while'
shift(262); // 'while'
break;
case 92: // 'constraint'
shift(92); // 'constraint'
break;
case 171: // 'loop'
shift(171); // 'loop'
break;
default:
shift(216); // 'returning'
}
eventHandler.endNonterminal("FunctionName", e0);
}
function parse_NCName()
{
eventHandler.startNonterminal("NCName", e0);
switch (l1)
{
case 26: // NCName^Token
shift(26); // NCName^Token
break;
case 65: // 'after'
shift(65); // 'after'
break;
case 70: // 'and'
shift(70); // 'and'
break;
case 74: // 'as'
shift(74); // 'as'
break;
case 75: // 'ascending'
shift(75); // 'ascending'
break;
case 79: // 'before'
shift(79); // 'before'
break;
case 83: // 'case'
shift(83); // 'case'
break;
case 84: // 'cast'
shift(84); // 'cast'
break;
case 85: // 'castable'
shift(85); // 'castable'
break;
case 89: // 'collation'
shift(89); // 'collation'
break;
case 100: // 'count'
shift(100); // 'count'
break;
case 104: // 'default'
shift(104); // 'default'
break;
case 108: // 'descending'
shift(108); // 'descending'
break;
case 113: // 'div'
shift(113); // 'div'
break;
case 117: // 'else'
shift(117); // 'else'
break;
case 118: // 'empty'
shift(118); // 'empty'
break;
case 121: // 'end'
shift(121); // 'end'
break;
case 123: // 'eq'
shift(123); // 'eq'
break;
case 126: // 'except'
shift(126); // 'except'
break;
case 132: // 'for'
shift(132); // 'for'
break;
case 141: // 'ge'
shift(141); // 'ge'
break;
case 143: // 'group'
shift(143); // 'group'
break;
case 145: // 'gt'
shift(145); // 'gt'
break;
case 146: // 'idiv'
shift(146); // 'idiv'
break;
case 155: // 'instance'
shift(155); // 'instance'
break;
case 157: // 'intersect'
shift(157); // 'intersect'
break;
case 158: // 'into'
shift(158); // 'into'
break;
case 159: // 'is'
shift(159); // 'is'
break;
case 167: // 'le'
shift(167); // 'le'
break;
case 169: // 'let'
shift(169); // 'let'
break;
case 173: // 'lt'
shift(173); // 'lt'
break;
case 175: // 'mod'
shift(175); // 'mod'
break;
case 176: // 'modify'
shift(176); // 'modify'
break;
case 181: // 'ne'
shift(181); // 'ne'
break;
case 193: // 'only'
shift(193); // 'only'
break;
case 195: // 'or'
shift(195); // 'or'
break;
case 196: // 'order'
shift(196); // 'order'
break;
case 215: // 'return'
shift(215); // 'return'
break;
case 219: // 'satisfies'
shift(219); // 'satisfies'
break;
case 231: // 'stable'
shift(231); // 'stable'
break;
case 232: // 'start'
shift(232); // 'start'
break;
case 243: // 'to'
shift(243); // 'to'
break;
case 244: // 'treat'
shift(244); // 'treat'
break;
case 249: // 'union'
shift(249); // 'union'
break;
case 261: // 'where'
shift(261); // 'where'
break;
case 265: // 'with'
shift(265); // 'with'
break;
case 68: // 'ancestor'
shift(68); // 'ancestor'
break;
case 69: // 'ancestor-or-self'
shift(69); // 'ancestor-or-self'
break;
case 77: // 'attribute'
shift(77); // 'attribute'
break;
case 88: // 'child'
shift(88); // 'child'
break;
case 91: // 'comment'
shift(91); // 'comment'
break;
case 98: // 'copy'
shift(98); // 'copy'
break;
case 103: // 'declare'
shift(103); // 'declare'
break;
case 105: // 'delete'
shift(105); // 'delete'
break;
case 106: // 'descendant'
shift(106); // 'descendant'
break;
case 107: // 'descendant-or-self'
shift(107); // 'descendant-or-self'
break;
case 114: // 'document'
shift(114); // 'document'
break;
case 115: // 'document-node'
shift(115); // 'document-node'
break;
case 116: // 'element'
shift(116); // 'element'
break;
case 119: // 'empty-sequence'
shift(119); // 'empty-sequence'
break;
case 124: // 'every'
shift(124); // 'every'
break;
case 129: // 'first'
shift(129); // 'first'
break;
case 130: // 'following'
shift(130); // 'following'
break;
case 131: // 'following-sibling'
shift(131); // 'following-sibling'
break;
case 140: // 'function'
shift(140); // 'function'
break;
case 147: // 'if'
shift(147); // 'if'
break;
case 148: // 'import'
shift(148); // 'import'
break;
case 154: // 'insert'
shift(154); // 'insert'
break;
case 160: // 'item'
shift(160); // 'item'
break;
case 165: // 'last'
shift(165); // 'last'
break;
case 177: // 'module'
shift(177); // 'module'
break;
case 179: // 'namespace'
shift(179); // 'namespace'
break;
case 180: // 'namespace-node'
shift(180); // 'namespace-node'
break;
case 186: // 'node'
shift(186); // 'node'
break;
case 197: // 'ordered'
shift(197); // 'ordered'
break;
case 201: // 'parent'
shift(201); // 'parent'
break;
case 207: // 'preceding'
shift(207); // 'preceding'
break;
case 208: // 'preceding-sibling'
shift(208); // 'preceding-sibling'
break;
case 211: // 'processing-instruction'
shift(211); // 'processing-instruction'
break;
case 213: // 'rename'
shift(213); // 'rename'
break;
case 214: // 'replace'
shift(214); // 'replace'
break;
case 221: // 'schema-attribute'
shift(221); // 'schema-attribute'
break;
case 222: // 'schema-element'
shift(222); // 'schema-element'
break;
case 224: // 'self'
shift(224); // 'self'
break;
case 230: // 'some'
shift(230); // 'some'
break;
case 238: // 'switch'
shift(238); // 'switch'
break;
case 239: // 'text'
shift(239); // 'text'
break;
case 245: // 'try'
shift(245); // 'try'
break;
case 248: // 'typeswitch'
shift(248); // 'typeswitch'
break;
case 251: // 'unordered'
shift(251); // 'unordered'
break;
case 255: // 'validate'
shift(255); // 'validate'
break;
case 257: // 'variable'
shift(257); // 'variable'
break;
case 269: // 'xquery'
shift(269); // 'xquery'
break;
case 67: // 'allowing'
shift(67); // 'allowing'
break;
case 76: // 'at'
shift(76); // 'at'
break;
case 78: // 'base-uri'
shift(78); // 'base-uri'
break;
case 80: // 'boundary-space'
shift(80); // 'boundary-space'
break;
case 81: // 'break'
shift(81); // 'break'
break;
case 86: // 'catch'
shift(86); // 'catch'
break;
case 93: // 'construction'
shift(93); // 'construction'
break;
case 96: // 'context'
shift(96); // 'context'
break;
case 97: // 'continue'
shift(97); // 'continue'
break;
case 99: // 'copy-namespaces'
shift(99); // 'copy-namespaces'
break;
case 101: // 'decimal-format'
shift(101); // 'decimal-format'
break;
case 120: // 'encoding'
shift(120); // 'encoding'
break;
case 127: // 'exit'
shift(127); // 'exit'
break;
case 128: // 'external'
shift(128); // 'external'
break;
case 136: // 'ft-option'
shift(136); // 'ft-option'
break;
case 149: // 'in'
shift(149); // 'in'
break;
case 150: // 'index'
shift(150); // 'index'
break;
case 156: // 'integrity'
shift(156); // 'integrity'
break;
case 166: // 'lax'
shift(166); // 'lax'
break;
case 187: // 'nodes'
shift(187); // 'nodes'
break;
case 194: // 'option'
shift(194); // 'option'
break;
case 198: // 'ordering'
shift(198); // 'ordering'
break;
case 217: // 'revalidation'
shift(217); // 'revalidation'
break;
case 220: // 'schema'
shift(220); // 'schema'
break;
case 223: // 'score'
shift(223); // 'score'
break;
case 229: // 'sliding'
shift(229); // 'sliding'
break;
case 235: // 'strict'
shift(235); // 'strict'
break;
case 246: // 'tumbling'
shift(246); // 'tumbling'
break;
case 247: // 'type'
shift(247); // 'type'
break;
case 252: // 'updating'
shift(252); // 'updating'
break;
case 256: // 'value'
shift(256); // 'value'
break;
case 258: // 'version'
shift(258); // 'version'
break;
case 262: // 'while'
shift(262); // 'while'
break;
case 92: // 'constraint'
shift(92); // 'constraint'
break;
case 171: // 'loop'
shift(171); // 'loop'
break;
default:
shift(216); // 'returning'
}
eventHandler.endNonterminal("NCName", e0);
}
function shift(t)
{
if (l1 == t)
{
whitespace();
eventHandler.terminal(XQueryTokenizer.TOKEN[l1], b1, e1 > size ? size : e1);
b0 = b1; e0 = e1; l1 = 0;
}
else
{
error(b1, e1, 0, l1, t);
}
}
function whitespace()
{
if (e0 != b1)
{
b0 = e0;
e0 = b1;
eventHandler.whitespace(b0, e0);
}
}
function matchW(set)
{
var code;
for (;;)
{
code = match(set);
if (code != 28) // S^WS
{
break;
}
}
return code;
}
function lookahead1W(set)
{
if (l1 == 0)
{
l1 = matchW(set);
b1 = begin;
e1 = end;
}
}
function lookahead1(set)
{
if (l1 == 0)
{
l1 = match(set);
b1 = begin;
e1 = end;
}
}
function error(b, e, s, l, t)
{
throw new self.ParseException(b, e, s, l, t);
}
var lk, b0, e0;
var l1, b1, e1;
var eventHandler;
var input;
var size;
var begin;
var end;
function match(tokenSetId)
{
var nonbmp = false;
begin = end;
var current = end;
var result = XQueryTokenizer.INITIAL[tokenSetId];
var state = 0;
for (var code = result & 4095; code != 0; )
{
var charclass;
var c0 = current < size ? input.charCodeAt(current) : 0;
++current;
if (c0 < 0x80)
{
charclass = XQueryTokenizer.MAP0[c0];
}
else if (c0 < 0xd800)
{
var c1 = c0 >> 4;
charclass = XQueryTokenizer.MAP1[(c0 & 15) + XQueryTokenizer.MAP1[(c1 & 31) + XQueryTokenizer.MAP1[c1 >> 5]]];
}
else
{
if (c0 < 0xdc00)
{
var c1 = current < size ? input.charCodeAt(current) : 0;
if (c1 >= 0xdc00 && c1 < 0xe000)
{
++current;
c0 = ((c0 & 0x3ff) << 10) + (c1 & 0x3ff) + 0x10000;
nonbmp = true;
}
}
var lo = 0, hi = 5;
for (var m = 3; ; m = (hi + lo) >> 1)
{
if (XQueryTokenizer.MAP2[m] > c0) hi = m - 1;
else if (XQueryTokenizer.MAP2[6 + m] < c0) lo = m + 1;
else {charclass = XQueryTokenizer.MAP2[12 + m]; break;}
if (lo > hi) {charclass = 0; break;}
}
}
state = code;
var i0 = (charclass << 12) + code - 1;
code = XQueryTokenizer.TRANSITION[(i0 & 15) + XQueryTokenizer.TRANSITION[i0 >> 4]];
if (code > 4095)
{
result = code;
code &= 4095;
end = current;
}
}
result >>= 12;
if (result == 0)
{
end = current - 1;
var c1 = end < size ? input.charCodeAt(end) : 0;
if (c1 >= 0xdc00 && c1 < 0xe000) --end;
return error(begin, end, state, -1, -1);
}
if (nonbmp)
{
for (var i = result >> 9; i > 0; --i)
{
--end;
var c1 = end < size ? input.charCodeAt(end) : 0;
if (c1 >= 0xdc00 && c1 < 0xe000) --end;
}
}
else
{
end -= result >> 9;
}
return (result & 511) - 1;
}
}
XQueryTokenizer.getTokenSet = function(tokenSetId)
{
var set = [];
var s = tokenSetId < 0 ? - tokenSetId : INITIAL[tokenSetId] & 4095;
for (var i = 0; i < 276; i += 32)
{
var j = i;
var i0 = (i >> 5) * 2062 + s - 1;
var i1 = i0 >> 2;
var i2 = i1 >> 2;
var f = XQueryTokenizer.EXPECTED[(i0 & 3) + XQueryTokenizer.EXPECTED[(i1 & 3) + XQueryTokenizer.EXPECTED[(i2 & 3) + XQueryTokenizer.EXPECTED[i2 >> 2]]]];
for ( ; f != 0; f >>>= 1, ++j)
{
if ((f & 1) != 0)
{
set.push(XQueryTokenizer.TOKEN[j]);
}
}
}
return set;
};
XQueryTokenizer.MAP0 =
[ 66, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 27, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 31, 31, 33, 31, 31, 31, 31, 31, 31, 34, 35, 36, 35, 31, 35, 37, 38, 39, 40, 41, 42, 43, 44, 45, 31, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 31, 61, 62, 63, 64, 35
];
XQueryTokenizer.MAP1 =
[ 108, 124, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 156, 181, 181, 181, 181, 181, 214, 215, 213, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 214, 247, 261, 277, 293, 309, 347, 363, 379, 416, 416, 416, 408, 331, 323, 331, 323, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 433, 433, 433, 433, 433, 433, 433, 316, 331, 331, 331, 331, 331, 331, 331, 331, 394, 416, 416, 417, 415, 416, 416, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 330, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 416, 66, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 27, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 35, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 31, 31, 33, 31, 31, 31, 31, 31, 31, 34, 35, 36, 35, 31, 35, 37, 38, 39, 40, 41, 42, 43, 44, 45, 31, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 31, 61, 62, 63, 64, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 31, 31, 35, 35, 35, 35, 35, 35, 35, 65, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65
];
XQueryTokenizer.MAP2 =
[ 57344, 63744, 64976, 65008, 65536, 983040, 63743, 64975, 65007, 65533, 983039, 1114111, 35, 31, 35, 31, 31, 35
];
XQueryTokenizer.INITIAL =
[ 1, 2, 36867, 45060, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
];
XQueryTokenizer.TRANSITION =
[ 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 22908, 18836, 17152, 19008, 19233, 20367, 19008, 17173, 30763, 36437, 17330, 17349, 18921, 17189, 17208, 17281, 20355, 17949, 17308, 17327, 17346, 18918, 17365, 21880, 18649, 18665, 19006, 17265, 22033, 20765, 17421, 20535, 17192, 18127, 21873, 17311, 18658, 18999, 19008, 17447, 17470, 17497, 17520, 17251, 36411, 17782, 20682, 17714, 18326, 17543, 17559, 17585, 21887, 17504, 17527, 17258, 36418, 18157, 21940, 17611, 36467, 18217, 17633, 17661, 21190, 17703, 21176, 17730, 34737, 21946, 17617, 36473, 18223, 36531, 17477, 19152, 17860, 17892, 17675, 17753, 17832, 17590, 21620, 17481, 17848, 17880, 18731, 17918, 36551, 17292, 17934, 17979, 18727, 18023, 36545, 18621, 18039, 18056, 18072, 18117, 18143, 18173, 18052, 18209, 18250, 18239, 18266, 17963, 18296, 18312, 18376, 17807, 36403, 19232, 17796, 17163, 30642, 18392, 17816, 32961, 17687, 18805, 18421, 18437, 18101, 17393, 18489, 18505, 18535, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 17590, 18579, 21711, 17152, 19008, 19233, 20367, 19008, 28684, 30763, 36437, 17330, 17349, 18921, 17189, 17208, 17281, 20355, 17949, 17308, 17327, 17346, 18918, 17365, 21880, 18649, 18665, 19006, 17265, 22033, 20765, 17421, 20535, 17192, 18127, 21873, 17311, 18658, 18999, 19008, 17447, 17470, 17497, 17520, 17251, 36411, 17782, 20682, 17714, 18326, 17543, 17559, 17585, 21887, 17504, 17527, 17258, 36418, 18157, 21940, 17611, 36467, 18217, 17633, 17661, 21190, 17703, 21176, 1
];
XQueryTokenizer.EXPECTED =
[ 290, 300, 304, 353, 296, 309, 305, 319, 315, 324, 328, 352, 354, 334, 338, 330, 320, 345, 349, 293, 358, 362, 341, 366, 312, 370, 374, 378, 382, 386, 390, 394, 398, 737, 402, 634, 439, 604, 634, 634, 634, 634, 408, 634, 634, 634, 404, 634, 634, 634, 457, 634, 634, 963, 634, 634, 413, 634, 634, 634, 634, 634, 634, 634, 663, 418, 422, 903, 902, 426, 431, 548, 634, 437, 521, 919, 443, 615, 409, 449, 455, 624, 731, 751, 634, 461, 465, 672, 470, 469, 474, 481, 485, 477, 489, 493, 629, 542, 497, 505, 603, 602, 991, 648, 510, 804, 634, 515, 958, 526, 525, 530, 768, 634, 546, 552, 711, 710, 593, 558, 562, 618, 566, 570, 574, 578, 582, 586, 590, 608, 612, 660, 822, 821, 634, 622, 596, 444, 628, 533, 724, 633, 640, 653, 647, 652, 536, 1008, 451, 450, 445, 657, 670, 676, 685, 689, 693, 697, 701, 704, 707, 715, 719, 798, 815, 634, 723, 762, 996, 634, 728, 969, 730, 735, 908, 634, 741, 679, 889, 511, 747, 634, 750, 755, 499, 666, 499, 501, 759, 772, 776, 780, 634, 787, 784, 797, 802, 809, 808, 427, 814, 1006, 517, 634, 519, 853, 634, 813, 850, 793, 634, 819, 826, 833, 832, 837, 843, 847, 857, 861, 863, 867, 871, 875, 879, 883, 643, 887, 539, 980, 979, 634, 893, 944, 634, 900, 896, 634, 907, 933, 506, 912, 917, 828, 433, 636, 635, 554, 961, 923, 930, 927, 937, 941, 634, 634, 634, 974, 948, 952, 985, 913, 968, 967, 743, 634, 973, 839, 634, 978, 599, 634, 984, 989, 765, 444, 995, 1000, 634, 1003, 790, 955, 1012, 681, 634, 634, 634, 634, 634, 414, 1016, 1020, 1024, 1085, 1027, 1090, 1090, 1046, 1080, 1137, 1108, 1215, 1049, 1032, 1039, 1085, 1085, 1085, 1085, 1058, 1062, 1068, 1085, 1086, 1090, 1090, 1091, 1072, 1064, 1107, 1090, 1090, 1090, 1118, 1123, 1138, 1078, 1074, 1084, 1085, 1085, 1085, 1087, 1090, 1062, 1052, 1060, 1114, 1062, 1104, 1085, 1085, 1090, 1090, 1028, 1122, 1063, 1128, 1139, 1127, 1158, 1085, 1085, 1151, 1090, 1090, 1090, 1095, 1090, 1132, 1073, 1136, 1143, 1061, 1150, 1085, 1155, 1098, 1101, 1146, 1162, 1169, 1101, 1185, 1151, 1090, 1110, 1173, 1054, 1087, 1109, 1177, 1165, 1089, 1204, 1184, 1107, 1189, 1193, 1088, 1197, 1180, 1201, 1208, 1042, 1212, 1219, 1223, 1227, 1231, 1235, 1245, 1777, 1527, 1686, 1686, 1238, 1686, 1254, 1686, 1686, 1686, 1294, 1669, 1686, 1686, 1686, 1322, 1625, 1534, 1268, 1624, 1275, 1281, 1443, 1292, 1300, 1686, 1686, 1686, 1350, 1826, 1306, 1686, 1686, 1240, 2032, 1317, 1321, 1686, 1686, 1253, 1686, 1326, 1686, 1686, 1686, 1418, 1709, 1446, 1686, 1686, 1686, 1492, 1686, 1295, 1447, 1686, 1686, 1258, 1686, 1736, 1686, 1686, 1520, 1355, 1686, 1288, 1348, 1361, 1686, 1359, 1686, 1364, 1498, 1368, 1302, 1362, 1381, 1389, 1395, 1486, 1686, 1371, 1377, 1370, 1686, 1375, 1382, 1384, 1402, 1408, 1385, 1383, 1619, 1413, 1423, 1428, 1433, 1686, 1686, 1270, 1686, 1338, 1686, 1440, 1686, 1686, 1686, 1499, 1465, 1686, 1686, 1686, 1639, 1473, 1884, 1686, 1686, 1293, 1864, 1686, 1686, 1296, 1321, 1483, 1686, 1686, 1686, 1646, 1686, 1748, 1496, 1686, 1418, 1675, 1686, 1418, 1702, 1686, 1418, 1981, 1686, 1429, 1409, 1427, 1504, 1692, 1686, 1686, 1313, 1448, 1651, 1508, 1686, 1686, 1340, 1686, 1903, 1686, 1686, 1435, 1513, 1686, 1283, 1287, 1519, 1686, 1524, 1363, 1568, 1938, 1539, 1566, 1579, 1479, 1533, 1538, 1553, 1544, 1552, 1557, 1563, 1574, 1557, 1583, 1589, 1590, 1759, 1594, 1603, 1607, 1611, 1686, 1436, 1514, 1686, 1434, 1656, 1686, 1434, 1680, 1686, 1453, 1686, 1686, 1686, 1559, 1617, 1686, 1770, 1418, 1623, 1769, 1629, 1686, 1515, 1335, 1686, 1285, 1686, 1671, 1921, 1650, 1686, 1686, 1344, 1308, 1666, 1686, 1686, 1686, 1659, 1685, 1686, 1686, 1686, 1686, 1241, 1686, 1686, 1844, 1691, 1686, 1630, 1977, 1970, 1362, 1686, 1686, 1686, 1693, 1698, 1686, 1686, 1686, 1697, 1686, 1764, 1715, 1686, 1634, 1638, 1686, 1599, 1585, 1686, 1271, 1686, 1269, 1686, 1721, 1686, 1686, 1354, 1686, 1801, 1686, 1799, 1686, 1640, 1686, 1686, 1461, 1686, 1686, 1732, 1686, 1944, 1686, 1740, 1686, 1746, 1415, 1396, 1686, 1598, 1547, 1417, 1597, 1416, 1577, 1546, 1397, 1577, 1547, 1548, 1570, 1398, 1753, 1686, 1652, 1509, 1686, 1686, 1686, 1757, 1686, 1419, 1686, 1763, 1418, 1768, 17
];
XQueryTokenizer.TOKEN =
[
"(0)",
"ModuleDecl",
"Annotation",
"OptionDecl",
"Operator",
"Variable",
"Tag",
"EndTag",
"PragmaContents",
"DirCommentContents",
"DirPIContents",
"CDataSectionContents",
"AttrTest",
"Wildcard",
"EQName",
"IntegerLiteral",
"DecimalLiteral",
"DoubleLiteral",
"PredefinedEntityRef",
"'\"\"'",
"EscapeApos",
"QuotChar",
"AposChar",
"ElementContentChar",
"QuotAttrContentChar",
"AposAttrContentChar",
"NCName",
"QName",
"S",
"CharRef",
"CommentContents",
"DocTag",
"DocCommentContents",
"EOF",
"'!'",
"'\"'",
"'#'",
"'#)'",
"''''",
"'('",
"'(#'",
"'(:'",
"'(:~'",
"')'",
"'*'",
"'*'",
"','",
"'-->'",
"'.'",
"'/'",
"'/>'",
"':'",
"':)'",
"';'",
"'<!--'",
"'<![CDATA['",
"'<?'",
"'='",
"'>'",
"'?'",
"'?>'",
"'NaN'",
"'['",
"']'",
"']]>'",
"'after'",
"'all'",
"'allowing'",
"'ancestor'",
"'ancestor-or-self'",
"'and'",
"'any'",
"'append'",
"'array'",
"'as'",
"'ascending'",
"'at'",
"'attribute'",
"'base-uri'",
"'before'",
"'boundary-space'",
"'break'",
"'by'",
"'case'",
"'cast'",
"'castable'",
"'catch'",
"'check'",
"'child'",
"'collation'",
"'collection'",
"'comment'",
"'constraint'",
"'construction'",
"'contains'",
"'content'",
"'context'",
"'continue'",
"'copy'",
"'copy-namespaces'",
"'count'",
"'decimal-format'",
"'decimal-separator'",
"'declare'",
"'default'",
"'delete'",
"'descendant'",
"'descendant-or-self'",
"'descending'",
"'diacritics'",
"'different'",
"'digit'",
"'distance'",
"'div'",
"'document'",
"'document-node'",
"'element'",
"'else'",
"'empty'",
"'empty-sequence'",
"'encoding'",
"'end'",
"'entire'",
"'eq'",
"'every'",
"'exactly'",
"'except'",
"'exit'",
"'external'",
"'first'",
"'following'",
"'following-sibling'",
"'for'",
"'foreach'",
"'foreign'",
"'from'",
"'ft-option'",
"'ftand'",
"'ftnot'",
"'ftor'",
"'function'",
"'ge'",
"'greatest'",
"'group'",
"'grouping-separator'",
"'gt'",
"'idiv'",
"'if'",
"'import'",
"'in'",
"'index'",
"'infinity'",
"'inherit'",
"'insensitive'",
"'insert'",
"'instance'",
"'integrity'",
"'intersect'",
"'into'",
"'is'",
"'item'",
"'json'",
"'json-item'",
"'key'",
"'language'",
"'last'",
"'lax'",
"'le'",
"'least'",
"'let'",
"'levels'",
"'loop'",
"'lowercase'",
"'lt'",
"'minus-sign'",
"'mod'",
"'modify'",
"'module'",
"'most'",
"'namespace'",
"'namespace-node'",
"'ne'",
"'next'",
"'no'",
"'no-inherit'",
"'no-preserve'",
"'node'",
"'nodes'",
"'not'",
"'object'",
"'occurs'",
"'of'",
"'on'",
"'only'",
"'option'",
"'or'",
"'order'",
"'ordered'",
"'ordering'",
"'paragraph'",
"'paragraphs'",
"'parent'",
"'pattern-separator'",
"'per-mille'",
"'percent'",
"'phrase'",
"'position'",
"'preceding'",
"'preceding-sibling'",
"'preserve'",
"'previous'",
"'processing-instruction'",
"'relationship'",
"'rename'",
"'replace'",
"'return'",
"'returning'",
"'revalidation'",
"'same'",
"'satisfies'",
"'schema'",
"'schema-attribute'",
"'schema-element'",
"'score'",
"'self'",
"'sensitive'",
"'sentence'",
"'sentences'",
"'skip'",
"'sliding'",
"'some'",
"'stable'",
"'start'",
"'stemming'",
"'stop'",
"'strict'",
"'strip'",
"'structured-item'",
"'switch'",
"'text'",
"'then'",
"'thesaurus'",
"'times'",
"'to'",
"'treat'",
"'try'",
"'tumbling'",
"'type'",
"'typeswitch'",
"'union'",
"'unique'",
"'unordered'",
"'updating'",
"'uppercase'",
"'using'",
"'validate'",
"'value'",
"'variable'",
"'version'",
"'weight'",
"'when'",
"'where'",
"'while'",
"'wildcards'",
"'window'",
"'with'",
"'without'",
"'word'",
"'words'",
"'xquery'",
"'zero-digit'",
"'{'",
"'{{'",
"'|'",
"'}'",
"'}}'"
];
},
{}],
2:[function(_dereq_,module,exports){
'use strict';
var XQueryTokenizer = _dereq_('./XQueryTokenizer').XQueryTokenizer;
var TokenHandler = function(code) {
var input = code;
this.tokens = [];
this.reset = function() {
input = input;
this.tokens = [];
};
this.startNonterminal = function() {};
this.endNonterminal = function() {};
this.terminal = function(name, begin, end) {
this.tokens.push({
name: name,
value: input.substring(begin, end)
});
};
this.whitespace = function(begin, end) {
this.tokens.push({
name: 'WS',
value: input.substring(begin, end)
});
};
};
var keys = 'after|ancestor|ancestor-or-self|and|as|ascending|attribute|before|case|cast|castable|child|collation|comment|copy|count|declare|default|delete|descendant|descendant-or-self|descending|div|document|document-node|element|else|empty|empty-sequence|end|eq|every|except|first|following|following-sibling|for|function|ge|group|gt|idiv|if|import|insert|instance|intersect|into|is|item|last|le|let|lt|mod|modify|module|namespace|namespace-node|ne|node|only|or|order|ordered|parent|preceding|preceding-sibling|processing-instruction|rename|replace|return|satisfies|schema-attribute|schema-element|self|some|stable|start|switch|text|to|treat|try|typeswitch|union|unordered|validate|where|with|xquery|contains|paragraphs|sentences|times|words|by|collectionreturn|variable|version|option|when|encoding|toswitch|catch|tumbling|sliding|window|at|using|stemming|collection|schema|while|on|nodes|index|external|then|in|updating|value|of|containsbreak|loop|continue|exit|returning|append|json|position|strict'.split('|');
var keywords = keys.map(function(val) { return { name: '\'' + val + '\'', token: 'keyword' }; });
var ncnames = keys.map(function(val) { return { name: '\'' + val + '\'', token: 'text', next: function(stack){ stack.pop(); } }; });
var cdata = 'constant.language';
var number = 'constant';
var xmlcomment = 'comment';
var pi = 'xml-pe';
var pragma = 'constant.buildin';
var n = function(name){
return '\'' + name + '\'';
};
var Rules = {
start: [
{ name: n('(#'), token: pragma, next: function(stack){ stack.push('Pragma'); } },
{ name: n('(:'), token: 'comment', next: function(stack){ stack.push('Comment'); } },
{ name: n('(:~'), token: 'comment.doc', next: function(stack){ stack.push('CommentDoc'); } },
{ name: n('<!--'), token: xmlcomment, next: function(stack){ stack.push('XMLComment'); } },
{ name: n('<?'), token: pi, next: function(stack) { stack.push('PI'); } },
{ name: n('\'\''), token: 'string', next: function(stack){ stack.push('AposString'); } },
{ name: n('"'), token: 'string', next: function(stack){ stack.push('QuotString'); } },
{ name: 'Annotation', token: 'support.function' },
{ name: 'ModuleDecl', token: 'keyword', next: function(stack){ stack.push('Prefix'); } },
{ name: 'OptionDecl', token: 'keyword', next: function(stack){ stack.push('_EQName'); } },
{ name: 'AttrTest', token: 'support.type' },
{ name: 'Variable', token: 'variable' },
{ name: n('<![CDATA['), token: cdata, next: function(stack){ stack.push('CData'); } },
{ name: 'IntegerLiteral', token: number },
{ name: 'DecimalLiteral', token: number },
{ name: 'DoubleLiteral', token: number },
{ name: 'Operator', token: 'keyword.operator' },
{ name: 'EQName', token: function(val) { return keys.indexOf(val) !== -1 ? 'keyword' : 'support.function'; } },
{ name: n('('), token: 'lparen' },
{ name: n(')'), token: 'rparen' },
{ name: 'Tag', token: 'meta.tag', next: function(stack){ stack.push('StartTag'); } },
{ name: n('}'), token: 'text', next: function(stack){ if(stack.length > 1) { stack.pop(); } } },
{ name: n('{'), token: 'text', next: function(stack){ stack.push('start'); } } //, next: function(stack){ if(stack.length > 1) { stack.pop(); } } }
].concat(keywords),
_EQName: [
{ name: 'EQName', token: 'text', next: function(stack) { stack.pop(); } }
].concat(ncnames),
Prefix: [
{ name: 'NCName', token: 'text', next: function(stack) { stack.pop(); } }
].concat(ncnames),
StartTag: [
{ name: n('>'), token: 'meta.tag', next: function(stack){ stack.push('TagContent'); } },
{ name: 'QName', token: 'entity.other.attribute-name' },
{ name: n('='), token: 'text' },
{ name: n('\'\''), token: 'string', next: function(stack){ stack.push('AposAttr'); } },
{ name: n('"'), token: 'string', next: function(stack){ stack.push('QuotAttr'); } },
{ name: n('/>'), token: 'meta.tag.r', next: function(stack){ stack.pop(); } }
],
TagContent: [
{ name: 'ElementContentChar', token: 'text' },
{ name: n('<![CDATA['), token: cdata, next: function(stack){ stack.push('CData'); } },
{ name: n('<!--'), token: xmlcomment, next: function(stack){ stack.push('XMLComment'); } },
{ name: 'Tag', token: 'meta.tag', next: function(stack){ stack.push('StartTag'); } },
{ name: 'PredefinedEntityRef', token: 'constant.language.escape' },
{ name: 'CharRef', token: 'constant.language.escape' },
{ name: n('{{'), token: 'text' },
{ name: n('}}'), token: 'text' },
{ name: n('{'), token: 'text', next: function(stack){ stack.push('start'); } },
{ name: 'EndTag', token: 'meta.tag', next: function(stack){ stack.pop(); stack.pop(); } }
],
AposAttr: [
{ name: n('\'\''), token: 'string', next: function(stack){ stack.pop(); } },
{ name: 'EscapeApos', token: 'constant.language.escape' },
{ name: 'AposAttrContentChar', token: 'string' },
{ name: 'PredefinedEntityRef', token: 'constant.language.escape' },
{ name: 'CharRef', token: 'constant.language.escape' },
{ name: n('{{'), token: 'string' },
{ name: n('}}'), token: 'string' },
{ name: n('{'), token: 'text', next: function(stack){ stack.push('start'); } }
],
QuotAttr: [
{ name: n('\"'), token: 'string', next: function(stack){ stack.pop(); } },
{ name: 'EscapeQuot', token: 'constant.language.escape' },
{ name: 'QuotAttrContentChar', token: 'string' },
{ name: 'PredefinedEntityRef', token: 'constant.language.escape' },
{ name: 'CharRef', token: 'constant.language.escape' },
{ name: n('{{'), token: 'string' },
{ name: n('}}'), token: 'string' },
{ name: n('{'), token: 'text', next: function(stack){ stack.push('start'); } }
],
Pragma: [
{ name: 'PragmaContents', token: pragma },
{ name: n('#'), token: pragma },
{ name: n('#)'), token: pragma, next: function(stack){ stack.pop(); } }
],
Comment: [
{ name: 'CommentContents', token: 'comment' },
{ name: n('(:'), token: 'comment', next: function(stack){ stack.push('Comment'); } },
{ name: n(':)'), token: 'comment', next: function(stack){ stack.pop(); } }
],
CommentDoc: [
{ name: 'DocCommentContents', token: 'comment.doc' },
{ name: 'DocTag', token: 'comment.doc.tag' },
{ name: n('(:'), token: 'comment.doc', next: function(stack){ stack.push('CommentDoc'); } },
{ name: n(':)'), token: 'comment.doc', next: function(stack){ stack.pop(); } }
],
XMLComment: [
{ name: 'DirCommentContents', token: xmlcomment },
{ name: n('-->'), token: xmlcomment, next: function(stack){ stack.pop(); } }
],
CData: [
{ name: 'CDataSectionContents', token: cdata },
{ name: n(']]>'), token: cdata, next: function(stack){ stack.pop(); } }
],
PI: [
{ name: 'DirPIContents', token: pi },
{ name: n('?'), token: pi },
{ name: n('?>'), token: pi, next: function(stack){ stack.pop(); } }
],
AposString: [
{ name: n('\'\''), token: 'string', next: function(stack){ stack.pop(); } },
{ name: 'PredefinedEntityRef', token: 'constant.language.escape' },
{ name: 'CharRef', token: 'constant.language.escape' },
{ name: 'EscapeApos', token: 'constant.language.escape' },
{ name: 'AposChar', token: 'string' }
],
QuotString: [
{ name: n('"'), token: 'string', next: function(stack){ stack.pop(); } },
{ name: 'PredefinedEntityRef', token: 'constant.language.escape' },
{ name: 'CharRef', token: 'constant.language.escape' },
{ name: 'EscapeQuot', token: 'constant.language.escape' },
{ name: 'QuotChar', token: 'string' }
]
};
exports.XQueryLexer = function() {
this.tokens = [];
this.getLineTokens = function(line, state, row) {
state = (state === 'start' || !state) ? '["start"]' : state;
var stack = JSON.parse(state);
var h = new TokenHandler(line);
var tokenizer = new XQueryTokenizer(line, h);
var tokens = [];
while(true) {
var currentState = stack[stack.length - 1];
try {
h.tokens = [];
tokenizer['parse_' + currentState]();
var info = null;
if(h.tokens.length > 1 && h.tokens[0].name === 'WS') {
tokens.push({
type: 'text',
value: h.tokens[0].value
});
h.tokens.splice(0, 1);
}
var token = h.tokens[0];
var rules = Rules[currentState];
for(var k = 0; k < rules.length; k++) {
var rule = Rules[currentState][k];
if((typeof(rule.name) === 'function' && rule.name(token)) || rule.name === token.name) {
info = rule;
break;
}
}
if(token.name === 'EOF') { break; }
if(token.value === '') { throw 'Encountered empty string lexical rule.'; }
tokens.push({
type: info === null ? 'text' : (typeof(info.token) === 'function' ? info.token(token.value) : info.token),
value: token.value
});
if(info && info.next) {
info.next(stack);
}
} catch(e) {
if(e instanceof tokenizer.ParseException) {
var index = 0;
for(var i=0; i < tokens.length; i++) {
index += tokens[i].value.length;
}
tokens.push({ type: 'text', value: line.substring(index) });
return {
tokens: tokens,
state: JSON.stringify(['start'])
};
} else {
throw e;
}
}
}
if(this.tokens[row] !== undefined) {
var cachedLine = this.lines[row];
var begin = sharedStart([line, cachedLine]);
var diff = cachedLine.length - line.length;
var idx = 0;
var col = 0;
for(var i = 0; i < tokens.length; i++) {
var t = tokens[i];
for(var j = 0; j < this.tokens[row].length; j++) {
var semanticToken = this.tokens[row][j];
if(
((col + t.value.length) <= begin.length && semanticToken.sc === col && semanticToken.ec === (col + t.value.length)) ||
(semanticToken.sc === (col + diff) && semanticToken.ec === (col + t.value.length + diff))
) {
idx = i;
t.type = semanticToken.type;
}
}
col += t.value.length;
}
}
return {
tokens: tokens,
state: JSON.stringify(stack)
};
};
function sharedStart(A) {
A = A.slice(0).sort();
var tem1, tem2, s;
tem1 = A[0];
s = tem1.length;
tem2 = A.pop();
while(s && tem2.indexOf(tem1) === -1) {
tem1 = tem1.substring(0, --s);
}
return tem1;
}
};
},
{"./XQueryTokenizer":1}]},{},[2])
(2)
});
ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
"use strict";
var oop = require("../../lib/oop");
var Behaviour = require("../behaviour").Behaviour;
var TokenIterator = require("../../token_iterator").TokenIterator;
var lang = require("../../lib/lang");
var SAFE_INSERT_IN_TOKENS =
["text", "paren.rparen", "punctuation.operator"];
var SAFE_INSERT_BEFORE_TOKENS =
["text", "paren.rparen", "punctuation.operator", "comment"];
var context;
var contextCache = {}
var initContext = function(editor) {
var id = -1;
if (editor.multiSelect) {
id = editor.selection.id;
if (contextCache.rangeCount != editor.multiSelect.rangeCount)
contextCache = {rangeCount: editor.multiSelect.rangeCount};
}
if (contextCache[id])
return context = contextCache[id];
context = contextCache[id] = {
autoInsertedBrackets: 0,
autoInsertedRow: -1,
autoInsertedLineEnd: "",
maybeInsertedBrackets: 0,
maybeInsertedRow: -1,
maybeInsertedLineStart: "",
maybeInsertedLineEnd: ""
};
};
var CstyleBehaviour = function() {
this.add("braces", "insertion", function(state, action, editor, session, text) {
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
if (text == '{') {
initContext(editor);
var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection);
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
return {
text: '{' + selected + '}',
selection: false
};
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
CstyleBehaviour.recordAutoInsert(editor, session, "}");
return {
text: '{}',
selection: [1, 1]
};
} else {
CstyleBehaviour.recordMaybeInsert(editor, session, "{");
return {
text: '{',
selection: [1, 1]
};
}
}
} else if (text == '}') {
initContext(editor);
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 && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
CstyleBehaviour.popAutoInsertedClosing();
return {
text: '',
selection: [1, 1]
};
}
}
} else if (text == "\n" || text == "\r\n") {
initContext(editor);
var closing = "";
if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
CstyleBehaviour.clearMaybeInsertedClosing();
}
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 next_indent = this.$getIndent(session.getLine(openBracePos.row));
} else if (closing) {
var next_indent = this.$getIndent(line);
} else {
CstyleBehaviour.clearMaybeInsertedClosing();
return;
}
var indent = next_indent + session.getTabString();
return {
text: '\n' + indent + '\n' + next_indent + closing,
selection: [1, indent.length, 1, indent.length]
};
} else {
CstyleBehaviour.clearMaybeInsertedClosing();
}
});
this.add("braces", "deletion", function(state, action, editor, session, range) {
var selected = session.doc.getTextRange(range);
if (!range.isMultiLine() && selected == '{') {
initContext(editor);
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;
} else {
context.maybeInsertedBrackets--;
}
}
});
this.add("parens", "insertion", function(state, action, editor, session, text) {
if (text == '(') {
initContext(editor);
var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection);
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
return {
text: '(' + selected + ')',
selection: false
};
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
CstyleBehaviour.recordAutoInsert(editor, session, ")");
return {
text: '()',
selection: [1, 1]
};
}
} else if (text == ')') {
initContext(editor);
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 && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
CstyleBehaviour.popAutoInsertedClosing();
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 == '(') {
initContext(editor);
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("brackets", "insertion", function(state, action, editor, session, text) {
if (text == '[') {
initContext(editor);
var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection);
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
return {
text: '[' + selected + ']',
selection: false
};
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
CstyleBehaviour.recordAutoInsert(editor, session, "]");
return {
text: '[]',
selection: [1, 1]
};
}
} else if (text == ']') {
initContext(editor);
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 && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
CstyleBehaviour.popAutoInsertedClosing();
return {
text: '',
selection: [1, 1]
};
}
}
}
});
this.add("brackets", "deletion", function(state, action, editor, session, range) {
var selected = session.doc.getTextRange(range);
if (!range.isMultiLine() && selected == '[') {
initContext(editor);
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 == "'") {
initContext(editor);
var quote = text;
var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection);
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
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);
if (leftChar == '\\') {
return null;
}
var tokens = session.getTokens(selection.start.row);
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;
}
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)))) {
if (!CstyleBehaviour.isSaneInsertion(editor, session))
return;
return {
text: quote + quote,
selection: [1,1]
};
} else if (token && token.type === "string") {
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 == "'")) {
initContext(editor);
var line = session.doc.getLine(range.start.row);
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
if (rightChar == selected) {
range.end.column++;
return range;
}
}
});
};
CstyleBehaviour.isSaneInsertion = function(editor, session) {
var cursor = editor.getCursorPosition();
var iterator = new TokenIterator(session, cursor.row, cursor.column);
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
return false;
}
iterator.stepForward();
return iterator.getCurrentTokenRow() !== cursor.row ||
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
};
CstyleBehaviour.$matchTokenType = function(token, types) {
return types.indexOf(token.type || token) > -1;
};
CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
context.autoInsertedBrackets = 0;
context.autoInsertedRow = cursor.row;
context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
context.autoInsertedBrackets++;
};
CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
if (!this.isMaybeInsertedClosing(cursor, line))
context.maybeInsertedBrackets = 0;
context.maybeInsertedRow = cursor.row;
context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
context.maybeInsertedLineEnd = line.substr(cursor.column);
context.maybeInsertedBrackets++;
};
CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
return context.autoInsertedBrackets > 0 &&
cursor.row === context.autoInsertedRow &&
bracket === context.autoInsertedLineEnd[0] &&
line.substr(cursor.column) === context.autoInsertedLineEnd;
};
CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
return context.maybeInsertedBrackets > 0 &&
cursor.row === context.maybeInsertedRow &&
line.substr(cursor.column) === context.maybeInsertedLineEnd &&
line.substr(0, cursor.column) == context.maybeInsertedLineStart;
};
CstyleBehaviour.popAutoInsertedClosing = function() {
context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
context.autoInsertedBrackets--;
};
CstyleBehaviour.clearMaybeInsertedClosing = function() {
if (context) {
context.maybeInsertedBrackets = 0;
context.maybeInsertedRow = -1;
}
};
oop.inherits(CstyleBehaviour, Behaviour);
exports.CstyleBehaviour = CstyleBehaviour;
});
ace.define("ace/mode/behaviour/xml",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator"], function(require, exports, module) {
"use strict";
var oop = require("../../lib/oop");
var Behaviour = require("../behaviour").Behaviour;
var TokenIterator = require("../../token_iterator").TokenIterator;
function is(token, type) {
return token.type.lastIndexOf(type + ".xml") > -1;
}
var XmlBehaviour = function () {
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
if (text == '"' || text == "'") {
var quote = text;
var selected = session.doc.getTextRange(editor.getSelectionRange());
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
return {
text: quote + selected + quote,
selection: false
};
}
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
var rightChar = line.substring(cursor.column, cursor.column + 1);
var iterator = new TokenIterator(session, cursor.row, cursor.column);
var token = iterator.getCurrentToken();
if (rightChar == quote && (is(token, "attribute-value") || is(token, "string"))) {
return {
text: "",
selection: [1, 1]
};
}
if (!token)
token = iterator.stepBackward();
if (!token)
return;
while (is(token, "tag-whitespace") || is(token, "whitespace")) {
token = iterator.stepBackward();
}
var rightSpace = !rightChar || rightChar.match(/\s/);
if (is(token, "attribute-equals") && (rightSpace || rightChar == '>') || (is(token, "decl-attribute-equals") && (rightSpace || rightChar == '?'))) {
return {
text: quote + quote,
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 == selected) {
range.end.column++;
return range;
}
}
});
this.add("autoclosing", "insertion", function (state, action, editor, session, text) {
if (text == '>') {
var position = editor.getCursorPosition();
var iterator = new TokenIterator(session, position.row, position.column);
var token = iterator.getCurrentToken() || iterator.stepBackward();
if (!token || !(is(token, "tag-name") || is(token, "tag-whitespace") || is(token, "attribute-name") || is(token, "attribute-equals") || is(token, "attribute-value")))
return;
if (is(token, "reference.attribute-value"))
return;
if (is(token, "attribute-value")) {
var firstChar = token.value.charAt(0);
if (firstChar == '"' || firstChar == "'") {
var lastChar = token.value.charAt(token.value.length - 1);
var tokenEnd = iterator.getCurrentTokenColumn() + token.value.length;
if (tokenEnd > position.column || tokenEnd == position.column && firstChar != lastChar)
return;
}
}
while (!is(token, "tag-name")) {
token = iterator.stepBackward();
}
var tokenRow = iterator.getCurrentTokenRow();
var tokenColumn = iterator.getCurrentTokenColumn();
if (is(iterator.stepBackward(), "end-tag-open"))
return;
var element = token.value;
if (tokenRow == position.row)
element = element.substring(0, position.column - tokenColumn);
if (this.voidElements.hasOwnProperty(element.toLowerCase()))
return;
return {
text: '>' + '</' + element + '>',
selection: [1, 1]
};
}
});
this.add('autoindent', 'insertion', function (state, action, editor, session, text) {
if (text == "\n") {
var cursor = editor.getCursorPosition();
var line = session.getLine(cursor.row);
var rightChars = line.substring(cursor.column, cursor.column + 2);
if (rightChars == '</') {
var next_indent = this.$getIndent(line);
var indent = next_indent + session.getTabString();
return {
text: '\n' + indent + '\n' + next_indent,
selection: [1, indent.length, 1, indent.length]
};
}
}
});
};
oop.inherits(XmlBehaviour, Behaviour);
exports.XmlBehaviour = XmlBehaviour;
});
ace.define("ace/mode/behaviour/xquery",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/mode/behaviour/cstyle","ace/mode/behaviour/xml","ace/token_iterator"], function(require, exports, module) {
"use strict";
var oop = require("../../lib/oop");
var Behaviour = require('../behaviour').Behaviour;
var CstyleBehaviour = require('./cstyle').CstyleBehaviour;
var XmlBehaviour = require("../behaviour/xml").XmlBehaviour;
var TokenIterator = require("../../token_iterator").TokenIterator;
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(XmlBehaviour); // Get xml behaviour
this.add("autoclosing", "insertion", function (state, action, editor, session, text) {
if (text == '>') {
var position = editor.getCursorPosition();
var iterator = new TokenIterator(session, position.row, position.column);
var token = iterator.getCurrentToken();
var atCursor = false;
var state = JSON.parse(state).pop();
if ((token && token.value === '>') || state !== "StartTag") return;
if (!token || !hasType(token, 'meta.tag') && !(hasType(token, 'text') && token.value.match('/'))){
do {
token = iterator.stepBackward();
} while (token && (hasType(token, 'string') || hasType(token, 'keyword.operator') || hasType(token, 'entity.attribute-name') || hasType(token, 'text')));
} else {
atCursor = true;
}
var previous = iterator.stepBackward();
if (!token || !hasType(token, 'meta.tag') || (previous !== null && previous.value.match('/'))) {
return
}
var tag = token.value.substring(1);
if (atCursor){
var tag = tag.substring(0, position.column - token.start);
}
return {
text: '>' + '</' + tag + '>',
selection: [1, 1]
}
}
});
}
oop.inherits(XQueryBehaviour, Behaviour);
exports.XQueryBehaviour = XQueryBehaviour;
});
ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
"use strict";
var oop = require("../../lib/oop");
var Range = require("../../range").Range;
var BaseFoldMode = require("./fold_mode").FoldMode;
var FoldMode = exports.FoldMode = function(commentRegex) {
if (commentRegex) {
this.foldingStartMarker = new RegExp(
this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
);
this.foldingStopMarker = new RegExp(
this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
);
}
};
oop.inherits(FoldMode, BaseFoldMode);
(function() {
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
var line = session.getLine(row);
var match = line.match(this.foldingStartMarker);
if (match) {
var i = match.index;
if (match[1])
return this.openingBracketBlock(session, match[1], row, i);
var range = session.getCommentFoldRange(row, i + match[0].length, 1);
if (range && !range.isMultiLine()) {
if (forceMultiline) {
range = this.getSectionRange(session, row);
} else if (foldStyle != "all")
range = null;
}
return range;
}
if (foldStyle === "markbegin")
return;
var match = line.match(this.foldingStopMarker);
if (match) {
var i = match.index + match[0].length;
if (match[1])
return this.closingBracketBlock(session, match[1], row, i);
return session.getCommentFoldRange(row, i, -1);
}
};
this.getSectionRange = function(session, row) {
var line = session.getLine(row);
var startIndent = line.search(/\S/);
var startRow = row;
var startColumn = line.length;
row = row + 1;
var endRow = row;
var maxRow = session.getLength();
while (++row < maxRow) {
line = session.getLine(row);
var indent = line.search(/\S/);
if (indent === -1)
continue;
if (startIndent > indent)
break;
var subRange = this.getFoldWidgetRange(session, "all", row);
if (subRange) {
if (subRange.start.row <= startRow) {
break;
} else if (subRange.isMultiLine()) {
row = subRange.end.row;
} else if (startIndent == indent) {
break;
}
}
endRow = row;
}
return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
};
}).call(FoldMode.prototype);
});
ace.define("ace/snippets",["require","exports","module","ace/lib/oop","ace/lib/event_emitter","ace/lib/lang","ace/range","ace/anchor","ace/keyboard/hash_handler","ace/tokenizer","ace/lib/dom","ace/editor"], function(require, exports, module) {
"use strict";
var oop = require("./lib/oop");
var EventEmitter = require("./lib/event_emitter").EventEmitter;
var lang = require("./lib/lang");
var Range = require("./range").Range;
var Anchor = require("./anchor").Anchor;
var HashHandler = require("./keyboard/hash_handler").HashHandler;
var Tokenizer = require("./tokenizer").Tokenizer;
var comparePoints = Range.comparePoints;
var SnippetManager = function() {
this.snippetMap = {};
this.snippetNameMap = {};
};
(function() {
oop.implement(this, EventEmitter);
this.getTokenizer = function() {
function TabstopToken(str, _, stack) {
str = str.substr(1);
if (/^\d+$/.test(str) && !stack.inFormatString)
return [{tabstopId: parseInt(str, 10)}];
return [{text: str}];
}
function escape(ch) {
return "(?:[^\\\\" + ch + "]|\\\\.)";
}
SnippetManager.$tokenizer = new Tokenizer({
start: [
{regex: /:/, onMatch: function(val, state, stack) {
if (stack.length && stack[0].expectIf) {
stack[0].expectIf = false;
stack[0].elseBranch = stack[0];
return [stack[0]];
}
return ":";
}},
{regex: /\\./, onMatch: function(val, state, stack) {
var ch = val[1];
if (ch == "}" && stack.length) {
val = ch;
}else if ("`$\\".indexOf(ch) != -1) {
val = ch;
} else if (stack.inFormatString) {
if (ch == "n")
val = "\n";
else if (ch == "t")
val = "\n";
else if ("ulULE".indexOf(ch) != -1) {
val = {changeCase: ch, local: ch > "a"};
}
}
return [val];
}},
{regex: /}/, onMatch: function(val, state, stack) {
return [stack.length ? stack.shift() : val];
}},
{regex: /\$(?:\d+|\w+)/, onMatch: TabstopToken},
{regex: /\$\{[\dA-Z_a-z]+/, onMatch: function(str, state, stack) {
var t = TabstopToken(str.substr(1), state, stack);
stack.unshift(t[0]);
return t;
}, next: "snippetVar"},
{regex: /\n/, token: "newline", merge: false}
],
snippetVar: [
{regex: "\\|" + escape("\\|") + "*\\|", onMatch: function(val, state, stack) {
stack[0].choices = val.slice(1, -1).split(",");
}, next: "start"},
{regex: "/(" + escape("/") + "+)/(?:(" + escape("/") + "*)/)(\\w*):?",
onMatch: function(val, state, stack) {
var ts = stack[0];
ts.fmtString = val;
val = this.splitRegex.exec(val);
ts.guard = val[1];
ts.fmt = val[2];
ts.flag = val[3];
return "";
}, next: "start"},
{regex: "`" + escape("`") + "*`", onMatch: function(val, state, stack) {
stack[0].code = val.splice(1, -1);
return "";
}, next: "start"},
{regex: "\\?", onMatch: function(val, state, stack) {
if (stack[0])
stack[0].expectIf = true;
}, next: "start"},
{regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "start"}
],
formatString: [
{regex: "/(" + escape("/") + "+)/", token: "regex"},
{regex: "", onMatch: function(val, state, stack) {
stack.inFormatString = true;
}, next: "start"}
]
});
SnippetManager.prototype.getTokenizer = function() {
return SnippetManager.$tokenizer;
};
return SnippetManager.$tokenizer;
};
this.tokenizeTmSnippet = function(str, startState) {
return this.getTokenizer().getLineTokens(str, startState).tokens.map(function(x) {
return x.value || x;
});
};
this.$getDefaultValue = function(editor, name) {
if (/^[A-Z]\d+$/.test(name)) {
var i = name.substr(1);
return (this.variables[name[0] + "__"] || {})[i];
}
if (/^\d+$/.test(name)) {
return (this.variables.__ || {})[name];
}
name = name.replace(/^TM_/, "");
if (!editor)
return;
var s = editor.session;
switch(name) {
case "CURRENT_WORD":
var r = s.getWordRange();
case "SELECTION":
case "SELECTED_TEXT":
return s.getTextRange(r);
case "CURRENT_LINE":
return s.getLine(editor.getCursorPosition().row);
case "PREV_LINE": // not possible in textmate
return s.getLine(editor.getCursorPosition().row - 1);
case "LINE_INDEX":
return editor.getCursorPosition().column;
case "LINE_NUMBER":
return editor.getCursorPosition().row + 1;
case "SOFT_TABS":
return s.getUseSoftTabs() ? "YES" : "NO";
case "TAB_SIZE":
return s.getTabSize();
case "FILENAME":
case "FILEPATH":
return "";
case "FULLNAME":
return "Ace";
}
};
this.variables = {};
this.getVariableValue = function(editor, varName) {
if (this.variables.hasOwnProperty(varName))
return this.variables[varName](editor, varName) || "";
return this.$getDefaultValue(editor, varName) || "";
};
this.tmStrFormat = function(str, ch, editor) {
var flag = ch.flag || "";
var re = ch.guard;
re = new RegExp(re, flag.replace(/[^gi]/, ""));
var fmtTokens = this.tokenizeTmSnippet(ch.fmt, "formatString");
var _self = this;
var formatted = str.replace(re, function() {
_self.variables.__ = arguments;
var fmtParts = _self.resolveVariables(fmtTokens, editor);
var gChangeCase = "E";
for (var i = 0; i < fmtParts.length; i++) {
var ch = fmtParts[i];
if (typeof ch == "object") {
fmtParts[i] = "";
if (ch.changeCase && ch.local) {
var next = fmtParts[i + 1];
if (next && typeof next == "string") {
if (ch.changeCase == "u")
fmtParts[i] = next[0].toUpperCase();
else
fmtParts[i] = next[0].toLowerCase();
fmtParts[i + 1] = next.substr(1);
}
} else if (ch.changeCase) {
gChangeCase = ch.changeCase;
}
} else if (gChangeCase == "U") {
fmtParts[i] = ch.toUpperCase();
} else if (gChangeCase == "L") {
fmtParts[i] = ch.toLowerCase();
}
}
return fmtParts.join("");
});
this.variables.__ = null;
return formatted;
};
this.resolveVariables = function(snippet, editor) {
var result = [];
for (var i = 0; i < snippet.length; i++) {
var ch = snippet[i];
if (typeof ch == "string") {
result.push(ch);
} else if (typeof ch != "object") {
continue;
} else if (ch.skip) {
gotoNext(ch);
} else if (ch.processed < i) {
continue;
} else if (ch.text) {
var value = this.getVariableValue(editor, ch.text);
if (value && ch.fmtString)
value = this.tmStrFormat(value, ch);
ch.processed = i;
if (ch.expectIf == null) {
if (value) {
result.push(value);
gotoNext(ch);
}
} else {
if (value) {
ch.skip = ch.elseBranch;
} else
gotoNext(ch);
}
} else if (ch.tabstopId != null) {
result.push(ch);
} else if (ch.changeCase != null) {
result.push(ch);
}
}
function gotoNext(ch) {
var i1 = snippet.indexOf(ch, i + 1);
if (i1 != -1)
i = i1;
}
return result;
};
this.insertSnippetForSelection = function(editor, snippetText) {
var cursor = editor.getCursorPosition();
var line = editor.session.getLine(cursor.row);
var tabString = editor.session.getTabString();
var indentString = line.match(/^\s*/)[0];
if (cursor.column < indentString.length)
indentString = indentString.slice(0, cursor.column);
var tokens = this.tokenizeTmSnippet(snippetText);
tokens = this.resolveVariables(tokens, editor);
tokens = tokens.map(function(x) {
if (x == "\n")
return x + indentString;
if (typeof x == "string")
return x.replace(/\t/g, tabString);
return x;
});
var tabstops = [];
tokens.forEach(function(p, i) {
if (typeof p != "object")
return;
var id = p.tabstopId;
var ts = tabstops[id];
if (!ts) {
ts = tabstops[id] = [];
ts.index = id;
ts.value = "";
}
if (ts.indexOf(p) !== -1)
return;
ts.push(p);
var i1 = tokens.indexOf(p, i + 1);
if (i1 === -1)
return;
var value = tokens.slice(i + 1, i1);
var isNested = value.some(function(t) {return typeof t === "object"});
if (isNested && !ts.value) {
ts.value = value;
} else if (value.length && (!ts.value || typeof ts.value !== "string")) {
ts.value = value.join("");
}
});
tabstops.forEach(function(ts) {ts.length = 0});
var expanding = {};
function copyValue(val) {
var copy = [];
for (var i = 0; i < val.length; i++) {
var p = val[i];
if (typeof p == "object") {
if (expanding[p.tabstopId])
continue;
var j = val.lastIndexOf(p, i - 1);
p = copy[j] || {tabstopId: p.tabstopId};
}
copy[i] = p;
}
return copy;
}
for (var i = 0; i < tokens.length; i++) {
var p = tokens[i];
if (typeof p != "object")
continue;
var id = p.tabstopId;
var i1 = tokens.indexOf(p, i + 1);
if (expanding[id]) {
if (expanding[id] === p)
expanding[id] = null;
continue;
}
var ts = tabstops[id];
var arg = typeof ts.value == "string" ? [ts.value] : copyValue(ts.value);
arg.unshift(i + 1, Math.max(0, i1 - i));
arg.push(p);
expanding[id] = p;
tokens.splice.apply(tokens, arg);
if (ts.indexOf(p) === -1)
ts.push(p);
}
var row = 0, column = 0;
var text = "";
tokens.forEach(function(t) {
if (typeof t === "string") {
if (t[0] === "\n"){
column = t.length - 1;
row ++;
} else
column += t.length;
text += t;
} else {
if (!t.start)
t.start = {row: row, column: column};
else
t.end = {row: row, column: column};
}
});
var range = editor.getSelectionRange();
var end = editor.session.replace(range, text);
var tabstopManager = new TabstopManager(editor);
var selectionId = editor.inVirtualSelectionMode && editor.selection.index;
tabstopManager.addTabstops(tabstops, range.start, end, selectionId);
};
this.insertSnippet = function(editor, snippetText) {
var self = this;
if (editor.inVirtualSelectionMode)
return self.insertSnippetForSelection(editor, snippetText);
editor.forEachSelection(function() {
self.insertSnippetForSelection(editor, snippetText);
}, null, {keepOrder: true});
if (editor.tabstopManager)
editor.tabstopManager.tabNext();
};
this.$getScope = function(editor) {
var scope = editor.session.$mode.$id || "";
scope = scope.split("/").pop();
if (scope === "html" || scope === "php") {
if (scope === "php" && !editor.session.$mode.inlinePhp)
scope = "html";
var c = editor.getCursorPosition();
var state = editor.session.getState(c.row);
if (typeof state === "object") {
state = state[0];
}
if (state.substring) {
if (state.substring(0, 3) == "js-")
scope = "javascript";
else if (state.substring(0, 4) == "css-")
scope = "css";
else if (state.substring(0, 4) == "php-")
scope = "php";
}
}
return scope;
};
this.getActiveScopes = function(editor) {
var scope = this.$getScope(editor);
var scopes = [scope];
var snippetMap = this.snippetMap;
if (snippetMap[scope] && snippetMap[scope].includeScopes) {
scopes.push.apply(scopes, snippetMap[scope].includeScopes);
}
scopes.push("_");
return scopes;
};
this.expandWithTab = function(editor, options) {
var self = this;
var result = editor.forEachSelection(function() {
return self.expandSnippetForSelection(editor, options);
}, null, {keepOrder: true});
if (result && editor.tabstopManager)
editor.tabstopManager.tabNext();
return result;
};
this.expandSnippetForSelection = function(editor, options) {
var cursor = editor.getCursorPosition();
var line = editor.session.getLine(cursor.row);
var before = line.substring(0, cursor.column);
var after = line.substr(cursor.column);
var snippetMap = this.snippetMap;
var snippet;
this.getActiveScopes(editor).some(function(scope) {
var snippets = snippetMap[scope];
if (snippets)
snippet = this.findMatchingSnippet(snippets, before, after);
return !!snippet;
}, this);
if (!snippet)
return false;
if (options && options.dryRun)
return true;
editor.session.doc.removeInLine(cursor.row,
cursor.column - snippet.replaceBefore.length,
cursor.column + snippet.replaceAfter.length
);
this.variables.M__ = snippet.matchBefore;
this.variables.T__ = snippet.matchAfter;
this.insertSnippetForSelection(editor, snippet.content);
this.variables.M__ = this.variables.T__ = null;
return true;
};
this.findMatchingSnippet = function(snippetList, before, after) {
for (var i = snippetList.length; i--;) {
var s = snippetList[i];
if (s.startRe && !s.startRe.test(before))
continue;
if (s.endRe && !s.endRe.test(after))
continue;
if (!s.startRe && !s.endRe)
continue;
s.matchBefore = s.startRe ? s.startRe.exec(before) : [""];
s.matchAfter = s.endRe ? s.endRe.exec(after) : [""];
s.replaceBefore = s.triggerRe ? s.triggerRe.exec(before)[0] : "";
s.replaceAfter = s.endTriggerRe ? s.endTriggerRe.exec(after)[0] : "";
return s;
}
};
this.snippetMap = {};
this.snippetNameMap = {};
this.register = function(snippets, scope) {
var snippetMap = this.snippetMap;
var snippetNameMap = this.snippetNameMap;
var self = this;
if (!snippets)
snippets = [];
function wrapRegexp(src) {
if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src))
src = "(?:" + src + ")";
return src || "";
}
function guardedRegexp(re, guard, opening) {
re = wrapRegexp(re);
guard = wrapRegexp(guard);
if (opening) {
re = guard + re;
if (re && re[re.length - 1] != "$")
re = re + "$";
} else {
re = re + guard;
if (re && re[0] != "^")
re = "^" + re;
}
return new RegExp(re);
}
function addSnippet(s) {
if (!s.scope)
s.scope = scope || "_";
scope = s.scope;
if (!snippetMap[scope]) {
snippetMap[scope] = [];
snippetNameMap[scope] = {};
}
var map = snippetNameMap[scope];
if (s.name) {
var old = map[s.name];
if (old)
self.unregister(old);
map[s.name] = s;
}
snippetMap[scope].push(s);
if (s.tabTrigger && !s.trigger) {
if (!s.guard && /^\w/.test(s.tabTrigger))
s.guard = "\\b";
s.trigger = lang.escapeRegExp(s.tabTrigger);
}
s.startRe = guardedRegexp(s.trigger, s.guard, true);
s.triggerRe = new RegExp(s.trigger, "", true);
s.endRe = guardedRegexp(s.endTrigger, s.endGuard, true);
s.endTriggerRe = new RegExp(s.endTrigger, "", true);
}
if (snippets && snippets.content)
addSnippet(snippets);
else if (Array.isArray(snippets))
snippets.forEach(addSnippet);
this._signal("registerSnippets", {scope: scope});
};
this.unregister = function(snippets, scope) {
var snippetMap = this.snippetMap;
var snippetNameMap = this.snippetNameMap;
function removeSnippet(s) {
var nameMap = snippetNameMap[s.scope||scope];
if (nameMap && nameMap[s.name]) {
delete nameMap[s.name];
var map = snippetMap[s.scope||scope];
var i = map && map.indexOf(s);
if (i >= 0)
map.splice(i, 1);
}
}
if (snippets.content)
removeSnippet(snippets);
else if (Array.isArray(snippets))
snippets.forEach(removeSnippet);
};
this.parseSnippetFile = function(str) {
str = str.replace(/\r/g, "");
var list = [], snippet = {};
var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
var m;
while (m = re.exec(str)) {
if (m[1]) {
try {
snippet = JSON.parse(m[1]);
list.push(snippet);
} catch (e) {}
} if (m[4]) {
snippet.content = m[4].replace(/^\t/gm, "");
list.push(snippet);
snippet = {};
} else {
var key = m[2], val = m[3];
if (key == "regex") {
var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g;
snippet.guard = guardRe.exec(val)[1];
snippet.trigger = guardRe.exec(val)[1];
snippet.endTrigger = guardRe.exec(val)[1];
snippet.endGuard = guardRe.exec(val)[1];
} else if (key == "snippet") {
snippet.tabTrigger = val.match(/^\S*/)[0];
if (!snippet.name)
snippet.name = val;
} else {
snippet[key] = val;
}
}
}
return list;
};
this.getSnippetByName = function(name, editor) {
var snippetMap = this.snippetNameMap;
var snippet;
this.getActiveScopes(editor).some(function(scope) {
var snippets = snippetMap[scope];
if (snippets)
snippet = snippets[name];
return !!snippet;
}, this);
return snippet;
};
}).call(SnippetManager.prototype);
var TabstopManager = function(editor) {
if (editor.tabstopManager)
return editor.tabstopManager;
editor.tabstopManager = this;
this.$onChange = this.onChange.bind(this);
this.$onChangeSelection = lang.delayedCall(this.onChangeSelection.bind(this)).schedule;
this.$onChangeSession = this.onChangeSession.bind(this);
this.$onAfterExec = this.onAfterExec.bind(this);
this.attach(editor);
};
(function() {
this.attach = function(editor) {
this.index = 0;
this.ranges = [];
this.tabstops = [];
this.$openTabstops = null;
this.selectedTabstop = null;
this.editor = editor;
this.editor.on("change", this.$onChange);
this.editor.on("changeSelection", this.$onChangeSelection);
this.editor.on("changeSession", this.$onChangeSession);
this.editor.commands.on("afterExec", this.$onAfterExec);
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
};
this.detach = function() {
this.tabstops.forEach(this.removeTabstopMarkers, this);
this.ranges = null;
this.tabstops = null;
this.selectedTabstop = null;
this.editor.removeListener("change", this.$onChange);
this.editor.removeListener("changeSelection", this.$onChangeSelection);
this.editor.removeListener("changeSession", this.$onChangeSession);
this.editor.commands.removeListener("afterExec", this.$onAfterExec);
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
this.editor.tabstopManager = null;
this.editor = null;
};
this.onChange = function(e) {
var changeRange = e.data.range;
var isRemove = e.data.action[0] == "r";
var start = changeRange.start;
var end = changeRange.end;
var startRow = start.row;
var endRow = end.row;
var lineDif = endRow - startRow;
var colDiff = end.column - start.column;
if (isRemove) {
lineDif = -lineDif;
colDiff = -colDiff;
}
if (!this.$inChange && isRemove) {
var ts = this.selectedTabstop;
var changedOutside = ts && !ts.some(function(r) {
return comparePoints(r.start, start) <= 0 && comparePoints(r.end, end) >= 0;
});
if (changedOutside)
return this.detach();
}
var ranges = this.ranges;
for (var i = 0; i < ranges.length; i++) {
var r = ranges[i];
if (r.end.row < start.row)
continue;
if (isRemove && comparePoints(start, r.start) < 0 && comparePoints(end, r.end) > 0) {
this.removeRange(r);
i--;
continue;
}
if (r.start.row == startRow && r.start.column > start.column)
r.start.column += colDiff;
if (r.end.row == startRow && r.end.column >= start.column)
r.end.column += colDiff;
if (r.start.row >= startRow)
r.start.row += lineDif;
if (r.end.row >= startRow)
r.end.row += lineDif;
if (comparePoints(r.start, r.end) > 0)
this.removeRange(r);
}
if (!ranges.length)
this.detach();
};
this.updateLinkedFields = function() {
var ts = this.selectedTabstop;
if (!ts || !ts.hasLinkedRanges)
return;
this.$inChange = true;
var session = this.editor.session;
var text = session.getTextRange(ts.firstNonLinked);
for (var i = ts.length; i--;) {
var range = ts[i];
if (!range.linked)
continue;
var fmt = exports.snippetManager.tmStrFormat(text, range.original);
session.replace(range, fmt);
}
this.$inChange = false;
};
this.onAfterExec = function(e) {
if (e.command && !e.command.readOnly)
this.updateLinkedFields();
};
this.onChangeSelection = function() {
if (!this.editor)
return;
var lead = this.editor.selection.lead;
var anchor = this.editor.selection.anchor;
var isEmpty = this.editor.selection.isEmpty();
for (var i = this.ranges.length; i--;) {
if (this.ranges[i].linked)
continue;
var containsLead = this.ranges[i].contains(lead.row, lead.column);
var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column);
if (containsLead && containsAnchor)
return;
}
this.detach();
};
this.onChangeSession = function() {
this.detach();
};
this.tabNext = function(dir) {
var max = this.tabstops.length;
var index = this.index + (dir || 1);
index = Math.min(Math.max(index, 1), max);
if (index == max)
index = 0;
this.selectTabstop(index);
if (index === 0)
this.detach();
};
this.selectTabstop = function(index) {
this.$openTabstops = null;
var ts = this.tabstops[this.index];
if (ts)
this.addTabstopMarkers(ts);
this.index = index;
ts = this.tabstops[this.index];
if (!ts || !ts.length)
return;
this.selectedTabstop = ts;
if (!this.editor.inVirtualSelectionMode) {
var sel = this.editor.multiSelect;
sel.toSingleRange(ts.firstNonLinked.clone());
for (var i = ts.length; i--;) {
if (ts.hasLinkedRanges && ts[i].linked)
continue;
sel.addRange(ts[i].clone(), true);
}
if (sel.ranges[0])
sel.addRange(sel.ranges[0].clone());
} else {
this.editor.selection.setRange(ts.firstNonLinked);
}
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
};
this.addTabstops = function(tabstops, start, end) {
if (!this.$openTabstops)
this.$openTabstops = [];
if (!tabstops[0]) {
var p = Range.fromPoints(end, end);
moveRelative(p.start, start);
moveRelative(p.end, start);
tabstops[0] = [p];
tabstops[0].index = 0;
}
var i = this.index;
var arg = [i + 1, 0];
var ranges = this.ranges;
tabstops.forEach(function(ts, index) {
var dest = this.$openTabstops[index] || ts;
for (var i = ts.length; i--;) {
var p = ts[i];
var range = Range.fromPoints(p.start, p.end || p.start);
movePoint(range.start, start);
movePoint(range.end, start);
range.original = p;
range.tabstop = dest;
ranges.push(range);
if (dest != ts)
dest.unshift(range);
else
dest[i] = range;
if (p.fmtString) {
range.linked = true;
dest.hasLinkedRanges = true;
} else if (!dest.firstNonLinked)
dest.firstNonLinked = range;
}
if (!dest.firstNonLinked)
dest.hasLinkedRanges = false;
if (dest === ts) {
arg.push(dest);
this.$openTabstops[index] = dest;
}
this.addTabstopMarkers(dest);
}, this);
if (arg.length > 2) {
if (this.tabstops.length)
arg.push(arg.splice(2, 1)[0]);
this.tabstops.splice.apply(this.tabstops, arg);
}
};
this.addTabstopMarkers = function(ts) {
var session = this.editor.session;
ts.forEach(function(range) {
if (!range.markerId)
range.markerId = session.addMarker(range, "ace_snippet-marker", "text");
});
};
this.removeTabstopMarkers = function(ts) {
var session = this.editor.session;
ts.forEach(function(range) {
session.removeMarker(range.markerId);
range.markerId = null;
});
};
this.removeRange = function(range) {
var i = range.tabstop.indexOf(range);
range.tabstop.splice(i, 1);
i = this.ranges.indexOf(range);
this.ranges.splice(i, 1);
this.editor.session.removeMarker(range.markerId);
if (!range.tabstop.length) {
i = this.tabstops.indexOf(range.tabstop);
if (i != -1)
this.tabstops.splice(i, 1);
if (!this.tabstops.length)
this.detach();
}
};
this.keyboardHandler = new HashHandler();
this.keyboardHandler.bindKeys({
"Tab": function(ed) {
if (exports.snippetManager && exports.snippetManager.expandWithTab(ed)) {
return;
}
ed.tabstopManager.tabNext(1);
},
"Shift-Tab": function(ed) {
ed.tabstopManager.tabNext(-1);
},
"Esc": function(ed) {
ed.tabstopManager.detach();
},
"Return": function(ed) {
return false;
}
});
}).call(TabstopManager.prototype);
var changeTracker = {};
changeTracker.onChange = Anchor.prototype.onChange;
changeTracker.setPosition = function(row, column) {
this.pos.row = row;
this.pos.column = column;
};
changeTracker.update = function(pos, delta, $insertRight) {
this.$insertRight = $insertRight;
this.pos = pos;
this.onChange(delta);
};
var movePoint = function(point, diff) {
if (point.row == 0)
point.column += diff.column;
point.row += diff.row;
};
var moveRelative = function(point, start) {
if (point.row == start.row)
point.column -= start.column;
point.row -= start.row;
};
require("./lib/dom").importCssString("\
.ace_snippet-marker {\
-moz-box-sizing: border-box;\
box-sizing: border-box;\
background: rgba(194, 193, 208, 0.09);\
border: 1px dotted rgba(211, 208, 235, 0.62);\
position: absolute;\
}");
exports.snippetManager = new SnippetManager();
var Editor = require("./editor").Editor;
(function() {
this.insertSnippet = function(content, options) {
return exports.snippetManager.insertSnippet(this, content, options);
};
this.expandSnippet = function(options) {
return exports.snippetManager.expandWithTab(this, options);
};
}).call(Editor.prototype);
});
ace.define("ace/autocomplete/popup",["require","exports","module","ace/edit_session","ace/virtual_renderer","ace/editor","ace/range","ace/lib/event","ace/lib/lang","ace/lib/dom"], function(require, exports, module) {
"use strict";
var EditSession = require("../edit_session").EditSession;
var Renderer = require("../virtual_renderer").VirtualRenderer;
var Editor = require("../editor").Editor;
var Range = require("../range").Range;
var event = require("../lib/event");
var lang = require("../lib/lang");
var dom = require("../lib/dom");
var $singleLineEditor = function(el) {
var renderer = new Renderer(el);
renderer.$maxLines = 4;
var editor = new Editor(renderer);
editor.setHighlightActiveLine(false);
editor.setShowPrintMargin(false);
editor.renderer.setShowGutter(false);
editor.renderer.setHighlightGutterLine(false);
editor.$mouseHandler.$focusWaitTimout = 0;
editor.$highlightTagPending = true;
return editor;
};
var AcePopup = function(parentNode) {
var el = dom.createElement("div");
var popup = new $singleLineEditor(el);
if (parentNode)
parentNode.appendChild(el);
el.style.display = "none";
popup.renderer.content.style.cursor = "default";
popup.renderer.setStyle("ace_autocomplete");
popup.setOption("displayIndentGuides", false);
popup.setOption("dragDelay", 150);
var noop = function(){};
popup.focus = noop;
popup.$isFocused = true;
popup.renderer.$cursorLayer.restartTimer = noop;
popup.renderer.$cursorLayer.element.style.opacity = 0;
popup.renderer.$maxLines = 8;
popup.renderer.$keepTextAreaAtCursor = false;
popup.setHighlightActiveLine(false);
popup.session.highlight("");
popup.session.$searchHighlight.clazz = "ace_highlight-marker";
popup.on("mousedown", function(e) {
var pos = e.getDocumentPosition();
popup.selection.moveToPosition(pos);
selectionMarker.start.row = selectionMarker.end.row = pos.row;
e.stop();
});
var lastMouseEvent;
var hoverMarker = new Range(-1,0,-1,Infinity);
var selectionMarker = new Range(-1,0,-1,Infinity);
selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine");
popup.setSelectOnHover = function(val) {
if (!val) {
hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
} else if (hoverMarker.id) {
popup.session.removeMarker(hoverMarker.id);
hoverMarker.id = null;
}
};
popup.setSelectOnHover(false);
popup.on("mousemove", function(e) {
if (!lastMouseEvent) {
lastMouseEvent = e;
return;
}
if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) {
return;
}
lastMouseEvent = e;
lastMouseEvent.scrollTop = popup.renderer.scrollTop;
var row = lastMouseEvent.getDocumentPosition().row;
if (hoverMarker.start.row != row) {
if (!hoverMarker.id)
popup.setRow(row);
setHoverMarker(row);
}
});
popup.renderer.on("beforeRender", function() {
if (lastMouseEvent && hoverMarker.start.row != -1) {
lastMouseEvent.$pos = null;
var row = lastMouseEvent.getDocumentPosition().row;
if (!hoverMarker.id)
popup.setRow(row);
setHoverMarker(row, true);
}
});
popup.renderer.on("afterRender", function() {
var row = popup.getRow();
var t = popup.renderer.$textLayer;
var selected = t.element.childNodes[row - t.config.firstRow];
if (selected == t.selectedNode)
return;
if (t.selectedNode)
dom.removeCssClass(t.selectedNode, "ace_selected");
t.selectedNode = selected;
if (selected)
dom.addCssClass(selected, "ace_selected");
});
var hideHoverMarker = function() { setHoverMarker(-1) };
var setHoverMarker = function(row, suppressRedraw) {
if (row !== hoverMarker.start.row) {
hoverMarker.start.row = hoverMarker.end.row = row;
if (!suppressRedraw)
popup.session._emit("changeBackMarker");
popup._emit("changeHoverMarker");
}
};
popup.getHoveredRow = function() {
return hoverMarker.start.row;
};
event.addListener(popup.container, "mouseout", hideHoverMarker);
popup.on("hide", hideHoverMarker);
popup.on("changeSelection", hideHoverMarker);
popup.session.doc.getLength = function() {
return popup.data.length;
};
popup.session.doc.getLine = function(i) {
var data = popup.data[i];
if (typeof data == "string")
return data;
return (data && data.value) || "";
};
var bgTokenizer = popup.session.bgTokenizer;
bgTokenizer.$tokenizeRow = function(row) {
var data = popup.data[row];
var tokens = [];
if (!data)
return tokens;
if (typeof data == "string")
data = {value: data};
if (!data.caption)
data.caption = data.value || data.name;
var last = -1;
var flag, c;
for (var i = 0; i < data.caption.length; i++) {
c = data.caption[i];
flag = data.matchMask & (1 << i) ? 1 : 0;
if (last !== flag) {
tokens.push({type: data.className || "" + ( flag ? "completion-highlight" : ""), value: c});
last = flag;
} else {
tokens[tokens.length - 1].value += c;
}
}
if (data.meta) {
var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth;
if (data.meta.length + data.caption.length < maxW - 2)
tokens.push({type: "rightAlignedText", value: data.meta});
}
return tokens;
};
bgTokenizer.$updateOnChange = noop;
bgTokenizer.start = noop;
popup.session.$computeWidth = function() {
return this.screenWidth = 0;
};
popup.isOpen = false;
popup.isTopdown = false;
popup.data = [];
popup.setData = function(list) {
popup.data = list || [];
popup.setValue(lang.stringRepeat("\n", list.length), -1);
popup.setRow(0);
};
popup.getData = function(row) {
return popup.data[row];
};
popup.getRow = function() {
return selectionMarker.start.row;
};
popup.setRow = function(line) {
line = Math.max(-1, Math.min(this.data.length, line));
if (selectionMarker.start.row != line) {
popup.selection.clearSelection();
selectionMarker.start.row = selectionMarker.end.row = line || 0;
popup.session._emit("changeBackMarker");
popup.moveCursorTo(line || 0, 0);
if (popup.isOpen)
popup._signal("select");
}
};
popup.on("changeSelection", function() {
if (popup.isOpen)
popup.setRow(popup.selection.lead.row);
});
popup.hide = function() {
this.container.style.display = "none";
this._signal("hide");
popup.isOpen = false;
};
popup.show = function(pos, lineHeight, topdownOnly) {
var el = this.container;
var screenHeight = window.innerHeight;
var screenWidth = window.innerWidth;
var renderer = this.renderer;
var maxH = renderer.$maxLines * lineHeight * 1.4;
var top = pos.top + this.$borderSize;
if (top + maxH > screenHeight - lineHeight && !topdownOnly) {
el.style.top = "";
el.style.bottom = screenHeight - top + "px";
popup.isTopdown = false;
} else {
top += lineHeight;
el.style.top = top + "px";
el.style.bottom = "";
popup.isTopdown = true;
}
el.style.display = "";
this.renderer.$textLayer.checkForSizeChanges();
var left = pos.left;
if (left + el.offsetWidth > screenWidth)
left = screenWidth - el.offsetWidth;
el.style.left = left + "px";
this._signal("show");
lastMouseEvent = null;
popup.isOpen = true;
};
popup.getTextLeftOffset = function() {
return this.$borderSize + this.renderer.$padding + this.$imageSize;
};
popup.$imageSize = 0;
popup.$borderSize = 1;
return popup;
};
dom.importCssString("\
.ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line {\
background-color: #CAD6FA;\
z-index: 1;\
}\
.ace_editor.ace_autocomplete .ace_line-hover {\
border: 1px solid #abbffe;\
margin-top: -1px;\
background: rgba(233,233,253,0.4);\
}\
.ace_editor.ace_autocomplete .ace_line-hover {\
position: absolute;\
z-index: 2;\
}\
.ace_editor.ace_autocomplete .ace_scroller {\
background: none;\
border: none;\
box-shadow: none;\
}\
.ace_rightAlignedText {\
color: gray;\
display: inline-block;\
position: absolute;\
right: 4px;\
text-align: right;\
z-index: -1;\
}\
.ace_editor.ace_autocomplete .ace_completion-highlight{\
color: #000;\
text-shadow: 0 0 0.01em;\
}\
.ace_editor.ace_autocomplete {\
width: 280px;\
z-index: 200000;\
background: #fbfbfb;\
color: #444;\
border: 1px lightgray solid;\
position: fixed;\
box-shadow: 2px 3px 5px rgba(0,0,0,.2);\
line-height: 1.4;\
}");
exports.AcePopup = AcePopup;
});
ace.define("ace/autocomplete/util",["require","exports","module"], function(require, exports, module) {
"use strict";
exports.parForEach = function(array, fn, callback) {
var completed = 0;
var arLength = array.length;
if (arLength === 0)
callback();
for (var i = 0; i < arLength; i++) {
fn(array[i], function(result, err) {
completed++;
if (completed === arLength)
callback(result, err);
});
}
};
var ID_REGEX = /[a-zA-Z_0-9\$\-\u00A2-\uFFFF]/;
exports.retrievePrecedingIdentifier = function(text, pos, regex) {
regex = regex || ID_REGEX;
var buf = [];
for (var i = pos-1; i >= 0; i--) {
if (regex.test(text[i]))
buf.push(text[i]);
else
break;
}
return buf.reverse().join("");
};
exports.retrieveFollowingIdentifier = function(text, pos, regex) {
regex = regex || ID_REGEX;
var buf = [];
for (var i = pos; i < text.length; i++) {
if (regex.test(text[i]))
buf.push(text[i]);
else
break;
}
return buf;
};
});
ace.define("ace/autocomplete",["require","exports","module","ace/keyboard/hash_handler","ace/autocomplete/popup","ace/autocomplete/util","ace/lib/event","ace/lib/lang","ace/snippets"], function(require, exports, module) {
"use strict";
var HashHandler = require("./keyboard/hash_handler").HashHandler;
var AcePopup = require("./autocomplete/popup").AcePopup;
var util = require("./autocomplete/util");
var event = require("./lib/event");
var lang = require("./lib/lang");
var snippetManager = require("./snippets").snippetManager;
var Autocomplete = function() {
this.autoInsert = true;
this.autoSelect = true;
this.keyboardHandler = new HashHandler();
this.keyboardHandler.bindKeys(this.commands);
this.blurListener = this.blurListener.bind(this);
this.changeListener = this.changeListener.bind(this);
this.mousedownListener = this.mousedownListener.bind(this);
this.mousewheelListener = this.mousewheelListener.bind(this);
this.changeTimer = lang.delayedCall(function() {
this.updateCompletions(true);
}.bind(this));
};
(function() {
this.gatherCompletionsId = 0;
this.$init = function() {
this.popup = new AcePopup(document.body || document.documentElement);
this.popup.on("click", function(e) {
this.insertMatch();
e.stop();
}.bind(this));
this.popup.focus = this.editor.focus.bind(this.editor);
};
this.openPopup = function(editor, prefix, keepPopupPosition) {
if (!this.popup)
this.$init();
this.popup.setData(this.completions.filtered);
var renderer = editor.renderer;
this.popup.setRow(this.autoSelect ? 0 : -1);
if (!keepPopupPosition) {
this.popup.setTheme(editor.getTheme());
this.popup.setFontSize(editor.getFontSize());
var lineHeight = renderer.layerConfig.lineHeight;
var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
pos.left -= this.popup.getTextLeftOffset();
var rect = editor.container.getBoundingClientRect();
pos.top += rect.top - renderer.layerConfig.offset;
pos.left += rect.left - editor.renderer.scrollLeft;
pos.left += renderer.$gutterLayer.gutterWidth;
this.popup.show(pos, lineHeight);
}
};
this.detach = function() {
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
this.editor.off("changeSelection", this.changeListener);
this.editor.off("blur", this.blurListener);
this.editor.off("mousedown", this.mousedownListener);
this.editor.off("mousewheel", this.mousewheelListener);
this.changeTimer.cancel();
if (this.popup && this.popup.isOpen) {
this.gatherCompletionsId += 1;
this.popup.hide();
}
if (this.base)
this.base.detach();
this.activated = false;
this.completions = this.base = null;
};
this.changeListener = function(e) {
var cursor = this.editor.selection.lead;
if (cursor.row != this.base.row || cursor.column < this.base.column) {
this.detach();
}
if (this.activated)
this.changeTimer.schedule();
else
this.detach();
};
this.blurListener = function() {
var el = document.activeElement;
if (el != this.editor.textInput.getElement() && el.parentNode != this.popup.container)
this.detach();
};
this.mousedownListener = function(e) {
this.detach();
};
this.mousewheelListener = function(e) {
this.detach();
};
this.goTo = function(where) {
var row = this.popup.getRow();
var max = this.popup.session.getLength() - 1;
switch(where) {
case "up": row = row <= 0 ? max : row - 1; break;
case "down": row = row >= max ? -1 : row + 1; break;
case "start": row = 0; break;
case "end": row = max; break;
}
this.popup.setRow(row);
};
this.insertMatch = function(data) {
if (!data)
data = this.popup.getData(this.popup.getRow());
if (!data)
return false;
if (data.completer && data.completer.insertMatch) {
data.completer.insertMatch(this.editor);
} else {
if (this.completions.filterText) {
var ranges = this.editor.selection.getAllRanges();
for (var i = 0, range; range = ranges[i]; i++) {
range.start.column -= this.completions.filterText.length;
this.editor.session.remove(range);
}
}
if (data.snippet)
snippetManager.insertSnippet(this.editor, data.snippet);
else
this.editor.execCommand("insertstring", data.value || data);
}
this.detach();
};
this.commands = {
"Up": function(editor) { editor.completer.goTo("up"); },
"Down": function(editor) { editor.completer.goTo("down"); },
"Ctrl-Up|Ctrl-Home": function(editor) { editor.completer.goTo("start"); },
"Ctrl-Down|Ctrl-End": function(editor) { editor.completer.goTo("end"); },
"Esc": function(editor) { editor.completer.detach(); },
"Space": function(editor) { editor.completer.detach(); editor.insert(" ");},
"Return": function(editor) { return editor.completer.insertMatch(); },
"Shift-Return": function(editor) { editor.completer.insertMatch(true); },
"Tab": function(editor) {
var result = editor.completer.insertMatch();
if (!result && !editor.tabstopManager)
editor.completer.goTo("down");
else
return result;
},
"PageUp": function(editor) { editor.completer.popup.gotoPageUp(); },
"PageDown": function(editor) { editor.completer.popup.gotoPageDown(); }
};
this.gatherCompletions = function(editor, callback) {
var session = editor.getSession();
var pos = editor.getCursorPosition();
var line = session.getLine(pos.row);
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
var matches = [];
var total = editor.completers.length;
editor.completers.forEach(function(completer, i) {
completer.getCompletions(editor, session, pos, prefix, function(err, results) {
if (!err)
matches = matches.concat(results);
var pos = editor.getCursorPosition();
var line = session.getLine(pos.row);
callback(null, {
prefix: util.retrievePrecedingIdentifier(line, pos.column, results[0] && results[0].identifierRegex),
matches: matches,
finished: (--total === 0)
});
});
});
return true;
};
this.showPopup = function(editor) {
if (this.editor)
this.detach();
this.activated = true;
this.editor = editor;
if (editor.completer != this) {
if (editor.completer)
editor.completer.detach();
editor.completer = this;
}
editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
editor.on("changeSelection", this.changeListener);
editor.on("blur", this.blurListener);
editor.on("mousedown", this.mousedownListener);
editor.on("mousewheel", this.mousewheelListener);
this.updateCompletions();
};
this.updateCompletions = function(keepPopupPosition) {
if (keepPopupPosition && this.base && this.completions) {
var pos = this.editor.getCursorPosition();
var prefix = this.editor.session.getTextRange({start: this.base, end: pos});
if (prefix == this.completions.filterText)
return;
this.completions.setFilter(prefix);
if (!this.completions.filtered.length)
return this.detach();
if (this.completions.filtered.length == 1
&& this.completions.filtered[0].value == prefix
&& !this.completions.filtered[0].snippet)
return this.detach();
this.openPopup(this.editor, prefix, keepPopupPosition);
return;
}
var _id = this.gatherCompletionsId;
this.gatherCompletions(this.editor, function(err, results) {
var detachIfFinished = function() {
if (!results.finished) return;
return this.detach();
}.bind(this);
var prefix = results.prefix;
var matches = results && results.matches;
if (!matches || !matches.length)
return detachIfFinished();
if (prefix.indexOf(results.prefix) !== 0 || _id != this.gatherCompletionsId)
return;
this.completions = new FilteredList(matches);
this.completions.setFilter(prefix);
var filtered = this.completions.filtered;
if (!filtered.length)
return detachIfFinished();
if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet)
return detachIfFinished();
if (this.autoInsert && filtered.length == 1)
return this.insertMatch(filtered[0]);
this.openPopup(this.editor, prefix, keepPopupPosition);
}.bind(this));
};
this.cancelContextMenu = function() {
this.editor.$mouseHandler.cancelContextMenu();
};
}).call(Autocomplete.prototype);
Autocomplete.startCommand = {
name: "startAutocomplete",
exec: function(editor) {
if (!editor.completer)
editor.completer = new Autocomplete();
editor.completer.autoInsert =
editor.completer.autoSelect = true;
editor.completer.showPopup(editor);
editor.completer.cancelContextMenu();
},
bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
};
var FilteredList = function(array, filterText, mutateData) {
this.all = array;
this.filtered = array;
this.filterText = filterText || "";
};
(function(){
this.setFilter = function(str) {
if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0)
var matches = this.filtered;
else
var matches = this.all;
this.filterText = str;
matches = this.filterCompletions(matches, this.filterText);
matches = matches.sort(function(a, b) {
return b.exactMatch - a.exactMatch || b.score - a.score;
});
var prev = null;
matches = matches.filter(function(item){
var caption = item.value || item.caption || item.snippet;
if (caption === prev) return false;
prev = caption;
return true;
});
this.filtered = matches;
};
this.filterCompletions = function(items, needle) {
var results = [];
var upper = needle.toUpperCase();
var lower = needle.toLowerCase();
loop: for (var i = 0, item; item = items[i]; i++) {
var caption = item.value || item.caption || item.snippet;
if (!caption) continue;
var lastIndex = -1;
var matchMask = 0;
var penalty = 0;
var index, distance;
for (var j = 0; j < needle.length; j++) {
var i1 = caption.indexOf(lower[j], lastIndex + 1);
var i2 = caption.indexOf(upper[j], lastIndex + 1);
index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
if (index < 0)
continue loop;
distance = index - lastIndex - 1;
if (distance > 0) {
if (lastIndex === -1)
penalty += 10;
penalty += distance;
}
matchMask = matchMask | (1 << index);
lastIndex = index;
}
item.matchMask = matchMask;
item.exactMatch = penalty ? 0 : 1;
item.score = (item.score || 0) - penalty;
results.push(item);
}
return results;
};
}).call(FilteredList.prototype);
exports.Autocomplete = Autocomplete;
exports.FilteredList = FilteredList;
});
ace.define("ace/autocomplete/text_completer",["require","exports","module","ace/range"], function(require, exports, module) {
var Range = require("../range").Range;
var splitRegex = /[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/;
function getWordIndex(doc, pos) {
var textBefore = doc.getTextRange(Range.fromPoints({row: 0, column:0}, pos));
return textBefore.split(splitRegex).length - 1;
}
function wordDistance(doc, pos) {
var prefixPos = getWordIndex(doc, pos);
var words = doc.getValue().split(splitRegex);
var wordScores = Object.create(null);
var currentWord = words[prefixPos];
words.forEach(function(word, idx) {
if (!word || word === currentWord) return;
var distance = Math.abs(prefixPos - idx);
var score = words.length - distance;
if (wordScores[word]) {
wordScores[word] = Math.max(score, wordScores[word]);
} else {
wordScores[word] = score;
}
});
return wordScores;
}
exports.getCompletions = function(editor, session, pos, prefix, callback) {
var wordScore = wordDistance(session, pos, prefix);
var wordList = Object.keys(wordScore);
callback(null, wordList.map(function(word) {
return {
caption: word,
value: word,
score: wordScore[word],
meta: "local"
};
}));
};
});
ace.define("ace/ext/language_tools",["require","exports","module","ace/snippets","ace/autocomplete","ace/config","ace/autocomplete/util","ace/autocomplete/text_completer","ace/editor","ace/config"], function(require, exports, module) {
"use strict";
var snippetManager = require("../snippets").snippetManager;
var Autocomplete = require("../autocomplete").Autocomplete;
var config = require("../config");
var util = require("../autocomplete/util");
var textCompleter = require("../autocomplete/text_completer");
var keyWordCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
var state = editor.session.getState(pos.row);
var completions = session.$mode.getCompletions(state, session, pos, prefix);
callback(null, completions);
}
};
var snippetCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
var snippetMap = snippetManager.snippetMap;
var completions = [];
snippetManager.getActiveScopes(editor).forEach(function(scope) {
var snippets = snippetMap[scope] || [];
for (var i = snippets.length; i--;) {
var s = snippets[i];
var caption = s.name || s.tabTrigger;
if (!caption)
continue;
completions.push({
caption: caption,
snippet: s.content,
meta: s.tabTrigger && !s.name ? s.tabTrigger + "\u21E5 " : "snippet"
});
}
}, this);
callback(null, completions);
}
};
var completers = [snippetCompleter, textCompleter, keyWordCompleter];
exports.addCompleter = function(completer) {
completers.push(completer);
};
exports.textCompleter = textCompleter;
exports.keyWordCompleter = keyWordCompleter;
exports.snippetCompleter = snippetCompleter;
var expandSnippet = {
name: "expandSnippet",
exec: function(editor) {
var success = snippetManager.expandWithTab(editor);
if (!success)
editor.execCommand("indent");
},
bindKey: "Tab"
};
var onChangeMode = function(e, editor) {
loadSnippetsForMode(editor.session.$mode);
};
var loadSnippetsForMode = function(mode) {
var id = mode.$id;
if (!snippetManager.files)
snippetManager.files = {};
loadSnippetFile(id);
if (mode.modes)
mode.modes.forEach(loadSnippetsForMode);
};
var loadSnippetFile = function(id) {
if (!id || snippetManager.files[id])
return;
var snippetFilePath = id.replace("mode", "snippets");
snippetManager.files[id] = {};
config.loadModule(snippetFilePath, function(m) {
if (m) {
snippetManager.files[id] = m;
if (!m.snippets && m.snippetText)
m.snippets = snippetManager.parseSnippetFile(m.snippetText);
snippetManager.register(m.snippets || [], m.scope);
if (m.includeScopes) {
snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
m.includeScopes.forEach(function(x) {
loadSnippetFile("ace/mode/" + x);
});
}
}
});
};
function getCompletionPrefix(editor) {
var pos = editor.getCursorPosition();
var line = editor.session.getLine(pos.row);
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
editor.completers.forEach(function(completer) {
if (completer.identifierRegexps) {
completer.identifierRegexps.forEach(function(identifierRegex) {
if (!prefix && identifierRegex)
prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
});
}
});
return prefix;
}
var doLiveAutocomplete = function(e) {
var editor = e.editor;
var text = e.args || "";
var hasCompleter = editor.completer && editor.completer.activated;
if (e.command.name === "backspace") {
if (hasCompleter && !getCompletionPrefix(editor))
editor.completer.detach();
}
else if (e.command.name === "insertstring") {
var prefix = getCompletionPrefix(editor);
if (prefix && !hasCompleter) {
if (!editor.completer) {
editor.completer = new Autocomplete();
}
editor.completer.autoSelect = false;
editor.completer.autoInsert = false;
editor.completer.showPopup(editor);
}
}
};
var Editor = require("../editor").Editor;
require("../config").defineOptions(Editor.prototype, "editor", {
enableBasicAutocompletion: {
set: function(val) {
if (val) {
if (!this.completers)
this.completers = Array.isArray(val)? val: completers;
this.commands.addCommand(Autocomplete.startCommand);
} else {
this.commands.removeCommand(Autocomplete.startCommand);
}
},
value: false
},
enableLiveAutocompletion: {
set: function(val) {
if (val) {
if (!this.completers)
this.completers = Array.isArray(val)? val: completers;
this.commands.on('afterExec', doLiveAutocomplete);
} else {
this.commands.removeListener('afterExec', doLiveAutocomplete);
}
},
value: false
},
enableSnippets: {
set: function(val) {
if (val) {
this.commands.addCommand(expandSnippet);
this.on("changeMode", onChangeMode);
onChangeMode(null, this);
} else {
this.commands.removeCommand(expandSnippet);
this.off("changeMode", onChangeMode);
}
},
value: false
}
});
});
ace.define("ace/mode/xquery",["require","exports","module","ace/worker/worker_client","ace/lib/oop","ace/mode/text","ace/mode/text_highlight_rules","ace/mode/xquery/xquery_lexer","ace/range","ace/mode/behaviour/xquery","ace/mode/folding/cstyle","ace/anchor","ace/ext/language_tools"], function(require, exports, module) {
"use strict";
var WorkerClient = require("../worker/worker_client").WorkerClient;
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var XQueryLexer = require("./xquery/xquery_lexer").XQueryLexer;
var Range = require("../range").Range;
var XQueryBehaviour = require("./behaviour/xquery").XQueryBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Anchor = require("../anchor").Anchor;
var LanguageTools = require("../ext/language_tools");
var Mode = function() {
this.$tokenizer = new XQueryLexer();
this.$behaviour = new XQueryBehaviour();
this.foldingRules = new CStyleFoldMode();
this.$highlightRules = new TextHighlightRules();
};
oop.inherits(Mode, TextMode);
(function() {
LanguageTools.addCompleter({
getCompletions: function(editor, session, pos, prefix, callback) {
session.$worker.emit("complete", { data: { pos: pos, prefix: prefix } });
session.$worker.on("complete", function(e){
callback(null, e.data);
});
}
});
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.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 + ":)");
}
};
this.createWorker = function(session) {
var worker = new WorkerClient(["ace"], "ace/mode/xquery_worker", "XQueryWorker");
var that = this;
worker.attachToDocument(session.getDocument());
worker.on("ok", function(e) {
session.clearAnnotations();
});
worker.on("markers", function(e) {
session.clearAnnotations();
that.addMarkers(e.data, session);
});
worker.on("highlight", function(tokens) {
that.$tokenizer.tokens = tokens.data.tokens;
that.$tokenizer.lines = session.getDocument().getAllLines();
var rows = Object.keys(that.$tokenizer.tokens);
for(var i=0; i < rows.length; i++) {
var row = parseInt(rows[i]);
delete session.bgTokenizer.lines[row];
delete session.bgTokenizer.states[row];
session.bgTokenizer.fireUpdateEvent(row, row);
}
});
return worker;
};
this.removeMarkers = function(session) {
var markers = session.getMarkers(false);
for (var id in markers) {
if (markers[id].clazz.indexOf('language_highlight_') === 0) {
session.removeMarker(id);
}
}
for (var i = 0; i < session.markerAnchors.length; i++) {
session.markerAnchors[i].detach();
}
session.markerAnchors = [];
};
this.addMarkers = function(annos, mySession) {
var _self = this;
if (!mySession.markerAnchors) mySession.markerAnchors = [];
this.removeMarkers(mySession);
mySession.languageAnnos = [];
annos.forEach(function(anno) {
var anchor = new Anchor(mySession.getDocument(), anno.pos.sl, anno.pos.sc || 0);
mySession.markerAnchors.push(anchor);
var markerId;
var colDiff = anno.pos.ec - anno.pos.sc;
var rowDiff = anno.pos.el - anno.pos.sl;
var gutterAnno = {
guttertext: anno.message,
type: anno.level || "warning",
text: anno.message
};
function updateFloat(single) {
if (markerId)
mySession.removeMarker(markerId);
gutterAnno.row = anchor.row;
if (anno.pos.sc !== undefined && anno.pos.ec !== undefined) {
var range = new Range(anno.pos.sl, anno.pos.sc, anno.pos.el, anno.pos.ec);
markerId = mySession.addMarker(range, "language_highlight_" + (anno.type ? anno.type : "default"));
}
if (single) mySession.setAnnotations(mySession.languageAnnos);
}
updateFloat();
anchor.on("change", function() {
updateFloat(true);
});
if (anno.message) mySession.languageAnnos.push(gutterAnno);
});
mySession.setAnnotations(mySession.languageAnnos);
};
this.$id = "ace/mode/xquery";
}).call(Mode.prototype);
exports.Mode = Mode;
});