Skip to content

Commit ea69c94

Browse files
committed
lean rules
1 parent f8bef9e commit ea69c94

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

main.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import './styles.scss'
2-
import { MarkdownView, Plugin } from 'obsidian'
2+
import { Plugin } from 'obsidian'
33

44
import './mode/lean/lean'
55

6-
export default class MLIRSyntaxHighlightPlugin extends Plugin {
6+
export default class LeanSyntaxHighlightPlugin extends Plugin {
77

8-
// these are the CodeMirror modes that Obsidian uses by default
98
modesToKeep = ["hypermd", "markdown", "null", "xml"];
109

1110
onload(): void {
@@ -15,8 +14,6 @@ export default class MLIRSyntaxHighlightPlugin extends Plugin {
1514
}
1615

1716
onunload() {
18-
// Delete all the codemirror modes, to disable the syntax highlighting
19-
// except the default ones, obviously
2017
for (const key in CodeMirror.modes) {
2118
if (CodeMirror.modes.hasOwnProperty(key) && !this.modesToKeep.includes(key)) {
2219
delete CodeMirror.modes[key];
@@ -27,7 +24,6 @@ export default class MLIRSyntaxHighlightPlugin extends Plugin {
2724
}
2825

2926
refreshLeaves = () => {
30-
// re-set the editor mode to refresh the syntax highlighting
3127
this.app.workspace.iterateCodeMirrors(cm => cm.setOption("mode", cm.getOption("mode")))
3228
}
3329
}

mode/lean/lean.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,21 @@
66
else
77
mod(CodeMirror)
88
})(function(CodeMirror) {
9-
// TODO
9+
"use strict"
10+
CodeMirror.defineSimpleMode("lean", {
11+
start: [
12+
{ regex: /\b0b[01]+\b/i, token: "number" },
13+
{ regex: /\b0o[0-7]+\b/i, token: "number" },
14+
{ regex: /\b0x[0-9a-f]+\b/i, token: "number" },
15+
{ regex: /\b-?\d+(?:\.\d+)?(?:e[-+]?\d+)?\b/i, token: "number" },
16+
{ regex: /(?:\/-[\s\S]*?-\/)|(?:--.*$)/m, token: "comment" },
17+
{ regex: /\b(?:theorem|show|have|from|suffices|nomatch|def|class|structure|instance|set_option|initialize|builtin_initialize|example|inductive|coinductive|axiom|constant|universe|universes|variable|variables|import|open|export|theory|prelude|renaming|hiding|exposing|do|by|let|extends|mutual|mut|where|rec|syntax|macro_rules|macro|deriving|fun|section|namespace|end|infix|infixl|infixr|postfix|prefix|notation|abbrev|if|then|else|calc|match|with|for|in|unless|try|catch|finally|return|continue|break|global|local|scoped|partial|unsafe|private|protected|noncomputable)\b/, token: "keyword" },
18+
{ regex: /#(print|check|eval|reduce|check_failure)/, token: "operator" },
19+
{ regex: /\+|\*|-|\/|:=|>>>|<<<|\^\^\^|&&&|\|\|\||\+\+|\^|%|~~~|<|<=|>|>=|==|=/, token: "operator" },
20+
{ regex: /[()\[\]{},:]/, token: "meta" },
21+
{ regex: /\b(?:true|false)\b/, token: "attribute" },
22+
{ regex: /\b(?:sorry|admit)\b/, token: "operator" },
23+
// { regex: /(\b(?:inductive|coinductive|structure|theorem|axiom|abbrev|lemma|def|instance|class|constant))(\s+)(\w+)/, token: ["keyword", null, "function"] }
24+
]
25+
})
1026
});

0 commit comments

Comments
 (0)