Merge remote-tracking branch 'origin/master' into selective-bracket-insertion

This commit is contained in:
Lennart Kats 2012-10-22 11:42:25 +02:00
commit 6338bd10f3
147 changed files with 40437 additions and 79600 deletions

View file

@ -4,7 +4,7 @@
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@ -15,7 +15,7 @@
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -44,7 +44,7 @@ function main(args) {
return "-" + x;
return x;
});
if (args[2] && (args[2][0] != "-" || args[2].indexOf("h") != -1))
type = args[2];
@ -66,8 +66,7 @@ function main(args) {
} else if (type == "bm") {
bookmarklet();
} else if (type == "full") {
ace();
demo();
demo(ace());
bookmarklet();
}
}
@ -120,7 +119,7 @@ function ace() {
console.log('# ace ---------');
// uncompressed
buildAce({
var project = buildAce({
compress: false,
noconflict: false
});
@ -153,9 +152,16 @@ function ace() {
source: ACE_HOME + "/ChangeLog.txt",
dest: BUILD_DIR + "/ChangeLog.txt"
});
return project;
}
function demo() {
function demo(project) {
project = project || buildAce({
compress: false,
noconflict: false,
coreOnly: true
});
console.log('# kitchen sink ---------');
var version, ref;
@ -166,23 +172,26 @@ function demo() {
ref = "";
version = "";
}
var changeComments = function(data) {
return (data
.replace(/<!\-\-DEVEL[\d\D]*?DEVEL\-\->/g, "")
.replace(/PACKAGE\-\->|<!\-\-PACKAGE/g, "")
.replace(/\/\*DEVEL[\d\D]*?DEVEL\*\//g, "")
.replace(/PACKAGE\*\/|\/\*PACKAGE/g, "")
.replace("%version%", version)
.replace("%commit%", ref)
);
}
function changeComments(data) {
return (data
.replace(/<!\-\-DEVEL[\d\D]*?DEVEL\-\->/g, "")
.replace(/PACKAGE\-\->|<!\-\-PACKAGE/g, "")
.replace(/\/\*DEVEL[\d\D]*?DEVEL\*\//g, "")
.replace(/PACKAGE\*\/|\/\*PACKAGE/g, "")
.replace("%version%", version)
.replace("%commit%", ref)
);
};
function fixDocPaths(data) {
return data.replace(/"(demo|build)\//g, "\"");
}
copy({
source: ACE_HOME + "/kitchen-sink.html",
dest: BUILD_DIR + "/kitchen-sink.html",
filter: [changeComments, function(data) {
return data.replace(/"(demo|build)\//g, "\"");
}]
filter: [changeComments, fixDocPaths]
});
copy({
@ -199,22 +208,17 @@ function demo() {
});
var demo = copy.createDataObject();
project.assumeAllFilesLoaded();
copy({
source: ACE_HOME + "/demo/kitchen-sink/demo.js",
dest: demo,
filter: [changeComments, function(data) {
return data.replace(/"(demo|build)\//g, "\"");
}, function(data) {
return data.replace("define(", "define('kitchen-sink/demo',");
}]
});
copy({
source: ACE_HOME + "/lib/ace/split.js",
dest: demo,
filter: [changeComments, function(data) {
return data.replace("define(", "define('ace/split',");
}]
source: [{
project: cloneProject(project),
require: [ "kitchen-sink/demo" ]
}],
filter: getWriteFilters({filters:[fixDocPaths]}, "demo"),
dest: demo
});
copy({
source: demo,
dest: BUILD_DIR + "/kitchen-sink/demo.js",
@ -223,7 +227,57 @@ function demo() {
copyFileSync(ACE_HOME + "/demo/kitchen-sink/logo.png", BUILD_DIR + "/kitchen-sink/logo.png");
}
function buildAce(options) {
function jsFileList(path, filter) {
path = ACE_HOME + "/" + path;
if (!filter)
filter = /_test/;
return fs.readdirSync(path).map(function(x) {
if (x.slice(-3) == ".js" && !filter.test(x))
return x.slice(0, -3);
}).filter(function(x){ return !!x });
}
function addSuffix(options) {
if (options.suffix == null) {
options.suffix = "";
if (options.compress)
options.suffix += "-min";
if (options.noconflict)
options.suffix += "-noconflict";
}
}
function getWriteFilters(options, projectType) {
var filters = [
copy.filter.moduleDefines,
removeUseStrict,
removeLicenceComments,
inlineTextModules
];
if (options.filters)
filters = filters.concat(options.filters);
if (projectType == "worker")
return filters;
if (options.noconflict)
filters.push(namespace(options.ns));
if (options.compress)
filters.push(copy.filter.uglifyjs);
if (options.exportModule && projectType == "main") {
if (options.noconflict)
filters.push(exportAce(options.ns, options.exportModule, options.ns));
else
filters.push(exportAce(options.ns, options.exportModule));
}
return filters;
}
var buildAce = function(options) {
var aceProject = {
roots: [ACE_HOME + '/lib', ACE_HOME + '/demo'],
textPluginPattern: /^ace\/requirejs\/text!/
@ -238,51 +292,22 @@ function buildAce(options) {
noconflict: false,
suffix: null,
name: "ace",
modes: fs.readdirSync(ACE_HOME + "/lib/ace/mode").map(function(x) {
if (x.slice(-3) == ".js" && !/_highlight_rules|_test|_worker|xml_util|_outdent|behaviour/.test(x))
return x.slice(0, -3);
}).filter(function(x) { return !!x; }),
themes: fs.readdirSync(ACE_HOME + "/lib/ace/theme").map(function(x){
return x.slice(-3) == ".js" && x.slice(0, -3);
}).filter(function(x){ return !!x; }),
modes: jsFileList("lib/ace/mode", /_highlight_rules|_test|_worker|xml_util|_outdent|behaviour/),
themes: jsFileList("lib/ace/theme"),
extensions: jsFileList("lib/ace/ext"),
workers: ["javascript", "coffee", "css", "json", "xquery"],
keybindings: ["vim", "emacs"]
};
for(var key in defaults)
if (!options.hasOwnProperty(key))
options[key] = defaults[key];
if (options.suffix == null) {
options.suffix = "";
if (options.compress)
options.suffix += "-min";
if (options.noconflict)
options.suffix += "-noconflict";
}
addSuffix(options);
if (!options.requires)
options.requires = [options.exportModule];
var filters = [
copy.filter.moduleDefines,
filterTextPlugin,
removeUseStrict,
removeLicenceCmments
];
if (options.noconflict) {
filters.push(namespace(options.ns));
if (options.exportModule)
var exportFilter = exportAce(options.ns, options.exportModule, options.ns);
} else if (options.exportModule) {
var exportFilter = exportAce(options.ns, options.exportModule);
}
if (options.compress)
filters.push(copy.filter.uglifyjs);
var targetDir = options.targetDir + options.suffix;
var name = options.name;
@ -300,10 +325,13 @@ function buildAce(options) {
filter: [ copy.filter.moduleDefines ],
dest: ace
});
if (options.coreOnly)
return project;
copy({
source: ace,
filter: exportFilter ? filters.concat(exportFilter) : filters,
filter: getWriteFilters(options, "main"),
dest: targetDir + '/' + name + ".js"
});
@ -317,7 +345,7 @@ function buildAce(options) {
project: cloneProject(project),
require: [ 'ace/mode/' + mode ]
}],
filter: filters,
filter: getWriteFilters(options, "mode"),
dest: targetDir + "/mode-" + mode + ".js"
});
});
@ -327,26 +355,29 @@ function buildAce(options) {
project.assumeAllFilesLoaded();
options.themes.forEach(function(theme) {
console.log("theme " + theme);
/*copy({
copy({
source: [{
project: cloneProject(project),
require: ["ace/theme/" + theme]
}],
filter: filters,
dest: targetDir + "/theme-" + theme + ".js"
});*/
// use this instead, to not create separate modules for js and css
var themePath = ACE_HOME + "/lib/ace/theme/" + theme
var js = fs.readFileSync(themePath + ".js", "utf8");
js = js.replace("define(", "define('ace/theme/" + theme + "', ['require', 'exports', 'module', 'ace/lib/dom'], ");
if (fs.existsSync(themePath + ".css", "utf8")) {
var css = fs.readFileSync(themePath + ".css", "utf8")
js = js.replace(/require\(.ace\/requirejs\/text!.*?\)/, quoteString(css))
}
filters.forEach(function(f) {js = f(js); });
fs.writeFileSync(targetDir + "/theme-" + theme + ".js", js);
filter: getWriteFilters(options, "theme"),
dest: targetDir + "/theme-" + theme.replace("_theme", "") + ".js"
});
});
console.log('# ace extensions ---------');
project.assumeAllFilesLoaded();
options.extensions.forEach(function(ext) {
console.log("extensions " + ext);
copy({
source: [{
project: cloneProject(project),
require: [ 'ace/ext/' + ext ]
}],
filter: getWriteFilters(options, "ext"),
dest: targetDir + "/ext-" + ext + ".js"
});
});
console.log('# ace key bindings ---------');
@ -359,19 +390,12 @@ function buildAce(options) {
project: cloneProject(project),
require: [ 'ace/keyboard/' + keybinding ]
}],
filter: filters,
filter: getWriteFilters(options, "keybinding"),
dest: targetDir + "/keybinding-" + keybinding + ".js"
});
});
console.log('# ace worker ---------');
filters = [
copy.filter.moduleDefines,
filterTextPlugin,
removeUseStrict,
removeLicenceCmments
];
options.workers.forEach(function(mode) {
console.log("worker for " + mode + " mode");
@ -390,7 +414,7 @@ function buildAce(options) {
'ace/mode/' + mode + '_worker'
]
}],
filter: filters,
filter: getWriteFilters(options, "worker"),
dest: worker
});
copy({
@ -404,14 +428,70 @@ function buildAce(options) {
});
console.log('# combining files into one ---------');
if (options.shrinkwrap) {
console.log('# combining files into one ---------');
copy({
source: { root:targetDir, exclude:/^worker\-/ },
dest: BUILD_DIR + '/ace-min.js'
});
}
return project;
};
// silence annoying messages from dryice
var buildAce = function(fn) {
return function() {
var log = console.log
console.log = function() {
if (typeof arguments[0] == "string" && /Ignoring requirement/.test(arguments[0]))
return;
log.apply(console, arguments);
}
var ret = fn.apply(null, arguments);
console.log = log;
return ret;
}
}(buildAce);
var textModules = {}
var detectTextModules = function(input, source) {
if (!source)
throw new Error('Missing filename for text module');
if (typeof input !== 'string')
input = input.toString();
var module = source.isLocation ? source.path : source;
input = input.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
input = input.replace(/\n\s+/g, "\n");
input = '"' + input.replace(/\n/g, '\\\n') + '"';
textModules[module] = input;
return "";
};
detectTextModules.onRead = true;
copy.filter.addDefines = detectTextModules;
function inlineTextModules(text) {
var lastDep = "";
return text.replace(/, *['"]ace\/requirejs\/text!(.*?)['"]|= *require\(['"](?:ace|[.\/]+)\/requirejs\/text!(.*?)['"]\)/g, function(_, dep, call) {
if (dep) {
if (!lastDep) {
lastDep = dep;
return "";
}
} else if (call) {
call = textModules[lastDep];
delete textModules[lastDep];
lastDep = "";
if (call)
return "= " + call;
}
console.log(dep, lastDep, call);
throw "inlining of multiple text modules is not supported";
});
}
// TODO: replace with project.clone once it is fixed in dryice
@ -432,6 +512,7 @@ function cloneProject(project) {
return clone;
}
function copyFileSync(srcFile, destFile) {
var BUF_LENGTH = 64*1024,
buf = new Buffer(BUF_LENGTH),
@ -458,16 +539,12 @@ function quoteString(str) {
return '"' + str.replace(/\\/, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\\n") + '"';
}
function filterTextPlugin(text) {
return text.replace(/(['"])ace\/requirejs\/text\!/g, "$1text!");
}
function removeUseStrict(text) {
return text.replace(/['"]use strict['"];/g, "");
}
function removeLicenceCmments(text) {
return text.replace(/(;)\s*\/\*[\d\D]*?\*\//g, "$1");
function removeLicenceComments(text) {
return text.replace(/(?:(;)|\n)\s*\/\*[\d\D]*?\*\/|\n\s*\/\/.*/g, "$1");
}
function namespace(ns) {

View file

@ -136,7 +136,7 @@
</div><div class="description"><p>Returns the value of the distance between the left of the editor and the leftmost part of the visible content.</p>
</div></div></div></div></article><article id="EditSession.getScrollTop" data-title="EditSession.getScrollTop (class method)" class="article"><div class="section method"><div class="memberContent"><div class="title"><i id="EditSession.getScrollTop" class="methodToggle methodClicker inactive icon-caret-right"></i><ul class="signatures"><li class="signature"><ul><li class="signature-call"><span id="EditSession.getScrollTop" class="member-name methodClicker"><span class="sigClassName">EditSession.</span><span class="sigMemberName">getScrollTop</span></span>(<span class="sigArgList"></span>)<li class="signature-returns"><ul class="argument-types"><li class="argument-type"><a href="http://www.nodemanual.org/latest/js_doc/Number.html" class="returnType " title="Number" data-id="Number">Number</a></li></ul></li></li></ul><ul class="metaInfo"></ul></li></ul></div><div class="sideToggler"><div id="ellipsis_EditSession.getScrollTop" class="ellipsis_description"><p>Returns the value of the distance between the top of the editor and the topmost part of the visible content.</p>
</div><div class="description"><p>Returns the value of the distance between the top of the editor and the topmost part of the visible content.</p>
</div></div></div></div></article><article id="EditSession.getSelection" data-title="EditSession.getSelection (class method)" class="article"><div class="section method"><div class="memberContent"><div class="title"><i id="EditSession.getSelection" class="methodToggle methodClicker inactive icon-caret-right"></i><ul class="signatures"><li class="signature"><ul><li class="signature-call"><span id="EditSession.getSelection" class="member-name methodClicker"><span class="sigClassName">EditSession.</span><span class="sigMemberName">getSelection</span></span>(<span class="sigArgList"></span>)<li class="signature-returns"><ul class="argument-types"><li class="argument-type"><a href="http://www.nodemanual.org/latest/js_doc/String.html" class="returnType " title="String" data-id="String">String</a></li></ul></li></li></ul><ul class="metaInfo"></ul></li></ul></div><div class="sideToggler"><div id="ellipsis_EditSession.getSelection" class="ellipsis_description"><p>Returns the string of the current selection.</p>
</div></div></div></div></article><article id="EditSession.getSelection" data-title="EditSession.getSelection (class method)" class="article"><div class="section method"><div class="memberContent"><div class="title"><i id="EditSession.getSelection" class="methodToggle methodClicker inactive icon-caret-right"></i><ul class="signatures"><li class="signature"><ul><li class="signature-call"><span id="EditSession.getSelection" class="member-name methodClicker"><span class="sigClassName">EditSession.</span><span class="sigMemberName">getSelection</span></span>(<span class="sigArgList"></span>)<li class="signature-returns"><ul class="argument-types"><li class="argument-type"><a href="selection.html" class="returnType " title="Selection" data-id="Selection">Selection</a></li></ul></li></li></ul><ul class="metaInfo"></ul></li></ul></div><div class="sideToggler"><div id="ellipsis_EditSession.getSelection" class="ellipsis_description"><p>Returns the string of the current selection.</p>
</div><div class="description"><p>Returns the string of the current selection.</p>
</div></div></div></div></article><article id="EditSession.getState" data-title="EditSession.getState (class method)" class="article"><div class="section method"><div class="memberContent"><div class="title"><i id="EditSession.getState" class="methodToggle methodClicker inactive icon-caret-right"></i><ul class="signatures"><li class="signature"><ul><li class="signature-call"><span id="EditSession.getState" class="member-name methodClicker"><span class="sigClassName">EditSession.</span><span class="sigMemberName">getState</span></span>(<span class="sigArgList"><a href="http://www.nodemanual.org/latest/js_doc/Number.html" class="argument methodClicker" title="Number" data-id="Number">Number</a> row</span>)<li class="signature-returns"><ul class="argument-types"><li class="argument-type"><a href="http://www.nodemanual.org/latest/js_doc/Array.html" class="returnType " title="Array" data-id="Array">Array</a></li></ul></li></li></ul><ul class="metaInfo"><li><span class="label related-to">Related to: <obj class="related_to"> </obj></span></li></ul></li></ul></div><div class="sideToggler"><div id="ellipsis_EditSession.getState" class="ellipsis_description"><p>Returns the state of tokenization at the end of a row.</p>
</div><div class="description"><p>Returns the state of tokenization at the end of a row.</p>
@ -147,9 +147,9 @@
</div><div class="description"><p>Returns the current value for tabs. If the user is using soft tabs, this will be a series of spaces (defined by <a href="#EditSession.getTabSize" class="link-short" title="EditSession.getTabSize (class method)" data-id="EditSession.getTabSize"><code>getTabSize()</code></a>); otherwise it&#39;s simply <code>&#39;\t&#39;</code>.</p>
</div></div></div></div></article><article id="EditSession.getTextRange" data-title="EditSession.getTextRange (class method)" class="article"><div class="section method"><div class="memberContent"><div class="title"><i id="EditSession.getTextRange" class="methodToggle methodClicker inactive icon-caret-right"></i><ul class="signatures"><li class="signature"><ul><li class="signature-call"><span id="EditSession.getTextRange" class="member-name methodClicker"><span class="sigClassName">EditSession.</span><span class="sigMemberName">getTextRange</span></span>(<span class="sigArgList"><a href="http://www.nodemanual.org/latest/js_doc/String.html" class="argument methodClicker" title="String" data-id="String">String</a> range</span>)<li class="signature-returns"><ul class="argument-types"><li class="argument-type"><a href="http://www.nodemanual.org/latest/js_doc/Array.html" class="returnType " title="Array" data-id="Array">Array</a></li></ul></li></li></ul><ul class="metaInfo"><li><span class="label related-to">Related to: <obj class="related_to"> </obj></span></li></ul></li></ul></div><div class="sideToggler"><div id="ellipsis_EditSession.getTextRange" class="ellipsis_description"><p>Given a range within the document, this function returns all the text within that range as a single string.</p>
</div><div class="description"><p>Given a range within the document, this function returns all the text within that range as a single string.</p>
<h4>Arguments</h4><table class="argumentTable argument-list table table-striped table-bordered"><tr class="argumentRow "><td class="argName ">range</td><td class="argType" "><a href="http://www.nodemanual.org/latest/js_doc/String.html" class="" title="String" data-id="String">String</a></td><td class="argDescription "><p>Required. The range to work with</p>
</td></tr></table></div></div></div></div></article><article id="EditSession.getTokenAt" data-title="EditSession.getTokenAt (class method)" class="article"><div class="section method"><div class="memberContent"><div class="title"><i id="EditSession.getTokenAt" class="methodToggle methodClicker inactive icon-caret-right"></i><ul class="signatures"><li class="signature"><ul><li class="signature-call"><span id="EditSession.getTokenAt" class="member-name methodClicker"><span class="sigClassName">EditSession.</span><span class="sigMemberName">getTokenAt</span></span>(<span class="sigArgList"><a href="http://www.nodemanual.org/latest/js_doc/Number.html" class="argument methodClicker" title="Number" data-id="Number">Number</a> row, <a href="http://www.nodemanual.org/latest/js_doc/Number.html" class="argument methodClicker" title="Number" data-id="Number">Number</a> column</span>)<li class="signature-returns"><ul class="argument-types"><li class="argument-type"><a href="http://www.nodemanual.org/latest/js_doc/Array.html" class="returnType " title="Array" data-id="Array">Array</a></li></ul></li></li></ul><ul class="metaInfo"></ul></li></ul></div><div class="sideToggler"><div id="ellipsis_EditSession.getTokenAt" class="ellipsis_description"><p>Returns an array of tokens at the indicated row and column.</p>
</div><div class="description"><p>Returns an array of tokens at the indicated row and column.</p>
<h4>Arguments</h4><table class="argumentTable argument-list table table-striped table-bordered"><tr class="argumentRow "><td class="argName ">range</td><td class="argType" "><a href="range.html" class="" title="Range" data-id="Range">Range</a></td><td class="argDescription "><p>Required. The range to work with</p>
</td></tr></table></div></div></div></div></article><article id="EditSession.getTokenAt" data-title="EditSession.getTokenAt (class method)" class="article"><div class="section method"><div class="memberContent"><div class="title"><i id="EditSession.getTokenAt" class="methodToggle methodClicker inactive icon-caret-right"></i><ul class="signatures"><li class="signature"><ul><li class="signature-call"><span id="EditSession.getTokenAt" class="member-name methodClicker"><span class="sigClassName">EditSession.</span><span class="sigMemberName">getTokenAt</span></span>(<span class="sigArgList"><a href="http://www.nodemanual.org/latest/js_doc/Number.html" class="argument methodClicker" title="Number" data-id="Number">Number</a> row, <a href="http://www.nodemanual.org/latest/js_doc/Number.html" class="argument methodClicker" title="Number" data-id="Number">Number</a> column</span>)<li class="signature-returns"><ul class="argument-types"><li class="argument-type"><a href="http://www.nodemanual.org/latest/js_doc/Array.html" class="returnType " title="Array" data-id="Array">Array</a></li></ul></li></li></ul><ul class="metaInfo"></ul></li></ul></div><div class="sideToggler"><div id="ellipsis_EditSession.getTokenAt" class="ellipsis_description"><p>Returns an object indicating the token at the current row. The object has two properties: <code>index</code> and <code>start</code>.</p>
</div><div class="description"><p>Returns an object indicating the token at the current row. The object has two properties: <code>index</code> and <code>start</code>.</p>
<h4>Arguments</h4><table class="argumentTable argument-list table table-striped table-bordered"><tr class="argumentRow "><td class="argName ">row</td><td class="argType" "><a href="http://www.nodemanual.org/latest/js_doc/Number.html" class="" title="Number" data-id="Number">Number</a></td><td class="argDescription "><p>Required. The row number to retrieve from</p>
</td></tr><tr class="argumentRow "><td class="argName ">column</td><td class="argType" "><a href="http://www.nodemanual.org/latest/js_doc/Number.html" class="" title="Number" data-id="Number">Number</a></td><td class="argDescription "><p>Required. The column number to retrieve from</p>
</td></tr></table></div></div></div></div></article><article id="EditSession.getTokens" data-title="EditSession.getTokens (class method)" class="article"><div class="section method"><div class="memberContent"><div class="title"><i id="EditSession.getTokens" class="methodToggle methodClicker inactive icon-caret-right"></i><ul class="signatures"><li class="signature"><ul><li class="signature-call"><span id="EditSession.getTokens" class="member-name methodClicker"><span class="sigClassName">EditSession.</span><span class="sigMemberName">getTokens</span></span>(<span class="sigArgList"><a href="http://www.nodemanual.org/latest/js_doc/Number.html" class="argument methodClicker" title="Number" data-id="Number">Number</a> row</span>)<li class="signature-returns"><ul class="argument-types"><li class="argument-type"><a href="http://www.nodemanual.org/latest/js_doc/Array.html" class="returnType " title="Array" data-id="Array">Array</a></li></ul></li></li></ul><ul class="metaInfo"><li><span class="label related-to">Related to: <obj class="related_to"> </obj></span></li></ul></li></ul></div><div class="sideToggler"><div id="ellipsis_EditSession.getTokens" class="ellipsis_description"><p>Starts tokenizing at the row indicated. Returns a list of objects of the tokenized rows.</p>

2
build

@ -1 +1 @@
Subproject commit c2f3abb2ecd3287f90225d804132f0fd26cfb639
Subproject commit 6149ca6b148e878d4c1341d4675ca3597d78dbdd

View file

@ -55,205 +55,18 @@ var Editor = require("ace/editor").Editor;
var MultiSelect = require("ace/multi_select").MultiSelect;
// workers do not work for file:
if (location.protocol == "file:")
EditSession.prototype.$useWorker = false;
/* if (location.protocol == "file:")
EditSession.prototype.$useWorker = false; */
/************** modes ***********************/
var modes = [];
function getModeFromPath(path) {
var mode = modesByName.text;
for (var i = 0; i < modes.length; i++) {
if (modes[i].supportsFile(path)) {
mode = modes[i];
break;
}
}
return mode;
};
var Mode = function(name, desc, extensions) {
this.name = name;
this.desc = desc;
this.mode = "ace/mode/" + name;
this.extRe = new RegExp("^.*\\.(" + extensions + ")$", "g");
};
Mode.prototype.supportsFile = function(filename) {
return filename.match(this.extRe);
};
var modesByName = {
c9search: ["C9Search" , "c9search_results"],
coffee: ["CoffeeScript" , "coffee|^Cakefile"],
coldfusion: ["ColdFusion" , "cfm"],
csharp: ["C#" , "cs"],
css: ["CSS" , "css"],
diff: ["Diff" , "diff|patch"],
glsl: ["Glsl" , "glsl|frag|vert"],
golang: ["Go" , "go"],
groovy: ["Groovy" , "groovy"],
haxe: ["haXe" , "hx"],
html: ["HTML" , "htm|html|xhtml"],
c_cpp: ["C/C++" , "c|cc|cpp|cxx|h|hh|hpp"],
clojure: ["Clojure" , "clj"],
jade: ["Jade" , "jade"],
java: ["Java" , "java"],
jsp: ["JSP" , "jsp"],
javascript: ["JavaScript" , "js"],
json: ["JSON" , "json"],
jsx: ["JSX" , "jsx"],
latex: ["LaTeX" , "latex|tex|ltx|bib"],
less: ["LESS" , "less"],
liquid: ["Liquid" , "liquid"],
lua: ["Lua" , "lua"],
luapage: ["LuaPage" , "lp"], // http://keplerproject.github.com/cgilua/manual.html#templates
markdown: ["Markdown" , "md|markdown"],
ocaml: ["OCaml" , "ml|mli"],
perl: ["Perl" , "pl|pm"],
pgsql: ["pgSQL" , "pgsql"],
php: ["PHP" , "php|phtml"],
powershell: ["Powershell" , "ps1"],
python: ["Python" , "py"],
ruby: ["Ruby" , "ru|gemspec|rake|rb"],
scad: ["OpenSCAD" , "scad"],
scala: ["Scala" , "scala"],
scss: ["SCSS" , "scss|sass"],
sh: ["SH" , "sh|bash|bat"],
sql: ["SQL" , "sql"],
svg: ["SVG" , "svg"],
tcl: ["Tcl" , "tcl"],
text: ["Text" , "txt"],
textile: ["Textile" , "textile"],
typescript: ["Typescript" , "typescript|ts|str"],
xml: ["XML" , "xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl"],
xquery: ["XQuery" , "xq"],
yaml: ["YAML" , "yaml"]
};
for (var name in modesByName) {
var mode = modesByName[name];
mode = new Mode(name, mode[0], mode[1])
modesByName[name] = mode;
modes.push(mode);
}
/*********** demo documents ***************************/
var fileCache = {};
function initDoc(file, path, doc) {
if (doc.prepare)
file = doc.prepare(file);
var session = new EditSession(file);
session.setUndoManager(new UndoManager());
doc.session = session;
doc.path = path;
if (doc.wrapped) {
session.setUseWrapMode(true);
session.setWrapLimitRange(80, 80);
}
var mode = getModeFromPath(path)
session.modeName = mode.name;
session.setMode(mode.mode);
}
function makeHuge(txt) {
for (var i = 0; i < 5; i++)
txt += txt;
return txt
}
var docs = {
"docs/javascript.js": "JavaScript",
"docs/clojure.clj": "Clojure",
"docs/coffeescript.coffee": "Coffeescript",
"docs/coldfusion.cfm": "ColdFusion",
"docs/cpp.cpp": "C/C++",
"docs/csharp.cs": "C#",
"docs/css.css": "CSS",
"docs/diff.diff": "Diff",
"docs/glsl.glsl": "Glsl",
"docs/golang.go": "Go",
"docs/groovy.groovy": "Groovy",
"docs/Haxe.hx": "haXe",
"docs/html.html": "HTML",
"docs/jade.jade": "Jade",
"docs/java.java": "Java",
"docs/jsp.jsp": "JSP",
"docs/json.json": "JSON",
"docs/jsx.jsx": "JSX",
"docs/latex.tex": {name: "LaTeX", wrapped: true},
"docs/less.less": "LESS",
"docs/liquid.liquid": "Liquid",
"docs/lua.lua": "Lua",
"docs/luapage.lp": "LuaPage",
"docs/markdown.md": {name: "Markdown", wrapped: true},
"docs/ocaml.ml": "OCaml",
"docs/OpenSCAD.scad": "OpenSCAD",
"docs/perl.pl": "Perl",
"docs/pgsql.pgsql": {name: "pgSQL", wrapped: true},
"docs/php.php": "PHP",
"docs/plaintext.txt": {name: "Plain Text", prepare: makeHuge, wrapped: true},
"docs/powershell.ps1": "Powershell",
"docs/python.py": "Python",
"docs/ruby.rb": "Ruby",
"docs/scala.scala": "Scala",
"docs/scss.scss": "SCSS",
"docs/sh.sh": "SH",
"docs/sql.sql": {name: "SQL", wrapped: true},
"docs/svg.svg": "SVG",
"docs/tcl.tcl": "Tcl",
"docs/textile.textile": {name: "Textile", wrapped: true},
"docs/typescript.ts": "Typescript",
"docs/xml.xml": "XML",
"docs/xquery.xq": "XQuery",
"docs/yaml.yaml": "YAML",
"docs/c9search.c9search_results": "C9 Search Results"
}
var ownSource = {
/* filled from require*/
};
var hugeDocs = {
"build/src/ace.js": "",
"build/src-min/ace.js": ""
};
if (window.require && window.require.s) try {
for (var path in window.require.s.contexts._.loaded) {
if (path.indexOf("!") != -1)
path = path.split("!").pop();
else
path = path + ".js";
ownSource[path] = ""
}
} catch(e) {}
function prepareDocList(docs) {
var list = []
for (var path in docs) {
var doc = docs[path];
if (typeof doc != "object")
doc = {name: doc || path};
doc.path = path;
doc.desc = doc.name.replace(/^(ace|docs|demo|build)\//, "");
if (doc.desc.length > 18)
doc.desc = doc.desc.slice(0, 7) + ".." + doc.desc.slice(-9)
fileCache[doc.name] = doc;
list.push(doc);
};
return list;
}
docs = prepareDocList(docs);
ownSource = prepareDocList(ownSource);
hugeDocs = prepareDocList(hugeDocs);
var doclist = require("./doclist");
var modelist = require("./modelist");
var layout = require("./layout");
var TokenTooltip = require("./token_tooltip").TokenTooltip;
var util = require("./util");
var saveOption = util.saveOption;
var fillDropdown = util.fillDropdown;
var bindCheckbox = util.bindCheckbox;
var bindDropdown = util.bindDropdown;
/*********** create editor ***************************/
var container = document.getElementById("editor");
@ -271,27 +84,30 @@ window.env = env;
window.ace = env.editor;
env.editor.setAnimatedScroll(true);
// add multiple cursor support to editor
require("ace/multi_select").MultiSelect(env.editor);
var consoleEl = dom.createElement("div");
container.parentNode.appendChild(consoleEl);
consoleEl.style.position="fixed"
consoleEl.style.bottom = "1px"
consoleEl.style.right = 0
consoleEl.style.background = "white"
consoleEl.style.border = "1px solid #baf"
consoleEl.style.zIndex = "100"
var cmdLine = new singleLineEditor(consoleEl);
consoleEl.style.cssText = "position:fixed; bottom:1px; right:0;\
border:1px solid #baf; zIndex:100";
var cmdLine = new layout.singleLineEditor(consoleEl);
cmdLine.editor = env.editor;
env.editor.cmdLine = cmdLine;
/**
* This demonstrates how you can define commands and bind shortcuts to them.
*/
env.editor.commands.addCommands([{
name: "gotoline",
bindKey: {win: "Ctrl-L", mac: "Command-L"},
exec: function(editor, line) {
if (typeof line == "object") {
var arg = this.name + " " + editor.getCursorPosition().row;
editor.cmdLine.setValue(arg, 1)
editor.cmdLine.focus()
return
editor.cmdLine.setValue(arg, 1);
editor.cmdLine.focus();
return;
}
line = parseInt(line, 10);
if (!isNaN(line))
@ -303,10 +119,10 @@ env.editor.commands.addCommands([{
bindKey: {win: "Ctrl-F", mac: "Command-F"},
exec: function(editor, needle) {
if (typeof needle == "object") {
var arg = this.name + " " + editor.getCopyText()
editor.cmdLine.setValue(arg, 1)
editor.cmdLine.focus()
return
var arg = this.name + " " + editor.getCopyText();
editor.cmdLine.setValue(arg, 1);
editor.cmdLine.focus();
return;
}
editor.find(needle);
},
@ -316,24 +132,32 @@ env.editor.commands.addCommands([{
bindKey: "shift-esc",
exec: function(editor, needle) { editor.cmdLine.focus(); },
readOnly: true
}])
}, {
name: "execute",
bindKey: "ctrl+enter",
exec: function(editor) {
try {
var r = eval(editor.getCopyText()||editor.getValue());
} catch(e) {
r = e;
}
editor.cmdLine.setValue(r + "")
},
readOnly: true
}]);
cmdLine.commands.bindKeys({
"Shift-Return|Ctrl-Return|Alt-Return": function(cmdLine) { cmdLine.insert("\n")},
"Shift-Return|Ctrl-Return|Alt-Return": function(cmdLine) { cmdLine.insert("\n"); },
"Esc|Shift-Esc": function(cmdLine){ cmdLine.editor.focus(); },
"Return": function(cmdLine){
var command = cmdLine.getValue().split(/\s+/);
var editor = cmdLine.editor;
editor.commands.exec(command[0], editor, command[1]);
editor.focus();
},
})
}
});
cmdLine.commands.removeCommands(["find", "gotoline", "findall", "replace", "replaceall"])
/**
* This demonstrates how you can define commands and bind shortcuts to them.
*/
cmdLine.commands.removeCommands(["find", "gotoline", "findall", "replace", "replaceall"]);
var commands = env.editor.commands;
commands.addCommand({
@ -354,28 +178,28 @@ var keybindings = {
"outdent": "[",
"gotolinestart": "^",
"gotolineend": "$"
})
})
};
/*********** manage layout ***************************/
var consoleHight = 20;
var consoleHeight = 20;
function onResize() {
var left = env.split.$container.offsetLeft;
var width = document.documentElement.clientWidth - left;
container.style.width = width + "px";
container.style.height = document.documentElement.clientHeight - consoleHight + "px";
container.style.height = document.documentElement.clientHeight - consoleHeight + "px";
env.split.resize();
consoleEl.style.width = width + "px";
cmdLine.resize()
cmdLine.resize();
}
window.onresize = onResize;
onResize();
/*********** options pane ***************************/
/*********** options panel ***************************/
var docEl = document.getElementById("doc");
var modeEl = document.getElementById("mode");
var wrapModeEl = document.getElementById("soft_wrap");
@ -392,54 +216,23 @@ var animateScrollEl = document.getElementById("animate_scroll");
var softTabEl = document.getElementById("soft_tab");
var behavioursEl = document.getElementById("enable_behaviours");
var group = document.createElement("optgroup");
group.setAttribute("label", "Mode Examples");
fillDropdown(docs, group);
docEl.appendChild(group);
var group = document.createElement("optgroup");
group.setAttribute("label", "Huge documents");
fillDropdown(hugeDocs, group);
docEl.appendChild(group);
var group = document.createElement("optgroup");
group.setAttribute("label", "own source");
fillDropdown(ownSource, group);
docEl.appendChild(group);
fillDropdown(modes, modeEl);
fillDropdown(docEl, doclist.all);
fillDropdown(modeEl, modelist.modes);
var modesByName = modelist.modesByName;
bindDropdown("mode", function(value) {
env.editor.getSession().setMode(modesByName[value].mode || modesByName.text.mode);
env.editor.getSession().modeName = value;
env.editor.session.setMode(modesByName[value].mode || modesByName.text.mode);
env.editor.session.modeName = value;
});
bindDropdown("doc", function(name) {
var doc = fileCache[name];
if (!doc)
return;
if (doc.session)
return setSession(doc.session)
//@todo do something while waiting
// env.editor.setSession(emptySession || (emptySession = new EditSession("")))
var path = doc.path;
var parts = path.split("/");
if (parts[0] == "docs")
path = "demo/kitchen-sink/" + path;
else if (parts[0] == "ace")
path = "lib/" + path;
net.get(path, function(x) {
initDoc(x, path, doc);
setSession(doc.session)
})
function setSession(session) {
var session = env.split.setSession(session);
doclist.loadDoc(name, function(session) {
if (!session)
return;
session = env.split.setSession(session);
updateUIEditorOptions();
env.editor.focus();
}
});
});
function updateUIEditorOptions() {
@ -465,40 +258,22 @@ function updateUIEditorOptions() {
saveOption(behavioursEl, editor.getBehavioursEnabled());
}
function saveOption(el, val) {
if (!el.onchange && !el.onclick)
return;
if ("checked" in el) {
if (val !== undefined)
el.checked = val;
localStorage && localStorage.setItem(el.id, el.checked ? 1 : 0);
}
else {
if (val !== undefined)
el.value = val;
localStorage && localStorage.setItem(el.id, el.value);
}
}
event.addListener(themeEl, "mouseover", function(e){
this.desiredValue = e.target.value;
if (!this.$timer)
this.$timer = setTimeout(this.updateTheme);
})
});
event.addListener(themeEl, "mouseout", function(e){
this.desiredValue = null;
if (!this.$timer)
this.$timer = setTimeout(this.updateTheme, 20);
})
});
themeEl.updateTheme = function(){
env.split.setTheme(themeEl.desiredValue || themeEl.selectedValue);
themeEl.$timer = null;
}
};
bindDropdown("theme", function(value) {
if (!value)
@ -516,33 +291,28 @@ bindDropdown("fontsize", function(value) {
});
bindDropdown("folding", function(value) {
env.editor.getSession().setFoldStyle(value);
env.editor.session.setFoldStyle(value);
env.editor.setShowFoldWidgets(value !== "manual");
});
bindDropdown("soft_wrap", function(value) {
var session = env.editor.getSession();
var session = env.editor.session;
var renderer = env.editor.renderer;
switch (value) {
case "off":
session.setUseWrapMode(false);
renderer.setPrintMarginColumn(80);
break;
case "40":
session.setUseWrapMode(true);
session.setWrapLimitRange(40, 40);
renderer.setPrintMarginColumn(40);
break;
case "80":
session.setUseWrapMode(true);
session.setWrapLimitRange(80, 80);
renderer.setPrintMarginColumn(80);
break;
case "free":
session.setUseWrapMode(true);
session.setWrapLimitRange(null, null);
renderer.setPrintMarginColumn(80);
break;
default:
session.setUseWrapMode(true);
var col = parseInt(value, 10);
session.setWrapLimitRange(col, col);
renderer.setPrintMarginColumn(col);
}
});
@ -583,7 +353,7 @@ bindCheckbox("animate_scroll", function(checked) {
});
bindCheckbox("soft_tab", function(checked) {
env.editor.getSession().setUseSoftTabs(checked);
env.editor.session.setUseSoftTabs(checked);
});
bindCheckbox("enable_behaviours", function(checked) {
@ -619,42 +389,15 @@ bindDropdown("split", function(value) {
}
});
function bindCheckbox(id, callback) {
var el = document.getElementById(id);
if (localStorage && localStorage.getItem(id))
el.checked = localStorage.getItem(id) == "1";
var onCheck = function() {
callback(!!el.checked);
saveOption(el);
};
el.onclick = onCheck;
onCheck();
}
function bindDropdown(id, callback) {
var el = document.getElementById(id);
if (localStorage && localStorage.getItem(id))
el.value = localStorage.getItem(id);
var onChange = function() {
callback(el.value);
saveOption(el);
};
el.onchange = onChange;
onChange();
}
function fillDropdown(list, el) {
list.forEach(function(item) {
var option = document.createElement("option");
option.setAttribute("value", item.name);
option.innerHTML = item.desc;
el.appendChild(option);
});
}
bindCheckbox("highlight_token", function(checked) {
var editor = env.editor;
if (editor.tokenTooltip && !checked) {
editor.tokenTooltip.destroy();
delete editor.tokenTooltip;
} else if (checked) {
editor.tokenTooltip = new TokenTooltip(editor);
}
});
/************** dragover ***************************/
event.addListener(container, "dragover", function(e) {
@ -683,96 +426,10 @@ event.addListener(container, "drop", function(e) {
}
});
// add multiple cursor support to editor
require("ace/multi_select").MultiSelect(env.editor);
function singleLineEditor(el) {
var renderer = new Renderer(el);
renderer.scrollBar.element.style.display = "none";
renderer.scrollBar.width = 0;
renderer.content.style.height = "auto";
renderer.screenToTextCoordinates = function(x, y) {
var pos = this.pixelToScreenCoordinates(x, y);
return this.session.screenToDocumentPosition(
Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)),
Math.max(pos.column, 0)
);
};
// todo size change event
renderer.$computeLayerConfig = function() {
var longestLine = this.$getLongestLine();
var firstRow = 0;
var lastRow = this.session.getLength();
var height = this.session.getScreenLength() * this.lineHeight;
this.scrollTop = 0;
var config = this.layerConfig;
config.width = longestLine;
config.padding = this.$padding;
config.firstRow = 0;
config.firstRowScreen = 0;
config.lastRow = lastRow;
config.lineHeight = this.lineHeight;
config.characterWidth = this.characterWidth;
config.minHeight = height;
config.maxHeight = height;
config.offset = 0;
config.height = height;
this.$gutterLayer.element.style.marginTop = 0 + "px";
this.content.style.marginTop = 0 + "px";
this.content.style.width = longestLine + 2 * this.$padding + "px";
this.content.style.height = height + "px";
this.scroller.style.height = height + "px";
this.container.style.height = height + "px";
};
renderer.isScrollableBy=function(){return false};
var editor = new Editor(renderer);
new MultiSelect(editor);
editor.session.setUndoManager(new UndoManager());
editor.setHighlightActiveLine(false);
editor.setShowPrintMargin(false);
editor.renderer.setShowGutter(false);
editor.renderer.setHighlightGutterLine(false);
return editor;
};
/** simple statusbar **/
var editor = env.editor;
var statusBarEl = dom.createElement("div");
statusBarEl.style.cssText = "color:gray;position:absolute;right:0;border-left:1px solid";
cmdLine.container.appendChild(statusBarEl);
var statusUpdate = lang.deferredCall(function() {
var status = [];
function add(s, sep) {s && status.push(s, sep || "|")}
if (editor.$vimModeHandler)
add(editor.$vimModeHandler.getStatusText());
else if (editor.commands.recording)
add("REC");
var c = editor.selection.lead;
add(c.row + ":" + c.column, " ");
if (!editor.selection.isEmpty()) {
var r = editor.getSelectionRange()
add("(" + (r.end.row - r.start.row) + ":" +(r.end.column - r.start.column) + ")");
}
status.pop();
statusBarEl.textContent = status.join("");
});
env.editor.on("changeStatus", function() {
statusUpdate.schedule(50);
});
env.editor.on("changeSelection", function() {
statusUpdate.schedule(50);
});
var StatusBar = require("./statusbar").StatusBar;
new StatusBar(env.editor, cmdLine.container);
});

View file

@ -0,0 +1,190 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var EditSession = require("ace/edit_session").EditSession;
var UndoManager = require("ace/undomanager").UndoManager;
var net = require("ace/lib/net");
var modelist = require("./modelist");
/*********** demo documents ***************************/
var fileCache = {};
function initDoc(file, path, doc) {
if (doc.prepare)
file = doc.prepare(file);
var session = new EditSession(file);
session.setUndoManager(new UndoManager());
doc.session = session;
doc.path = path;
if (doc.wrapped) {
session.setUseWrapMode(true);
session.setWrapLimitRange(80, 80);
}
var mode = modelist.getModeFromPath(path);
session.modeName = mode.name;
session.setMode(mode.mode);
}
function makeHuge(txt) {
for (var i = 0; i < 5; i++)
txt += txt;
return txt;
}
var docs = {
"docs/AsciiDoc.asciidoc": "AsciiDoc",
"docs/javascript.js": "JavaScript",
"docs/clojure.clj": "Clojure",
"docs/coffeescript.coffee": "Coffeescript",
"docs/coldfusion.cfm": "ColdFusion",
"docs/cpp.cpp": "C/C++",
"docs/csharp.cs": "C#",
"docs/css.css": "CSS",
"docs/diff.diff": "Diff",
"docs/glsl.glsl": "Glsl",
"docs/golang.go": "Go",
"docs/groovy.groovy": "Groovy",
"docs/Haxe.hx": "haXe",
"docs/html.html": "HTML",
"docs/jade.jade": "Jade",
"docs/java.java": "Java",
"docs/jsp.jsp": "JSP",
"docs/json.json": "JSON",
"docs/jsx.jsx": "JSX",
"docs/latex.tex": {name: "LaTeX", wrapped: true},
"docs/less.less": "LESS",
"docs/liquid.liquid": "Liquid",
"docs/lua.lua": "Lua",
"docs/luapage.lp": "LuaPage",
"docs/markdown.md": {name: "Markdown", wrapped: true},
"docs/ocaml.ml": "OCaml",
"docs/OpenSCAD.scad": "OpenSCAD",
"docs/perl.pl": "Perl",
"docs/pgsql.pgsql": {name: "pgSQL", wrapped: true},
"docs/php.php": "PHP",
"docs/plaintext.txt": {name: "Plain Text", prepare: makeHuge, wrapped: true},
"docs/powershell.ps1": "Powershell",
"docs/python.py": "Python",
"docs/ruby.rb": "Ruby",
"docs/scala.scala": "Scala",
"docs/scss.scss": "SCSS",
"docs/sh.sh": "SH",
"docs/sql.sql": {name: "SQL", wrapped: true},
"docs/svg.svg": "SVG",
"docs/tcl.tcl": "Tcl",
"docs/textile.textile": {name: "Textile", wrapped: true},
"docs/typescript.ts": "Typescript",
"docs/xml.xml": "XML",
"docs/xquery.xq": "XQuery",
"docs/yaml.yaml": "YAML",
"docs/c9search.c9search_results": "C9 Search Results"
};
var ownSource = {
/* filled from require*/
};
var hugeDocs = {
"build/src/ace.js": "",
"build/src-min/ace.js": ""
};
if (window.require && window.require.s) try {
for (var path in window.require.s.contexts._.defined) {
if (path.indexOf("!") != -1)
path = path.split("!").pop();
else
path = path + ".js";
ownSource[path] = "";
}
} catch(e) {}
function prepareDocList(docs) {
var list = [];
for (var path in docs) {
var doc = docs[path];
if (typeof doc != "object")
doc = {name: doc || path};
doc.path = path;
doc.desc = doc.name.replace(/^(ace|docs|demo|build)\//, "");
if (doc.desc.length > 18)
doc.desc = doc.desc.slice(0, 7) + ".." + doc.desc.slice(-9);
fileCache[doc.name] = doc;
list.push(doc);
}
return list;
}
function loadDoc(name, callback) {
var doc = fileCache[name];
if (!doc)
return callback(null);
if (doc.session)
return callback(doc.session);
// TODO: show load screen while waiting
var path = doc.path;
var parts = path.split("/");
if (parts[0] == "docs")
path = "demo/kitchen-sink/" + path;
else if (parts[0] == "ace")
path = "lib/" + path;
net.get(path, function(x) {
initDoc(x, path, doc);
callback(doc.session);
});
}
module.exports = {
fileCache: fileCache,
docs: prepareDocList(docs),
ownSource: prepareDocList(ownSource),
hugeDocs: prepareDocList(hugeDocs),
initDoc: initDoc,
loadDoc: loadDoc
};
module.exports.all = {
"Mode Examples": module.exports.docs,
"Huge documents": module.exports.hugeDocs,
"own source": module.exports.ownSource
};
});

File diff suppressed because it is too large Load diff

194
demo/kitchen-sink/layout.js Normal file
View file

@ -0,0 +1,194 @@
define(function(require, exports, module) {
"use strict";
var dom = require("ace/lib/dom");
var event = require("ace/lib/event");
var EditSession = require("ace/edit_session").EditSession;
var UndoManager = require("ace/undomanager").UndoManager;
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
var Editor = require("ace/editor").Editor;
var MultiSelect = require("ace/multi_select").MultiSelect;
dom.importCssString("\
splitter {\
border: 1px solid #C6C6D2;\
width: 0px;\
cursor: ew-resize;\
z-index:10}\
splitter:hover {\
margin-left: -2px;\
width:3px;\
border-color: #B5B4E0;\
}\
", "splitEditor");
exports.edit = function(el) {
if (typeof(el) == "string")
el = document.getElementById(el);
var editor = new Editor(new Renderer(el, require("ace/theme/textmate")));
editor.resize();
event.addListener(window, "resize", function() {
editor.resize();
});
return editor;
};
var SplitRoot = function(el, theme, position, getSize) {
el.style.position = position || "relative";
this.container = el;
this.getSize = getSize || this.getSize;
this.resize = this.$resize.bind(this);
event.addListener(el.ownerDocument.defaultView, "resize", this.resize);
this.editor = this.createEditor();
};
(function(){
this.createEditor = function() {
var el = document.createElement("div");
el.className = this.$editorCSS;
el.style.cssText = "position: absolute; top:0px; bottom:0px";
this.$container.appendChild(el);
var session = new EditSession("");
var editor = new Editor(new Renderer(el, this.$theme));
/*editor.on("focus", function() {
this._emit("focus", editor);
}.bind(this));*/
this.$editors.push(editor);
editor.setFontSize(this.$fontSize);
return editor;
};
this.$resize = function() {
var size = this.getSize(this.container);
this.rect = {
x: size.left,
y: size.top,
w: size.width,
h: size.height
};
this.item.resize(this.rect);
};
this.getSize = function(el) {
return el.getBoundingClientRect();
};
this.destroy = function() {
var win = this.container.ownerDocument.defaultView;
event.removeListener(win, "resize", this.resize);
};
}).call(SplitRoot.prototype);
var Split = function(){
};
(function(){
this.execute = function(options) {
this.$u.execute(options);
};
}).call(Split.prototype);
exports.singleLineEditor = function(el) {
var renderer = new Renderer(el);
el.style.overflow = "hidden";
renderer.scrollBar.element.style.top = "0";
renderer.scrollBar.element.style.display = "none";
renderer.scrollBar.orginalWidth = renderer.scrollBar.width;
renderer.scrollBar.width = 0;
renderer.content.style.height = "auto";
renderer.screenToTextCoordinates = function(x, y) {
var pos = this.pixelToScreenCoordinates(x, y);
return this.session.screenToDocumentPosition(
Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)),
Math.max(pos.column, 0)
);
};
renderer.maxLines = 4;
renderer.$computeLayerConfigWithScroll = renderer.$computeLayerConfig;
renderer.$computeLayerConfig = function() {
var config = this.layerConfig;
var height = this.session.getScreenLength() * this.lineHeight;
if (config.height != height) {
var vScroll = height > this.maxLines * this.lineHeight;
if (vScroll != this.$vScroll) {
if (vScroll) {
this.scrollBar.element.style.display = "";
this.scrollBar.width = this.scrollBar.orginalWidth;
this.container.style.height = config.height + "px";
height = config.height;
this.scrollTop = height - this.maxLines * this.lineHeight;
} else {
this.scrollBar.element.style.display = "none";
this.scrollBar.width = 0;
}
this.onResize();
this.$vScroll = vScroll;
}
if (this.$vScroll)
return renderer.$computeLayerConfigWithScroll();
this.container.style.height = height + "px";
this.scroller.style.height = height + "px";
this.content.style.height = height + "px";
this._emit("resize");
}
var longestLine = this.$getLongestLine();
var firstRow = 0;
var lastRow = this.session.getLength();
this.scrollTop = 0;
config.width = longestLine;
config.padding = this.$padding;
config.firstRow = 0;
config.firstRowScreen = 0;
config.lastRow = lastRow;
config.lineHeight = this.lineHeight;
config.characterWidth = this.characterWidth;
config.minHeight = height;
config.maxHeight = height;
config.offset = 0;
config.height = height;
this.$gutterLayer.element.style.marginTop = 0 + "px";
this.content.style.marginTop = 0 + "px";
this.content.style.width = longestLine + 2 * this.$padding + "px";
};
renderer.isScrollableBy=function(){return false};
renderer.setStyle("ace_one-line");
var editor = new Editor(renderer);
new MultiSelect(editor);
editor.session.setUndoManager(new UndoManager());
editor.setHighlightActiveLine(false);
editor.setShowPrintMargin(false);
editor.renderer.setShowGutter(false);
editor.renderer.setHighlightGutterLine(false);
editor.$mouseHandler.$focusWaitTimout = 0;
return editor;
};
});

View file

@ -1,52 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Editor</title>
<style type="text/css" media="screen">
body {
overflow: hidden;
margin: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
#editor {
}
</style>
</head>
<body>
define(function(require, exports, module) {
"use strict";
<div id="toolbar"></div>
<pre id="editor"></pre>
<script src="../build/src/ace.js" type="text/javascript"></script>
<script src="../build/kitchen-sink/demo.js" type="text/javascript"></script>
<script>
var $ = document.getElementById.bind(document);
function bindDropdown(el, callback) {
var onChange = function() {
callback(el.value);
};
el.onchange = onChange;
onChange();
}
function fillDropdown(list, el) {
list.forEach(function(item) {
var option = document.createElement("option");
option.setAttribute("value", item.name);
option.innerHTML = item.desc;
el.appendChild(option);
});
}
/************** modes ***********************/
var modes = [];
function getModeFromPath(path) {
@ -58,7 +12,7 @@ function getModeFromPath(path) {
}
}
return mode;
};
}
var Mode = function(name, desc, extensions) {
this.name = name;
@ -72,19 +26,23 @@ Mode.prototype.supportsFile = function(filename) {
};
var modesByName = {
asciidoc: ["AsciiDoc" , "asciidoc"],
c9search: ["C9Search" , "c9search_results"],
coffee: ["CoffeeScript" , "coffee|^Cakefile"],
coldfusion: ["ColdFusion" , "cfm"],
csharp: ["C#" , "cs"],
css: ["CSS" , "css"],
diff: ["Diff" , "diff|patch"],
glsl: ["Glsl" , "glsl|frag|vert"],
golang: ["Go" , "go"],
groovy: ["Groovy" , "groovy"],
haxe: ["haXe" , "hx"],
html: ["HTML" , "htm|html|xhtml"],
c_cpp: ["C/C++" , "c|cc|cpp|cxx|h|hh|hpp"],
clojure: ["Clojure" , "clj"],
jade: ["Jade" , "jade"],
java: ["Java" , "java"],
jsp: ["JSP" , "jsp"],
javascript: ["JavaScript" , "js"],
json: ["JSON" , "json"],
jsx: ["JSX" , "jsx"],
@ -107,8 +65,10 @@ var modesByName = {
sh: ["SH" , "sh|bash|bat"],
sql: ["SQL" , "sql"],
svg: ["SVG" , "svg"],
tcl: ["Tcl" , "tcl"],
text: ["Text" , "txt"],
textile: ["Textile" , "textile"],
typescript: ["Typescript" , "typescript|ts|str"],
xml: ["XML" , "xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl"],
xquery: ["XQuery" , "xq"],
yaml: ["YAML" , "yaml"]
@ -116,69 +76,16 @@ var modesByName = {
for (var name in modesByName) {
var mode = modesByName[name];
mode = new Mode(name, mode[0], mode[1])
mode = new Mode(name, mode[0], mode[1]);
modesByName[name] = mode;
modes.push(mode);
}
module.exports = {
getModeFromPath: getModeFromPath,
modes: modes,
modesByName: modesByName
};
var container = document.getElementById("editor");
container.style.position = "absolute";
// Splitting.
var Split = require("ace/split").Split;
var split = new Split(container, null, 1);
split.setOrientation(split.BESIDE);
split.setSplits(2);
var editor1 = split.getEditor(0);
var editor2 = split.getEditor(1);
var toolbar = $("toolbar");
var modeEl = document.createElement("select");
fillDropdown(modes, modeEl);
bindDropdown(modeEl, function(value) {
editor1.session.setMode((modesByName[value] || modesByName.text).mode);
});
toolbar.appendChild(modeEl);
var button = document.createElement("input");
button.setAttribute("type", "button");
button.value = "generate test";
toolbar.appendChild(button)
function onResize() {
var top = toolbar.clientHeight;
var width = document.documentElement.clientWidth;
container.style.top = top + "px";
container.style.width = width + "px";
container.style.height = document.documentElement.clientHeight - top + "px";
split.resize();
}
window.onresize = onResize;
onResize();
button.onclick = function() {
var s = editor1.session
tok = s.bgTokenizer
var data = []
for (var i = 0; i < s.getLength(); i++) {
data.push({
text: s.getLine(i),
state: [tok.getState(i - 1), tok.getState(i)],
tokens: tok.getTokens(i)
})
}
data = JSON.stringify(data, null, 4);
data = data.replace(/(\n\s*)"(\w+)":/g, "$1$2:");
editor2.insert(data);
}
</script>
</body>
</html>

View file

@ -0,0 +1,48 @@
define(function(require, exports, module) {
"use strict";
/** simple statusbar **/
var dom = require("ace/lib/dom");
var lang = require("ace/lib/lang");
var StatusBar = function(editor, parentNode) {
this.element = dom.createElement("div");
this.element.style.cssText = "color: gray; position:absolute; right:0; border-left:1px solid";
parentNode.appendChild(this.element);
var statusUpdate = lang.deferredCall(function(){
this.updateStatus(editor)
}.bind(this));
editor.on("changeStatus", function() {
statusUpdate.schedule(50);
});
editor.on("changeSelection", function() {
statusUpdate.schedule(50);
});
};
(function(){
this.updateStatus = function(editor) {
var status = [];
function add(str, separator) {
str && status.push(str, separator || "|");
}
if (editor.$vimModeHandler)
add(editor.$vimModeHandler.getStatusText());
else if (editor.commands.recording)
add("REC");
var c = editor.selection.lead;
add(c.row + ":" + c.column, " ");
if (!editor.selection.isEmpty()) {
var r = editor.getSelectionRange();
add("(" + (r.end.row - r.start.row) + ":" +(r.end.column - r.start.column) + ")");
}
status.pop();
this.element.textContent = status.join("");
};
}).call(StatusBar.prototype);
exports.StatusBar = StatusBar;
});

View file

@ -1,7 +1,3 @@
/*PACKAGE
@import url(//fonts.googleapis.com/css?family=Droid+Sans+Mono);
PACKAGE*/
html {
height: 100%;
width: 100%;

View file

@ -0,0 +1,183 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var dom = require("ace/lib/dom");
var event = require("ace/lib/event");
var Range = require("ace/range").Range;
var tooltipNode;
var TokenTooltip = function(editor) {
if (editor.tokenTooltip)
return;
editor.tokenTooltip = this;
this.editor = editor;
editor.tooltip = tooltipNode || this.$init();
this.update = this.update.bind(this);
this.onMouseMove = this.onMouseMove.bind(this);
this.onMouseOut = this.onMouseOut.bind(this);
event.addListener(editor.renderer.scroller, "mousemove", this.onMouseMove);
event.addListener(editor.renderer.content, "mouseout", this.onMouseOut);
};
(function(){
this.token = {};
this.range = new Range();
this.update = function() {
this.$timer = null;
var r = this.editor.renderer;
if (this.lastT - (r.timeStamp || 0) > 1000) {
r.rect = null;
r.timeStamp = this.lastT;
this.maxHeight = innerHeight;
this.maxWidth = innerWidth;
}
var canvasPos = r.rect || (r.rect = r.scroller.getBoundingClientRect());
var offset = (this.x + r.scrollLeft - canvasPos.left - r.$padding) / r.characterWidth;
var row = Math.floor((this.y + r.scrollTop - canvasPos.top) / r.lineHeight);
var col = Math.round(offset);
var screenPos = {row: row, column: col, side: offset - col > 0 ? 1 : -1};
var session = this.editor.session;
var docPos = session.screenToDocumentPosition(screenPos.row, screenPos.column);
var token = session.getTokenAt(docPos.row, docPos.column);
if (!token && !session.getLine(docPos.row)) {
token = {
type: "",
value: "",
state: session.bgTokenizer.getState(0)
};
}
if (!token) {
session.removeMarker(this.marker);
tooltipNode.style.display = "none";
this.isOpen = false;
return;
}
if (!this.isOpen) {
tooltipNode.style.display = "";
this.isOpen = true;
}
var tokenText = token.type;
if (token.state)
tokenText += "|" + token.state;
if (token.merge)
tokenText += "\n merge";
if (token.stateTransitions)
tokenText += "\n " + token.stateTransitions.join("\n ");
if (this.tokenText != tokenText) {
tooltipNode.textContent = tokenText;
this.tooltipWidth = tooltipNode.offsetWidth;
this.tooltipHeight = tooltipNode.offsetHeight;
this.tokenText = tokenText;
}
this.updateTooltipPosition(this.x, this.y);
this.token = token;
session.removeMarker(this.marker);
this.range = new Range(docPos.row, token.start, docPos.row, token.start + token.value.length);
this.marker = session.addMarker(this.range, "ace_bracket", "text");
};
this.onMouseMove = function(e) {
this.x = e.clientX;
this.y = e.clientY;
if (this.isOpen) {
this.lastT = e.timeStamp;
this.updateTooltipPosition(this.x, this.y);
}
if (!this.$timer)
this.$timer = setTimeout(this.update, 100);
};
this.onMouseOut = function(e) {
var t = e && e.relatedTarget;
var ct = e && e.currentTarget;
while(t && (t = t.parentNode)) {
if (t == ct)
return;
}
tooltipNode.style.display = "none";
this.editor.session.removeMarker(this.marker);
this.$timer = clearTimeout(this.$timer);
this.isOpen = false;
};
this.updateTooltipPosition = function(x, y) {
var st = tooltipNode.style;
if (x + 10 + this.tooltipWidth > this.maxWidth)
x = innerWidth - this.tooltipWidth - 10;
if (y > innerHeight * 0.75 || y + 20 + this.tooltipHeight > this.maxHeight);
y = y - this.tooltipHeight - 30;
st.left = x + 10 + "px";
st.top = y + 20 + "px";
};
this.$init = function() {
tooltipNode = document.documentElement.appendChild(dom.createElement("div"));
var st = tooltipNode.style;
st.position = "fixed";
st.display = "none";
st.background = "lightyellow";
st.borderRadius = "";
st.border = "1px solid gray";
st.padding = "1px";
st.zIndex = 1000;
st.fontFamily = "monospace";
st.whiteSpace = "pre-line";
return tooltipNode;
};
this.destroy = function() {
this.onMouseOut();
event.removeListener(this.editor.renderer.scroller, "mousemove", this.onMouseMove);
event.removeListener(this.editor.renderer.content, "mouseout", this.onMouseOut);
delete this.editor.tokenTooltip;
};
}).call(TokenTooltip.prototype);
exports.TokenTooltip = TokenTooltip;
});

234
demo/kitchen-sink/util.js Normal file
View file

@ -0,0 +1,234 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var dom = require("ace/lib/dom");
var event = require("ace/lib/event");
var EditSession = require("ace/edit_session").EditSession;
var UndoManager = require("ace/undomanager").UndoManager;
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
var Editor = require("ace/editor").Editor;
var MultiSelect = require("ace/multi_select").MultiSelect;
exports.createSplitEditor = function(el) {
if (typeof(el) == "string")
el = document.getElementById(el);
var e0 = document.createElement("div");
var s = document.createElement("splitter");
var e1 = document.createElement("div");
el.appendChild(e0);
el.appendChild(e1);
el.appendChild(s);
e0.style.position = e1.style.position = s.style.position = "absolute";
el.style.position = "relative";
var split = {$container: el};
split.editor0 = split[0] = new Editor(new Renderer(e0, require("ace/theme/textmate")));
split.editor1 = split[1] = new Editor(new Renderer(e1, require("ace/theme/textmate")));
split.splitter = s;
MultiSelect(split.editor0);
MultiSelect(split.editor1);
s.ratio = 0.5;
split.resize = function resize(){
var height = el.parentNode.clientHeight - el.offsetTop;
var total = el.clientWidth;
var w1 = total * s.ratio;
var w2 = total * (1- s.ratio);
s.style.left = w1 - 1 + "px";
s.style.height = el.style.height = height + "px";
var st0 = split[0].container.style;
var st1 = split[1].container.style;
st0.width = w1 + "px";
st1.width = w2 + "px";
st0.left = 0 + "px";
st1.left = w1 + "px";
st0.top = st1.top = "0px";
st0.height = st1.height = height + "px";
split[0].resize();
split[1].resize();
};
split.onMouseDown = function(e) {
var rect = el.getBoundingClientRect();
var x = e.clientX;
var y = e.clientY;
var button = e.button;
if (button !== 0) {
return;
}
var onMouseMove = function(e) {
x = e.clientX;
y = e.clientY;
};
var onResizeEnd = function(e) {
clearInterval(timerId);
};
var onResizeInterval = function() {
s.ratio = (x - rect.left) / rect.width
split.resize()
};
event.capture(s, onMouseMove, onResizeEnd);
var timerId = setInterval(onResizeInterval, 40);
return e.preventDefault();
};
event.addListener(s, "mousedown", split.onMouseDown);
event.addListener(window, "resize", split.resize);
split.resize();
return split;
};
/***************************/
exports.stripLeadingComments = function(str) {
if(str.slice(0,2)=='/*') {
var j = str.indexOf('*/')+2;
str = str.substr(j);
}
return str.trim() + "\n";
};
/***************************/
exports.saveOption = function(el, val) {
if (!el.onchange && !el.onclick)
return;
if ("checked" in el) {
if (val !== undefined)
el.checked = val;
localStorage && localStorage.setItem(el.id, el.checked ? 1 : 0);
}
else {
if (val !== undefined)
el.value = val;
localStorage && localStorage.setItem(el.id, el.value);
}
};
exports.bindCheckbox = function(id, callback, noInit) {
if (typeof id == "string")
var el = document.getElementById(id);
else {
var el = id;
id = el.id;
}
var el = document.getElementById(id);
if (localStorage && localStorage.getItem(id))
el.checked = localStorage.getItem(id) == "1";
var onCheck = function() {
callback(!!el.checked);
exports.saveOption(el);
};
el.onclick = onCheck;
noInit || onCheck();
};
exports.bindDropdown = function(id, callback, noInit) {
if (typeof id == "string")
var el = document.getElementById(id);
else {
var el = id;
id = el.id;
}
if (localStorage && localStorage.getItem(id))
el.value = localStorage.getItem(id);
var onChange = function() {
callback(el.value);
exports.saveOption(el);
};
el.onchange = onChange;
noInit || onChange();
};
exports.fillDropdown = function(el, values) {
if (typeof el == "string")
el = document.getElementById(el);
dropdown(values).forEach(function(e) {
el.appendChild(e);
});
};
function elt(tag, attributes, content) {
var el = dom.createElement(tag);
if (typeof content == "string") {
el.textContent = content;
} else if (content) {
content.forEach(function(ch) {
el.appendChild(ch);
});
}
for (var i in attributes)
el.setAttribute(i, attributes[i]);
return el;
}
function optgroup(values) {
return values.map(function(item) {
if (typeof item == "string")
item = {name: item, desc: item};
return elt("option", {value: item.name}, item.desc);
});
}
function dropdown(values) {
if (Array.isArray(values))
return optgroup(values);
return Object.keys(values).map(function(i) {
return elt("optgroup", {"label": i}, optgroup(values[i]));
});
}
});

View file

@ -3,7 +3,7 @@ include lib
#documentation.span8
-if (isIndex)
!= content
!= indexContent
-else
mixin api()

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -102,6 +102,7 @@ $(function() {
});
$(window).on("hashchange", function(e) {
_gaq.push(['_trackPageview',location.pathname + location.search + location.hash]);
tabs.each(function() {
var idx = $.bbq.getState("nav") || "about";
var section = e.fragment.split("&")[1] || "";

View file

@ -86,7 +86,7 @@ console.log(addResult);</div>
<p id="embed_link"><a href="#nav=embedding">Learn how to embed this in your own site</a></p>
<p class="highlight_note">Looking for a more full-featured demo? Check out the
<a href="http://ace.ajax.org/build/kitchen-sink.html" target="_blank">kitchen sink</a>.</p>
<h2>ACE Features</h2>
<h2>Features</h2>
<ul class="content-list">
<li><a href="http://pcwalton.blogspot.com/2010/11/syntax-highlighting-specification.html">Syntax highlighting</a> for over 40 languages (TextMate/Sublime/<em>.tmlanguage</em> files can be imported)</li>
<li>Over 20 themes (TextMate/Sublime/<em>.tmtheme</em> files can be imported)</li>
@ -137,7 +137,7 @@ console.log(addResult);</div>
</div>
<div class="tab-pane fade active in" id="embedding">
<h1>Embedding ACE in Your Site</h1>
<p>ACE can be easily embedded into a web page:</p>
<p>ACE can be easily embedded into a web page. Just copy the code below:</p>
<div id="embed_ace_wrapper" class="ace_editor_wrapper">
<div id="embedded_ace_code">&lt;!DOCTYPE html>
@ -173,7 +173,10 @@ console.log(addResult);</div>
common operations, such as setting a different language mode or
getting the contents from the editor.</p>
<h2>Loading ACE from a Local URL</h2>
<p>The above code is sufficient to get started, but if you want to clone host ACE locally you can
<p>The above code is all you need to embed ACE in your site (including setting language modes
and themes). Plus it's super fast because it's on Amazon's distributed content network.
</p>
<p>But, if you want to clone host ACE locally you can
use one of the <a href="https://github.com/ajaxorg/ace-builds/">pre-packaged versions</a>. Just copy
one of <code>src*</code> subdirectories somewhere into your project, or use RequireJS to load the
contents of <a href="https://github.com/ajaxorg/ace/tree/master/lib/ace">lib/ace</a> as <code>ace</code>:</p>
@ -496,6 +499,21 @@ tests for the highlighting.</p>
style="position: relative; left: 13px; top: -4px; width: 75px" />
<a href="http://plnkr.co/edit/">Plunker</a>
</li>
<li>
<img src="doc/site/images/KERA-med-web.png"
style="position: relative; left: 3px;top: 23px;width: 97px;" />
<a href="http://kera.io/">Kera.io</a>
</li>
<li>
<img src="doc/site/images/sassmeister-logo.png"
style="position: relative; left: 10px;top: -5px;width: 80px;" />
<a href="http://sassmeister.com/">SassMeister</a>
</li>
<li>
<img src="doc/site/images/spandexio-logo.png"
style="position: relative; left: 10px;top: -5px;width: 80px;" />
<a href="http://SpanDeX.io/">SpanDeX.io</a>
</li>
<li>
<a href="https://github.com/Gozala/sky-edit">Sky Edit</a>
</li>

View file

@ -33,27 +33,36 @@
* ***** END LICENSE BLOCK ***** */
var buildAce = require("./Makefile.dryice").buildAce;
var fs = require("fs");
var ACE_HOME = __dirname;
try {
var aceProject = {
roots: [
ACE_HOME + '/lib',
ACE_HOME + '/demo'
],
textPluginPattern: /^ace\/requirejs\/text!/
};
buildAce(aceProject, {
compress: false,
noconflict: false,
suffix: "",
compat: true,
name: "ace"
});
} catch (e) {
console.log("--- Ace Build error ---");
console.log(e);
process.exit(0);
function getVersion(path) {
if (fs.existsSync(path + "/.git-ref"))
return fs.readFileSync(path + "/.git-ref", "utf8");
if (fs.existsSync(path + "/.git/ORIG_HEAD"))
return fs.readFileSync(path + "/.git/ORIG_HEAD", "utf8");
}
if (process.argv.indexOf("-c") > 0) try {
var version = getVersion(ACE_HOME);
var oldVersion = getVersion(ACE_HOME + "/build");
if (version && oldVersion == version) {
console.log("ace build is up to date");
process.exit(0);
}
fs.writeFileSync(ACE_HOME + "/build/.git-ref", version, "utf8");
} catch (e) {}
try {
buildAce({
compress: false,
noconflict: false,
suffix: "",
name: "ace"
});
} catch (e) {
console.log("--- Ace Build error ---");
console.log(e);
process.exit(0);
}

View file

@ -1,5 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<!DOCTYPE html>
<html lang="en">
<head>
@ -7,25 +6,29 @@
<title>Ace Kitchen Sink</title>
<meta name="author" content="Fabian Jakobs">
<!--
Ace
version %version%
commit %commit%
-->
<!--DEVEL-->
<link rel="stylesheet" href="demo/kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
<script src="http://use.edgefonts.net/source-code-pro.js"></script>
<!--DEVEL-->
<!--PACKAGE
<link rel="stylesheet" href="kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
<script src="http://use.edgefonts.net/source-code-pro.js"></script>
PACKAGE-->
</head>
<body>
<div id="optionsPanel" style="position:absolute;height:100%">
<a href="http://ajaxorg.github.com/ace/" >
<img id="logo" src="demo/kitchen-sink/logo.png">
</a>
<div style="position: absolute; overflow: hidden; top:80px; bottom:0">
<div style="width: 120%; height:100%; overflow-y: scroll">
<table id="controls">
<tr>
<td>
@ -234,9 +237,20 @@
<input type="checkbox" id="fade_fold_widgets">
</td>
</tr>
<tr>
<td >
<label for="highlight_token">Show token info</label>
</td>
<td>
<input type="checkbox" id="highlight_token">
</td>
</tr>
</table>
</td></tr>
</table>
</div>
</div>
</div>
<div id="editor"></div>

View file

@ -53,8 +53,8 @@ var MultiSelect = require("./multi_select").MultiSelect;
// The following require()s are for inclusion in the built ace file
require("./worker/worker_client");
require("./keyboard/hash_handler");
require("./keyboard/state_handler");
require("./placeholder");
require("./mode/folding/fold_mode");
exports.config = require("./config");
/**
* Ace.edit(el) -> Editor

View file

@ -321,6 +321,11 @@ exports.commands = [{
bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
exec: function(editor) { editor.duplicateSelection(); },
multiSelectAction: "forEach"
}, {
name: "sortlines",
bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
exec: function(editor) { editor.sortLines(); },
multiSelectAction: "forEach"
}, {
name: "togglecomment",
bindKey: bindKey("Ctrl-/", "Command-/"),

View file

@ -1,7 +1,7 @@
.ace_editor {
position: absolute;
overflow: hidden;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Droid Sans Mono', 'Consolas', monospace;
font-family: 'Menlo', 'Monaco', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
font-size: 12px;
}
@ -242,6 +242,8 @@
-webkit-box-sizing: border-box;
box-sizing: border-box;
cursor: default;
white-space: pre-line;
word-wrap: break-word;
}
.ace_folding-enabled > .ace_gutter-cell {
@ -345,6 +347,10 @@
font-weight: bold;
}
.ace_nobold .ace_bold {
font-weight: normal;
}
.ace_italic {
font-style: italic;
}

View file

@ -318,7 +318,7 @@ var EditSession = function(text, mode) {
};
/**
* EditSession.getSelection() -> String
* EditSession.getSelection() -> Selection
*
* Returns the string of the current selection.
**/
@ -349,11 +349,11 @@ var EditSession = function(text, mode) {
};
/**
* EditSession.getTokenAt(row, column) -> Array
* EditSession.getTokenAt(row, column) -> Object
* - row (Number): The row number to retrieve from
* - column (Number): The column number to retrieve from
*
* Returns an array of tokens at the indicated row and column.
* Returns an object indicating the token at the current row. The object has two properties: `index` and `start`.
**/
this.getTokenAt = function(row, column) {
var tokens = this.bgTokenizer.getTokens(row);
@ -752,15 +752,7 @@ var EditSession = function(text, mode) {
* Sets annotations for the `EditSession`. This functions emits the `'changeAnnotation'` event.
**/
this.setAnnotations = function(annotations) {
this.$annotations = {};
for (var i=0; i<annotations.length; i++) {
var annotation = annotations[i];
var row = annotation.row;
if (this.$annotations[row])
this.$annotations[row].push(annotation);
else
this.$annotations[row] = [annotation];
}
this.$annotations = annotations;
this._emit("changeAnnotation", {});
};
@ -1212,8 +1204,8 @@ var EditSession = function(text, mode) {
};
/** related to: Document.getTextRange
* EditSession.getTextRange(range) -> Array
* - range (String): The range to work with
* EditSession.getTextRange(range) -> String
* - range (Range): The range to work with
*
* {:Document.getTextRange.desc}
**/

View file

@ -683,6 +683,7 @@ function Folding() {
};
this.onFoldWidgetClick = function(row, e) {
e = e.domEvent;
var type = this.getFoldWidget(row);
var line = this.getLine(row);
var onlySubfolds = e.shiftKey;

View file

@ -1276,6 +1276,31 @@ var Editor = function(renderer, session) {
this.session.outdentRows(selection.getRange());
};
// TODO: move out of core when we have good mechanism for managing extensions
this.sortLines = function() {
var rows = this.$getSelectedRows();
var session = this.session;
var lines = [];
for (i = rows.first; i <= rows.last; i++)
lines.push(session.getLine(i));
lines.sort(function(a, b) {
if (a.toLowerCase() < b.toLowerCase()) return -1;
if (a.toLowerCase() > b.toLowerCase()) return 1;
return 0;
});
var deleteRange = new Range(0, 0, 0, 0);
for (var i = rows.first; i <= rows.last; i++) {
var line = session.getLine(i);
deleteRange.start.row = i;
deleteRange.end.row = i;
deleteRange.end.column = line.length;
session.replace(deleteRange, lines[i-rows.first]);
}
};
/**
* Editor.toggleCommentLines()
*
@ -1308,20 +1333,20 @@ var Editor = function(renderer, session) {
this.duplicateSelection = function() {
var sel = this.selection;
var doc = this.session;
var range = sel.getRange();
if (range.isEmpty()) {
var row = range.start.row;
doc.duplicateLines(row, row);
} else {
var reverse = sel.isBackwards()
var point = sel.isBackwards() ? range.start : range.end;
var endPoint = doc.insert(point, doc.getTextRange(range), false);
range.start = point;
range.end = endPoint;
sel.setSelectionRange(range, reverse)
}
var doc = this.session;
var range = sel.getRange();
if (range.isEmpty()) {
var row = range.start.row;
doc.duplicateLines(row, row);
} else {
var reverse = sel.isBackwards()
var point = sel.isBackwards() ? range.start : range.end;
var endPoint = doc.insert(point, doc.getTextRange(range), false);
range.start = point;
range.end = endPoint;
sel.setSelectionRange(range, reverse)
}
};
/** related to: EditSession.moveLinesDown
@ -2101,4 +2126,4 @@ var Editor = function(renderer, session) {
exports.Editor = Editor;
});
});

View file

@ -36,7 +36,7 @@ var UA = require("../lib/useragent");
var net = require("../lib/net");
var ace = require("../ace");
require("ace/theme/textmate");
require("../theme/textmate");
module.exports = exports = ace;

View file

@ -304,76 +304,76 @@ var inputBuffer = exports.inputBuffer = {
lastInsertCommands: [],
push: function(editor, char, keyId) {
push: function(editor, ch, keyId) {
this.idle = false;
var wObj = this.waitingForParam;
if (wObj) {
this.exec(editor, wObj, char);
this.exec(editor, wObj, ch);
}
// If input is a number (that doesn't start with 0)
else if (!(char === "0" && !this.currentCount.length) &&
(char.match(/^\d+$/) && this.isAccepting(NUMBER))) {
// Assuming that char is always of type String, and not Number
this.currentCount += char;
else if (!(ch === "0" && !this.currentCount.length) &&
(ch.match(/^\d+$/) && this.isAccepting(NUMBER))) {
// Assuming that ch is always of type String, and not Number
this.currentCount += ch;
this.currentCmd = NUMBER;
this.accepting = [NUMBER, OPERATOR, MOTION, ACTION];
}
else if (!this.operator && this.isAccepting(OPERATOR) && operators[char]) {
else if (!this.operator && this.isAccepting(OPERATOR) && operators[ch]) {
this.operator = {
char: char,
ch: ch,
count: this.getCount()
};
this.currentCmd = OPERATOR;
this.accepting = [NUMBER, MOTION, ACTION];
this.exec(editor, { operator: this.operator });
}
else if (motions[char] && this.isAccepting(MOTION)) {
else if (motions[ch] && this.isAccepting(MOTION)) {
this.currentCmd = MOTION;
var ctx = {
operator: this.operator,
motion: {
char: char,
ch: ch,
count: this.getCount()
}
};
if (motions[char].param)
if (motions[ch].param)
this.waitForParam(ctx);
else
this.exec(editor, ctx);
}
else if (alias[char] && this.isAccepting(MOTION)) {
alias[char].operator.count = this.getCount();
this.exec(editor, alias[char]);
else if (alias[ch] && this.isAccepting(MOTION)) {
alias[ch].operator.count = this.getCount();
this.exec(editor, alias[ch]);
}
else if (actions[char] && this.isAccepting(ACTION)) {
else if (actions[ch] && this.isAccepting(ACTION)) {
var actionObj = {
action: {
fn: actions[char].fn,
fn: actions[ch].fn,
count: this.getCount()
}
};
if (actions[char].param) {
if (actions[ch].param) {
this.waitForParam(actionObj);
}
else {
this.exec(editor, actionObj);
}
if (actions[char].acceptsMotion)
if (actions[ch].acceptsMotion)
this.idle = false;
}
else if (this.operator) {
this.exec(editor, { operator: this.operator }, char);
this.exec(editor, { operator: this.operator }, ch);
}
else {
this.reset();
}
if (this.waitingForParam || this.motion || this.operator) {
this.status += char;
this.status += ch;
} else if (this.currentCount) {
this.status = this.currentCount;
} else if (this.status) {
@ -410,18 +410,18 @@ var inputBuffer = exports.inputBuffer = {
}
if (o && !editor.selection.isEmpty()) {
if (operators[o.char].selFn) {
operators[o.char].selFn(editor, editor.getSelectionRange(), o.count, param);
if (operators[o.ch].selFn) {
operators[o.ch].selFn(editor, editor.getSelectionRange(), o.count, param);
this.reset();
}
return;
}
// There is an operator, but no motion or action. We try to pass the
// current char to the operator to see if it responds to it (an example
// current ch to the operator to see if it responds to it (an example
// of this is the 'dd' operator).
else if (!m && !a && o && param) {
operators[o.char].fn(editor, null, o.count, param);
operators[o.ch].fn(editor, null, o.count, param);
this.reset();
}
else if (m) {
@ -434,7 +434,7 @@ var inputBuffer = exports.inputBuffer = {
}
};
var motionObj = motions[m.char];
var motionObj = motions[m.ch];
var selectable = motionObj.sel;
if (!o) {
@ -446,7 +446,7 @@ var inputBuffer = exports.inputBuffer = {
else if (selectable) {
repeat(function() {
run(motionObj.sel);
operators[o.char].fn(editor, editor.getSelectionRange(), o.count, param);
operators[o.ch].fn(editor, editor.getSelectionRange(), o.count, param);
}, o.count || 1);
}
this.reset();

View file

@ -34,57 +34,57 @@ define(function(require, exports, module) {
module.exports = {
"x": {
operator: {
char: "d",
ch: "d",
count: 1
},
motion: {
char: "l",
ch: "l",
count: 1
}
},
"X": {
operator: {
char: "d",
ch: "d",
count: 1
},
motion: {
char: "h",
ch: "h",
count: 1
}
},
"D": {
operator: {
char: "d",
ch: "d",
count: 1
},
motion: {
char: "$",
ch: "$",
count: 1
}
},
"C": {
operator: {
char: "c",
ch: "c",
count: 1
},
motion: {
char: "$",
ch: "$",
count: 1
}
},
"s": {
operator: {
char: "c",
ch: "c",
count: 1
},
motion: {
char: "l",
ch: "l",
count: 1
}
},
"S": {
operator: {
char: "c",
ch: "c",
count: 1
},
param: "c"

View file

@ -127,7 +127,7 @@ var StringStream = function(editor, cursor) {
};
};
var Search = require("ace/search").Search;
var Search = require("../../../search").Search;
var search = new Search();
function find(editor, needle, dir) {
@ -136,7 +136,7 @@ function find(editor, needle, dir) {
return search.find(editor.session);
}
var Range = require("ace/range").Range;
var Range = require("../../../range").Range;
module.exports = {
"w": new Motion(function(editor) {
@ -580,7 +580,7 @@ module.exports = {
sel: function(editor, range, count, param) {
keepScrollPosition(editor, editor.selectPageUp);
}
},
}
};
module.exports.backspace = module.exports.left = module.exports.h;

View file

@ -99,24 +99,24 @@ module.exports = {
this.onVisualLineMode = false;
}
},
getRightNthChar: function(editor, cursor, char, n) {
getRightNthChar: function(editor, cursor, ch, n) {
var line = editor.getSession().getLine(cursor.row);
var matches = line.substr(cursor.column + 1).split(char);
var matches = line.substr(cursor.column + 1).split(ch);
return n < matches.length ? matches.slice(0, n).join(char).length : null;
return n < matches.length ? matches.slice(0, n).join(ch).length : null;
},
getLeftNthChar: function(editor, cursor, char, n) {
getLeftNthChar: function(editor, cursor, ch, n) {
var line = editor.getSession().getLine(cursor.row);
var matches = line.substr(0, cursor.column).split(char);
var matches = line.substr(0, cursor.column).split(ch);
return n < matches.length ? matches.slice(-1 * n).join(char).length : null;
return n < matches.length ? matches.slice(-1 * n).join(ch).length : null;
},
toRealChar: function(char) {
if (char.length === 1)
return char;
toRealChar: function(ch) {
if (ch.length === 1)
return ch;
if (/^shift-./.test(char))
return char[char.length - 1].toUpperCase();
if (/^shift-./.test(ch))
return ch[ch.length - 1].toUpperCase();
else
return "";
},

View file

@ -33,6 +33,7 @@ define(function(require, exports, module) {
var dom = require("../lib/dom");
var oop = require("../lib/oop");
var lang = require("../lib/lang");
var EventEmitter = require("../lib/event_emitter").EventEmitter;
var Gutter = function(parentEl) {
@ -44,14 +45,18 @@ var Gutter = function(parentEl) {
this.gutterWidth = 0;
this.$annotations = [];
this.$updateAnnotations = this.$updateAnnotations.bind(this);
};
(function() {
oop.implement(this, EventEmitter);
this.setSession = function(session) {
if (this.session)
this.session.removeEventListener("change", this.$updateAnnotations);
this.session = session;
session.on("change", this.$updateAnnotations);
};
this.addGutterDecoration = function(row, className){
@ -68,28 +73,46 @@ var Gutter = function(parentEl) {
this.setAnnotations = function(annotations) {
// iterate over sparse array
this.$annotations = [];
for (var row in annotations) if (annotations.hasOwnProperty(row)) {
var rowAnnotations = annotations[row];
if (!rowAnnotations)
continue;
this.$annotations = []
var rowInfo, row;
for (var i = 0; i < annotations.length; i++) {
var annotation = annotations[i];
var row = annotation.row;
var rowInfo = this.$annotations[row];
if (!rowInfo)
rowInfo = this.$annotations[row] = {text: []};
var annoText = annotation.text;
annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";
var rowInfo = this.$annotations[row] = {
text: []
};
for (var i=0; i<rowAnnotations.length; i++) {
var annotation = rowAnnotations[i];
var annoText = annotation.text.replace(/"/g, "&quot;").replace(/'/g, "&#8217;").replace(/</, "&lt;");
if (rowInfo.text.indexOf(annoText) === -1)
rowInfo.text.push(annoText);
var type = annotation.type;
if (type == "error")
rowInfo.className = " ace_error";
else if (type == "warning" && rowInfo.className != " ace_error")
rowInfo.className = " ace_warning";
else if (type == "info" && (!rowInfo.className))
rowInfo.className = " ace_info";
}
if (rowInfo.text.indexOf(annoText) === -1)
rowInfo.text.push(annoText);
var type = annotation.type;
if (type == "error")
rowInfo.className = " ace_error";
else if (type == "warning" && rowInfo.className != " ace_error")
rowInfo.className = " ace_warning";
else if (type == "info" && (!rowInfo.className))
rowInfo.className = " ace_info";
}
};
this.$updateAnnotations = function (e) {
if (!this.$annotations.length)
return;
var delta = e.data;
var range = delta.range;
var firstRow = range.start.row;
var len = range.end.row - firstRow;
if (len === 0) {
// do nothing
} else if (delta.action == "removeText" || delta.action == "removeLines") {
this.$annotations.splice(firstRow, len + 1, null);
} else {
var args = Array(len + 1);
args.unshift(firstRow, 1);
this.$annotations.splice.apply(this.$annotations, args);
}
};

View file

@ -42,7 +42,8 @@ var Text = function(parentEl) {
this.element.className = "ace_layer ace_text-layer";
parentEl.appendChild(this.element);
this.$characterSize = this.$measureSizes() || {width: 0, height: 0};
this.$characterSize = {width: 0, height: 0};
this.checkForSizeChanges();
this.$pollSizeChanges();
};
@ -72,7 +73,11 @@ var Text = function(parentEl) {
this.checkForSizeChanges = function() {
var size = this.$measureSizes();
if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
this.$measureNode.style.fontWeight = "bold";
var boldSize = this.$measureSizes();
this.$measureNode.style.fontWeight = "";
this.$characterSize = size;
this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height;
this._emit("changeCharacterSize", {data: size});
}
};

View file

@ -117,6 +117,10 @@ exports.escapeRegExp = function(str) {
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
};
exports.escapeHTML = function(str) {
return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
};
exports.getMatchOffsets = function(string, regExp) {
var matches = [];

View file

@ -4,6 +4,8 @@ function foo(items, nada) {
} // Real Tab.
}
regexp = /p|p/ // ends here
r = /d{1,2}?f{e}++r*?\d+?[]r[^r-o\f\f[\f]?r{7}+r\{7}+rr--rr$^(?:d|s)(?=a|)(?!y)[]|$?|^*/ o
a=/a/ jk = / / / / /
/************************************/

View file

@ -20,9 +20,9 @@
{
"state": "start",
"data": [
[ "keyword", "using" ],
[ "keyword.control", "using" ],
[ "text", " " ],
[ "keyword", "namespace" ],
[ "keyword.operator", "namespace" ],
[ "text", " " ],
[ "identifier", "std" ],
[ "punctuation.operator", ";" ]
@ -35,9 +35,9 @@
{
"state": "start",
"data": [
[ "keyword", "int" ],
[ "storage.type", "int" ],
[ "text", " " ],
[ "identifier", "main" ],
[ "entity.name.function", "main" ],
[ "text", " " ],
[ "paren.lparen", "(" ],
[ "paren.rparen", ")" ]
@ -53,7 +53,7 @@
"state": "start",
"data": [
[ "text", " " ],
[ "keyword", "int" ],
[ "storage.type", "int" ],
[ "text", " " ],
[ "identifier", "a" ],
[ "punctuation.operator", "," ],
@ -109,7 +109,7 @@
"state": "start",
"data": [
[ "text", " " ],
[ "keyword", "return" ],
[ "keyword.control", "return" ],
[ "text", " " ],
[ "constant.numeric", "0" ],
[ "punctuation.operator", ";" ]

View file

@ -41,7 +41,7 @@
"data": [
[ "keyword", "void" ],
[ "text", " " ],
[ "identifier", "main" ],
[ "entity.name.function", "main" ],
[ "paren.lparen", "(" ],
[ "paren.rparen", ")" ],
[ "text", " " ],

View file

@ -81,6 +81,24 @@
"state": "start",
"data": []
},
{
"state": "start",
"data": [
[ "identifier", "regexp" ],
[ "text", " " ],
[ "keyword.operator", "=" ],
[ "text", " " ],
[ "string.regexp", "/p" ],
[ "constant.language.escape", "|" ],
[ "string.regexp", "p/" ],
[ "text", " " ],
[ "comment", "// ends here" ]
]
},
{
"state": "start",
"data": []
},
{
"state": "start",
"data": [
@ -118,10 +136,13 @@
[ "constant.language.escape", "$" ],
[ "constant.language.escape", "^" ],
[ "constant.language.escape", "(?:" ],
[ "string.regexp", "d|s" ],
[ "string.regexp", "d" ],
[ "constant.language.escape", "|" ],
[ "string.regexp", "s" ],
[ "constant.language.escape", ")" ],
[ "constant.language.escape", "(?=" ],
[ "string.regexp", "a|" ],
[ "string.regexp", "a" ],
[ "constant.language.escape", "|" ],
[ "constant.language.escape", ")" ],
[ "constant.language.escape", "(?!" ],
[ "string.regexp", "y" ],

View file

@ -3,7 +3,7 @@
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -29,20 +29,36 @@
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
// Global variables to hide from the interpreter
exports.hiddenHostGlobals = { Narcissus: true };
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var AsciidocHighlightRules = require("./asciidoc_highlight_rules").AsciidocHighlightRules;
var AsciidocFoldMode = require("./folding/asciidoc").FoldMode;
// Desugar SpiderMonkey language extensions?
exports.desugarExtensions = false;
var Mode = function() {
var highlighter = new AsciidocHighlightRules();
this.$tokenizer = new Tokenizer(highlighter.getRules());
this.foldingRules = new AsciidocFoldMode();
};
oop.inherits(Mode, TextMode);
// Allow HTML comments?
exports.allowHTMLComments = false;
// Allow non-standard Mozilla extensions?
exports.mozillaMode = true;
// Allow experimental paren-free mode?
exports.parenFreeMode = false;
(function() {
this.getNextLineIndent = function(state, line, tab) {
if (state == "listblock") {
var match = /^((?:.+)?)([-+*][ ]+)/.exec(line);
if (match) {
return new Array(match[1].length + 1).join(" ") + match[2];
} else {
return "";
}
} else {
return this.$getIndent(line);
}
};
}).call(Mode.prototype);
exports.Mode = Mode;
});

View file

@ -0,0 +1,233 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var AsciidocHighlightRules = function() {
var identifierRe = "[a-zA-Z\u00a1-\uffff]+\\b";
this.$rules = {
"start": [
{token: "empty", regex: /$/},
{token: "literal", regex: /^\.{4,}\s*$/, next: "listingBlock"},
{token: "literal", regex: /^-{4,}\s*$/, next: "literalBlock"},
{token: "string", regex: /^\+{4,}\s*$/, next: "passthroughBlock"},
{token: "keyword", regex: /^={4,}\s*$/},
{token: "text", regex: /^\s*$/},
// immediately return to the start mode without matching anything
{token: "empty", regex: "", next: "dissallowDelimitedBlock"}
],
"dissallowDelimitedBlock": [
{include: "paragraphEnd"},
{token: "comment", regex: '^//.+$'},
{token: "keyword", regex: "^(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION):"},
{include: "listStart"},
{token: "literal", regex: /^\s+.+$/, next: "indentedBlock"},
{token: "empty", regex: "", next: "text"}
],
"paragraphEnd": [
{token: "doc.comment", regex: /^\/{4,}\s*$/, next: "commentBlock"},
{token: "tableBlock", regex: /^\s*[|!]=+\s*$/, next: "tableBlock"},
// open block, ruller
{token: "keyword", regex: /^(?:--|''')\s*$/, next: "start"},
{token: "option", regex: /^\[.*\]\s*$/, next: "start"},
{token: "pageBreak", regex: /^>{3,}$/, next: "start"},
{token: "literal", regex: /^\.{4,}\s*$/, next: "listingBlock"},
{token: "titleUnderline", regex: /^(?:={2,}|-{2,}|~{2,}|\^{2,}|\+{2,})\s*$/, next: "start"},
{token: "singleLineTitle", regex: /^={1,5}\s+\S.*$/, next: "start"},
{token: "otherBlock", regex: /^(?:\*{2,}|_{2,})\s*$/, next: "start"},
// .optional title
{token: "optionalTitle", regex: /^\.[^.\s].+$/, next: "start"}
],
"listStart": [
{token: "keyword", regex: /^\s*(?:\d+\.|[a-zA-Z]\.|[ixvmIXVM]+\)|\*{1,5}|-|\.{1,5})\s/, next: "listText"},
{token: "meta.tag", regex: /^.+(?::{2,4}|;;)(?: |$)/, next: "listText"},
{token: "support.function.list.callout", regex: /^(?:<\d+>|\d+>|>) /, next: "text"},
// continuation
{token: "keyword", regex: /^\+\s*$/, next: "start"}
],
"text": [
{token: ["link", "variable.language"], regex: /((?:https?:\/\/|ftp:\/\/|file:\/\/|mailto:|callto:)[^\s\[]+)(\[.*?\])/},
{token: "link", regex: /(?:https?:\/\/|ftp:\/\/|file:\/\/|mailto:|callto:)[^\s\[]+/},
{token: "link", regex: /\b[\w\.\/\-]+@[\w\.\/\-]+\b/},
{include: "macros"},
{include: "paragraphEnd"},
{token: "literal", regex:/\+{3,}/, next:"smallPassthrough"},
{token: "escape", regex: /\((?:C|TM|R)\)|\.{3}|->|<-|=>|<=|&#(?:\d+|x[a-fA-F\d]+);|(?: |^)--(?=\s+\S)/},
{token: "escape", regex: /\\[_*'`+#]|\\{2}[_*'`+#]{2}/},
{token: "keyword", regex: /\s\+$/},
// any word
{token: "text", regex: identifierRe},
{token: ["keyword", "string", "keyword"],
regex: /(<<[\w\d\-$]+,)(.*?)(>>|$)/, merge: true},
{token: "keyword", regex: /<<[\w\d\-$]+,?|>>/, merge: true},
{token: "constant.character", regex: /\({2,3}.*?\){2,3}/, merge: true},
// Anchor
{token: "keyword", regex: /\[\[.+?\]\]/},
// bibliography
{token: "support", regex: /^\[{3}[\w\d =\-]+\]{3}/},
{include: "quotes"},
// text block end
{token: "empty", regex: /^\s*$/, next: "start"}
],
"listText": [
{include: "listStart"},
{include: "text"}
],
"indentedBlock": [
{token: "literal", regex: /^[\s\w].+$/, next: "indentedBlock"},
{token: "literal", regex: "", next: "start"}
],
"listingBlock": [
{token: "literal", regex: /^\.{4,}\s*$/, next: "dissallowDelimitedBlock"},
{token: "constant.numeric", regex: '<\\d+>'},
{token: "literal", regex: '[^<]+', merge: true},
{token: "literal", regex: '<', merge: true}
],
"literalBlock": [
{token: "literal", regex: /^-{4,}\s*$/, next: "dissallowDelimitedBlock"},
{token: "constant.numeric", regex: '<\\d+>'},
{token: "literal", regex: '[^<]+', merge: true},
{token: "literal", regex: '<', merge: true}
],
"passthroughBlock": [
{token: "literal", regex: /^\+{4,}\s*$/, next: "dissallowDelimitedBlock"},
{token: "literal", regex: identifierRe + "|\\d+", merge: true},
{include: "macros"},
{token: "literal", regex: ".", merge: true}
],
"smallPassthrough": [
{token: "literal", regex: /[+]{3,}/, next: "dissallowDelimitedBlock"},
{token: "literal", regex: /^\s*$/, next: "dissallowDelimitedBlock", merge: true},
{token: "literal", regex: identifierRe + "|\\d+", merge: true},
{include: "macros"}
],
"commentBlock": [
{token: "doc.comment", regex: /^\/{4,}\s*$/, next: "dissallowDelimitedBlock"},
{token: "doc.comment", regex: '^.*$'}
],
"tableBlock": [
{token: "tableBlock", regex: /^\s*\|={3,}\s*$/, next: "dissallowDelimitedBlock"},
{token: "tableBlock", regex: /^\s*!={3,}\s*$/, next: "innerTableBlock"},
{token: "tableBlock", regex: /\|/},
{include: "text", noEscape: true}
],
"innerTableBlock": [
{token: "tableBlock", regex: /^\s*!={3,}\s*$/, next: "tableBlock"},
{token: "tableBlock", regex: /^\s*|={3,}\s*$/, next: "dissallowDelimitedBlock"},
{token: "tableBlock", regex: /\!/}
],
"macros": [
{token: "macro", regex: /{[\w\-$]+}/},
{token: ["text", "string", "text", "constant.character", "text"], regex: /({)([\w\-$]+)(:)?(.+)?(})/},
{token: ["markup.list.macro", "keyword", "string"], regex: /([\w\.\/\-]+::?)([^\s\[]+)(\[.*?\])?/},
{token: ["markup.list.macro", "keyword"], regex: /([\w\.\/\-]+::?)(\[.*?\])/},
{token: "keyword", regex: /^:.+?:(?= |$)/}
],
"quotes": [
{token: "string.italic", regex: /__[^_\s].*?__/},
{token: "string.italic", regex: quoteRule("_")},
{token: "keyword.bold", regex: /\*\*[^*\s].*?\*\*/},
{token: "keyword.bold", regex: quoteRule("\\*")},
{token: "literal", regex: quoteRule("\\+")},
{token: "literal", regex: /\+\+[^+\s].*?\+\+/},
{token: "literal", regex: /\$\$.+?\$\$/},
{token: "literal", regex: quoteRule("`")},
{token: "keyword", regex: quoteRule("^")},
{token: "keyword", regex: quoteRule("~")},
{token: "keyword", regex: /##?/},
{token: "keyword", regex: /(?:\B|^)``|\b''/}
]
};
function quoteRule(ch) {
var prefix = /\w/.test(ch) ? "\\b" : "(?:\\B|^)";
return prefix + ch + "[^" + ch + "].*?" + ch + "(?![\\w*])";
}
//addQuoteBlock("text")
var tokenMap = {
macro: "constant.character",
tableBlock: "doc.comment",
titleUnderline: "markup.heading",
singleLineTitle: "markup.heading",
pageBreak: "string",
option: "string.regexp",
otherBlock: "markup.list",
literal: "support.function",
optionalTitle: "constant.numeric",
escape: "constant.language.escape",
link: "markup.underline.list"
};
for (var state in this.$rules) {
var stateRules = this.$rules[state];
for (var i = stateRules.length; i--; ) {
var rule = stateRules[i];
if (rule.include || typeof rule == "string") {
var args = [i, 1].concat(this.$rules[rule.include || rule]);
if (rule.noEscape) {
args = args.filter(function(x) {
return !x.next;
});
}
stateRules.splice.apply(stateRules, args);
} else if (rule.token in tokenMap) {
rule.token = tokenMap[rule.token];
}
}
}
};
oop.inherits(AsciidocHighlightRules, TextHighlightRules);
exports.AsciidocHighlightRules = AsciidocHighlightRules;
});

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 Jeremy Ashkenas
/**
* Copyright (c) 2009-2012 Jeremy Ashkenas
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@ -24,9 +24,9 @@
*/
define(function(require, exports, module) {
// Generated by CoffeeScript 1.2.1-pre
// Generated by CoffeeScript 1.3.3
var extend, flatten;
var extend, flatten, _ref;
exports.starts = function(string, literal, start) {
return literal === string.substr(start, literal.length);
@ -43,7 +43,9 @@ define(function(require, exports, module) {
_results = [];
for (_i = 0, _len = array.length; _i < _len; _i++) {
item = array[_i];
if (item) _results.push(item);
if (item) {
_results.push(item);
}
}
return _results;
};
@ -51,7 +53,9 @@ define(function(require, exports, module) {
exports.count = function(string, substr) {
var num, pos;
num = pos = 0;
if (!substr.length) return 1 / 0;
if (!substr.length) {
return 1 / 0;
}
while (pos = 1 + string.indexOf(substr, pos)) {
num++;
}
@ -96,5 +100,16 @@ define(function(require, exports, module) {
return array[array.length - (back || 0) - 1];
};
exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
var e, _i, _len;
for (_i = 0, _len = this.length; _i < _len; _i++) {
e = this[_i];
if (fn(e)) {
return true;
}
}
return false;
};
});
});

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 Jeremy Ashkenas
/**
* Copyright (c) 2009-2012 Jeremy Ashkenas
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@ -24,7 +24,7 @@
*/
define(function(require, exports, module) {
// Generated by CoffeeScript 1.2.1-pre
// Generated by CoffeeScript 1.3.3
var BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _ref, _ref1,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
@ -35,14 +35,16 @@ define(function(require, exports, module) {
exports.Lexer = Lexer = (function() {
Lexer.name = 'Lexer';
function Lexer() {}
Lexer.prototype.tokenize = function(code, opts) {
var i, tag;
if (opts == null) opts = {};
if (WHITESPACE.test(code)) code = "\n" + code;
if (opts == null) {
opts = {};
}
if (WHITESPACE.test(code)) {
code = "\n" + code;
}
code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
this.code = code;
this.line = opts.line || 0;
@ -57,14 +59,20 @@ define(function(require, exports, module) {
i += this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
}
this.closeIndentation();
if (tag = this.ends.pop()) this.error("missing " + tag);
if (opts.rewrite === false) return this.tokens;
if (tag = this.ends.pop()) {
this.error("missing " + tag);
}
if (opts.rewrite === false) {
return this.tokens;
}
return (new Rewriter).rewrite(this.tokens);
};
Lexer.prototype.identifierToken = function() {
var colon, forcedIdentifier, id, input, match, prev, tag, _ref2, _ref3;
if (!(match = IDENTIFIER.exec(this.chunk))) return 0;
if (!(match = IDENTIFIER.exec(this.chunk))) {
return 0;
}
input = match[0], id = match[1], colon = match[2];
if (id === 'own' && this.tag() === 'FOR') {
this.token('OWN', id);
@ -105,7 +113,9 @@ define(function(require, exports, module) {
}
}
if (!forcedIdentifier) {
if (__indexOf.call(COFFEE_ALIASES, id) >= 0) id = COFFEE_ALIAS_MAP[id];
if (__indexOf.call(COFFEE_ALIASES, id) >= 0) {
id = COFFEE_ALIAS_MAP[id];
}
tag = (function() {
switch (id) {
case '!':
@ -118,8 +128,6 @@ define(function(require, exports, module) {
return 'LOGIC';
case 'true':
case 'false':
case 'null':
case 'undefined':
return 'BOOL';
case 'break':
case 'continue':
@ -130,29 +138,33 @@ define(function(require, exports, module) {
})();
}
this.token(tag, id);
if (colon) this.token(':', ':');
if (colon) {
this.token(':', ':');
}
return input.length;
};
Lexer.prototype.numberToken = function() {
var binaryLiteral, lexedLength, match, number, octalLiteral;
if (!(match = NUMBER.exec(this.chunk))) return 0;
if (!(match = NUMBER.exec(this.chunk))) {
return 0;
}
number = match[0];
if (/E/.test(number)) {
this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
} else if (/[BOX]/.test(number)) {
if (/^0[BOX]/.test(number)) {
this.error("radix prefix '" + number + "' must be lowercase");
} else if (/^0[89]/.test(number)) {
} else if (/E/.test(number) && !/^0x/.test(number)) {
this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
} else if (/^0\d*[89]/.test(number)) {
this.error("decimal literal '" + number + "' must not be prefixed with '0'");
} else if (/^0[0-7]/.test(number)) {
} else if (/^0\d+/.test(number)) {
this.error("octal literal '" + number + "' must be prefixed with '0o'");
}
lexedLength = number.length;
if (octalLiteral = /0o([0-7]+)/.exec(number)) {
number = (parseInt(octalLiteral[1], 8)).toString();
if (octalLiteral = /^0o([0-7]+)/.exec(number)) {
number = '0x' + (parseInt(octalLiteral[1], 8)).toString(16);
}
if (binaryLiteral = /0b([01]+)/.exec(number)) {
number = (parseInt(binaryLiteral[1], 2)).toString();
if (binaryLiteral = /^0b([01]+)/.exec(number)) {
number = '0x' + (parseInt(binaryLiteral[1], 2)).toString(16);
}
this.token('NUMBER', number);
return lexedLength;
@ -162,11 +174,15 @@ define(function(require, exports, module) {
var match, octalEsc, string;
switch (this.chunk.charAt(0)) {
case "'":
if (!(match = SIMPLESTR.exec(this.chunk))) return 0;
if (!(match = SIMPLESTR.exec(this.chunk))) {
return 0;
}
this.token('STRING', (string = match[0]).replace(MULTILINER, '\\\n'));
break;
case '"':
if (!(string = this.balancedString(this.chunk, '"'))) return 0;
if (!(string = this.balancedString(this.chunk, '"'))) {
return 0;
}
if (0 < string.indexOf('#{', 1)) {
this.interpolateString(string.slice(1, -1));
} else {
@ -176,7 +192,7 @@ define(function(require, exports, module) {
default:
return 0;
}
if (octalEsc = /^(?:\\.|[^\\])*\\[0-7]/.test(string)) {
if (octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test(string)) {
this.error("octal escape sequences " + string + " are not allowed");
}
this.line += count(string, '\n');
@ -185,7 +201,9 @@ define(function(require, exports, module) {
Lexer.prototype.heredocToken = function() {
var doc, heredoc, match, quote;
if (!(match = HEREDOC.exec(this.chunk))) return 0;
if (!(match = HEREDOC.exec(this.chunk))) {
return 0;
}
heredoc = match[0];
quote = heredoc.charAt(0);
doc = this.sanitizeHeredoc(match[2], {
@ -205,7 +223,9 @@ define(function(require, exports, module) {
Lexer.prototype.commentToken = function() {
var comment, here, match;
if (!(match = this.chunk.match(COMMENT))) return 0;
if (!(match = this.chunk.match(COMMENT))) {
return 0;
}
comment = match[0], here = match[1];
if (here) {
this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
@ -223,12 +243,15 @@ define(function(require, exports, module) {
return 0;
}
this.token('JS', (script = match[0]).slice(1, -1));
this.line += count(script, '\n');
return script.length;
};
Lexer.prototype.regexToken = function() {
var flags, length, match, prev, regex, _ref2, _ref3;
if (this.chunk.charAt(0) !== '/') return 0;
if (this.chunk.charAt(0) !== '/') {
return 0;
}
if (match = HEREGEX.exec(this.chunk)) {
length = this.heregexToken(match);
this.line += count(match[0], '\n');
@ -238,12 +261,16 @@ define(function(require, exports, module) {
if (prev && (_ref2 = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref2) >= 0)) {
return 0;
}
if (!(match = REGEX.exec(this.chunk))) return 0;
if (!(match = REGEX.exec(this.chunk))) {
return 0;
}
_ref3 = match, match = _ref3[0], regex = _ref3[1], flags = _ref3[2];
if (regex.slice(0, 2) === '/*') {
this.error('regular expressions cannot begin with `*`');
}
if (regex === '//') regex = '/(?:)/';
if (regex === '//') {
regex = '/(?:)/';
}
this.token('REGEX', "" + regex + flags);
return match.length;
};
@ -270,7 +297,9 @@ define(function(require, exports, module) {
if (tag === 'TOKENS') {
tokens.push.apply(tokens, value);
} else {
if (!(value = value.replace(HEREGEX_OMIT, ''))) continue;
if (!(value = value.replace(HEREGEX_OMIT, ''))) {
continue;
}
value = value.replace(/\\/g, '\\\\');
tokens.push(['STRING', this.makeString(value, '"', true)]);
}
@ -281,18 +310,21 @@ define(function(require, exports, module) {
this.tokens.push(['STRING', '""'], ['+', '+']);
}
(_ref5 = this.tokens).push.apply(_ref5, tokens);
if (flags) this.tokens.push([',', ','], ['STRING', '"' + flags + '"']);
if (flags) {
this.tokens.push([',', ','], ['STRING', '"' + flags + '"']);
}
this.token(')', ')');
return heregex.length;
};
Lexer.prototype.lineToken = function() {
var diff, indent, match, noNewlines, prev, size;
if (!(match = MULTI_DENT.exec(this.chunk))) return 0;
var diff, indent, match, noNewlines, size;
if (!(match = MULTI_DENT.exec(this.chunk))) {
return 0;
}
indent = match[0];
this.line += count(indent, '\n');
this.seenFor = false;
prev = last(this.tokens, 1);
size = indent.length - 1 - indent.lastIndexOf('\n');
noNewlines = this.unfinished();
if (size - this.indebt === this.indent) {
@ -342,7 +374,9 @@ define(function(require, exports, module) {
this.token('OUTDENT', dent);
}
}
if (dent) this.outdebt -= moveOut;
if (dent) {
this.outdebt -= moveOut;
}
while (this.value() === ';') {
this.tokens.pop();
}
@ -358,7 +392,9 @@ define(function(require, exports, module) {
return 0;
}
prev = last(this.tokens);
if (prev) prev[match ? 'spaced' : 'newLine'] = true;
if (prev) {
prev[match ? 'spaced' : 'newLine'] = true;
}
if (match) {
return match[0].length;
} else {
@ -370,12 +406,16 @@ define(function(require, exports, module) {
while (this.value() === ';') {
this.tokens.pop();
}
if (this.tag() !== 'TERMINATOR') this.token('TERMINATOR', '\n');
if (this.tag() !== 'TERMINATOR') {
this.token('TERMINATOR', '\n');
}
return this;
};
Lexer.prototype.suppressNewlines = function() {
if (this.value() === '\\') this.tokens.pop();
if (this.value() === '\\') {
this.tokens.pop();
}
return this;
};
@ -383,7 +423,9 @@ define(function(require, exports, module) {
var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5;
if (match = OPERATOR.exec(this.chunk)) {
value = match[0];
if (CODE.test(value)) this.tagParameters();
if (CODE.test(value)) {
this.tagParameters();
}
} else {
value = this.chunk.charAt(0);
}
@ -416,7 +458,9 @@ define(function(require, exports, module) {
tag = 'LOGIC';
} else if (prev && !prev.spaced) {
if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0)) {
if (prev[0] === '?') prev[0] = 'FUNC_EXIST';
if (prev[0] === '?') {
prev[0] = 'FUNC_EXIST';
}
tag = 'CALL_START';
} else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) {
tag = 'INDEX_START';
@ -448,7 +492,9 @@ define(function(require, exports, module) {
if (HEREDOC_ILLEGAL.test(doc)) {
this.error("block comment cannot contain \"*/\", starting");
}
if (doc.indexOf('\n') <= 0) return doc;
if (doc.indexOf('\n') <= 0) {
return doc;
}
} else {
while (match = HEREDOC_INDENT.exec(doc)) {
attempt = match[1];
@ -457,14 +503,20 @@ define(function(require, exports, module) {
}
}
}
if (indent) doc = doc.replace(RegExp("\\n" + indent, "g"), '\n');
if (!herecomment) doc = doc.replace(/^\n/, '');
if (indent) {
doc = doc.replace(RegExp("\\n" + indent, "g"), '\n');
}
if (!herecomment) {
doc = doc.replace(/^\n/, '');
}
return doc;
};
Lexer.prototype.tagParameters = function() {
var i, stack, tok, tokens;
if (this.tag() !== ')') return this;
if (this.tag() !== ')') {
return this;
}
stack = [];
tokens = this.tokens;
i = tokens.length;
@ -508,7 +560,9 @@ define(function(require, exports, module) {
continue;
case end:
stack.pop();
if (!stack.length) return str.slice(0, i + 1 || 9e9);
if (!stack.length) {
return str.slice(0, +i + 1 || 9e9);
}
end = stack[stack.length - 1];
continue;
}
@ -528,7 +582,9 @@ define(function(require, exports, module) {
Lexer.prototype.interpolateString = function(str, options) {
var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _i, _len, _ref2, _ref3, _ref4;
if (options == null) options = {};
if (options == null) {
options = {};
}
heredoc = options.heredoc, regex = options.regex;
tokens = [];
pi = 0;
@ -541,7 +597,9 @@ define(function(require, exports, module) {
if (!(letter === '#' && str.charAt(i + 1) === '{' && (expr = this.balancedString(str.slice(i + 1), '}')))) {
continue;
}
if (pi < i) tokens.push(['NEOSTRING', str.slice(pi, i)]);
if (pi < i) {
tokens.push(['NEOSTRING', str.slice(pi, i)]);
}
inner = expr.slice(1, -1);
if (inner.length) {
nested = new Lexer().tokenize(inner, {
@ -563,28 +621,44 @@ define(function(require, exports, module) {
i += expr.length;
pi = i + 1;
}
if ((i > pi && pi < str.length)) tokens.push(['NEOSTRING', str.slice(pi)]);
if (regex) return tokens;
if (!tokens.length) return this.token('STRING', '""');
if (tokens[0][0] !== 'NEOSTRING') tokens.unshift(['', '']);
if (interpolated = tokens.length > 1) this.token('(', '(');
if ((i > pi && pi < str.length)) {
tokens.push(['NEOSTRING', str.slice(pi)]);
}
if (regex) {
return tokens;
}
if (!tokens.length) {
return this.token('STRING', '""');
}
if (tokens[0][0] !== 'NEOSTRING') {
tokens.unshift(['', '']);
}
if (interpolated = tokens.length > 1) {
this.token('(', '(');
}
for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
_ref3 = tokens[i], tag = _ref3[0], value = _ref3[1];
if (i) this.token('+', '+');
if (i) {
this.token('+', '+');
}
if (tag === 'TOKENS') {
(_ref4 = this.tokens).push.apply(_ref4, value);
} else {
this.token('STRING', this.makeString(value, '"', heredoc));
}
}
if (interpolated) this.token(')', ')');
if (interpolated) {
this.token(')', ')');
}
return tokens;
};
Lexer.prototype.pair = function(tag) {
var size, wanted;
if (tag !== (wanted = last(this.ends))) {
if ('OUTDENT' !== wanted) this.error("unmatched " + tag);
if ('OUTDENT' !== wanted) {
this.error("unmatched " + tag);
}
this.indent -= size = last(this.indents);
this.outdentToken(size, true);
return this.pair(tag);
@ -616,7 +690,9 @@ define(function(require, exports, module) {
};
Lexer.prototype.makeString = function(body, quote, heredoc) {
if (!body) return quote + quote;
if (!body) {
return quote + quote;
}
body = body.replace(/\\([\s\S])/g, function(match, contents) {
if (contents === '\n' || contents === quote) {
return contents;
@ -663,7 +739,7 @@ define(function(require, exports, module) {
COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf', 'implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'yield'];
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf', 'implements', 'interface', 'package', 'private', 'protected', 'public', 'static', 'yield'];
STRICT_PROSCRIBED = ['arguments', 'eval'];
@ -723,17 +799,17 @@ define(function(require, exports, module) {
RELATION = ['IN', 'OF', 'INSTANCEOF'];
BOOL = ['TRUE', 'FALSE', 'NULL', 'UNDEFINED'];
BOOL = ['TRUE', 'FALSE'];
NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', '++', '--', ']'];
NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', 'NULL', 'UNDEFINED', '++', '--', ']'];
NOT_SPACED_REGEX = NOT_REGEX.concat(')', '}', 'THIS', 'IDENTIFIER', 'STRING');
CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER'];
INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL');
INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL', 'NULL', 'UNDEFINED');
LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
});
});

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 Jeremy Ashkenas
/**
* Copyright (c) 2009-2012 Jeremy Ashkenas
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@ -24,7 +24,7 @@
*/
define(function(require, exports, module) {
// Generated by CoffeeScript 1.2.1-pre
// Generated by CoffeeScript 1.3.3
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, left, rite, _i, _len, _ref,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
@ -32,8 +32,6 @@ define(function(require, exports, module) {
exports.Rewriter = (function() {
Rewriter.name = 'Rewriter';
function Rewriter() {}
Rewriter.prototype.rewrite = function(tokens) {
@ -67,7 +65,9 @@ define(function(require, exports, module) {
if (levels === 0 && condition.call(this, token, i)) {
return action.call(this, token, i);
}
if (!token || levels < 0) return action.call(this, token, i - 1);
if (!token || levels < 0) {
return action.call(this, token, i - 1);
}
if (_ref = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0) {
levels += 1;
} else if (_ref1 = token[0], __indexOf.call(EXPRESSION_END, _ref1) >= 0) {
@ -83,9 +83,13 @@ define(function(require, exports, module) {
_ref = this.tokens;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
tag = _ref[i][0];
if (tag !== 'TERMINATOR') break;
if (tag !== 'TERMINATOR') {
break;
}
}
if (i) {
return this.tokens.splice(0, i);
}
if (i) return this.tokens.splice(0, i);
};
Rewriter.prototype.removeMidExpressionNewlines = function() {
@ -109,7 +113,9 @@ define(function(require, exports, module) {
return this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END';
};
return this.scanTokens(function(token, i) {
if (token[0] === 'CALL_START') this.detectEnd(i + 1, condition, action);
if (token[0] === 'CALL_START') {
this.detectEnd(i + 1, condition, action);
}
return 1;
});
};
@ -124,25 +130,32 @@ define(function(require, exports, module) {
return token[0] = 'INDEX_END';
};
return this.scanTokens(function(token, i) {
if (token[0] === 'INDEX_START') this.detectEnd(i + 1, condition, action);
if (token[0] === 'INDEX_START') {
this.detectEnd(i + 1, condition, action);
}
return 1;
});
};
Rewriter.prototype.addImplicitBraces = function() {
var action, condition, sameLine, stack, start, startIndent, startsLine;
var action, condition, sameLine, stack, start, startIndent, startIndex, startsLine;
stack = [];
start = null;
startsLine = null;
sameLine = true;
startIndent = 0;
startIndex = 0;
condition = function(token, i) {
var one, tag, three, two, _ref, _ref1;
_ref = this.tokens.slice(i + 1, (i + 3) + 1 || 9e9), one = _ref[0], two = _ref[1], three = _ref[2];
if ('HERECOMMENT' === (one != null ? one[0] : void 0)) return false;
_ref = this.tokens.slice(i + 1, +(i + 3) + 1 || 9e9), one = _ref[0], two = _ref[1], three = _ref[2];
if ('HERECOMMENT' === (one != null ? one[0] : void 0)) {
return false;
}
tag = token[0];
if (__indexOf.call(LINEBREAKS, tag) >= 0) sameLine = false;
return (((tag === 'TERMINATOR' || tag === 'OUTDENT') || (__indexOf.call(IMPLICIT_END, tag) >= 0 && sameLine)) && ((!startsLine && this.tag(i - 1) !== ',') || !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':'))) || (tag === ',' && one && ((_ref1 = one[0]) !== 'IDENTIFIER' && _ref1 !== 'NUMBER' && _ref1 !== 'STRING' && _ref1 !== '@' && _ref1 !== 'TERMINATOR' && _ref1 !== 'OUTDENT'));
if (__indexOf.call(LINEBREAKS, tag) >= 0) {
sameLine = false;
}
return (((tag === 'TERMINATOR' || tag === 'OUTDENT') || (__indexOf.call(IMPLICIT_END, tag) >= 0 && sameLine && !(i - startIndex === 1))) && ((!startsLine && this.tag(i - 1) !== ',') || !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':'))) || (tag === ',' && one && ((_ref1 = one[0]) !== 'IDENTIFIER' && _ref1 !== 'NUMBER' && _ref1 !== 'STRING' && _ref1 !== '@' && _ref1 !== 'TERMINATOR' && _ref1 !== 'OUTDENT'));
};
action = function(token, i) {
var tok;
@ -163,6 +176,7 @@ define(function(require, exports, module) {
return 1;
}
sameLine = true;
startIndex = i + 1;
stack.push(['{']);
idx = ago === '@' ? i - 2 : i - 1;
while (this.tag(idx - 2) === 'HERECOMMENT') {
@ -185,7 +199,9 @@ define(function(require, exports, module) {
condition = function(token, i) {
var post, tag, _ref, _ref1;
tag = token[0];
if (!seenSingle && token.fromThen) return true;
if (!seenSingle && token.fromThen) {
return true;
}
if (tag === 'IF' || tag === 'ELSE' || tag === 'CATCH' || tag === '->' || tag === '=>' || tag === 'CLASS') {
seenSingle = true;
}
@ -206,19 +222,27 @@ define(function(require, exports, module) {
if (tag === 'CLASS' || tag === 'IF' || tag === 'FOR' || tag === 'WHILE') {
noCall = true;
}
_ref = tokens.slice(i - 1, (i + 1) + 1 || 9e9), prev = _ref[0], current = _ref[1], next = _ref[2];
_ref = tokens.slice(i - 1, +(i + 1) + 1 || 9e9), prev = _ref[0], current = _ref[1], next = _ref[2];
callObject = !noCall && tag === 'INDENT' && next && next.generated && next[0] === '{' && prev && (_ref1 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref1) >= 0);
seenSingle = false;
seenControl = false;
if (__indexOf.call(LINEBREAKS, tag) >= 0) noCall = false;
if (prev && !prev.spaced && tag === '?') token.call = true;
if (token.fromThen) return 1;
if (__indexOf.call(LINEBREAKS, tag) >= 0) {
noCall = false;
}
if (prev && !prev.spaced && tag === '?') {
token.call = true;
}
if (token.fromThen) {
return 1;
}
if (!(callObject || (prev != null ? prev.spaced : void 0) && (prev.call || (_ref2 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref2) >= 0)) && (__indexOf.call(IMPLICIT_CALL, tag) >= 0 || !(token.spaced || token.newLine) && __indexOf.call(IMPLICIT_UNSPACED_CALL, tag) >= 0))) {
return 1;
}
tokens.splice(i, 0, this.generate('CALL_START', '(', token[2]));
this.detectEnd(i + 1, condition, action);
if (prev[0] === '?') prev[0] = 'FUNC_EXIST';
if (prev[0] === '?') {
prev[0] = 'FUNC_EXIST';
}
return 2;
});
};
@ -251,10 +275,14 @@ define(function(require, exports, module) {
if (__indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
starter = tag;
_ref1 = this.indentation(token, true), indent = _ref1[0], outdent = _ref1[1];
if (starter === 'THEN') indent.fromThen = true;
if (starter === 'THEN') {
indent.fromThen = true;
}
tokens.splice(i + 1, 0, indent);
this.detectEnd(i + 2, condition, action);
if (tag === 'THEN') tokens.splice(i, 1);
if (tag === 'THEN') {
tokens.splice(i, 1);
}
return 1;
}
return 1;
@ -274,7 +302,9 @@ define(function(require, exports, module) {
}
};
return this.scanTokens(function(token, i) {
if (token[0] !== 'IF') return 1;
if (token[0] !== 'IF') {
return 1;
}
original = token;
this.detectEnd(i + 1, condition, action);
return 1;
@ -283,10 +313,14 @@ define(function(require, exports, module) {
Rewriter.prototype.indentation = function(token, implicit) {
var indent, outdent;
if (implicit == null) implicit = false;
if (implicit == null) {
implicit = false;
}
indent = ['INDENT', 2, token[2]];
outdent = ['OUTDENT', 2, token[2]];
if (implicit) indent.generated = outdent.generated = true;
if (implicit) {
indent.generated = outdent.generated = true;
}
return [indent, outdent];
};
@ -324,7 +358,7 @@ define(function(require, exports, module) {
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS'];
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'UNARY', 'SUPER', '@', '->', '=>', '[', '(', '{', '--', '++'];
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'NULL', 'UNDEFINED', 'UNARY', 'SUPER', '@', '->', '=>', '[', '(', '{', '--', '++'];
IMPLICIT_UNSPACED_CALL = ['+', '-'];
@ -339,4 +373,4 @@ define(function(require, exports, module) {
LINEBREAKS = ['TERMINATOR', 'INDENT', 'OUTDENT'];
});
});

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 Jeremy Ashkenas
/**
* Copyright (c) 2009-2012 Jeremy Ashkenas
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@ -24,7 +24,7 @@
*/
define(function(require, exports, module) {
// Generated by CoffeeScript 1.2.1-pre
// Generated by CoffeeScript 1.3.3
var Scope, extend, last, _ref;
@ -32,8 +32,6 @@ define(function(require, exports, module) {
exports.Scope = Scope = (function() {
Scope.name = 'Scope';
Scope.root = null;
function Scope(parent, expressions, method) {
@ -47,11 +45,15 @@ define(function(require, exports, module) {
}
];
this.positions = {};
if (!this.parent) Scope.root = this;
if (!this.parent) {
Scope.root = this;
}
}
Scope.prototype.add = function(name, type, immediate) {
if (this.shared && !immediate) return this.parent.add(name, type, immediate);
if (this.shared && !immediate) {
return this.parent.add(name, type, immediate);
}
if (Object.prototype.hasOwnProperty.call(this.positions, name)) {
return this.variables[this.positions[name]].type = type;
} else {
@ -62,22 +64,31 @@ define(function(require, exports, module) {
}
};
Scope.prototype.find = function(name, options) {
if (this.check(name, options)) return true;
Scope.prototype.namedMethod = function() {
if (this.method.name || !this.parent) {
return this.method;
}
return this.parent.namedMethod();
};
Scope.prototype.find = function(name) {
if (this.check(name)) {
return true;
}
this.add(name, 'var');
return false;
};
Scope.prototype.parameter = function(name) {
if (this.shared && this.parent.check(name, true)) return;
if (this.shared && this.parent.check(name, true)) {
return;
}
return this.add(name, 'param');
};
Scope.prototype.check = function(name, immediate) {
var found, _ref1;
found = !!this.type(name);
if (found || immediate) return found;
return !!((_ref1 = this.parent) != null ? _ref1.check(name) : void 0);
Scope.prototype.check = function(name) {
var _ref1;
return !!(this.type(name) || ((_ref1 = this.parent) != null ? _ref1.check(name) : void 0));
};
Scope.prototype.temporary = function(name, index) {
@ -93,19 +104,25 @@ define(function(require, exports, module) {
_ref1 = this.variables;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
v = _ref1[_i];
if (v.name === name) return v.type;
if (v.name === name) {
return v.type;
}
}
return null;
};
Scope.prototype.freeVariable = function(name, reserve) {
var index, temp;
if (reserve == null) reserve = true;
if (reserve == null) {
reserve = true;
}
index = 0;
while (this.check((temp = this.temporary(name, index)))) {
index++;
}
if (reserve) this.add(temp, 'var', true);
if (reserve) {
this.add(temp, 'var', true);
}
return temp;
};
@ -141,7 +158,9 @@ define(function(require, exports, module) {
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
v = _ref1[_i];
if (v.type.assigned) _results.push("" + v.name + " = " + v.type.value);
if (v.type.assigned) {
_results.push("" + v.name + " = " + v.type.value);
}
}
return _results;
};
@ -151,4 +170,4 @@ define(function(require, exports, module) {
})();
});
});

View file

@ -143,7 +143,7 @@ define(function(require, exports, module) {
next : "heregex"
}, {
token : "string.regex",
regex : "/(?!\\s)[^[/\\n\\\\]*(?: (?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[/\\n\\\\]*)*/[imgy]{0,4}(?!\\w)"
regex : /(?:\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/)(?:[imgy]{0,4})(?!\w)/
}, {
token : "comment",
merge : true,

View file

@ -54,7 +54,13 @@ module.exports = {
assert.equal(tokens.length, 1);
assert.equal(tokens[0].type, "keyword");
},
"test: tokenize regexp": function() {
var tokens = this.tokenizer.getLineTokens('/"[a]/', "start").tokens;
assert.equal(tokens.length, 1);
assert.equal(tokens[0].type, "string.regex");
},
"test: tokenize function: 'foo = ({args}) ->'": function() {
var tokens = this.tokenizer.getLineTokens("foo = ({args}) ->", "start").tokens;
var correct = [

View file

@ -58,11 +58,11 @@ var ColdfusionHighlightRules = function() {
next : "comment"
}, {
token : "meta.tag",
regex : "<(?=\s*script)",
regex : "<(?=script)",
next : "script"
}, {
token : "meta.tag",
regex : "<(?=\s*style)",
regex : "<(?=style)",
next : "style"
}, {
token : "meta.tag", // opening tag

View file

@ -74,25 +74,19 @@ oop.inherits(Mode, TextMode);
this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};
this.createWorker = function(session) {
var worker = new WorkerClient(["ace"], "ace/mode/css_worker", "Worker");
worker.attachToDocument(session.getDocument());
worker.on("csslint", function(e) {
var errors = [];
e.data.forEach(function(message) {
errors.push({
row: message.line - 1,
column: message.col - 1,
text: message.message,
type: message.type,
lint: message
});
});
session.setAnnotations(errors);
session.setAnnotations(e.data);
});
worker.on("terminate", function() {
session.clearAnnotations();
});
return worker;
};

View file

@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* Build time: 2-March-2012 02:47:11 */
/* Build time: 14-May-2012 10:24:48 */
/*!
Parser-Lib
@ -47,7 +47,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* Version v0.1.6, Build time: 2-March-2012 02:44:32 */
/* Version v0.1.7, Build time: 4-May-2012 03:57:04 */
var parserlib = {};
(function(){
@ -957,7 +957,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* Version v0.1.6, Build time: 2-March-2012 02:44:32 */
/* Version v0.1.7, Build time: 4-May-2012 03:57:04 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@ -2171,7 +2171,7 @@ Parser.prototype = function(){
//there must be a next selector
if (nextSelector === null){
this._unexpectedToken(this.LT(1));
this._unexpectedToken(tokenStream.LT(1));
} else {
//nextSelector is an instance of SelectorPart
@ -2666,7 +2666,8 @@ Parser.prototype = function(){
expr = null,
prio = null,
error = null,
invalid = null;
invalid = null,
propertyName= "";
property = this._property();
if (property !== null){
@ -2683,8 +2684,20 @@ Parser.prototype = function(){
prio = this._prio();
/*
* If hacks should be allowed, then only check the root
* property. If hacks should not be allowed, treat
* _property or *property as invalid properties.
*/
propertyName = property.toString();
if (this.options.starHack && property.hack == "*" ||
this.options.underscoreHack && property.hack == "_") {
propertyName = property.text;
}
try {
this._validateProperty(property, expr);
this._validateProperty(propertyName, expr);
} catch (ex) {
invalid = ex;
}
@ -3525,6 +3538,7 @@ var Properties = {
"background-repeat" : { multi: "<repeat-style>" },
"background-size" : { multi: "<bg-size>", comma: true },
"baseline-shift" : "baseline | sub | super | <percentage> | <length>",
"behavior" : 1,
"binding" : 1,
"bleed" : "<length>",
"bookmark-label" : "<content> | <attr> | <string>",
@ -3871,6 +3885,7 @@ var Properties = {
"text-justify" : "auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida",
"text-outline" : 1,
"text-overflow" : 1,
"text-rendering" : "auto | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit",
"text-shadow" : 1,
"text-transform" : "capitalize | uppercase | lowercase | none | inherit",
"text-wrap" : "normal | none | avoid",
@ -5950,7 +5965,7 @@ var ValidationTypes = {
i, len, found = false;
for (i=0,len=args.length; i < len && !found; i++){
if (text == args[i]){
if (text == args[i].toLowerCase()){
found = true;
}
}
@ -6042,7 +6057,7 @@ var ValidationTypes = {
},
"<gradient>": function(part) {
return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial|linear)\-gradient/i.test(part);
return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(part);
},
"<box>": function(part){
@ -6134,6 +6149,18 @@ var ValidationTypes = {
part,
i, len;
/*
<position> = [
[ left | center | right | top | bottom | <percentage> | <length> ]
|
[ left | center | right | <percentage> | <length> ]
[ top | center | bottom | <percentage> | <length> ]
|
[ center | [ left | right ] [ <percentage> | <length> ]? ] &&
[ center | [ top | bottom ] [ <percentage> | <length> ]? ]
]
*/
if (ValidationTypes.isAny(expression, "top | bottom")) {
result = true;
@ -6306,7 +6333,7 @@ var CSSLint = (function(){
formatters = [],
api = new parserlib.util.EventTarget();
api.version = "0.9.7";
api.version = "0.9.8";
//-------------------------------------------------------------------------
// Rule Management
@ -7633,7 +7660,7 @@ CSSLint.addRule({
parser.addListener("endstylesheet", function(){
reporter.stat("important", count);
if (count >= 10){
reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specifity issues.", rule);
reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
}
});
}
@ -8290,8 +8317,35 @@ CSSLint.addRule({
});
/*
* Rule: Don't use text-indent for image replacement if you need to support rtl.
*
* Rule: Don't use properties with a star prefix.
*
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "star-property-hack",
name: "Disallow properties with a star prefix",
desc: "Checks for the star property hack (targets IE6/7)",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
//check if property name starts with "*"
parser.addListener("property", function(event){
var property = event.property;
if (property.hack == "*") {
reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
}
});
}
});
/*
* Rule: Don't use text-indent for image replacement if you need to support rtl.
*
*/
/*global CSSLint*/
CSSLint.addRule({
@ -8301,27 +8355,29 @@ CSSLint.addRule({
name: "Disallow negative text-indent",
desc: "Checks for text indent less than -99px",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
textIndent = false;
textIndent,
direction;
function startRule(event){
textIndent = false;
direction = "inherit";
}
//event handler for end of rules
function endRule(event){
if (textIndent){
if (textIndent && direction != "ltr"){
reporter.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", textIndent.line, textIndent.col, rule);
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
//check for use of "font-size"
parser.addListener("property", function(event){
var name = event.property.toString().toLowerCase(),
@ -8330,16 +8386,43 @@ CSSLint.addRule({
if (name == "text-indent" && value.parts[0].value < -99){
textIndent = event.property;
} else if (name == "direction" && value == "ltr"){
textIndent = false;
direction = "ltr";
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endfontface", endRule);
}
});
/*
* Rule: Don't use properties with a underscore prefix.
*
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "underscore-property-hack",
name: "Disallow properties with an underscore prefix",
desc: "Checks for the underscore property hack (targets IE6)",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this;
//check if property name starts with "_"
parser.addListener("property", function(event){
var property = event.property;
if (property.hack == "_") {
reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
}
});
}
});
/*
* Rule: Headings (h1-h6) should be defined only once.
*/
@ -8669,343 +8752,6 @@ CSSLint.addRule({
});
/*global CSSLint*/
CSSLint.addFormatter({
//format information
id: "checkstyle-xml",
name: "Checkstyle XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function(){
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function(){
return "</checkstyle>";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = [];
/**
* Generate a source string for a rule.
* Checkstyle source strings usually resemble Java class names e.g
* net.csslint.SomeRuleName
* @param {Object} rule
* @return rule source as {String}
*/
var generateSource = function(rule) {
if (!rule || !('name' in rule)) {
return "";
}
return 'net.csslint.' + rule.name.replace(/\s/g,'');
};
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - &lt; is the escape sequence for <
* - &gt; is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var escapeSpecialCharacters = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
};
if (messages.length > 0) {
output.push("<file name=\""+filename+"\">");
CSSLint.Util.forEach(messages, function (message, i) {
//ignore rollups for now
if (!message.rollup) {
output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
" message=\"" + escapeSpecialCharacters(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
}
});
output.push("</file>");
}
return output.join("");
}
});
/*global CSSLint*/
CSSLint.addFormatter({
//format information
id: "compact",
name: "Compact, 'porcelain' format",
/**
* Return content to be printed before all file results.
* @return {String} to prepend before all results
*/
startFormat: function() {
return "";
},
/**
* Return content to be printed after all file results.
* @return {String} to append after all results
*/
endFormat: function() {
return "";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (Optional) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = "";
options = options || {};
/**
* Capitalize and return given string.
* @param str {String} to capitalize
* @return {String} capitalized
*/
var capitalize = function(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
};
if (messages.length === 0) {
return options.quiet ? "" : filename + ": Lint Free!";
}
CSSLint.Util.forEach(messages, function(message, i) {
if (message.rollup) {
output += filename + ": " + capitalize(message.type) + " - " + message.message + "\n";
} else {
output += filename + ": " + "line " + message.line +
", col " + message.col + ", " + capitalize(message.type) + " - " + message.message + "\n";
}
});
return output;
}
});
/*global CSSLint*/
CSSLint.addFormatter({
//format information
id: "csslint-xml",
name: "CSSLint XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function(){
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><csslint>";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function(){
return "</csslint>";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = [];
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - &lt; is the escape sequence for <
* - &gt; is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var escapeSpecialCharacters = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
};
if (messages.length > 0) {
output.push("<file name=\""+filename+"\">");
CSSLint.Util.forEach(messages, function (message, i) {
if (message.rollup) {
output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
} else {
output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
}
});
output.push("</file>");
}
return output.join("");
}
});
/*global CSSLint*/
CSSLint.addFormatter({
//format information
id: "lint-xml",
name: "Lint XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function(){
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><lint>";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function(){
return "</lint>";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = [];
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - &lt; is the escape sequence for <
* - &gt; is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var escapeSpecialCharacters = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
};
if (messages.length > 0) {
output.push("<file name=\""+filename+"\">");
CSSLint.Util.forEach(messages, function (message, i) {
if (message.rollup) {
output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
} else {
output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
}
});
output.push("</file>");
}
return output.join("");
}
});
/*global CSSLint*/
CSSLint.addFormatter({
//format information
id: "text",
name: "Plain Text",
/**
* Return content to be printed before all file results.
* @return {String} to prepend before all results
*/
startFormat: function() {
return "";
},
/**
* Return content to be printed after all file results.
* @return {String} to append after all results
*/
endFormat: function() {
return "";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (Optional) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = "";
options = options || {};
if (messages.length === 0) {
return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + ".";
}
output = "\n\ncsslint: There are " + messages.length + " problems in " + filename + ".";
var pos = filename.lastIndexOf("/"),
shortFilename = filename;
if (pos === -1){
pos = filename.lastIndexOf("\\");
}
if (pos > -1){
shortFilename = filename.substring(pos+1);
}
CSSLint.Util.forEach(messages, function (message, i) {
output = output + "\n\n" + shortFilename;
if (message.rollup) {
output += "\n" + (i+1) + ": " + message.type;
output += "\n" + message.message;
} else {
output += "\n" + (i+1) + ": " + message.type + " at line " + message.line + ", col " + message.col;
output += "\n" + message.message;
output += "\n" + message.evidence;
}
});
return output;
}
});
exports.CSSLint = CSSLint;

View file

@ -27,33 +27,68 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var lang = require("../lib/lang");
var Mirror = require("../worker/mirror").Mirror;
var CSSLint = require("./css/csslint").CSSLint;
var Worker = exports.Worker = function(sender) {
Mirror.call(this, sender);
this.setTimeout(200);
this.setTimeout(400);
this.ruleset = null;
this.setDisabledRules("");
this.setInfoRules("adjoining-classes|qualified-headings|zero-units|gradients|import|outline-none");
};
oop.inherits(Worker, Mirror);
(function() {
this.setInfoRules = function(ruleNames) {
if (typeof ruleNames == "string")
ruleNames = ruleNames.split("|");
this.infoRules = lang.arrayToMap(ruleNames);
this.doc.getValue() && this.deferredUpdate.schedule(100);
};
this.setDisabledRules = function(ruleNames) {
if (!ruleNames) {
this.ruleset = null;
} else {
if (typeof ruleNames == "string")
ruleNames = ruleNames.split("|");
var all = {};
CSSLint.getRules().forEach(function(x){
all[x.id] = true;
});
ruleNames.forEach(function(x) {
delete all[x];
});
console.log(all)
this.ruleset = all;
}
this.doc.getValue() && this.deferredUpdate.schedule(100);
};
this.onUpdate = function() {
var value = this.doc.getValue();
var result = CSSLint.verify(value);
var infoRules = this.infoRules;
var result = CSSLint.verify(value, this.ruleset);
this.sender.emit("csslint", result.messages.map(function(msg) {
delete msg.rule;
return msg;
return {
row: msg.line - 1,
column: msg.col - 1,
text: msg.message,
type: infoRules[msg.rule.id] ? "info" : msg.type
}
}));
};
}).call(Worker.prototype);
});

View file

@ -74,14 +74,14 @@ var DiffHighlightRules = function() {
"support.constant",
"text",
"invalid"
],
]
}, { // removed
"regex": "^([<\\-])(.*?)(\\s*)$",
"token": [
"support.function",
"string",
"invalid"
],
]
}, {
"regex": "^(diff)(\\s+--\\w+)?(.+?)( .+)?$",
"token": ["variable", "variable", "keyword", "variable"]

View file

@ -0,0 +1,142 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var oop = require("../../lib/oop");
var BaseFoldMode = require("./fold_mode").FoldMode;
var Range = require("../../range").Range;
var FoldMode = exports.FoldMode = function() {};
oop.inherits(FoldMode, BaseFoldMode);
(function() {
this.foldingStartMarker = /^(?:\|={10,}|[\.\/=\-~^+]{4,}|={1,5} )/;
this.singleLineHeadingRe = /^={1,5}(?=\s+\S)/;
this.getFoldWidget = function(session, foldStyle, row) {
var line = session.getLine(row);
if (!this.foldingStartMarker.test(line))
return ""
if (line[0] == "=") {
if (this.singleLineHeadingRe.test(line))
return "start";
if (session.getLine(row - 1).length != session.getLine(row).length)
return "";
return "start";
}
if (session.bgTokenizer.getState(row) == "dissallowDelimitedBlock")
return "end";
return "start";
};
this.getFoldWidgetRange = function(session, foldStyle, row) {
var line = session.getLine(row);
var startColumn = line.length;
var maxRow = session.getLength();
var startRow = row;
var endRow = row;
if (!line.match(this.foldingStartMarker))
return;
var token;
function getTokenType(row) {
token = session.getTokens(row)[0];
return token && token.type;
}
var levels = ["=","-","~","^","+"];
var heading = "markup.heading";
var singleLineHeadingRe = this.singleLineHeadingRe;
function getLevel() {
var match = token.value.match(singleLineHeadingRe);
if (match)
return match[0].length;
var level = levels.indexOf(token.value[0]) + 1;
if (level == 1) {
if (session.getLine(row - 1).length != session.getLine(row).length)
return Infinity;
}
return level;
}
if (getTokenType(row) == heading) {
var startHeadingLevel = getLevel();
while (++row < maxRow) {
if (getTokenType(row) != heading)
continue;
var level = getLevel();
if (level <= startHeadingLevel)
break;
}
var isSingleLineHeading = token && token.value.match(this.singleLineHeadingRe);
endRow = isSingleLineHeading ? row - 1 : row - 2;
if (endRow > startRow) {
while (endRow > startRow && (!getTokenType(endRow) || token.value[0] == "["))
endRow--;
}
if (endRow > startRow) {
var endColumn = session.getLine(endRow).length;
return new Range(startRow, startColumn, endRow, endColumn);
}
} else {
var state = session.bgTokenizer.getState(row);
if (state == "dissallowDelimitedBlock") {
while (row -- > 0) {
if (session.bgTokenizer.getState(row).lastIndexOf("Block") == -1)
break;
}
endRow = row + 1;
if (endRow < startRow) {
var endColumn = session.getLine(row).length;
return new Range(endRow, 5, startRow, startColumn - 5);
}
} else {
while (++row < maxRow) {
if (session.bgTokenizer.getState(row) == "dissallowDelimitedBlock")
break;
}
endRow = row;
if (endRow > startRow) {
var endColumn = session.getLine(row).length;
return new Range(startRow, 5, endRow, endColumn - 5);
}
}
}
};
}).call(FoldMode.prototype);
});

View file

@ -47,7 +47,7 @@ module.exports = {
']',
'[ ',
'{ ',
'[ #-',
'[ #-'
]);
var mode = new PythonMode();

View file

@ -80,11 +80,11 @@ var HtmlHighlightRules = function() {
regex : "<\\!.*?>"
}, {
token : "meta.tag",
regex : "<(?=\s*script\\b)",
regex : "<(?=script\\b)",
next : "script"
}, {
token : "meta.tag",
regex : "<(?=\s*style\\b)",
regex : "<(?=style\\b)",
next : "style"
}, {
token : "meta.tag", // opening tag

View file

@ -40,8 +40,8 @@ var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var JadeHighlightRules = require("./jade_highlight_rules").JadeHighlightRules;
// var JavascriptMode = require("ace/mode/javascript").Mode;
// var CssMode = require("ace/mode/css").Mode;
// var JavascriptMode = require("../mode/javascript").Mode;
// var CssMode = require("../mode/css").Mode;
var Mode = function() {
var highlighter = new JadeHighlightRules();

View file

@ -82,7 +82,7 @@ var JadeHighlightRules = function() {
},
{
"token" : "punctuation.section.comment",
"regex" : "^\\s*\/\/(?:\\s*[^-\\s]|\\s+\\S)(?:.*$)",
"regex" : "^\\s*\/\/(?:\\s*[^-\\s]|\\s+\\S)(?:.*$)"
},
{
"token" : function(space, text) {
@ -120,11 +120,11 @@ var JadeHighlightRules = function() {
"token": [ "storage.type.function.jade", "entity.name.function.jade"],
"regex": "^(\\s*mixin)( [\\w\\-]+)"
},
/* {
{
"token": "source.js.embedded.jade",
"regex": "^\\s*-|=|!=",
"next": "js_code"
},*/
"regex": "^\\s*(?:-|=|!=)",
"next": "js-start"
},
/*{
"token": "entity.name.tag.script.jade",
"regex": "^\\s*script",
@ -219,7 +219,21 @@ var JadeHighlightRules = function() {
"next": "start"
}
],
"tag_attributes": [
"tag_attributes": [
{
"token" : "string",
"regex" : "'(?=.)",
"next" : "qstring"
},
{
"token" : "string",
"regex" : '"(?=.)',
"next" : "qqstring"
},
{
"token": "entity.other.attribute-name.jade",
"regex": "\\b[a-zA-Z\\-:]+"
},
{
"token": ["entity.other.attribute-name.jade", "punctuation"],
"regex": "\\b([a-zA-Z:\\.-]+)(=)",
@ -284,6 +298,12 @@ var JadeHighlightRules = function() {
}
]
};
this.embedRules(JavaScriptHighlightRules, "js-", [{
token: "text",
regex: ".$",
next: "start"
}]);
/*
this.embedRules(MarkdownHighlightRules, "markdown-", [{
token : "support.function",
@ -324,4 +344,4 @@ var JadeHighlightRules = function() {
oop.inherits(JadeHighlightRules, TextHighlightRules);
exports.JadeHighlightRules = JadeHighlightRules;
});
});

View file

@ -55,8 +55,7 @@ var JavaHighlightRules = function() {
"variable.language": "this",
"keyword": keywords,
"constant.language": buildinConstants,
"support.function": langClasses,
"support.function": langClasses
}, "identifier");
// regexp must not have capturing parentheses. Use (?:) instead.

View file

@ -123,25 +123,9 @@ oop.inherits(Mode, TextMode);
this.createWorker = function(session) {
var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
worker.attachToDocument(session.getDocument());
worker.on("jslint", function(results) {
var errors = [];
for (var i=0; i<results.data.length; i++) {
var error = results.data[i];
if (error)
errors.push({
row: error.line-1,
column: error.character-1,
text: error.reason,
type: "warning",
lint: error
});
}
session.setAnnotations(errors);
});
worker.on("narcissus", function(e) {
session.setAnnotations([e.data]);
session.setAnnotations(results.data);
});
worker.on("terminate", function() {

File diff suppressed because it is too large Load diff

View file

@ -32,7 +32,6 @@ define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var unicode = require("../unicode");
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
@ -51,11 +50,11 @@ var JavaScriptHighlightRules = function() {
"JSON|Math|" + // Other
"this|arguments|prototype|window|document" , // Pseudo
"invalid.deprecated":
"__parent__|__count__|escape|unescape|with|__proto__|debugger",
"__parent__|__count__|escape|unescape|with|__proto__",
"keyword":
"const|yield|import|get|set" +
"const|yield|import|get|set|" +
"break|case|catch|continue|default|delete|do|else|finally|for|function|" +
"if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|",
"if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger",
"storage.type":
"const|let|var|function",
"invalid.illegal":
@ -63,9 +62,10 @@ var JavaScriptHighlightRules = function() {
"public|interface|package|protected|static",
"constant.language":
"null|Infinity|NaN|undefined",
"support.function":
"alert"
}, "identifier");
// keywords which can be followed by regular expressions
var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield";
@ -255,14 +255,14 @@ var JavaScriptHighlightRules = function() {
}, {
// invalid operators
token : "invalid",
regex: /\{\d+,?(?:\d+)?}[+*]|[+*^$?][+*]|\?\?/ // |[^$][?]
regex: /\{\d+,?(?:\d+)?}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
}, {
// operators
token : "constant.language.escape",
regex: /\(\?[:=!]|\)|\{\d+,?(?:\d+)?}|[+*]\?|[(|)$^+*?]/
regex: /\(\?[:=!]|\)|{\d+,?(?:\d+)?}|{,\d+}|[+*]\?|[(|)$^+*?]/
}, {
token: "string.regexp",
regex: /{|[^\[\\{()$^+*?\/]+/,
regex: /{|[^{\[\/\\(|)$^+*?]+/,
merge: true
}, {
token: "constant.language.escape",
@ -286,7 +286,7 @@ var JavaScriptHighlightRules = function() {
merge: true
}, {
token: "constant.language.escape",
regex: "-",
regex: "-"
}, {
token: "string.regexp.charachterclass",
regex: /[^\]\-\\]+/,

View file

@ -27,55 +27,160 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var Mirror = require("../worker/mirror").Mirror;
var lint = require("../worker/jshint").JSHINT;
var parser = require("../narcissus/parser");
var lint = require("./javascript/jshint").JSHINT;
function startRegex(arr) {
return RegExp("^(" + arr.join("|") + ")");
}
var disabledWarningsRe = startRegex([
"Bad for in variable '(.+)'.",
'Missing "use strict"'
]);
var errorsRe = startRegex([
"Unexpected",
"Expected ",
"Confusing (plus|minus)",
"\\{a\\} unterminated regular expression",
"Unclosed ",
"Unmatched ",
"Unbegun comment",
"Bad invocation",
"Missing space after",
"Missing operator at"
]);
var infoRe = startRegex([
"Expected an assignment",
"Bad escapement of EOL",
"Unexpected comma",
"Unexpected space",
"Missing radix parameter.",
"A leading decimal point can",
"\\['\\{a\\}'\\] is better written in dot notation."
]);
var JavaScriptWorker = exports.JavaScriptWorker = function(sender) {
Mirror.call(this, sender);
this.setTimeout(500);
this.setOptions();
};
oop.inherits(JavaScriptWorker, Mirror);
(function() {
this.setOptions = function(options) {
this.options = options || {
// undef: true,
// unused: true,
es5: true,
esnext: true,
devel: true,
browser: true,
node: true,
laxcomma: true,
laxbreak: true,
lastsemic: true,
onevar: false,
passfail: false,
maxerr: 100,
expr: true,
multistr: true,
globalstrict: true
};
this.doc.getValue() && this.deferredUpdate.schedule(100);
};
this.changeOptions = function(newOptions) {
oop.mixin(this.options, newOptions);
this.doc.getValue() && this.deferredUpdate.schedule(100);
};
this.isValidJS = function(str) {
try {
// evaluated code can only create variables in this function
eval("throw 0;" + str);
} catch(e) {
if (e === 0)
return true;
}
return false
};
this.onUpdate = function() {
var value = this.doc.getValue();
value = value.replace(/^#!.*\n/, "\n");
// var start = new Date();
try {
parser.parse(value);
} catch(e) {
// console.log("narcissus")
// console.log(e);
var chunks = e.message.split(":")
var message = chunks.pop().trim();
var lineNumber = parseInt(chunks.pop().trim()) - 1;
this.sender.emit("narcissus", {
row: lineNumber,
column: null, // TODO convert e.cursor
text: message,
type: "error"
});
if (!value) {
this.sender.emit("jslint", []);
return;
} finally {
// console.log("parse time: " + (new Date() - start));
}
// var start = new Date();
// console.log("jslint")
lint(value, {undef: false, onevar: false, passfail: false});
this.sender.emit("jslint", lint.errors);
// console.log("lint time: " + (new Date() - start));
}
var errors = [];
// jshint reports many false errors
// report them as error only if code is actually invalid
var maxErrorLevel = this.isValidJS(value) ? "warning" : "error";
// var start = new Date();
lint(value, this.options);
var results = lint.errors;
var errorAdded = false
for (var i = 0; i < results.length; i++) {
var error = results[i];
if (!error)
continue;
var raw = error.raw;
var type = "warning";
if (raw == "Missing semicolon.") {
var str = error.evidence.substr(error.character);
str = str.charAt(str.search(/\S/));
if (maxErrorLevel == "error" && str && /[\w\d{(['"]/.test(str)) {
error.reason = 'Missing ";" before statement';
type = "error";
} else {
type = "info";
}
}
else if (disabledWarningsRe.test(raw)) {
continue;
}
else if (infoRe.test(raw)) {
type = "info"
}
else if (errorsRe.test(raw)) {
errorAdded = true;
type = maxErrorLevel;
}
else if (raw == "'{a}' is not defined.") {
type = "warning";
}
else if (raw == "'{a}' is defined but never used.") {
type = "info";
}
errors.push({
row: error.line-1,
column: error.character-1,
text: error.reason,
type: type,
raw: raw
});
if (errorAdded) {
// break;
}
}
// console.log("lint time: " + (new Date() - start));
this.sender.emit("jslint", errors);
};
}).call(JavaScriptWorker.prototype);
});

View file

@ -58,11 +58,11 @@ module.exports = {
worker.setValue("Juhu Kinners");
worker.deferredUpdate.call();
var error = this.sender.events[0][1];
assert.equal(error.text, "missing ; before statement");
var error = this.sender.events[0][1][0];
assert.equal(error.text, 'Missing ";" before statement');
assert.equal(error.type, "error");
assert.equal(error.row, 0);
assert.equal(error.column, null);
assert.equal(error.column, 4);
},
"test invalid multi line string": function() {
@ -70,18 +70,23 @@ module.exports = {
worker.setValue('"a\n\\nn"');
worker.deferredUpdate.call();
var error = this.sender.events[0][1];
assert.equal(error.text, "Unterminated string literal");
var error = this.sender.events[0][1][0];
assert.equal(error.text, "Unclosed string.");
assert.equal(error.type, "error");
assert.equal(error.row, 0);
assert.equal(error.column, null);
assert.equal(error.column, 0);
},
"test check for narcissus bug": function() {
"test another invalid string": function() {
var worker = new JavaScriptWorker(this.sender);
worker.setValue("if('");
worker.deferredUpdate.call();
assert.equal(this.sender.events[0][1].type, "error");
var error = this.sender.events[0][1][0];
assert.equal(error.text, "Unclosed string.");
assert.equal(error.type, "error");
assert.equal(error.row, 0);
assert.equal(error.column, 3);
}
};

View file

@ -36,14 +36,9 @@ var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var JspHighlightRules = require("./jsp_highlight_rules").JspHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Range = require("../range").Range;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var JavaScriptMode = require("./javascript").Mode;
var CssMode = require("./css").Mode;
var Mode = function() {
var highlighter = new JspHighlightRules();
this.$tokenizer = new Tokenizer(highlighter.getRules());

View file

@ -9,7 +9,7 @@ var LatexHighlightRules = function() {
"start" : [{
// A tex command e.g. \foo
token : "keyword",
regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)",
regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
}, {
// Curly and square braces
token : "lparen",

View file

@ -51,7 +51,7 @@ oop.inherits(Mode, TextMode);
"elseif": 1,
"repeat": 1,
"end": -1,
"until": -1,
"until": -1
};
var outdentKeywords = [
"else",

View file

@ -404,7 +404,7 @@ var PgsqlHighlightRules = function() {
var keywordMapper = this.createKeywordMapper({
"support.function": builtinFunctions,
"keyword": keywords,
"keyword": keywords
}, "identifier", true);

View file

@ -39,6 +39,7 @@ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutd
var Range = require("../range").Range;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var unicode = require("../unicode");
var Mode = function() {
this.$tokenizer = new Tokenizer(new PhpHighlightRules().getRules());
@ -50,6 +51,20 @@ oop.inherits(Mode, TextMode);
(function() {
this.tokenRe = new RegExp("^["
+ unicode.packages.L
+ unicode.packages.Mn + unicode.packages.Mc
+ unicode.packages.Nd
+ unicode.packages.Pc + "\_]+", "g"
);
this.nonTokenRe = new RegExp("^(?:[^"
+ unicode.packages.L
+ unicode.packages.Mn + unicode.packages.Mc
+ unicode.packages.Nd
+ unicode.packages.Pc + "\_]|\s])+", "g"
);
this.toggleCommentLines = function(state, doc, startRow, endRow) {
var outdent = true;
var re = /^(\s*)#/;

View file

@ -1045,7 +1045,7 @@ var PhpHighlightRules = function() {
for (var i in this.$rules) {
this.$rules[i].unshift({
token : "support.php_tag", // php open tag
regex : "<\\?(?:php|\\=)",
regex : "<\\?(?:php|\\=)?",
next : "php-start"
});
}

View file

@ -122,11 +122,11 @@ var RubyHighlightRules = function() {
token : "text", // namespaces aren't symbols
regex : "::"
}, {
token : "variable.instancce", // instance variable
regex : "@{1,2}(?:[a-zA-Z_]|\d)+"
token : "variable.instance", // instance variable
regex : "@{1,2}[a-zA-Z_\\d]+"
}, {
token : "variable.class", // class name
regex : "[A-Z](?:[a-zA-Z_]|\d)+"
regex : "[A-Z][a-zA-Z_\\d]+"
}, {
token : "string", // symbol
regex : "[:](?:[A-Za-z_]|[@$](?=[a-zA-Z0-9_]))[a-zA-Z0-9_]*[!=?]?"

View file

@ -40,7 +40,7 @@ var scadHighlightRules = function() {
var keywordMapper = this.createKeywordMapper({
"variable.language": "this",
"keyword": "module|if|else|for",
"constant.language": "NULL",
"constant.language": "NULL"
}, "identifier");
// regexp must not have capturing parentheses. Use (?:) instead.

View file

@ -126,7 +126,7 @@ var ScalaHighlightRules = function() {
"string" : [
{
token : "escape",
regex : '\\\\"',
regex : '\\\\"'
}, {
token : "string",
merge : true,

View file

@ -92,7 +92,7 @@ var ShHighlightRules = function() {
regex : variable
}, {
token : "support.function",
regex : func,
regex : func
}, {
token : "support.function",
regex : fileDescriptor

View file

@ -37,7 +37,7 @@ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var SqlHighlightRules = function() {
var keywords = (
"select|from|where|and|or|group|by|order|limit|offset|having|as|case|" +
"select|insert|update|delete|from|where|and|or|group|by|order|limit|offset|having|as|case|" +
"when|else|end|type|left|right|join|on|outer|desc|asc"
);

View file

@ -41,7 +41,7 @@ var SvgHighlightRules = function() {
this.$rules.start.splice(3, 0, {
token : "meta.tag",
regex : "<(?=\s*script)",
regex : "<(?=script)",
next : "script"
});

View file

@ -150,16 +150,16 @@ var TclHighlightRules = function() {
}],
"variable" : [
{
token : "variable.instancce", // variable xotcl with braces
regex : "(?:[:][:])?(?:[a-zA-Z_]|\d)+(?:(?:[:][:])?(?:[a-zA-Z_]|\d)+)?(?:[(](?:[a-zA-Z_]|\d)+[)])?",
token : "variable.instance", // variable xotcl with braces
regex : "(?:[:][:])?[a-zA-Z_\\d]+(?:(?:[:][:])?[a-zA-Z_\\d]+)?(?:[(][a-zA-Z_\\d]+[)])?",
next : "start"
}, {
token : "variable.instancce", // variable tcl
regex : "(?:[a-zA-Z_]|\d)+(?:[(](?:[a-zA-Z_]|\d)+[)])?",
token : "variable.instance", // variable tcl
regex : "[a-zA-Z_\\d]+(?:[(][a-zA-Z_\\d]+[)])?",
next : "start"
}, {
token : "variable.instancce", // variable tcl with braces
regex : "{?(?:[a-zA-Z_]|\d)+}?",
token : "variable.instance", // variable tcl with braces
regex : "{?[a-zA-Z_\\d]+}?",
next : "start"
}],
"qqstring" : [ {

View file

@ -1,53 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module){
var Position = exports.Position = function(line, offset, length)
{
this.line = line;
this.offset = offset;
this.length = length;
this.getLine = function()
{
return this.line;
};
this.getOffset = function()
{
return this.offset;
};
this.getLength = function()
{
return this.length;
};
};
});

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,63 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module){
var org = require("./antlr3-all").org;
var XQDTLexer = exports.XQDTLexer = function(input, state)
{
XQDTLexer.superclass.constructor.call(this, input, state);
};
org.antlr.lang.extend(XQDTLexer, org.antlr.runtime.Lexer, {
comments: [],
addComment: function(start, stop){ this.comments.push({ start: start, stop: stop }); },
isWsExplicit: false,
setIsWsExplicit: function (wsExplicit) {
//console.log("A WS: " + wsExplicit);
this.isWsExplicit = wsExplicit;
//console.log("B WS: " + wsExplicit);
},
addToStack: function (stack) {
stack.push(this);
},
rewindToIndex: function(index) {
var stream = this.input;
stream.seek(index);
}
});
});

View file

@ -1,57 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module){
var org = require("./antlr3-all").org;
var XQuerySemanticHighlighter = require("./XQuerySemanticHighlighter").XQuerySemanticHighlighter;
var XQDTParser = exports.XQDTParser = function(input, state)
{
this.highlighter = new XQuerySemanticHighlighter();
var that = this;
input.getTokenSource().addComment = function(start, stop) {
var comments = input.getTokenSource().comments;
for(var i in comments)
{
var c = comments[i];
that.highlighter.addToken(c.start, c.stop, "comment");
}
input.getTokenSource().comments = [];
that.highlighter.addToken(start, stop, "comment")
};
XQDTParser.superclass.constructor.call(this, input, state);
};
org.antlr.lang.extend(XQDTParser, org.antlr.runtime.Parser, {
});
});

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,161 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module){
var Position = require("./Position").Position;
var XQuerySemanticHighlighter = exports.XQuerySemanticHighlighter = function() {
this.tokenizer = null;
this.plain = null;
this.source = [];
this.lines = [];
this.getTokens = function() {
var resultLines = new Array(this.source.length);
var resultStates = new Array(this.source.length);
var previousState = "start";
var i = 0;
for(i in this.source){
var lineTokens = [];
var tokens = [];
if(this.lines[i]) {
tokens = this.lines[i].sort(function(a, b){ return a.position.getOffset() - b.position.getOffset(); });
}
var sourceLine = this.source[i];
var tokenizedLine = "";
var cursor = 0;
var j = 0;
for(j in tokens)
{
var token = tokens[j];
var position = token.position;
if(position.getOffset() > cursor) {
var value = sourceLine.substring(cursor, position.getOffset());
tokenizedLine += value;
lineTokens.push({
type: "text",
value: value
});
}
cursor = position.getOffset() + position.getLength();
value = sourceLine.substring(position.getOffset(), cursor);
tokenizedLine += value;
lineTokens.push({
type: token.type,
value: value
});
}
var nextState = "start";
if(lineTokens.length > 0) {
lineTokens[lineTokens.length - 1].type;
}
nextState = (nextState != "comment" && nextState != "string" && nextState != "cdata" && nextState != "tag") ? "start" : nextState;
if(cursor < (sourceLine.length )) {
value = sourceLine.substring(cursor);
lineTokens.push({
type: "text",
value: value
});
tokenizedLine += value;
}
//Check if the tokenized line is equal to the original one:
if(sourceLine == tokenizedLine) {
resultLines[i] = lineTokens;
resultStates[i] = nextState;
//result[i] = { line: sourceLine, startState: previousState, tokens: { tokens: lineTokens, state: nextState } };
} else {
//console.log("sourceLine: " + sourceLine);
//console.log("tokenizedLine: " + tokenizedLine);
resultLines[i] = [{ type: "text", value: sourceLine }];
resultStates[i] = nextState;
//result[i] = { tokens: [ { type: "text", value: sourceLine } ], state: nextState };
}
if(resultLines[i].length === 1 && resultLines[i][0].type === "text" && this.tokenizer instanceof Object) {
var prev = resultStates[i - 1] ? resultStates[i - 1] : "start";
var result = this.tokenizer.getLineTokens(resultLines[i][0].value, prev);
resultLines[i] = result.tokens;
resultStates[i] = result.state;
}
}
return {states: resultStates, lines: resultLines};
};
this.addToken = function(start, stop, type) {
var before = this.plain.substring(0, start);
var startLine = this.plain.substring(0, start).split("\n").length;
startLine = startLine == 0 ? 0 : startLine - 1;
var offset = before.lastIndexOf("\n");
offset = offset == -1 ? start : start - before.lastIndexOf("\n") - 1;
var cursor = start;
var text = this.plain.substring(start, stop);
var currentLine = startLine;
for(var i in text)
{
var c = text[i];
if(c == "\n") {
var s = i;
s = s < stop ? s : stop;
this.addPosition(new Position(currentLine, offset, s), type);
currentLine++;
offset = 0;
cursor = i;
}
};
this.addPosition(new Position(currentLine, offset, stop - cursor + 1), type);
};
this.addPosition = function(position, type)
{
var line = position.getLine();
if(!this.lines[line]) {
this.lines[line] = [];
}
this.lines[line].push({
type: type,
position: position
});
};
this.setSource = function(source)
{
this.plain = source.data;
this.source = this.plain.split("\n");
};
//console.log("Line: " + token.getLine());
//console.log(token.getText());
//console.log(type);
};
});

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,345 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module){
var SyntaxHighlighter = exports.SyntaxHighlighter = function(source, tree)
{
var keywords = ['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', 'then', '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', 'collection', 'allowing', 'at', 'base-uri', 'boundary-space', 'break', 'catch', 'construction', 'context', 'continue', 'copy-namespaces', 'decimal-format', 'encoding', 'exit', 'external', 'ft-option', 'in', 'index', 'integrity', 'lax', 'nodes', 'option', 'ordering', 'revalidation', 'schema', 'score', 'sliding', 'strict', 'tumbling', 'type', 'updating', 'value', 'variable', 'version', 'while', 'constraint', 'loop', 'returning', 'append', 'array', 'json-item', 'object', 'structured-item', 'when', 'next', 'previous'];
var states = ["cdata", "comment", "tag"];
var info = { lines: [ [] ], states: [] };
var inName = false;
this.getTokens = function() {
this.visit(tree);
return info;
};
this.addTokens = function(value, type)
{
var tokens = value.split("\n");
var lastState = "start";
for(var i in tokens)
{
if(i > 0) {
info.lines.push([]);
info.states.push(lastState);
}
var value = tokens[i];
var linesLength = info.lines.length - 1;
var linesIdx = info.lines[linesLength];
linesIdx.push({ value: value, type: type });
lastState = states.indexOf(type) != -1 ? type : "start";
}
};
this.getNodeValue = function(node)
{
return source.substring(node.begin, node.end);
};
this.DirPIConstructor = function(node)
{
var value = this.getNodeValue(node);
this.addTokens(value, "xml_pe");
return true;
};
this.DirElemConstructor = function(node)
{
for(var i in node.children)
{
var child = node.children[i];
if(child.name === "TOKEN" || child.name === "QName") {
var value = this.getNodeValue(child);
this.addTokens(value, "meta.tag");
} else {
this.visit(child);
}
}
return true;
};
this.DirAttributeList = function(node)
{
for(var i in node.children)
{
var child = node.children[i];
if(child.name === "QName") {
var value = this.getNodeValue(child);
this.addTokens(value, "meta.tag");
} else {
this.visit(child);
}
}
return true;
};
this.DirAttributeValue = function(node)
{
for(var i in node.children)
{
var child = node.children[i];
if(child.name === "TOKEN") {
var value = this.getNodeValue(child);
this.addTokens(value, "string");
} else {
this.visit(child);
}
}
return true;
};
this.QuotAttrContentChar = function(node)
{
var value = this.getNodeValue(node);
this.addTokens(value, "string");
return true;
};
//this.EQName = function(node)
//{
// var value = source.substring(node.begin, node.end);
// this.addTokens(value, "support.function");
// return true;
//};
this.FunctionName = function(node)
{
for(var i in node.children) {
var child = node.children[i];
if(child.name === "EQName" || child.name === "TOKEN") {
var value = child.children[0].value;
this.addTokens(value, "support.function");
} else {
this.visit(child);
}
}
return true;
};
this.StringConcatExpr = function(node)
{
for(var i in node.children) {
var child = node.children[i];
if(child.name === "TOKEN") {
var value = this.getNodeValue(child);
this.addTokens(value, "keyword.operator");
} else {
this.visit(child);
}
}
return true;
};
this.AdditiveExpr = function(node)
{
for(var i in node.children) {
var child = node.children[i];
if(child.name === "TOKEN") {
var value = this.getNodeValue(child);
this.addTokens(value, "keyword.operator");
} else {
this.visit(child);
}
}
return true;
};
this.MultiplicativeExpr = function(node)
{
for(var i in node.children) {
var child = node.children[i];
if(child.name === "TOKEN") {
var value = this.getNodeValue(child);
this.addTokens(value, "keyword.operator");
} else {
this.visit(child);
}
}
return true;
};
this.UnaryExpr = function(node)
{
for(var i in node.children) {
var child = node.children[i];
if(child.name === "TOKEN") {
var value = this.getNodeValue(child);
this.addTokens(value, "keyword.operator");
} else {
this.visit(child);
}
}
return true;
};
this.GeneralComp = function(node)
{
for(var i in node.children) {
var child = node.children[i];
if(child.name === "TOKEN") {
var value = this.getNodeValue(child);
this.addTokens(value, "keyword.operator");
} else {
this.visit(child);
}
}
return true;
};
this.NumericLiteral = function(node)
{
for(var i in node.children) {
var child = node.children[i];
if(child.name != "TEXT") {
var value = this.getNodeValue(child);
this.addTokens(value, "constant");
} else {
this.visit(child);
}
}return true;
}
this.DirCommentConstructor = function(node)
{
for(var i in node.children) {
var child = node.children[i];
if(child.name != "TEXT") {
var value = this.getNodeValue(child);
this.addTokens(value, "comment");
} else {
this.visit(child);
}
}return true;
}
this.Comment = function(node)
{
return true;
};
this.URILiteral = function(node)
{
var value = this.getNodeValue(node);
this.addTokens(value, "string");
return true;
};
this.StringLiteral = function(node)
{
var value = this.getNodeValue(node);
this.addTokens(value, "string");
return true;
};
this.NCName = function(node)
{
inName = true;
for(var i in node.children)
{
var child = node.children[i];
this.visit(child);
}
inName = false;
return true;
};
this.EQName = function(node)
{
inName = true;
for(var i in node.children)
{
var child = node.children[i];
this.visit(child);
}
inName = false;
return true;
};
this.TOKEN = function(node)
{
value = node.children[0].value;
if(keywords.indexOf(value) > -1 && !inName) {
this.addTokens(value, "keyword");
return true;
} else {
return false;
}
};
this.EverythingElse = function(node)
{
if(typeof node["pos"] === "object")
{
var value = node.value;
var openingIdx = value.indexOf("(:");
while(openingIdx > -1) {
var text = value.substring(0, openingIdx);
this.addTokens(text, "text");
var closingIdx = value.substring(openingIdx).indexOf(":)") + 3;
var comment = value.substring(openingIdx, closingIdx);
this.addTokens(comment, "comment");
value = value.substring(closingIdx);
openingIdx = value.indexOf("(:");
}
this.addTokens(value, "text");
}
return false;
};
this.visit = function(node){
var name = node.name;
var skip = false;
if(typeof this[name] === "function")
skip = this[name](node) === true ? true : false ;
else
skip = this.EverythingElse(node) === true ? true : false;
if(!skip && typeof node.children === "object")
{
for(var i = 0; i < node.children.length; i++)
{
var child = node.children[i];
if(child.name === "TOKEN" && child.children[0].value === "$") {
i++;
var next = node.children[i];
var value = source.substring(child.children[0].pos.begin, next.end);
this.addTokens(value, "variable");
} else {
this.visit(child);
}
}
}
};
};
});

View file

@ -1,48 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
var antlr = require("./antlr3-all");
var org = antlr.org;
var NewLazyTokenStream = antlr.NewLazyTokenStream;
var XQueryLexer = require("./XQueryLexer").XQueryLexer;
var XQueryParser = require("./XQueryParser").XQueryParser;
exports.getParser = function(code) {
var cstream = new org.antlr.runtime.ANTLRStringStream(code);
var lexer = new XQueryLexer(cstream);
var tstream = new NewLazyTokenStream(lexer);
tstream.jumpToFirstValidToken();
var parser = new XQueryParser(tstream);
parser.setSource(cstream);
return parser;
};
});

View file

@ -33,10 +33,8 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var Mirror = require("../worker/mirror").Mirror;
var xquery = require("../mode/xquery/xquery");
var Tokenizer = require("../tokenizer").Tokenizer;
var XQueryHighlightRules = require("./xquery_highlight_rules").XQueryHighlightRules;
var XQueryParser = require("./xquery/XQueryParser").XQueryParser;
var SyntaxHighlighter = require("../mode/xquery/visitors/SyntaxHighlighter").SyntaxHighlighter;
window.addEventListener = function() {};
@ -52,26 +50,26 @@ oop.inherits(XQueryWorker, Mirror);
this.onUpdate = function() {
this.sender.emit("start");
var value = this.doc.getValue();
var parser = xquery.getParser(value);
var ast = parser.p_Module();
if(parser.hasErrors()) {
var errors = parser.getErrors();
var i = 0;
for(i in errors) {
var error = errors[i];
this.sender.emit("error", {
row: error.line,
column: error.column,
text: error.message,
type: "error"
});
}
} else {
this.sender.emit("ok");
var parser = new XQueryParser(value);
try {
parser.parse_XQuery();
var ast = parser.getAST();
this.sender.emit("ok");
var highlighter = new SyntaxHighlighter(value, ast);
var tokens = highlighter.getTokens();
this.sender.emit("highlight", tokens);
} catch(e) {
var prefix = value.substring(0, e.getBegin());
var line = prefix.split("\n").length;
var column = e.getBegin() - prefix.lastIndexOf("\n");
var message = parser.getErrorMessage(e);
this.sender.emit("error", {
row: line - 1,
column: column,
text: message,
type: "error"
});
}
parser.highlighter.tokenizer = new Tokenizer(new XQueryHighlightRules().getRules());
var tokens = parser.highlighter.getTokens();
this.sender.emit("highlight", tokens);
};
}).call(XQueryWorker.prototype);

View file

@ -44,14 +44,23 @@ var YamlHighlightRules = function() {
token : "comment",
regex : "#.*$"
}, {
token : "comment",
regex : "^---"
token : "list.markup",
regex : /^(?:-{3}|\.{3})\s*(?=#|$)/
}, {
token : "list.markup",
regex : /^\s*[\-?](?:$|\s)/
}, {
token: "variable",
token: "constant",
regex: "!![\\w//]+"
}, {
token: "constant.language",
regex: "[&\\*][a-zA-Z0-9-_]+"
}, {
token: ["identifier", "text"],
regex: "(\\w+\\s*:)(\\w*)"
token: ["meta.tag", "keyword"],
regex: /^(\s*\w.*?)(\:(?:\s+|$))/
},{
token: ["meta.tag", "keyword"],
regex: /(\w+?)(\s*\:(?:\s+|$))/
}, {
token : "keyword.operator",
regex : "<<\\w*:\\w*"
@ -71,10 +80,13 @@ var YamlHighlightRules = function() {
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
}, {
token : "constant.numeric", // float
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
regex : /[+\-]?[\d_]+(?:(?:\.[\d_]*)?(?:[eE][+\-]?[\d_]+)?)?\b/
}, {
token : "constant.numeric", // other number
regex : /[+\-]?\.inf\b|NaN\b|0x[\dA-Fa-f_]+|0b[10_]+/
}, {
token : "constant.language.boolean",
regex : "(?:true|false|yes|no)\\b"
regex : "(?:true|false|TRUE|FALSE|True|False|yes|no)\\b"
}, {
token : "invalid.illegal", // comments are not allowed
regex : "\\/\\/.*$"
@ -87,6 +99,9 @@ var YamlHighlightRules = function() {
}, {
token : "text",
regex : "\\s+"
}, {
token : "text",
regex : "\\w+"
}
],
"qqstring" : [
@ -99,7 +114,7 @@ var YamlHighlightRules = function() {
merge : true,
regex : '.+'
}
]}
]};
};

View file

@ -90,7 +90,7 @@ function GutterHandler(mouseHandler) {
if (tooltipAnnotation == annotation)
return;
tooltipAnnotation = annotation.text.join("\n");
tooltipAnnotation = annotation.text.join("<br/>");
tooltip.style.display = "block";
tooltip.innerHTML = tooltipAnnotation;
@ -134,7 +134,7 @@ function GutterHandler(mouseHandler) {
return;
tooltipTimeout = setTimeout(function() {
tooltipTimeout = null;
if (mouseEvent)
if (mouseEvent && !mouseHandler.isMousePressed)
showTooltip();
else
hideTooltip();

View file

@ -115,6 +115,8 @@ var MouseHandler = function(editor) {
this.x = ev.x;
this.y = ev.y;
this.isMousePressed = true;
// do not move textarea during selection
var renderer = this.editor.renderer;
@ -135,6 +137,7 @@ var MouseHandler = function(editor) {
renderer.$keepTextAreaAtCursor = true;
renderer.$moveTextAreaToCursor();
}
self.isMousePressed = false;
};
var onCaptureInterval = function() {

View file

@ -1,683 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
/*
* Narcissus - JS implemented in JS.
*
* Well-known constants and lookup tables. Many consts are generated from the
* tokens table via eval to minimize redundancy, so consumers must be compiled
* separately to take advantage of the simple switch-case constant propagation
* done by SpiderMonkey.
*/
define(function(require, exports, module) {
var tokens = [
// End of source.
"END",
// Operators and punctuators. Some pair-wise order matters, e.g. (+, -)
// and (UNARY_PLUS, UNARY_MINUS).
"\n", ";",
",",
"=",
"?", ":", "CONDITIONAL",
"||",
"&&",
"|",
"^",
"&",
"==", "!=", "===", "!==",
"<", "<=", ">=", ">",
"<<", ">>", ">>>",
"+", "-",
"*", "/", "%",
"!", "~", "UNARY_PLUS", "UNARY_MINUS",
"++", "--",
".",
"[", "]",
"{", "}",
"(", ")",
// Nonterminal tree node type codes.
"SCRIPT", "BLOCK", "LABEL", "FOR_IN", "CALL", "NEW_WITH_ARGS", "INDEX",
"ARRAY_INIT", "OBJECT_INIT", "PROPERTY_INIT", "GETTER", "SETTER",
"GROUP", "LIST", "LET_BLOCK", "ARRAY_COMP", "GENERATOR", "COMP_TAIL",
// Contextual keywords.
"IMPLEMENTS", "INTERFACE", "LET", "MODULE", "PACKAGE", "PRIVATE",
"PROTECTED", "PUBLIC", "STATIC", "USE", "YIELD",
// Terminals.
"IDENTIFIER", "NUMBER", "STRING", "REGEXP",
// Keywords.
"break",
"case", "catch", "const", "continue",
"debugger", "default", "delete", "do",
"else", "export",
"false", "finally", "for", "function",
"if", "import", "in", "instanceof",
"new", "null",
"return",
"switch",
"this", "throw", "true", "try", "typeof",
"var", "void",
"while", "with",
];
var strictKeywords = {
__proto__: null,
"implements": true,
"interface": true,
"let": true,
//"module": true,
"package": true,
"private": true,
"protected": true,
"public": true,
"static": true,
"use": true,
"yield": true
};
var statementStartTokens = [
"break",
"const", "continue",
"debugger", "do",
"for",
"if",
"let",
"return",
"switch",
"throw", "try",
"var",
"yield",
"while", "with",
];
// Whitespace characters (see ECMA-262 7.2)
var whitespaceChars = [
// normal whitespace:
"\u0009", "\u000B", "\u000C", "\u0020", "\u00A0", "\uFEFF",
// high-Unicode whitespace:
"\u1680", "\u180E",
"\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006",
"\u2007", "\u2008", "\u2009", "\u200A",
"\u202F", "\u205F", "\u3000"
];
var whitespace = {};
for (var i = 0; i < whitespaceChars.length; i++) {
whitespace[whitespaceChars[i]] = true;
}
// Operator and punctuator mapping from token to tree node type name.
// NB: because the lexer doesn't backtrack, all token prefixes must themselves
// be valid tokens (e.g. !== is acceptable because its prefixes are the valid
// tokens != and !).
var opTypeNames = {
'\n': "NEWLINE",
';': "SEMICOLON",
',': "COMMA",
'?': "HOOK",
':': "COLON",
'||': "OR",
'&&': "AND",
'|': "BITWISE_OR",
'^': "BITWISE_XOR",
'&': "BITWISE_AND",
'===': "STRICT_EQ",
'==': "EQ",
'=': "ASSIGN",
'!==': "STRICT_NE",
'!=': "NE",
'<<': "LSH",
'<=': "LE",
'<': "LT",
'>>>': "URSH",
'>>': "RSH",
'>=': "GE",
'>': "GT",
'++': "INCREMENT",
'--': "DECREMENT",
'+': "PLUS",
'-': "MINUS",
'*': "MUL",
'/': "DIV",
'%': "MOD",
'!': "NOT",
'~': "BITWISE_NOT",
'.': "DOT",
'[': "LEFT_BRACKET",
']': "RIGHT_BRACKET",
'{': "LEFT_CURLY",
'}': "RIGHT_CURLY",
'(': "LEFT_PAREN",
')': "RIGHT_PAREN"
};
// Hash of keyword identifier to tokens index. NB: we must null __proto__ to
// avoid toString, etc. namespace pollution.
var keywords = {__proto__: null};
var mozillaKeywords = {__proto__: null};
// Define const END, etc., based on the token names. Also map name to index.
var tokenIds = {};
var hostSupportsEvalConst = (function() {
try {
return eval("(function(s) { eval(s); return x })('const x = true;')");
} catch (e) {
return false;
}
})();
// Building up a string to be eval'd in different contexts.
var consts = hostSupportsEvalConst ? "const " : "var ";
for (var i = 0, j = tokens.length; i < j; i++) {
if (i > 0)
consts += ", ";
var t = tokens[i];
var name;
if (/^[a-z]/.test(t)) {
name = t.toUpperCase();
if (name === "LET" || name === "YIELD")
mozillaKeywords[name] = i;
if (strictKeywords[name])
strictKeywords[name] = i;
keywords[t] = i;
} else {
name = (/^\W/.test(t) ? opTypeNames[t] : t);
}
consts += name + " = " + i;
tokenIds[name] = i;
tokens[t] = i;
}
consts += ";";
var isStatementStartCode = {__proto__: null};
for (i = 0, j = statementStartTokens.length; i < j; i++)
isStatementStartCode[keywords[statementStartTokens[i]]] = true;
// Map assignment operators to their indexes in the tokens array.
var assignOps = ['|', '^', '&', '<<', '>>', '>>>', '+', '-', '*', '/', '%'];
for (i = 0, j = assignOps.length; i < j; i++) {
t = assignOps[i];
assignOps[t] = tokens[t];
}
function defineGetter(obj, prop, fn, dontDelete, dontEnum) {
Object.defineProperty(obj, prop,
{ get: fn, configurable: !dontDelete, enumerable: !dontEnum });
}
function defineGetterSetter(obj, prop, getter, setter, dontDelete, dontEnum) {
Object.defineProperty(obj, prop, {
get: getter,
set: setter,
configurable: !dontDelete,
enumerable: !dontEnum
});
}
function defineMemoGetter(obj, prop, fn, dontDelete, dontEnum) {
Object.defineProperty(obj, prop, {
get: function() {
var val = fn();
defineProperty(obj, prop, val, dontDelete, true, dontEnum);
return val;
},
configurable: true,
enumerable: !dontEnum
});
}
function defineProperty(obj, prop, val, dontDelete, readOnly, dontEnum) {
Object.defineProperty(obj, prop,
{ value: val, writable: !readOnly, configurable: !dontDelete,
enumerable: !dontEnum });
}
// Returns true if fn is a native function. (Note: SpiderMonkey specific.)
function isNativeCode(fn) {
// Relies on the toString method to identify native code.
return ((typeof fn) === "function") && fn.toString().match(/\[native code\]/);
}
var Fpapply = Function.prototype.apply;
function apply(f, o, a) {
return Fpapply.call(f, [o].concat(a));
}
var applyNew;
// ES5's bind is a simpler way to implement applyNew
if (Function.prototype.bind) {
applyNew = function applyNew(f, a) {
return new (f.bind.apply(f, [,].concat(Array.prototype.slice.call(a))))();
};
} else {
applyNew = function applyNew(f, a) {
switch (a.length) {
case 0:
return new f();
case 1:
return new f(a[0]);
case 2:
return new f(a[0], a[1]);
case 3:
return new f(a[0], a[1], a[2]);
default:
var argStr = "a[0]";
for (var i = 1, n = a.length; i < n; i++)
argStr += ",a[" + i + "]";
return eval("new f(" + argStr + ")");
}
};
}
function getPropertyDescriptor(obj, name) {
while (obj) {
if (({}).hasOwnProperty.call(obj, name))
return Object.getOwnPropertyDescriptor(obj, name);
obj = Object.getPrototypeOf(obj);
}
}
function getPropertyNames(obj) {
var table = Object.create(null, {});
while (obj) {
var names = Object.getOwnPropertyNames(obj);
for (var i = 0, n = names.length; i < n; i++)
table[names[i]] = true;
obj = Object.getPrototypeOf(obj);
}
return Object.keys(table);
}
function getOwnProperties(obj) {
var map = {};
for (var name in Object.getOwnPropertyNames(obj))
map[name] = Object.getOwnPropertyDescriptor(obj, name);
return map;
}
function blacklistHandler(target, blacklist) {
var mask = Object.create(null, {});
var redirect = Dict.create(blacklist).mapObject(function(name) { return mask; });
return mixinHandler(redirect, target);
}
function whitelistHandler(target, whitelist) {
var catchall = Object.create(null, {});
var redirect = Dict.create(whitelist).mapObject(function(name) { return target; });
return mixinHandler(redirect, catchall);
}
/*
* Mixin proxies break the single-inheritance model of prototypes, so
* the handler treats all properties as own-properties:
*
* X
* |
* +------------+------------+
* | O |
* | | |
* | O O O |
* | | | | |
* | O O O O |
* | | | | | |
* | O O O O O |
* | | | | | | |
* +-(*)--(w)--(x)--(y)--(z)-+
*/
function mixinHandler(redirect, catchall) {
function targetFor(name) {
return hasOwn(redirect, name) ? redirect[name] : catchall;
}
function getMuxPropertyDescriptor(name) {
var desc = getPropertyDescriptor(targetFor(name), name);
if (desc)
desc.configurable = true;
return desc;
}
function getMuxPropertyNames() {
var names1 = Object.getOwnPropertyNames(redirect).filter(function(name) {
return name in redirect[name];
});
var names2 = getPropertyNames(catchall).filter(function(name) {
return !hasOwn(redirect, name);
});
return names1.concat(names2);
}
function enumerateMux() {
var result = Object.getOwnPropertyNames(redirect).filter(function(name) {
return name in redirect[name];
});
for (name in catchall) {
if (!hasOwn(redirect, name))
result.push(name);
};
return result;
}
function hasMux(name) {
return name in targetFor(name);
}
return {
getOwnPropertyDescriptor: getMuxPropertyDescriptor,
getPropertyDescriptor: getMuxPropertyDescriptor,
getOwnPropertyNames: getMuxPropertyNames,
defineProperty: function(name, desc) {
Object.defineProperty(targetFor(name), name, desc);
},
"delete": function(name) {
var target = targetFor(name);
return delete target[name];
},
// FIXME: ha ha ha
fix: function() { },
has: hasMux,
hasOwn: hasMux,
get: function(receiver, name) {
var target = targetFor(name);
return target[name];
},
set: function(receiver, name, val) {
var target = targetFor(name);
target[name] = val;
return true;
},
enumerate: enumerateMux,
keys: enumerateMux
};
}
function makePassthruHandler(obj) {
// Handler copied from
// http://wiki.ecmascript.org/doku.php?id=harmony:proxies&s=proxy%20object#examplea_no-op_forwarding_proxy
return {
getOwnPropertyDescriptor: function(name) {
var desc = Object.getOwnPropertyDescriptor(obj, name);
// a trapping proxy's properties must always be configurable
desc.configurable = true;
return desc;
},
getPropertyDescriptor: function(name) {
var desc = getPropertyDescriptor(obj, name);
// a trapping proxy's properties must always be configurable
desc.configurable = true;
return desc;
},
getOwnPropertyNames: function() {
return Object.getOwnPropertyNames(obj);
},
defineProperty: function(name, desc) {
Object.defineProperty(obj, name, desc);
},
"delete": function(name) { return delete obj[name]; },
fix: function() {
if (Object.isFrozen(obj)) {
return getOwnProperties(obj);
}
// As long as obj is not frozen, the proxy won't allow itself to be fixed.
return undefined; // will cause a TypeError to be thrown
},
has: function(name) { return name in obj; },
hasOwn: function(name) { return ({}).hasOwnProperty.call(obj, name); },
get: function(receiver, name) { return obj[name]; },
// bad behavior when set fails in non-strict mode
set: function(receiver, name, val) { obj[name] = val; return true; },
enumerate: function() {
var result = [];
for (name in obj) { result.push(name); };
return result;
},
keys: function() { return Object.keys(obj); }
};
}
var hasOwnProperty = ({}).hasOwnProperty;
function hasOwn(obj, name) {
return hasOwnProperty.call(obj, name);
}
function Dict(table, size) {
this.table = table || Object.create(null, {});
this.size = size || 0;
}
Dict.create = function(table) {
var init = Object.create(null, {});
var size = 0;
var names = Object.getOwnPropertyNames(table);
for (var i = 0, n = names.length; i < n; i++) {
var name = names[i];
init[name] = table[name];
size++;
}
return new Dict(init, size);
};
Dict.prototype = {
has: function(x) { return hasOwnProperty.call(this.table, x); },
set: function(x, v) {
if (!hasOwnProperty.call(this.table, x))
this.size++;
this.table[x] = v;
},
get: function(x) { return this.table[x]; },
getDef: function(x, thunk) {
if (!hasOwnProperty.call(this.table, x)) {
this.size++;
this.table[x] = thunk();
}
return this.table[x];
},
forEach: function(f) {
var table = this.table;
for (var key in table)
f.call(this, key, table[key]);
},
map: function(f) {
var table1 = this.table;
var table2 = Object.create(null, {});
this.forEach(function(key, val) {
table2[key] = f.call(this, val, key);
});
return new Dict(table2, this.size);
},
mapObject: function(f) {
var table1 = this.table;
var table2 = Object.create(null, {});
this.forEach(function(key, val) {
table2[key] = f.call(this, val, key);
});
return table2;
},
toObject: function() {
return this.mapObject(function(val) { return val; });
},
choose: function() {
return Object.getOwnPropertyNames(this.table)[0];
},
remove: function(x) {
if (hasOwnProperty.call(this.table, x)) {
this.size--;
delete this.table[x];
}
},
copy: function() {
var table = Object.create(null, {});
for (var key in this.table)
table[key] = this.table[key];
return new Dict(table, this.size);
},
keys: function() {
return Object.keys(this.table);
},
toString: function() { return "[object Dict]" }
};
var _WeakMap = typeof WeakMap === "function" ? WeakMap : (function() {
// shim for ES6 WeakMap with poor asymptotics
function WeakMap(array) {
this.array = array || [];
}
function searchMap(map, key, found, notFound) {
var a = map.array;
for (var i = 0, n = a.length; i < n; i++) {
var pair = a[i];
if (pair.key === key)
return found(pair, i);
}
return notFound();
}
WeakMap.prototype = {
has: function(x) {
return searchMap(this, x, function() { return true }, function() { return false });
},
set: function(x, v) {
var a = this.array;
searchMap(this, x,
function(pair) { pair.value = v },
function() { a.push({ key: x, value: v }) });
},
get: function(x) {
return searchMap(this, x,
function(pair) { return pair.value },
function() { return null });
},
"delete": function(x) {
var a = this.array;
searchMap(this, x,
function(pair, i) { a.splice(i, 1) },
function() { });
},
toString: function() { return "[object WeakMap]" }
};
return WeakMap;
})();
// non-destructive stack
function Stack(elts) {
this.elts = elts || null;
}
Stack.prototype = {
push: function(x) {
return new Stack({ top: x, rest: this.elts });
},
top: function() {
if (!this.elts)
throw new Error("empty stack");
return this.elts.top;
},
isEmpty: function() {
return this.top === null;
},
find: function(test) {
for (var elts = this.elts; elts; elts = elts.rest) {
if (test(elts.top))
return elts.top;
}
return null;
},
has: function(x) {
return Boolean(this.find(function(elt) { return elt === x }));
},
forEach: function(f) {
for (var elts = this.elts; elts; elts = elts.rest) {
f(elts.top);
}
}
};
if (!Array.prototype.copy) {
defineProperty(Array.prototype, "copy",
function() {
var result = [];
for (var i = 0, n = this.length; i < n; i++)
result[i] = this[i];
return result;
}, false, false, true);
}
if (!Array.prototype.top) {
defineProperty(Array.prototype, "top",
function() {
return this.length && this[this.length-1];
}, false, false, true);
}
exports.tokens = tokens;
exports.whitespace = whitespace;
exports.opTypeNames = opTypeNames;
exports.keywords = keywords;
exports.mozillaKeywords = mozillaKeywords;
exports.strictKeywords = strictKeywords;
exports.isStatementStartCode = isStatementStartCode;
exports.tokenIds = tokenIds;
exports.consts = consts;
exports.assignOps = assignOps;
exports.defineGetter = defineGetter;
exports.defineGetterSetter = defineGetterSetter;
exports.defineMemoGetter = defineMemoGetter;
exports.defineProperty = defineProperty;
exports.isNativeCode = isNativeCode;
exports.apply = apply;
exports.applyNew = applyNew;
exports.mixinHandler = mixinHandler;
exports.whitelistHandler = whitelistHandler;
exports.blacklistHandler = blacklistHandler;
exports.makePassthruHandler = makePassthruHandler;
exports.Dict = Dict;
exports.WeakMap = _WeakMap;
exports.Stack = Stack;
});

View file

@ -1,584 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
/*
* Narcissus - JS implemented in JS.
*
* Lexical scanner.
*/
define(function(require, exports, module) {
var definitions = require('./definitions');
// Set constants in the local scope.
eval(definitions.consts);
// Build up a trie of operator tokens.
var opTokens = {};
for (var op in definitions.opTypeNames) {
if (op === '\n' || op === '.')
continue;
var node = opTokens;
for (var i = 0; i < op.length; i++) {
var ch = op[i];
if (!(ch in node))
node[ch] = {};
node = node[ch];
node.op = op;
}
}
/*
* Since JavaScript provides no convenient way to determine if a
* character is in a particular Unicode category, we use
* metacircularity to accomplish this (oh yeaaaah!)
*/
function isValidIdentifierChar(ch, first) {
// check directly for ASCII
if (ch <= "\u007F") {
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch === '$' || ch === '_' ||
(!first && (ch >= '0' && ch <= '9'))) {
return true;
}
return false;
}
// create an object to test this in
var x = {};
x["x"+ch] = true;
x[ch] = true;
// then use eval to determine if it's a valid character
var valid = false;
try {
valid = (Function("x", "return (x." + (first?"":"x") + ch + ");")(x) === true);
} catch (ex) {}
return valid;
}
function isIdentifier(str) {
if (typeof str !== "string")
return false;
if (str.length === 0)
return false;
if (!isValidIdentifierChar(str[0], true))
return false;
for (var i = 1; i < str.length; i++) {
if (!isValidIdentifierChar(str[i], false))
return false;
}
return true;
}
/*
* Tokenizer :: (source, filename, line number, boolean) -> Tokenizer
*/
function Tokenizer(s, f, l, allowHTMLComments) {
this.cursor = 0;
this.source = String(s);
this.tokens = [];
this.tokenIndex = 0;
this.lookahead = 0;
this.scanNewlines = false;
this.filename = f || "";
this.lineno = l || 1;
this.allowHTMLComments = allowHTMLComments;
this.blockComments = null;
}
Tokenizer.prototype = {
get done() {
// We need to set scanOperand to true here because the first thing
// might be a regexp.
return this.peek(true) === END;
},
get token() {
return this.tokens[this.tokenIndex];
},
match: function (tt, scanOperand, keywordIsName) {
return this.get(scanOperand, keywordIsName) === tt || this.unget();
},
mustMatch: function (tt, keywordIsName) {
if (!this.match(tt, false, keywordIsName)) {
throw this.newSyntaxError("Missing " +
definitions.tokens[tt].toLowerCase());
}
return this.token;
},
peek: function (scanOperand) {
var tt, next;
if (this.lookahead) {
next = this.tokens[(this.tokenIndex + this.lookahead) & 3];
tt = (this.scanNewlines && next.lineno !== this.lineno)
? NEWLINE
: next.type;
} else {
tt = this.get(scanOperand);
this.unget();
}
return tt;
},
peekOnSameLine: function (scanOperand) {
this.scanNewlines = true;
var tt = this.peek(scanOperand);
this.scanNewlines = false;
return tt;
},
lastBlockComment: function() {
var length = this.blockComments.length;
return length ? this.blockComments[length - 1] : null;
},
// Eat comments and whitespace.
skip: function () {
var input = this.source;
this.blockComments = [];
for (;;) {
var ch = input[this.cursor++];
var next = input[this.cursor];
// handle \r, \r\n and (always preferable) \n
if (ch === '\r') {
// if the next character is \n, we don't care about this at all
if (next === '\n') continue;
// otherwise, we want to consider this as a newline
ch = '\n';
}
if (ch === '\n' && !this.scanNewlines) {
this.lineno++;
} else if (ch === '/' && next === '*') {
var commentStart = ++this.cursor;
for (;;) {
ch = input[this.cursor++];
if (ch === undefined)
throw this.newSyntaxError("Unterminated comment");
if (ch === '*') {
next = input[this.cursor];
if (next === '/') {
var commentEnd = this.cursor - 1;
this.cursor++;
break;
}
} else if (ch === '\n') {
this.lineno++;
}
}
this.blockComments.push(input.substring(commentStart, commentEnd));
} else if ((ch === '/' && next === '/') ||
(this.allowHTMLComments && ch === '<' && next === '!' &&
input[this.cursor + 1] === '-' && input[this.cursor + 2] === '-' &&
(this.cursor += 2))) {
this.cursor++;
for (;;) {
ch = input[this.cursor++];
next = input[this.cursor];
if (ch === undefined)
return;
if (ch === '\r') {
// check for \r\n
if (next !== '\n') ch = '\n';
}
if (ch === '\n') {
if (this.scanNewlines) {
this.cursor--;
} else {
this.lineno++;
}
break;
}
}
} else if (!(ch in definitions.whitespace)) {
this.cursor--;
return;
}
}
},
// Lex the exponential part of a number, if present. Return true iff an
// exponential part was found.
lexExponent: function() {
var input = this.source;
var next = input[this.cursor];
if (next === 'e' || next === 'E') {
this.cursor++;
ch = input[this.cursor++];
if (ch === '+' || ch === '-')
ch = input[this.cursor++];
if (ch < '0' || ch > '9')
throw this.newSyntaxError("Missing exponent");
do {
ch = input[this.cursor++];
} while (ch >= '0' && ch <= '9');
this.cursor--;
return true;
}
return false;
},
lexZeroNumber: function (ch) {
var token = this.token, input = this.source;
token.type = NUMBER;
ch = input[this.cursor++];
if (ch === '.') {
do {
ch = input[this.cursor++];
} while (ch >= '0' && ch <= '9');
this.cursor--;
this.lexExponent();
token.value = parseFloat(
input.substring(token.start, this.cursor));
} else if (ch === 'x' || ch === 'X') {
do {
ch = input[this.cursor++];
} while ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') ||
(ch >= 'A' && ch <= 'F'));
this.cursor--;
token.value = parseInt(input.substring(token.start, this.cursor));
} else if (ch >= '0' && ch <= '7') {
do {
ch = input[this.cursor++];
} while (ch >= '0' && ch <= '7');
this.cursor--;
token.value = parseInt(input.substring(token.start, this.cursor));
} else {
this.cursor--;
this.lexExponent(); // 0E1, &c.
token.value = 0;
}
},
lexNumber: function (ch) {
var token = this.token, input = this.source;
token.type = NUMBER;
var floating = false;
do {
ch = input[this.cursor++];
if (ch === '.' && !floating) {
floating = true;
ch = input[this.cursor++];
}
} while (ch >= '0' && ch <= '9');
this.cursor--;
var exponent = this.lexExponent();
floating = floating || exponent;
var str = input.substring(token.start, this.cursor);
token.value = floating ? parseFloat(str) : parseInt(str);
},
lexDot: function (ch) {
var token = this.token, input = this.source;
var next = input[this.cursor];
if (next >= '0' && next <= '9') {
do {
ch = input[this.cursor++];
} while (ch >= '0' && ch <= '9');
this.cursor--;
this.lexExponent();
token.type = NUMBER;
token.value = parseFloat(
input.substring(token.start, this.cursor));
} else {
token.type = DOT;
token.assignOp = null;
token.value = '.';
}
},
lexString: function (ch) {
var token = this.token, input = this.source;
token.type = STRING;
var hasEscapes = false;
var delim = ch;
if (input.length <= this.cursor)
throw this.newSyntaxError("Unterminated string literal");
while ((ch = input[this.cursor++]) !== delim) {
if (ch == '\n' || ch == '\r')
throw this.newSyntaxError("Unterminated string literal");
if (this.cursor == input.length)
throw this.newSyntaxError("Unterminated string literal");
if (ch === '\\') {
hasEscapes = true;
if (++this.cursor == input.length)
throw this.newSyntaxError("Unterminated string literal");
}
}
token.value = hasEscapes
? eval(input.substring(token.start, this.cursor))
: input.substring(token.start + 1, this.cursor - 1);
},
lexRegExp: function (ch) {
var token = this.token, input = this.source;
token.type = REGEXP;
do {
ch = input[this.cursor++];
if (ch === '\\') {
this.cursor++;
} else if (ch === '[') {
do {
if (ch === undefined)
throw this.newSyntaxError("Unterminated character class");
if (ch === '\\')
this.cursor++;
ch = input[this.cursor++];
} while (ch !== ']');
} else if (ch === undefined) {
throw this.newSyntaxError("Unterminated regex");
}
} while (ch !== '/');
do {
ch = input[this.cursor++];
} while (ch >= 'a' && ch <= 'z');
this.cursor--;
token.value = eval(input.substring(token.start, this.cursor));
},
lexOp: function (ch) {
var token = this.token, input = this.source;
// A bit ugly, but it seems wasteful to write a trie lookup routine
// for only 3 characters...
var node = opTokens[ch];
var next = input[this.cursor];
if (next in node) {
node = node[next];
this.cursor++;
next = input[this.cursor];
if (next in node) {
node = node[next];
this.cursor++;
next = input[this.cursor];
}
}
var op = node.op;
if (definitions.assignOps[op] && input[this.cursor] === '=') {
this.cursor++;
token.type = ASSIGN;
token.assignOp = definitions.tokenIds[definitions.opTypeNames[op]];
op += '=';
} else {
token.type = definitions.tokenIds[definitions.opTypeNames[op]];
token.assignOp = null;
}
token.value = op;
},
// FIXME: Unicode escape sequences
lexIdent: function (ch, keywordIsName) {
var token = this.token;
var id = ch;
while ((ch = this.getValidIdentifierChar(false)) !== null) {
id += ch;
}
token.type = IDENTIFIER;
token.value = id;
if (keywordIsName)
return;
var kw;
if (this.parser.mozillaMode) {
kw = definitions.mozillaKeywords[id];
if (kw) {
token.type = kw;
return;
}
}
if (this.parser.x.strictMode) {
kw = definitions.strictKeywords[id];
if (kw) {
token.type = kw;
return;
}
}
kw = definitions.keywords[id];
if (kw)
token.type = kw;
},
/*
* Tokenizer.get :: ([boolean[, boolean]]) -> token type
*
* Consume input *only* if there is no lookahead.
* Dispatch to the appropriate lexing function depending on the input.
*/
get: function (scanOperand, keywordIsName) {
var token;
while (this.lookahead) {
--this.lookahead;
this.tokenIndex = (this.tokenIndex + 1) & 3;
token = this.tokens[this.tokenIndex];
if (token.type !== NEWLINE || this.scanNewlines)
return token.type;
}
this.skip();
this.tokenIndex = (this.tokenIndex + 1) & 3;
token = this.tokens[this.tokenIndex];
if (!token)
this.tokens[this.tokenIndex] = token = {};
var input = this.source;
if (this.cursor >= input.length)
return token.type = END;
token.start = this.cursor;
token.lineno = this.lineno;
var ich = this.getValidIdentifierChar(true);
var ch = (ich === null) ? input[this.cursor++] : null;
if (ich !== null) {
this.lexIdent(ich, keywordIsName);
} else if (scanOperand && ch === '/') {
this.lexRegExp(ch);
} else if (ch in opTokens) {
this.lexOp(ch);
} else if (ch === '.') {
this.lexDot(ch);
} else if (ch >= '1' && ch <= '9') {
this.lexNumber(ch);
} else if (ch === '0') {
this.lexZeroNumber(ch);
} else if (ch === '"' || ch === "'") {
this.lexString(ch);
} else if (this.scanNewlines && (ch === '\n' || ch === '\r')) {
// if this was a \r, look for \r\n
if (ch === '\r' && input[this.cursor] === '\n') this.cursor++;
token.type = NEWLINE;
token.value = '\n';
this.lineno++;
} else {
throw this.newSyntaxError("Illegal token");
}
token.end = this.cursor;
return token.type;
},
/*
* Tokenizer.unget :: void -> undefined
*
* Match depends on unget returning undefined.
*/
unget: function () {
if (++this.lookahead === 4) throw "PANIC: too much lookahead!";
this.tokenIndex = (this.tokenIndex - 1) & 3;
},
newSyntaxError: function (m) {
m = (this.filename ? this.filename + ":" : "") + this.lineno + ": " + m;
var e = new SyntaxError(m, this.filename, this.lineno);
e.source = this.source;
e.cursor = this.lookahead
? this.tokens[(this.tokenIndex + this.lookahead) & 3].start
: this.cursor;
return e;
},
/* Gets a single valid identifier char from the input stream, or null
* if there is none.
*/
getValidIdentifierChar: function(first) {
var input = this.source;
if (this.cursor >= input.length) return null;
var ch = input[this.cursor];
// first check for \u escapes
if (ch === '\\' && input[this.cursor+1] === 'u') {
// get the character value
try {
ch = String.fromCharCode(parseInt(
input.substring(this.cursor + 2, this.cursor + 6),
16));
} catch (ex) {
return null;
}
this.cursor += 5;
}
var valid = isValidIdentifierChar(ch, first);
if (valid) this.cursor++;
return (valid ? ch : null);
},
};
exports.isIdentifier = isIdentifier;
exports.Tokenizer = Tokenizer;
});

File diff suppressed because it is too large Load diff

View file

@ -30,7 +30,7 @@
define(function(require, exports, module) {
"use strict";
var Range = require('./range').Range;
var Range = require("./range").Range;
var EventEmitter = require("./lib/event_emitter").EventEmitter;
var oop = require("./lib/oop");

View file

@ -41,8 +41,8 @@ var Editor = require("./editor").Editor;
var MockRenderer = require("./test/mockrenderer").MockRenderer;
var assert = require("./test/assertions");
var JavaScriptMode = require("./mode/javascript").Mode;
var PlaceHolder = require('./placeholder').PlaceHolder;
var UndoManager = require('./undomanager').UndoManager;
var PlaceHolder = require("./placeholder").PlaceHolder;
var UndoManager = require("./undomanager").UndoManager;
module.exports = {

View file

@ -44,7 +44,7 @@ define(function (require, exports, module) {
if (globalRequire && globalRequire.nodeRequire)
onLoad(globalRequire.nodeRequire('fs').readFileSync(req.toUrl(name), 'utf8'));
else
require("ace/lib/net").get(req.toUrl(name), onLoad);
require("../lib/net").get(req.toUrl(name), onLoad);
};
});

View file

@ -43,7 +43,7 @@ module.exports = {
"test: configure the search object" : function() {
var search = new Search();
search.set({
needle: "juhu",
needle: "juhu"
});
},
@ -397,7 +397,7 @@ module.exports = {
var search = new Search().set({
needle: "[ ]+$",
regExp: true,
wrap: true,
wrap: true
});
session.getSelection().moveCursorTo(1, 2);
@ -414,7 +414,7 @@ module.exports = {
var search = new Search().set({
needle: "foo",
wrap: true,
wholeWord: true,
wholeWord: true
});
session.getSelection().moveCursorTo(0, 4);
@ -437,7 +437,7 @@ module.exports = {
needle: "foo",
wrap: true,
wholeWord: true,
backwards: true,
backwards: true
});
session.getSelection().moveCursorTo(0, 13);

View file

@ -25,7 +25,7 @@ define(function(require, exports, module) {
exports.isDark = true;
exports.cssClass = "ace-ambiance";
exports.cssText = require("ace/requirejs/text!./ambiance.css");
exports.cssText = require("../requirejs/text!./ambiance.css");
var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);

Some files were not shown because too many files have changed in this diff Show more