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
|
|
|
|
|
'("import" "abbreviation" "opaque_hint" "tactic_hint" "definition" "renaming"
|
2014-08-28 16:33:09 +00:00
|
|
|
|
"inline" "hiding" "exposing" "parameter" "parameters" "begin" "proof" "qed" "conjecture"
|
2014-08-18 20:32:58 +00:00
|
|
|
|
"hypothesis" "lemma" "corollary" "variable" "variables" "print" "theorem"
|
2014-09-04 01:37:01 +00:00
|
|
|
|
"context" "open" "as" "export" "axiom" "inductive" "with" "structure" "universe" "alias" "help" "environment"
|
2014-08-18 20:32:58 +00:00
|
|
|
|
"options" "precedence" "postfix" "prefix" "calc_trans" "calc_subst" "calc_refl"
|
|
|
|
|
"infix" "infixl" "infixr" "notation" "eval" "check" "exit" "coercion" "end"
|
2014-09-02 22:03:33 +00:00
|
|
|
|
"private" "using" "namespace" "builtin" "including" "instance" "class" "section"
|
2014-08-18 20:32:58 +00:00
|
|
|
|
"set_option" "add_rewrite" "extends")
|
|
|
|
|
"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
|
|
|
|
|
(modify-syntax-entry ?/ "_ 14nb" st)
|
2014-08-19 17:24:19 +00:00
|
|
|
|
(modify-syntax-entry ?- "_ 123" st)
|
2014-08-18 20:32:58 +00:00
|
|
|
|
(modify-syntax-entry ?\n ">" st)
|
|
|
|
|
|
|
|
|
|
;; ' and _ can be names
|
|
|
|
|
(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-08-18 20:32:58 +00:00
|
|
|
|
(,(rx symbol-start (or "calc" "have" "obtains" "show" "by" "in" "let" "forall" "fun"
|
|
|
|
|
"exists" "if" "then" "else" "assume" "take" "obtain" "from") symbol-end)
|
|
|
|
|
. font-lock-keyword-face)
|
|
|
|
|
;; String
|
|
|
|
|
("\"[^\"]*\"" . 'font-lock-string-face)
|
|
|
|
|
;; Constants
|
2014-08-28 18:25:24 +00:00
|
|
|
|
(,(rx (or "#" "@" "->" "∼" "↔" "/" "==" "=" ":=" "<->" "/\\" "\\/" "∧" "∨" "≠" "<" ">" "≤" "≥" "¬" "<=" ">=" "⁻¹" "⬝" "▸" "+" "*" "-" "/")) . 'font-lock-constant-face)
|
2014-09-03 22:26:21 +00:00
|
|
|
|
(,(rx (or "λ" "→" "∃" "∀" ":=")) . 'font-lock-constant-face )
|
2014-08-18 20:32:58 +00:00
|
|
|
|
;; universe/inductive/theorem... "names"
|
|
|
|
|
(,(rx symbol-start
|
2014-08-19 17:24:19 +00:00
|
|
|
|
(group (or "universe" "inductive" "theorem" "axiom" "lemma" "hypothesis"
|
|
|
|
|
"abbreviation" "definition" "variable" "parameter"))
|
|
|
|
|
symbol-end
|
2014-09-02 22:09:49 +00:00
|
|
|
|
(zero-or-more (or whitespace "(" "{" "["))
|
2014-08-19 17:24:19 +00:00
|
|
|
|
(group (zero-or-more (not whitespace))))
|
|
|
|
|
(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-09-07 23:59:53 +00:00
|
|
|
|
(,(rx (or "\[notation\]" "\[protected\]" "\[private\]" "\[instance\]" "\[class\]" "\[coercion\]" "\[inline\]")) . 'font-lock-doc-face)
|
2014-09-03 23:00:38 +00:00
|
|
|
|
;; tactics
|
|
|
|
|
(,(rx symbol-start
|
|
|
|
|
(or "\\b.*_tac" "Cond" "or_else" "then" "try" "when" "assumption" "apply" "back" "beta" "done" "exact" "repeat")
|
|
|
|
|
symbol-end)
|
|
|
|
|
. 'font-lock-constant-face)
|
2014-09-06 01:38:35 +00:00
|
|
|
|
;; Types
|
|
|
|
|
(,(rx symbol-start (or "bool" "int" "nat" "real" "Prop" "Type" "ℕ" "ℤ") symbol-end) . 'font-lock-type-face)
|
2014-08-18 20:32:58 +00:00
|
|
|
|
;; sorry
|
|
|
|
|
(,(rx symbol-start "sorry" symbol-end) . 'font-lock-warning-face)
|
|
|
|
|
;; lean-keywords
|
|
|
|
|
(, (concat "\\(" (regexp-opt lean-keywords 'words) "\\)")
|
|
|
|
|
(1 'font-lock-keyword-face)))))
|
|
|
|
|
(provide 'lean-syntax)
|