GPQAPP
280 строк · 7.5 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4/**
5* Link to the project's GitHub page:
6* https://github.com/duralog/CodeMirror
7*/
8
9(function(mod) {10if (typeof exports == "object" && typeof module == "object") // CommonJS11mod(require("../../lib/codemirror"));12else if (typeof define == "function" && define.amd) // AMD13define(["../../lib/codemirror"], mod);14else // Plain browser env15mod(CodeMirror);16})(function(CodeMirror) {17"use strict";18
19CodeMirror.defineMode('livescript', function(){20var tokenBase = function(stream, state) {21var next_rule = state.next || "start";22if (next_rule) {23state.next = state.next;24var nr = Rules[next_rule];25if (nr.splice) {26for (var i$ = 0; i$ < nr.length; ++i$) {27var r = nr[i$];28if (r.regex && stream.match(r.regex)) {29state.next = r.next || state.next;30return r.token;31}32}33stream.next();34return 'error';35}36if (stream.match(r = Rules[next_rule])) {37if (r.regex && stream.match(r.regex)) {38state.next = r.next;39return r.token;40} else {41stream.next();42return 'error';43}44}45}46stream.next();47return 'error';48};49var external = {50startState: function(){51return {52next: 'start',53lastToken: {style: null, indent: 0, content: ""}54};55},56token: function(stream, state){57while (stream.pos == stream.start)58var style = tokenBase(stream, state);59state.lastToken = {60style: style,61indent: stream.indentation(),62content: stream.current()63};64return style.replace(/\./g, ' ');65},66indent: function(state){67var indentation = state.lastToken.indent;68if (state.lastToken.content.match(indenter)) {69indentation += 2;70}71return indentation;72}73};74return external;75});76
77var identifier = '(?![\\d\\s])[$\\w\\xAA-\\uFFDC](?:(?!\\s)[$\\w\\xAA-\\uFFDC]|-[A-Za-z])*';78var indenter = RegExp('(?:[({[=:]|[-~]>|\\b(?:e(?:lse|xport)|d(?:o|efault)|t(?:ry|hen)|finally|import(?:\\s*all)?|const|var|let|new|catch(?:\\s*' + identifier + ')?))\\s*$');79var keywordend = '(?![$\\w]|-[A-Za-z]|\\s*:(?![:=]))';80var stringfill = {81token: 'string',82regex: '.+'83};84var Rules = {85start: [86{87token: 'comment.doc',88regex: '/\\*',89next: 'comment'90}, {91token: 'comment',92regex: '#.*'93}, {94token: 'keyword',95regex: '(?:t(?:h(?:is|row|en)|ry|ypeof!?)|c(?:on(?:tinue|st)|a(?:se|tch)|lass)|i(?:n(?:stanceof)?|mp(?:ort(?:\\s+all)?|lements)|[fs])|d(?:e(?:fault|lete|bugger)|o)|f(?:or(?:\\s+own)?|inally|unction)|s(?:uper|witch)|e(?:lse|x(?:tends|port)|val)|a(?:nd|rguments)|n(?:ew|ot)|un(?:less|til)|w(?:hile|ith)|o[fr]|return|break|let|var|loop)' + keywordend96}, {97token: 'constant.language',98regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend99}, {100token: 'invalid.illegal',101regex: '(?:p(?:ackage|r(?:ivate|otected)|ublic)|i(?:mplements|nterface)|enum|static|yield)' + keywordend102}, {103token: 'language.support.class',104regex: '(?:R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|Array|Boolean|Date|Function|Number|Object|TypeError|URIError)' + keywordend105}, {106token: 'language.support.function',107regex: '(?:is(?:NaN|Finite)|parse(?:Int|Float)|Math|JSON|(?:en|de)codeURI(?:Component)?)' + keywordend108}, {109token: 'variable.language',110regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend111}, {112token: 'identifier',113regex: identifier + '\\s*:(?![:=])'114}, {115token: 'variable',116regex: identifier117}, {118token: 'keyword.operator',119regex: '(?:\\.{3}|\\s+\\?)'120}, {121token: 'keyword.variable',122regex: '(?:@+|::|\\.\\.)',123next: 'key'124}, {125token: 'keyword.operator',126regex: '\\.\\s*',127next: 'key'128}, {129token: 'string',130regex: '\\\\\\S[^\\s,;)}\\]]*'131}, {132token: 'string.doc',133regex: '\'\'\'',134next: 'qdoc'135}, {136token: 'string.doc',137regex: '"""',138next: 'qqdoc'139}, {140token: 'string',141regex: '\'',142next: 'qstring'143}, {144token: 'string',145regex: '"',146next: 'qqstring'147}, {148token: 'string',149regex: '`',150next: 'js'151}, {152token: 'string',153regex: '<\\[',154next: 'words'155}, {156token: 'string.regex',157regex: '//',158next: 'heregex'159}, {160token: 'string.regex',161regex: '\\/(?:[^[\\/\\n\\\\]*(?:(?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[\\/\\n\\\\]*)*)\\/[gimy$]{0,4}',162next: 'key'163}, {164token: 'constant.numeric',165regex: '(?:0x[\\da-fA-F][\\da-fA-F_]*|(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]*|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)(?:e[+-]?\\d[\\d_]*)?[\\w$]*)'166}, {167token: 'lparen',168regex: '[({[]'169}, {170token: 'rparen',171regex: '[)}\\]]',172next: 'key'173}, {174token: 'keyword.operator',175regex: '\\S+'176}, {177token: 'text',178regex: '\\s+'179}180],181heregex: [182{183token: 'string.regex',184regex: '.*?//[gimy$?]{0,4}',185next: 'start'186}, {187token: 'string.regex',188regex: '\\s*#{'189}, {190token: 'comment.regex',191regex: '\\s+(?:#.*)?'192}, {193token: 'string.regex',194regex: '\\S+'195}196],197key: [198{199token: 'keyword.operator',200regex: '[.?@!]+'201}, {202token: 'identifier',203regex: identifier,204next: 'start'205}, {206token: 'text',207regex: '',208next: 'start'209}210],211comment: [212{213token: 'comment.doc',214regex: '.*?\\*/',215next: 'start'216}, {217token: 'comment.doc',218regex: '.+'219}220],221qdoc: [222{223token: 'string',224regex: ".*?'''",225next: 'key'226}, stringfill227],228qqdoc: [229{230token: 'string',231regex: '.*?"""',232next: 'key'233}, stringfill234],235qstring: [236{237token: 'string',238regex: '[^\\\\\']*(?:\\\\.[^\\\\\']*)*\'',239next: 'key'240}, stringfill241],242qqstring: [243{244token: 'string',245regex: '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"',246next: 'key'247}, stringfill248],249js: [250{251token: 'string',252regex: '[^\\\\`]*(?:\\\\.[^\\\\`]*)*`',253next: 'key'254}, stringfill255],256words: [257{258token: 'string',259regex: '.*?\\]>',260next: 'key'261}, stringfill262]263};264for (var idx in Rules) {265var r = Rules[idx];266if (r.splice) {267for (var i = 0, len = r.length; i < len; ++i) {268var rr = r[i];269if (typeof rr.regex === 'string') {270Rules[idx][i].regex = new RegExp('^' + rr.regex);271}272}273} else if (typeof rr.regex === 'string') {274Rules[idx].regex = new RegExp('^' + r.regex);275}276}277
278CodeMirror.defineMIME('text/x-livescript', 'livescript');279
280});281