2014-08-18 20:32:58 +00:00
|
|
|
|
;; Copyright (c) 2013, 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
|
;; Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
;;
|
|
|
|
|
;; Author: Leonardo de Moura
|
|
|
|
|
;; Soonho Kong
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
(require 'rx)
|
|
|
|
|
|
|
|
|
|
(defconst lean-keywords
|
2015-01-25 04:23:21 +00:00
|
|
|
|
'("import" "prelude" "tactic_hint" "protected" "private" "opaque" "definition" "renaming"
|
2014-10-02 23:20:52 +00:00
|
|
|
|
"hiding" "exposing" "parameter" "parameters" "begin" "proof" "qed" "conjecture" "constant" "constants"
|
2015-02-12 02:46:03 +00:00
|
|
|
|
"hypothesis" "lemma" "corollary" "variable" "variables" "premise" "premises"
|
|
|
|
|
"print" "theorem" "example" "abbreviation"
|
2015-04-22 18:32:02 +00:00
|
|
|
|
"open" "as" "export" "axiom" "axioms" "inductive" "with" "structure" "record" "universe" "universes"
|
2015-04-28 00:46:13 +00:00
|
|
|
|
"alias" "help" "environment" "options" "precedence" "reserve"
|
2015-01-10 18:11:13 +00:00
|
|
|
|
"calc_trans" "calc_subst" "calc_refl" "calc_symm" "match"
|
2015-04-28 00:46:13 +00:00
|
|
|
|
"infix" "infixl" "infixr" "notation" "postfix" "prefix"
|
|
|
|
|
"tactic_infix" "tactic_infixl" "tactic_infixr" "tactic_notation" "tactic_postfix" "tactic_prefix"
|
|
|
|
|
"eval" "check" "coercion" "end"
|
2015-01-25 04:23:21 +00:00
|
|
|
|
"using" "namespace" "section" "fields" "find_decl"
|
2015-01-26 19:31:12 +00:00
|
|
|
|
"attribute" "local" "set_option" "add_rewrite" "extends" "include" "omit" "classes"
|
2015-03-15 03:32:39 +00:00
|
|
|
|
"instances" "coercions" "metaclasses" "raw" "migrate" "replacing")
|
2014-08-18 20:32:58 +00:00
|
|
|
|
"lean keywords")
|
|
|
|
|
|
|
|
|
|
(defconst lean-syntax-table
|
2014-08-19 17:24:19 +00:00
|
|
|
|
(let ((st (make-syntax-table)))
|
2014-08-18 20:32:58 +00:00
|
|
|
|
;; Matching parens
|
|
|
|
|
(modify-syntax-entry ?\[ "(]" st)
|
|
|
|
|
(modify-syntax-entry ?\] ")[" st)
|
2014-08-19 17:24:19 +00:00
|
|
|
|
(modify-syntax-entry ?\{ "(}" st)
|
|
|
|
|
(modify-syntax-entry ?\} "){" st)
|
2014-08-18 20:32:58 +00:00
|
|
|
|
|
2014-08-25 18:20:01 +00:00
|
|
|
|
;; comment
|
2014-11-07 22:48:21 +00:00
|
|
|
|
(modify-syntax-entry ?/ ". 14nb" st)
|
|
|
|
|
(modify-syntax-entry ?- ". 123" st)
|
2014-08-18 20:32:58 +00:00
|
|
|
|
(modify-syntax-entry ?\n ">" st)
|
|
|
|
|
|
2014-09-30 22:33:49 +00:00
|
|
|
|
;; Word constituent
|
|
|
|
|
(--map (modify-syntax-entry it "w" st)
|
|
|
|
|
(list ?a ?b ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m
|
|
|
|
|
?n ?o ?p ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z
|
|
|
|
|
?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K ?L ?M
|
|
|
|
|
?N ?O ?P ?Q ?R ?S ?T ?U ?V ?W ?X ?Y ?Z))
|
|
|
|
|
(--map (modify-syntax-entry it "w" st)
|
|
|
|
|
(list ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
|
|
|
|
|
(--map (modify-syntax-entry it "w" st)
|
|
|
|
|
(list ?α ?β ?γ ?δ ?ε ?ζ ?η ?θ ?ι ?κ ;;?λ
|
|
|
|
|
?μ ?ν ?ξ ?ο ?π ?ρ ?ς ?σ ?τ ?υ
|
|
|
|
|
?φ ?χ ?ψ ?ω))
|
|
|
|
|
(--map (modify-syntax-entry it "w" st)
|
|
|
|
|
(list ?ϊ ?ϋ ?ό ?ύ ?ώ ?Ϗ ?ϐ ?ϑ ?ϒ ?ϓ ?ϔ ?ϕ ?ϖ
|
|
|
|
|
?ϗ ?Ϙ ?ϙ ?Ϛ ?ϛ ?Ϝ ?ϝ ?Ϟ ?ϟ ?Ϡ ?ϡ ?Ϣ ?ϣ
|
|
|
|
|
?Ϥ ?ϥ ?Ϧ ?ϧ ?Ϩ ?ϩ ?Ϫ ?ϫ ?Ϭ ?ϭ ?Ϯ ?ϯ ?ϰ
|
|
|
|
|
?ϱ ?ϲ ?ϳ ?ϴ ?ϵ ?϶ ?Ϸ ?ϸ ?Ϲ ?Ϻ ?ϻ))
|
|
|
|
|
(--map (modify-syntax-entry it "w" st)
|
|
|
|
|
(list ?ἀ ?ἁ ?ἂ ?ἃ ?ἄ ?ἅ ?ἆ ?ἇ ?Ἀ ?Ἁ ?Ἂ ?Ἃ ?Ἄ
|
|
|
|
|
?Ἅ ?Ἆ ?Ἇ ?ἐ ?ἑ ?ἒ ?ἓ ?ἔ ?ἕ ? ? ?Ἐ ?Ἑ
|
|
|
|
|
?Ἒ ?Ἓ ?Ἔ ?Ἕ ? ? ?ἠ ?ἡ ?ἢ ?ἣ ?ἤ ?ἥ
|
|
|
|
|
?ἦ ?ἧ ?Ἠ ?Ἡ ?Ἢ ?Ἣ ?Ἤ ?Ἥ ?Ἦ ?Ἧ ?ἰ ?ἱ
|
|
|
|
|
?ἲ ?ἳ ?ἴ ?ἵ ?ἶ ?ἷ ?Ἰ ?Ἱ ?Ἲ ?Ἳ ?Ἴ ?Ἵ ?Ἶ ?Ἷ
|
|
|
|
|
?ὀ ?ὁ ?ὂ ?ὃ ?ὄ ?ὅ ? ? ?Ὀ ?Ὁ ?Ὂ ?Ὃ
|
|
|
|
|
?Ὄ ?Ὅ ? ? ?ὐ ?ὑ ?ὒ ?ὓ ?ὔ ?ὕ ?ὖ ?ὗ
|
|
|
|
|
? ?Ὑ ? ?Ὓ ? ?Ὕ ? ?Ὗ ?ὠ ?ὡ ?ὢ
|
|
|
|
|
?ὣ ?ὤ ?ὥ ?ὦ ?ὧ ?Ὠ ?Ὡ ?Ὢ ?Ὣ ?Ὤ ?Ὥ ?Ὦ
|
|
|
|
|
?Ὧ ?ὰ ?ά ?ὲ ?έ ?ὴ ?ή ?ὶ ?ί ?ὸ ?ό ?ὺ ?ύ ?ὼ
|
|
|
|
|
?ώ ? ? ?ᾀ ?ᾁ ?ᾂ ?ᾃ ?ᾄ ?ᾅ ?ᾆ ?ᾇ ?ᾈ
|
|
|
|
|
?ᾉ ?ᾊ ?ᾋ ?ᾌ ?ᾍ ?ᾎ ?ᾏ ?ᾐ ?ᾑ ?ᾒ ?ᾓ ?ᾔ
|
|
|
|
|
?ᾕ ?ᾖ ?ᾗ ?ᾘ ?ᾙ ?ᾚ ?ᾛ ?ᾜ ?ᾝ ?ᾞ ?ᾟ ?ᾠ ?ᾡ ?ᾢ
|
|
|
|
|
?ᾣ ?ᾤ ?ᾥ ?ᾦ ?ᾧ ?ᾨ ?ᾩ ?ᾪ ?ᾫ ?ᾬ ?ᾭ ?ᾮ ?ᾯ ?ᾰ
|
|
|
|
|
?ᾱ ?ᾲ ?ᾳ ?ᾴ ? ?ᾶ ?ᾷ ?Ᾰ ?Ᾱ ?Ὰ ?Ά ?ᾼ ?᾽
|
|
|
|
|
?ι ?᾿ ?῀ ?῁ ?ῂ ?ῃ ?ῄ ? ?ῆ ?ῇ ?Ὲ ?Έ ?Ὴ
|
|
|
|
|
?Ή ?ῌ ?῍ ?῎ ?῏ ?ῐ ?ῑ ?ῒ ?ΐ ? ? ?ῖ ?ῗ
|
|
|
|
|
?Ῐ ?Ῑ ?Ὶ ?Ί ? ?῝ ?῞ ?῟ ?ῠ ?ῡ ?ῢ ?ΰ ?ῤ ?ῥ
|
|
|
|
|
?ῦ ?ῧ ?Ῠ ?Ῡ ?Ὺ ?Ύ ?Ῥ ?῭ ?΅ ?` ? ? ?ῲ ?ῳ
|
|
|
|
|
?ῴ ? ?ῶ ?ῷ ?Ὸ ?Ό ?Ὼ ?Ώ ?ῼ ?´ ?῾))
|
|
|
|
|
(--map (modify-syntax-entry it "w" st)
|
|
|
|
|
(list ?℀ ?℁ ?ℂ ?℃ ?℄ ?℅ ?℆ ?ℇ ?℈ ?℉ ?ℊ ?ℋ ?ℌ ?ℍ ?ℎ
|
|
|
|
|
?ℏ ?ℐ ?ℑ ?ℒ ?ℓ ?℔ ?ℕ ?№ ?℗ ?℘ ?ℙ ?ℚ ?ℛ ?ℜ ?ℝ
|
|
|
|
|
?℞ ?℟ ?℠ ?℡ ?™ ?℣ ?ℤ ?℥ ?Ω ?℧ ?ℨ ?℩ ?K ?Å ?ℬ
|
|
|
|
|
?ℭ ?℮ ?ℯ ?ℰ ?ℱ ?Ⅎ ?ℳ ?ℴ ?ℵ ?ℶ ?ℷ ?ℸ ?ℹ ?℺ ?℻
|
|
|
|
|
?ℼ ?ℽ ?ℾ ?ℿ ?⅀ ?⅁ ?⅂ ?⅃ ?⅄ ?ⅅ ?ⅆ ?ⅇ ?ⅈ ?ⅉ ?⅊
|
|
|
|
|
?⅋ ?⅌ ?⅍ ?ⅎ ?⅏))
|
2014-08-18 20:32:58 +00:00
|
|
|
|
(modify-syntax-entry ?' "w" st)
|
|
|
|
|
(modify-syntax-entry ?_ "w" st)
|
|
|
|
|
|
|
|
|
|
;; Lean operator chars
|
|
|
|
|
(mapc #'(lambda (ch) (modify-syntax-entry ch "_" st))
|
2014-08-25 18:20:01 +00:00
|
|
|
|
"!#$%&*+.<=>@^|~:")
|
2014-08-18 20:32:58 +00:00
|
|
|
|
|
|
|
|
|
;; Whitespace is whitespace
|
|
|
|
|
(modify-syntax-entry ?\ " " st)
|
|
|
|
|
(modify-syntax-entry ?\t " " st)
|
|
|
|
|
|
2014-08-19 17:24:19 +00:00
|
|
|
|
;; Strings
|
2014-08-18 20:32:58 +00:00
|
|
|
|
(modify-syntax-entry ?\" "\"" st)
|
|
|
|
|
(modify-syntax-entry ?\\ "/" st)
|
|
|
|
|
st))
|
|
|
|
|
|
|
|
|
|
(defconst lean-font-lock-defaults
|
2014-09-06 01:38:35 +00:00
|
|
|
|
`((;; Keywords
|
2015-02-03 01:02:14 +00:00
|
|
|
|
(,(rx word-start (or "calc" "have" "obtains" "show" "by" "in" "at" "let" "forall" "fun"
|
2015-02-25 22:30:42 +00:00
|
|
|
|
"exists" "if" "dif" "then" "else" "assume" "assert" "take" "obtain" "from") word-end)
|
2014-08-18 20:32:58 +00:00
|
|
|
|
. font-lock-keyword-face)
|
|
|
|
|
;; String
|
|
|
|
|
("\"[^\"]*\"" . 'font-lock-string-face)
|
|
|
|
|
;; Constants
|
2014-11-07 04:57:10 +00:00
|
|
|
|
(,(rx symbol-start (or "#" "@" "->" "∼" "↔" "/" "==" "=" ":=" "<->" "/\\" "\\/" "∧" "∨" "≠" "<" ">" "≤" "≥" "¬" "<=" ">=" "⁻¹" "⬝" "▸" "+" "*" "-" "/") symbol-end)
|
|
|
|
|
. 'font-lock-constant-face)
|
|
|
|
|
(,(rx symbol-start (or "λ" "→" "∃" "∀" ":=") symbol-end) . 'font-lock-constant-face )
|
2014-08-18 20:32:58 +00:00
|
|
|
|
;; universe/inductive/theorem... "names"
|
2014-09-29 17:31:38 +00:00
|
|
|
|
(,(rx word-start
|
2014-12-30 19:24:22 +00:00
|
|
|
|
(group (or "inductive" "structure" "record" "theorem" "axiom" "axioms" "lemma" "hypothesis" "definition" "constant"))
|
2014-09-29 17:31:38 +00:00
|
|
|
|
word-end
|
2014-09-02 22:09:49 +00:00
|
|
|
|
(zero-or-more (or whitespace "(" "{" "["))
|
2014-11-07 04:57:10 +00:00
|
|
|
|
(group (zero-or-more (not (any " \t\n\r{([")))))
|
2014-08-19 17:24:19 +00:00
|
|
|
|
(2 'font-lock-function-name-face))
|
2014-08-28 18:16:29 +00:00
|
|
|
|
("\\(set_option\\)[ \t]*\\([^ \t\n]*\\)" (2 'font-lock-constant-face))
|
2014-08-18 20:32:58 +00:00
|
|
|
|
;; place holder
|
|
|
|
|
(,(rx symbol-start "_" symbol-end) . 'font-lock-preprocessor-face)
|
2014-09-03 22:26:21 +00:00
|
|
|
|
;; modifiers
|
2014-11-07 05:34:05 +00:00
|
|
|
|
(,(rx (or "\[persistent\]" "\[notation\]" "\[visible\]" "\[instance\]" "\[class\]" "\[parsing-only\]"
|
2015-04-05 09:47:37 +00:00
|
|
|
|
"\[coercion\]" "\[unfold-f\]" "\[reducible\]" "\[irreducible\]" "\[semireducible\]" "\[quasireducible\]" "\[wf\]"
|
2015-03-05 22:34:56 +00:00
|
|
|
|
"\[whnf\]" "\[multiple-instances\]" "\[none\]"
|
2015-02-11 18:35:38 +00:00
|
|
|
|
"\[decls\]" "\[declarations\]" "\[all-transparent\]" "\[coercions\]" "\[classes\]"
|
2015-02-12 03:09:14 +00:00
|
|
|
|
"\[notations\]" "\[abbreviations\]" "\[begin-end-hints\]" "\[tactic-hints\]" "\[reduce-hints\]"))
|
2014-11-10 20:46:04 +00:00
|
|
|
|
. 'font-lock-doc-face)
|
2014-09-28 19:20:42 +00:00
|
|
|
|
(,(rx "\[priority" (zero-or-more (not (any "\]"))) "\]") . font-lock-doc-face)
|
2015-02-06 20:57:11 +00:00
|
|
|
|
(,(rx "\[unfold-c" (zero-or-more (not (any "\]"))) "\]") . font-lock-doc-face)
|
2014-09-03 23:00:38 +00:00
|
|
|
|
;; tactics
|
2014-11-29 06:41:46 +00:00
|
|
|
|
("cases[ \t\n]+[^ \t\n]+[ \t\n]+\\(with\\)" (1 'font-lock-constant-face))
|
2014-10-22 23:15:00 +00:00
|
|
|
|
(,(rx (not (any "\.")) word-start
|
2015-02-24 19:57:34 +00:00
|
|
|
|
(group
|
|
|
|
|
(or "\\b.*_tac" "Cond" "or_else" "then" "try" "when" "assumption" "eassumption" "rapply"
|
2015-05-01 22:07:28 +00:00
|
|
|
|
"apply" "fapply" "eapply" "rename" "intro" "intros" "all_goals" "fold"
|
2015-04-06 20:23:38 +00:00
|
|
|
|
"generalize" "generalizes" "clear" "clears" "revert" "reverts" "back" "beta" "done" "exact" "rexact"
|
|
|
|
|
"refine" "repeat" "whnf" "rotate" "rotate_left" "rotate_right" "inversion" "cases" "rewrite" "esimp"
|
2015-05-01 19:45:21 +00:00
|
|
|
|
"unfold" "change" "check_expr" "contradiction" "exfalso" "split" "existsi" "constructor" "left" "right"
|
2015-05-02 19:58:46 +00:00
|
|
|
|
"injection" "congruence"))
|
2014-09-29 17:31:38 +00:00
|
|
|
|
word-end)
|
2015-02-24 19:57:34 +00:00
|
|
|
|
(1 'font-lock-constant-face))
|
2014-09-06 01:38:35 +00:00
|
|
|
|
;; Types
|
2014-12-06 06:14:28 +00:00
|
|
|
|
(,(rx word-start (or "Prop" "Type" "Type'" "Type₊" "Type₀" "Type₁" "Type₂" "Type₃") symbol-end) . 'font-lock-type-face)
|
2014-11-07 04:57:10 +00:00
|
|
|
|
(,(rx word-start (group "Type") ".") (1 'font-lock-type-face))
|
2014-08-18 20:32:58 +00:00
|
|
|
|
;; sorry
|
2014-09-29 17:31:38 +00:00
|
|
|
|
(,(rx word-start "sorry" word-end) . 'font-lock-warning-face)
|
2015-04-20 21:45:39 +00:00
|
|
|
|
(,(rx word-start "exit" word-end) . 'font-lock-warning-face)
|
2014-09-12 01:11:58 +00:00
|
|
|
|
;; extra-keywords
|
|
|
|
|
(,(rx (or "∎")) . 'font-lock-keyword-face)
|
2014-08-18 20:32:58 +00:00
|
|
|
|
;; lean-keywords
|
|
|
|
|
(, (concat "\\(" (regexp-opt lean-keywords 'words) "\\)")
|
|
|
|
|
(1 'font-lock-keyword-face)))))
|
2014-10-29 21:28:43 +00:00
|
|
|
|
|
|
|
|
|
;; Syntax Highlighting for Lean Info Mode
|
|
|
|
|
(defconst lean-info-font-lock-defaults
|
|
|
|
|
(let ((new-entries
|
|
|
|
|
`(;; Please add more after this:
|
|
|
|
|
(,(rx word-start (group (+ wordchar)) word-end (+ white) ":")
|
|
|
|
|
(1 'font-lock-variable-name-face))
|
|
|
|
|
(,(rx white ":" white)
|
|
|
|
|
. 'font-lock-keyword-face)
|
|
|
|
|
(,(rx "⊢" white)
|
|
|
|
|
. 'font-lock-keyword-face)
|
|
|
|
|
(,(rx "[" (group "stale") "]")
|
|
|
|
|
(1 'font-lock-warning-face))
|
|
|
|
|
(,(rx line-start "No Goal" line-end)
|
|
|
|
|
. 'font-lock-constant-face)))
|
|
|
|
|
(inherited-entries (car lean-font-lock-defaults)))
|
|
|
|
|
`(,(-concat new-entries inherited-entries))))
|
|
|
|
|
|
2014-08-18 20:32:58 +00:00
|
|
|
|
(provide 'lean-syntax)
|