Annotate a list of tokens as keywords
function annotateKeywords(keywords) {
return keywords.map(function (t) {
t.keyword = true;
t.origin = "ecmascript";
return t;
});
}
function isSupportedLanguage(languageId) {
return SUPPORTED_LANGUAGES.indexOf(languageId) !== -1;
}
var KEYWORD_NAMES = [
"break", "case", "catch", "class", "const", "continue", "debugger",
"default", "delete", "do", "else", "export", "extends", "finally",
"for", "function", "if", "import", "in", "instanceof", "let", "new",
"return", "super", "switch", "this", "throw", "try", "typeof", "var",
"void", "while", "with", "yield"
],
KEYWORD_TOKENS = KEYWORD_NAMES.map(function (t) {
return makeToken(t, []);
}),
KEYWORDS = annotateKeywords(KEYWORD_TOKENS);
var LITERAL_NAMES = [
"true", "false", "null"
],
LITERAL_TOKENS = LITERAL_NAMES.map(function (t) {
return makeToken(t, []);
}),
LITERALS = annotateLiterals(LITERAL_TOKENS);
exports.makeToken = makeToken;
exports.hintable = hintable;
exports.hintableKey = hintableKey;
exports.maybeIdentifier = maybeIdentifier;
exports.eventName = eventName;
exports.annotateLiterals = annotateLiterals;
exports.isSupportedLanguage = isSupportedLanguage;
exports.KEYWORDS = KEYWORDS;
exports.LITERALS = LITERALS;
exports.LANGUAGE_ID = LANGUAGE_ID;
exports.SINGLE_QUOTE = SINGLE_QUOTE;
exports.DOUBLE_QUOTE = DOUBLE_QUOTE;
exports.SUPPORTED_LANGUAGES = SUPPORTED_LANGUAGES;
});
Annotate a list of tokens as literals of a particular kind; if string literals, annotate with an appropriate delimiter.
function annotateLiterals(literals, kind) {
return literals.map(function (t) {
t.literal = true;
t.kind = kind;
t.origin = "ecmascript";
if (kind === "string") {
if (/[^\\]"/.test(t.value)) {
t.delimiter = SINGLE_QUOTE;
} else {
t.delimiter = DOUBLE_QUOTE;
}
}
return t;
});
}
Get a JS-hints-specific event name. Used to prevent event namespace pollution.
function eventName(name) {
var EVENT_TAG = "brackets-js-hints";
return name + "." + EVENT_TAG;
}
Is the token's class hintable? (A very conservative test.)
function hintable(token) {
function _isInsideRegExp(token) {
return token.state && (token.state.lastType === "regexp" ||
(token.state.localState && token.state.localState.lastType === "regexp"));
}
switch (token.type) {
case "comment":
case "number":
case "regexp":
case "string":
case "def": // exclude variable & param decls
return false;
case "string-2":
// exclude strings inside a regexp
return !_isInsideRegExp(token);
default:
return true;
}
}
Determine if hints should be displayed for the given key.
function hintableKey(key, showOnDot) {
return (key === null || (showOnDot && key === ".") || maybeIdentifier(key));
}
Create a hint token with name value that occurs at the given list of positions.
function makeToken(value, positions) {
positions = positions || [];
return {
value: value,
positions: positions
};
}
Is the string key perhaps a valid JavaScript identifier?
function maybeIdentifier(key) {
var result = false,
i;
for (i = 0; i < key.length; i++) {
result = Acorn.isIdentifierChar(key.charCodeAt(i));
if (!result) {
break;
}
}
return result;
}