Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/codemirror/mode/lean.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import * as CodeMirror from "codemirror";67/*8This is just a first tiny quick step. To finish this:910- Look at https://codemirror.net/demo/simplemode.html for how this works.11- Put everything from https://github.com/leanprover/vscode-lean/blob/master/syntaxes/lean.json in here.1213playgroud to see the alternative of negative look ahead in action: https://regex101.com/r/lop9Se/11415*/1617// This is redundant with the regexp's below, but we need this to do completions18// before the terms are ever used.19export const completions: string[] = "import|prelude|theory|definition|def|abbreviation|instance|renaming|hiding|exposing|parameter|parameters|begin|constant|constants|lemma|variable|variables|theorem|example|open|axiom|inductive|coinductive|with|structure|universe|universes|alias|precedence|reserve|postfix|prefix|infix|infixl|infixr|notation|end|using|namespace|section|local|set_option|extends|include|omit|class|classes|instances|raw|run_cmd|print|eval|reduce|check|help|exit|calc|have|this|match|do|suffices|show|by|in|at|let|forall|fun|exists|assume|from|Prop|Type|Sort".split(20"|"21);22completions.sort();2324(CodeMirror as any).defineSimpleMode("lean", {25start: [26{ regex: /"(?:[^\\]|\\.)*?(?:"|$)/, token: "string" },27{ regex: /\/-/, token: "comment", next: "blockcomment" },28{29regex: /#(print|eval|reduce|check|help|exit)\b/,30token: "variable-3",31},32{ regex: /--.*/, token: "comment" },33{ regex: /[-+\/*=<>!]+/, token: "operator" },34{35regex: /((?!\.).{1}|^)\b(import|prelude|theory|definition|def|abbreviation|instance|renaming|hiding|exposing|parameter|parameters|begin|constant|constants|lemma|variable|variables|theorem|example|open|axiom|inductive|coinductive|with|structure|universe|universes|alias|precedence|reserve|postfix|prefix|infix|infixl|infixr|notation|end|using|namespace|section|local|set_option|extends|include|omit|class|classes|instances|raw|run_cmd)\b/,36token: "keyword",37},38{39regex: /((?!\.).{1}|^)\b(calc|have|this|match|do|suffices|show|by|in|at|let|forall|fun|exists|assume|from)\b/,40token: "variable-2",41},42{43regex: /\b(Prop|Type|Sort)\b/,44token: "atom",45},46{47regex: /0x[a-f\d]+|[-+]?(?:\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?/i,48token: "number",49},50{ regex: /\/-.*?-\//, token: "comment" },51{ regex: /begin/, indent: true },52{ regex: /end/, dedent: true },53{ regex: /[a-z$][\w$]*/, token: "variable" },54{ regex: /b?"/, token: "string", next: "string" },55],56string: [57{ regex: /"/, token: "string", next: "start" },58{ regex: /(?:[^\\"]|\\(?:.|$))*/, token: "string" },59],60blockcomment: [61{ regex: /.*?-\//, token: "comment", next: "start" },62{ regex: /.*/, token: "comment" },63],64meta: {65dontIndentStates: ["comment"],66lineComment: "--",67},68});697071