LaravelTest
168 строк · 4.4 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode('smalltalk', function(config) {15
16var specialChars = /[+\-\/\\*~<>=@%|&?!.,:;^]/;17var keywords = /true|false|nil|self|super|thisContext/;18
19var Context = function(tokenizer, parent) {20this.next = tokenizer;21this.parent = parent;22};23
24var Token = function(name, context, eos) {25this.name = name;26this.context = context;27this.eos = eos;28};29
30var State = function() {31this.context = new Context(next, null);32this.expectVariable = true;33this.indentation = 0;34this.userIndentationDelta = 0;35};36
37State.prototype.userIndent = function(indentation) {38this.userIndentationDelta = indentation > 0 ? (indentation / config.indentUnit - this.indentation) : 0;39};40
41var next = function(stream, context, state) {42var token = new Token(null, context, false);43var aChar = stream.next();44
45if (aChar === '"') {46token = nextComment(stream, new Context(nextComment, context));47
48} else if (aChar === '\'') {49token = nextString(stream, new Context(nextString, context));50
51} else if (aChar === '#') {52if (stream.peek() === '\'') {53stream.next();54token = nextSymbol(stream, new Context(nextSymbol, context));55} else {56if (stream.eatWhile(/[^\s.{}\[\]()]/))57token.name = 'string-2';58else59token.name = 'meta';60}61
62} else if (aChar === '$') {63if (stream.next() === '<') {64stream.eatWhile(/[^\s>]/);65stream.next();66}67token.name = 'string-2';68
69} else if (aChar === '|' && state.expectVariable) {70token.context = new Context(nextTemporaries, context);71
72} else if (/[\[\]{}()]/.test(aChar)) {73token.name = 'bracket';74token.eos = /[\[{(]/.test(aChar);75
76if (aChar === '[') {77state.indentation++;78} else if (aChar === ']') {79state.indentation = Math.max(0, state.indentation - 1);80}81
82} else if (specialChars.test(aChar)) {83stream.eatWhile(specialChars);84token.name = 'operator';85token.eos = aChar !== ';'; // ; cascaded message expression86
87} else if (/\d/.test(aChar)) {88stream.eatWhile(/[\w\d]/);89token.name = 'number';90
91} else if (/[\w_]/.test(aChar)) {92stream.eatWhile(/[\w\d_]/);93token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null;94
95} else {96token.eos = state.expectVariable;97}98
99return token;100};101
102var nextComment = function(stream, context) {103stream.eatWhile(/[^"]/);104return new Token('comment', stream.eat('"') ? context.parent : context, true);105};106
107var nextString = function(stream, context) {108stream.eatWhile(/[^']/);109return new Token('string', stream.eat('\'') ? context.parent : context, false);110};111
112var nextSymbol = function(stream, context) {113stream.eatWhile(/[^']/);114return new Token('string-2', stream.eat('\'') ? context.parent : context, false);115};116
117var nextTemporaries = function(stream, context) {118var token = new Token(null, context, false);119var aChar = stream.next();120
121if (aChar === '|') {122token.context = context.parent;123token.eos = true;124
125} else {126stream.eatWhile(/[^|]/);127token.name = 'variable';128}129
130return token;131};132
133return {134startState: function() {135return new State;136},137
138token: function(stream, state) {139state.userIndent(stream.indentation());140
141if (stream.eatSpace()) {142return null;143}144
145var token = state.context.next(stream, state.context, state);146state.context = token.context;147state.expectVariable = token.eos;148
149return token.name;150},151
152blankLine: function(state) {153state.userIndent(0);154},155
156indent: function(state, textAfter) {157var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta;158return (state.indentation + i) * config.indentUnit;159},160
161electricChars: ']'162};163
164});165
166CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'});167
168});169