Skip to content

Commit 426016a

Browse files
committed
Fix highlighting - don't consider every symbol after comment a comment
1 parent f291560 commit 426016a

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>Brainfuck Debugger</title>
6-
<link rel="stylesheet" href="normalize.min.css">
6+
<link rel="stylesheet" href="thirdparty/normalize.min.css">
77
<link rel="stylesheet" href="style.css">
88
<link rel="stylesheet" href="/node_modules/codemirror-minified/lib/codemirror.css">
99
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
1010
<script src="/node_modules/codemirror-minified/lib/codemirror.js" defer></script>
1111
<script src="/node_modules/codemirror-minified/keymap/vim.js" defer></script>
1212
<script src="/node_modules/codemirror-minified/keymap/emacs.js" defer></script>
13-
<script src="/node_modules/codemirror-minified/mode/brainfuck/brainfuck.js" defer></script>
13+
<script src="thirdparty/brainfuck-highlight.min.js" defer></script>
1414
<script src="controller.js" type="module"></script>
1515
</head>
1616
<body>

thirdparty/brainfuck-highlight.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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) {
7+
if (typeof exports == "object" && typeof module == "object")
8+
mod(require("../../lib/codemirror"))
9+
else if (typeof define == "function" && define.amd)
10+
define(["../../lib/codemirror"], mod)
11+
else
12+
mod(CodeMirror)
13+
})(function(CodeMirror) {
14+
"use strict"
15+
var reserve = "><+-.,[]".split("");
16+
/*
17+
comments can be either:
18+
placed behind lines
19+
20+
+++ this is a comment
21+
22+
where reserved characters cannot be used
23+
or in a loop
24+
[
25+
this is ok to use [ ] and stuff
26+
]
27+
or preceded by #
28+
*/
29+
CodeMirror.defineMode("brainfuck", function() {
30+
return {
31+
startState: function() {
32+
return {
33+
commentLine: false,
34+
left: 0,
35+
right: 0,
36+
commentLoop: false
37+
}
38+
},
39+
token: function(stream, state) {
40+
if (stream.eatSpace()) return null
41+
if(stream.sol()){
42+
state.commentLine = false;
43+
}
44+
var ch = stream.next().toString();
45+
if(reserve.indexOf(ch) !== -1){
46+
if(state.commentLine === true){
47+
if(stream.eol()){
48+
state.commentLine = false;
49+
}
50+
return "comment";
51+
}
52+
if(ch === "]" || ch === "["){
53+
if(ch === "["){
54+
state.left++;
55+
}
56+
else{
57+
state.right++;
58+
}
59+
return "bracket";
60+
}
61+
else if(ch === "+" || ch === "-"){
62+
return "keyword";
63+
}
64+
else if(ch === "<" || ch === ">"){
65+
return "atom";
66+
}
67+
else if(ch === "." || ch === ","){
68+
return "def";
69+
}
70+
}
71+
else{
72+
return "comment";
73+
}
74+
}
75+
};
76+
});
77+
CodeMirror.defineMIME("text/x-brainfuck","brainfuck")
78+
});

thirdparty/brainfuck-highlight.min.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

0 commit comments

Comments
 (0)