GPQAPP
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4// Brainfuck mode created by Michael Kaminsky https://github.com/mkaminsky11
5
6(function(mod) {7if (typeof exports == "object" && typeof module == "object")8mod(require("../../lib/codemirror"))9else if (typeof define == "function" && define.amd)10define(["../../lib/codemirror"], mod)11else12mod(CodeMirror)13})(function(CodeMirror) {14"use strict"15var reserve = "><+-.,[]".split("");16/*17comments can be either:
18placed behind lines
19
20+++ this is a comment
21
22where reserved characters cannot be used
23or in a loop
24[
25this is ok to use [ ] and stuff
26]
27or preceded by #
28*/
29CodeMirror.defineMode("brainfuck", function() {30return {31startState: function() {32return {33commentLine: false,34left: 0,35right: 0,36commentLoop: false37}38},39token: function(stream, state) {40if (stream.eatSpace()) return null41if(stream.sol()){42state.commentLine = false;43}44var ch = stream.next().toString();45if(reserve.indexOf(ch) !== -1){46if(state.commentLine === true){47if(stream.eol()){48state.commentLine = false;49}50return "comment";51}52if(ch === "]" || ch === "["){53if(ch === "["){54state.left++;55}56else{57state.right++;58}59return "bracket";60}61else if(ch === "+" || ch === "-"){62return "keyword";63}64else if(ch === "<" || ch === ">"){65return "atom";66}67else if(ch === "." || ch === ","){68return "def";69}70}71else{72state.commentLine = true;73if(stream.eol()){74state.commentLine = false;75}76return "comment";77}78if(stream.eol()){79state.commentLine = false;80}81}82};83});84CodeMirror.defineMIME("text/x-brainfuck","brainfuck")85});86