123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- const KEYWORDS = [
- "as", // for exports
- "in",
- "of",
- "if",
- "for",
- "while",
- "finally",
- "var",
- "new",
- "function",
- "do",
- "return",
- "void",
- "else",
- "break",
- "catch",
- "instanceof",
- "with",
- "throw",
- "case",
- "default",
- "try",
- "switch",
- "continue",
- "typeof",
- "delete",
- "let",
- "yield",
- "const",
- "class",
- // JS handles these with a special rule
- // "get",
- // "set",
- "debugger",
- "async",
- "await",
- "static",
- "import",
- "from",
- "export",
- "extends"
- ];
- const LITERALS = [
- "true",
- "false",
- "null",
- "undefined",
- "NaN",
- "Infinity"
- ];
- const TYPES = [
- "Intl",
- "DataView",
- "Number",
- "Math",
- "Date",
- "String",
- "RegExp",
- "Object",
- "Function",
- "Boolean",
- "Error",
- "Symbol",
- "Set",
- "Map",
- "WeakSet",
- "WeakMap",
- "Proxy",
- "Reflect",
- "JSON",
- "Promise",
- "Float64Array",
- "Int16Array",
- "Int32Array",
- "Int8Array",
- "Uint16Array",
- "Uint32Array",
- "Float32Array",
- "Array",
- "Uint8Array",
- "Uint8ClampedArray",
- "ArrayBuffer",
- "BigInt64Array",
- "BigUint64Array",
- "BigInt"
- ];
- const ERROR_TYPES = [
- "EvalError",
- "InternalError",
- "RangeError",
- "ReferenceError",
- "SyntaxError",
- "TypeError",
- "URIError"
- ];
- const BUILT_IN_GLOBALS = [
- "setInterval",
- "setTimeout",
- "clearInterval",
- "clearTimeout",
- "require",
- "exports",
- "eval",
- "isFinite",
- "isNaN",
- "parseFloat",
- "parseInt",
- "decodeURI",
- "decodeURIComponent",
- "encodeURI",
- "encodeURIComponent",
- "escape",
- "unescape"
- ];
- const BUILT_IN_VARIABLES = [
- "arguments",
- "this",
- "super",
- "console",
- "window",
- "document",
- "localStorage",
- "module",
- "global" // Node.js
- ];
- const BUILT_INS = [].concat(
- BUILT_IN_GLOBALS,
- BUILT_IN_VARIABLES,
- TYPES,
- ERROR_TYPES
- );
- /*
- Language: LiveScript
- Author: Taneli Vatanen <taneli.vatanen@gmail.com>
- Contributors: Jen Evers-Corvina <jen@sevvie.net>
- Origin: coffeescript.js
- Description: LiveScript is a programming language that transcompiles to JavaScript. For info about language see http://livescript.net/
- Website: https://livescript.net
- Category: scripting
- */
- function livescript(hljs) {
- const LIVESCRIPT_BUILT_INS = [
- 'npm',
- 'print'
- ];
- const LIVESCRIPT_LITERALS = [
- 'yes',
- 'no',
- 'on',
- 'off',
- 'it',
- 'that',
- 'void'
- ];
- const LIVESCRIPT_KEYWORDS = [
- 'then',
- 'unless',
- 'until',
- 'loop',
- 'of',
- 'by',
- 'when',
- 'and',
- 'or',
- 'is',
- 'isnt',
- 'not',
- 'it',
- 'that',
- 'otherwise',
- 'from',
- 'to',
- 'til',
- 'fallthrough',
- 'case',
- 'enum',
- 'native',
- 'list',
- 'map',
- '__hasProp',
- '__extends',
- '__slice',
- '__bind',
- '__indexOf'
- ];
- const KEYWORDS$1 = {
- keyword: KEYWORDS.concat(LIVESCRIPT_KEYWORDS),
- literal: LITERALS.concat(LIVESCRIPT_LITERALS),
- built_in: BUILT_INS.concat(LIVESCRIPT_BUILT_INS)
- };
- const JS_IDENT_RE = '[A-Za-z$_](?:-[0-9A-Za-z$_]|[0-9A-Za-z$_])*';
- const TITLE = hljs.inherit(hljs.TITLE_MODE, {
- begin: JS_IDENT_RE
- });
- const SUBST = {
- className: 'subst',
- begin: /#\{/,
- end: /\}/,
- keywords: KEYWORDS$1
- };
- const SUBST_SIMPLE = {
- className: 'subst',
- begin: /#[A-Za-z$_]/,
- end: /(?:-[0-9A-Za-z$_]|[0-9A-Za-z$_])*/,
- keywords: KEYWORDS$1
- };
- const EXPRESSIONS = [
- hljs.BINARY_NUMBER_MODE,
- {
- className: 'number',
- begin: '(\\b0[xX][a-fA-F0-9_]+)|(\\b\\d(\\d|_\\d)*(\\.(\\d(\\d|_\\d)*)?)?(_*[eE]([-+]\\d(_\\d|\\d)*)?)?[_a-z]*)',
- relevance: 0,
- starts: {
- end: '(\\s*/)?',
- relevance: 0
- } // a number tries to eat the following slash to prevent treating it as a regexp
- },
- {
- className: 'string',
- variants: [
- {
- begin: /'''/,
- end: /'''/,
- contains: [hljs.BACKSLASH_ESCAPE]
- },
- {
- begin: /'/,
- end: /'/,
- contains: [hljs.BACKSLASH_ESCAPE]
- },
- {
- begin: /"""/,
- end: /"""/,
- contains: [
- hljs.BACKSLASH_ESCAPE,
- SUBST,
- SUBST_SIMPLE
- ]
- },
- {
- begin: /"/,
- end: /"/,
- contains: [
- hljs.BACKSLASH_ESCAPE,
- SUBST,
- SUBST_SIMPLE
- ]
- },
- {
- begin: /\\/,
- end: /(\s|$)/,
- excludeEnd: true
- }
- ]
- },
- {
- className: 'regexp',
- variants: [
- {
- begin: '//',
- end: '//[gim]*',
- contains: [
- SUBST,
- hljs.HASH_COMMENT_MODE
- ]
- },
- {
- // regex can't start with space to parse x / 2 / 3 as two divisions
- // regex can't start with *, and it supports an "illegal" in the main mode
- begin: /\/(?![ *])(\\.|[^\\\n])*?\/[gim]*(?=\W)/
- }
- ]
- },
- {
- begin: '@' + JS_IDENT_RE
- },
- {
- begin: '``',
- end: '``',
- excludeBegin: true,
- excludeEnd: true,
- subLanguage: 'javascript'
- }
- ];
- SUBST.contains = EXPRESSIONS;
- const PARAMS = {
- className: 'params',
- begin: '\\(',
- returnBegin: true,
- /* We need another contained nameless mode to not have every nested
- pair of parens to be called "params" */
- contains: [
- {
- begin: /\(/,
- end: /\)/,
- keywords: KEYWORDS$1,
- contains: ['self'].concat(EXPRESSIONS)
- }
- ]
- };
- const SYMBOLS = {
- begin: '(#=>|=>|\\|>>|-?->|!->)'
- };
- return {
- name: 'LiveScript',
- aliases: ['ls'],
- keywords: KEYWORDS$1,
- illegal: /\/\*/,
- contains: EXPRESSIONS.concat([
- hljs.COMMENT('\\/\\*', '\\*\\/'),
- hljs.HASH_COMMENT_MODE,
- SYMBOLS, // relevance booster
- {
- className: 'function',
- contains: [
- TITLE,
- PARAMS
- ],
- returnBegin: true,
- variants: [
- {
- begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?(\\(.*\\)\\s*)?\\B->\\*?',
- end: '->\\*?'
- },
- {
- begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?!?(\\(.*\\)\\s*)?\\B[-~]{1,2}>\\*?',
- end: '[-~]{1,2}>\\*?'
- },
- {
- begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?(\\(.*\\)\\s*)?\\B!?[-~]{1,2}>\\*?',
- end: '!?[-~]{1,2}>\\*?'
- }
- ]
- },
- {
- className: 'class',
- beginKeywords: 'class',
- end: '$',
- illegal: /[:="\[\]]/,
- contains: [
- {
- beginKeywords: 'extends',
- endsWithParent: true,
- illegal: /[:="\[\]]/,
- contains: [TITLE]
- },
- TITLE
- ]
- },
- {
- begin: JS_IDENT_RE + ':',
- end: ':',
- returnBegin: true,
- returnEnd: true,
- relevance: 0
- }
- ])
- };
- }
- module.exports = livescript;
|