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
|
2014-09-19 22:40:39 +00:00
|
|
|
|
'("import" "reducible" "irreducible" "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"
|
2014-11-01 18:35:38 +00:00
|
|
|
|
"hypothesis" "lemma" "corollary" "variable" "variables" "print" "theorem" "example"
|
2014-11-05 19:40:08 +00:00
|
|
|
|
"context" "open" "as" "export" "axiom" "inductive" "with" "structure" "record" "universe" "universes"
|
2014-10-31 06:24:09 +00:00
|
|
|
|
"alias" "help" "environment" "options" "precedence" "reserve" "postfix" "prefix"
|
|
|
|
|
"calc_trans" "calc_subst" "calc_refl" "calc_symm"
|
2014-08-18 20:32:58 +00:00
|
|
|
|
"infix" "infixl" "infixr" "notation" "eval" "check" "exit" "coercion" "end"
|
2014-11-05 22:06:54 +00:00
|
|
|
|
"using" "namespace" "instance" "class" "section" "fields"
|
2014-10-08 00:28:26 +00:00
|
|
|
|
"set_option" "add_rewrite" "extends" "include" "omit" "classes" "instances" "coercions" "raw")
|
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
|
2014-09-29 17:31:38 +00:00
|
|
|
|
(,(rx word-start (or "calc" "have" "obtains" "show" "by" "in" "let" "forall" "fun"
|
2014-11-22 17:56:09 +00:00
|
|
|
|
"exists" "if" "dif" "then" "else" "assume" "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-11-05 19:40:08 +00:00
|
|
|
|
(group (or "inductive" "structure" "record" "theorem" "axiom" "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\]"
|
2014-11-17 04:51:42 +00:00
|
|
|
|
"\[coercion\]" "\[reducible\]" "\[off\]" "\[none\]" "\[on\]" "\[whnf\]" "\[decls\]" "\[strict\]" "\[local\]"))
|
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)
|
2014-09-03 23:00:38 +00:00
|
|
|
|
;; tactics
|
2014-10-22 23:15:00 +00:00
|
|
|
|
(,(rx (not (any "\.")) word-start
|
2014-10-26 22:45:26 +00:00
|
|
|
|
(or "\\b.*_tac" "Cond" "or_else" "then" "try" "when" "assumption" "eassumption" "rapply" "apply" "rename" "intro" "intros"
|
2014-11-23 22:39:35 +00:00
|
|
|
|
"generalize" "generalizes" "back" "beta" "done" "exact" "repeat" "whnf" "rotate" "rotate_left" "rotate_right")
|
2014-09-29 17:31:38 +00:00
|
|
|
|
word-end)
|
2014-09-03 23:00:38 +00:00
|
|
|
|
. 'font-lock-constant-face)
|
2014-09-06 01:38:35 +00:00
|
|
|
|
;; Types
|
2014-11-07 04:57:10 +00:00
|
|
|
|
(,(rx word-start (or "Prop" "Type" "Type'" "Type₊" "Type₁" "Type₂" "Type₃") symbol-end) . 'font-lock-type-face)
|
|
|
|
|
(,(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)
|
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)
|