1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 03:12:25 +01:00

Update Lean.sublime-syntax from Lean 3 to Lean 4

Resolves #3286

1. `lean4.json` → `lean4.tmLanguage`

    1. Download `vscode-lean4/syntaxes/lean4.json` from https://github.com/leanprover/vscode-lean4/pull/623 (now merged).
    2. Install the VS Code extension [TextMate Languages (pedro-w)](https://marketplace.visualstudio.com/items?itemName=pedro-w.tmlanguage).
    3. Open `lean4.json` in VS Code, <kbd>F1</kbd>, and “Convert to tmLanguage PLIST File”.

2. `lean4.tmLanguage` → `lean4.sublime-syntax`

    Open `lean4.tmLanguage` in Sublime text, “Tools → Developer → New Syntax from lean4.tmLanguage…”.
This commit is contained in:
Y.D.X.
2025-06-09 17:21:34 +08:00
parent e2aa4bc33c
commit 0918984249
6 changed files with 204 additions and 169 deletions

2
.gitmodules vendored
View File

@@ -196,7 +196,7 @@
branch = bat-source branch = bat-source
[submodule "assets/syntaxes/02_Extra/Lean"] [submodule "assets/syntaxes/02_Extra/Lean"]
path = assets/syntaxes/02_Extra/Lean path = assets/syntaxes/02_Extra/Lean
url = https://github.com/leanprover/vscode-lean.git url = https://github.com/leanprover/vscode-lean4.git
[submodule "assets/syntaxes/02_Extra/Zig"] [submodule "assets/syntaxes/02_Extra/Zig"]
path = assets/syntaxes/02_Extra/Zig path = assets/syntaxes/02_Extra/Zig
url = https://github.com/ziglang/sublime-zig-language.git url = https://github.com/ziglang/sublime-zig-language.git

View File

@@ -1,125 +1,130 @@
%YAML 1.2 %YAML 1.2
--- ---
# http://www.sublimetext.com/docs/3/syntax.html # http://www.sublimetext.com/docs/syntax.html
name: Lean name: Lean 4
file_extensions: file_extensions:
- lean - lean
scope: source.lean scope: source.lean4
contexts: contexts:
main: main:
- include: comments - include: comments
- match: '\b(?<!\.)(inductive|coinductive|structure|theorem|axiom|axioms|abbreviation|lemma|definition|def|instance|class|constant)\b\s+(\{[^}]*\})?' - match: \b(Prop|Type|Sort)\b
scope: storage.type.lean4
- match: '\battribute\b\s*\[[^\]]*\]'
scope: storage.modifier.lean4
- match: '@\[[^\]]*\]'
scope: storage.modifier.lean4
- match: \b(?<!\.)(global|local|scoped|partial|unsafe|private|protected|noncomputable)(?!\.)\b
scope: storage.modifier.lean4
- match: \b(sorry|admit|stop)\b
scope: invalid.illegal.lean4
- match: '#(print|eval|reduce|check|check_failure)\b'
scope: keyword.other.lean4
- match: \bderiving\s+instance\b
scope: keyword.other.command.lean4
- match: '\b(?<!\.)(inductive|coinductive|structure|theorem|axiom|abbrev|lemma|def|instance|class|constant)\b\s+(\{[^}]*\})?'
captures: captures:
1: keyword.other.definitioncommand.lean 1: keyword.other.definitioncommand.lean4
push: push:
- meta_scope: meta.definitioncommand.lean - meta_scope: meta.definitioncommand.lean4
- match: '(?=\bwith\b|\bextends\b|[:\|\(\[\{⦃<>])' - match: '(?=\bwith\b|\bextends\b|\bwhere\b|[:\|\(\[\{⦃<>])'
pop: true pop: true
- include: comments - include: comments
- include: definitionName - include: definitionName
- match: "," - match: ','
- match: \b(Prop|Type|Sort)\b - match: \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)(?!\.)\b
scope: storage.type.lean scope: keyword.other.lean4
- match: '\battribute\b\s*\[[^\]]*\]'
scope: storage.modifier.lean
- match: '@\[[^\]]*\]'
scope: storage.modifier.lean
- match: \b(?<!\.)(private|meta|mutual|protected|noncomputable)\b
scope: keyword.control.definition.modifier.lean
- match: \b(sorry)\b
scope: invalid.illegal.lean
- match: '#print\s+(def|definition|inductive|instance|structure|axiom|axioms|class)\b'
scope: keyword.other.command.lean
- match: '#(print|eval|reduce|check|help|exit|find|where)\b'
scope: keyword.other.command.lean
- match: \b(?<!\.)(import|export|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|restate_axiom)(?!\.)\b
scope: keyword.other.lean
- match: \b(?<!\.)(calc|have|this|match|do|suffices|show|by|in|at|let|forall|fun|exists|assume|from|obtain|haveI|λ)(?!\.)\b
scope: keyword.other.lean
- match: « - match: «
push: push:
- meta_content_scope: entity.name.lean - meta_content_scope: entity.name.lean4
- match: » - match: »
pop: true pop: true
- match: \b(?<!\.)(if|then|else)\b - match: (s!)"
scope: keyword.control.lean
- match: '"'
captures: captures:
0: punctuation.definition.string.begin.lean 1: keyword.other.lean4
push: push:
- meta_scope: string.quoted.double.lean - meta_scope: string.interpolated.lean4
- match: '"' - match: '"'
captures:
0: punctuation.definition.string.end.lean
pop: true pop: true
- match: '\\[\\"nt'']' - match: '(\{)'
scope: constant.character.escape.lean captures:
1: keyword.other.lean4
push:
- match: '(\})'
captures:
1: keyword.other.lean4
pop: true
- include: main
- match: '\\[\\"ntr'']'
scope: constant.character.escape.lean4
- match: '\\x[0-9A-Fa-f][0-9A-Fa-f]' - match: '\\x[0-9A-Fa-f][0-9A-Fa-f]'
scope: constant.character.escape.lean scope: constant.character.escape.lean4
- match: '\\u[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]' - match: '\\u[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]'
scope: constant.character.escape.lean scope: constant.character.escape.lean4
- match: '"'
push:
- meta_scope: string.quoted.double.lean4
- match: '"'
pop: true
- match: '\\[\\"ntr'']'
scope: constant.character.escape.lean4
- match: '\\x[0-9A-Fa-f][0-9A-Fa-f]'
scope: constant.character.escape.lean4
- match: '\\u[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]'
scope: constant.character.escape.lean4
- match: \b(true|false)\b
scope: constant.language.lean4
- match: '''[^\\'']''' - match: '''[^\\'']'''
scope: string.quoted.single.lean scope: string.quoted.single.lean4
- match: '''(\\(x..|u....|.))''' - match: '''(\\(x[0-9A-Fa-f][0-9A-Fa-f]|u[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]|.))'''
scope: string.quoted.single.lean scope: string.quoted.single.lean4
captures: captures:
1: constant.character.escape.lean 1: constant.character.escape.lean4
- match: '`+[^\[(]\S+' - match: '`+[^\[(]\S+'
scope: entity.name.lean scope: entity.name.lean4
- match: '\b([0-9]+|0([xX][0-9a-fA-F]+))\b' - match: '\b([0-9]+|0([xX][0-9a-fA-F]+)|[-]?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?)\b'
scope: constant.numeric.lean scope: constant.numeric.lean4
blockComment: blockComment:
- match: /- - match: /-
push: push:
- meta_scope: comment.block.lean - meta_scope: comment.block.lean4
- match: "-/" - match: '-/'
pop: true pop: true
- include: scope:source.lean.markdown - include: scope:source.lean4.markdown
- include: blockComment - include: blockComment
comments: comments:
- include: dashComment - include: dashComment
- include: docComment - include: docComment
- include: stringBlock
- include: modDocComment - include: modDocComment
- include: blockComment - include: blockComment
dashComment: dashComment:
- match: (--) - match: '--'
captures:
0: punctuation.definition.comment.lean
push: push:
- meta_scope: comment.line.double-dash.lean - meta_scope: comment.line.double-dash.lean4
- match: $ - match: $
pop: true pop: true
- include: scope:source.lean.markdown - include: scope:source.lean4.markdown
definitionName: definitionName:
- match: '\b[^:«»\(\)\{\}[:space:]=→λ∀?][^:«»\(\)\{\}[:space:]]*' - match: '\b[^:«»\(\)\{\}[:space:]=→λ∀?][^:«»\(\)\{\}[:space:]]*'
scope: entity.name.function.lean scope: entity.name.function.lean4
- match: « - match: «
push: push:
- meta_content_scope: entity.name.function.lean - meta_content_scope: entity.name.function.lean4
- match: » - match: »
pop: true pop: true
docComment: docComment:
- match: /-- - match: /--
push: push:
- meta_scope: comment.block.documentation.lean - meta_scope: comment.block.documentation.lean4
- match: "-/" - match: '-/'
pop: true pop: true
- include: scope:source.lean.markdown - include: scope:source.lean4.markdown
- include: blockComment - include: blockComment
modDocComment: modDocComment:
- match: /-! - match: /-!
push: push:
- meta_scope: comment.block.documentation.lean - meta_scope: comment.block.documentation.lean4
- match: "-/" - match: '-/'
pop: true pop: true
- include: scope:source.lean.markdown - include: scope:source.lean4.markdown
- include: blockComment
stringBlock:
- match: /-"
push:
- meta_scope: comment.block.string.lean
- match: '"-/'
pop: true
- include: scope:source.lean.markdown
- include: blockComment - include: blockComment

View File

@@ -102,4 +102,4 @@ The following files have been manually modified after converting from a `.tmLang
https://github.com/seanjames777/SML-Language-Definition/blob/master/sml.tmLanguage https://github.com/seanjames777/SML-Language-Definition/blob/master/sml.tmLanguage
* `Cabal.sublime_syntax` has been added manually from * `Cabal.sublime_syntax` has been added manually from
https://github.com/SublimeHaskell/SublimeHaskell/ - we don't want to include the whole submodule because it includes other syntaxes ("Haskell improved") as well. https://github.com/SublimeHaskell/SublimeHaskell/ - we don't want to include the whole submodule because it includes other syntaxes ("Haskell improved") as well.
* `Lean.sublime-syntax` has been added manually from https://github.com/leanprover/vscode-lean/blob/master/syntaxes/lean.json via conversion. * `Lean.sublime-syntax` has been added manually from https://github.com/leanprover/vscode-lean4/blob/master/vscode-lean4/syntaxes/lean4.json via conversion.

View File

@@ -1,67 +1,82 @@
import data.matrix.notation import MIL.Common
import data.vector2 import Mathlib.Topology.Instances.Real.Defs
/-! open Set Filter Topology
Helpers that don't currently fit elsewhere... variable {α : Type*}
variable (s t : Set )
variable (ssubt : s t)
variable {α : Type*} (s : Set (Set α))
-- Apostrophes are allowed in variable names
variable (f'_x x' : )
variable (bangwI' jablu'DI' QaQqu' nay' Ghay'cha' he' : )
-/ -- In the next example we could use `tauto` in each proof instead of knowing the lemmas
example {α : Type*} (s : Set α) : Filter α :=
 { sets := { t | s t }
 univ_sets := subset_univ s
 sets_of_superset := fun hU hUV Subset.trans hU hUV
 inter_sets := fun hU hV subset_inter hU hV }
lemma split_eq {m n : Type*} (x : m × n) (p p' : m × n) :
 p = x p' = x (x p x p') := by tauto
-- For `playfield`s, the piece type and/or piece index type.
variables (X : Type*)
variables [has_repr X]
namespace chess.utils namespace chess.utils
section repr section repr
/-- @[class] structure One₂ (α : Type) where
An auxiliary wrapper for `option X` that allows for overriding the `has_repr` instance  /-- The element one -/
for `option`, and rather, output just the value in the `some` and a custom provided  one : α
`string` for `none`.
-/
structure option_wrapper :=
(val : option X)
(none_s : string)
instance wrapped_option_repr : has_repr (option_wrapper X) := structure StandardTwoSimplex where
λ val, s, (option.map has_repr.repr val).get_or_else s  x : 
 y : 
 z : 
 x_nonneg : 0 x
 y_nonneg : 0 y
 z_nonneg : 0 z
 sum_eq : x + y + z = 1
variables {X} #check Pi.ringHom
/-- #check ker_Pi_Quotient_mk
Construct an `option_wrapper` term from a provided `option X` and the `string` #eval 1 + 1
that will override the `has_repr.repr` for `none`.
-/
def option_wrap (val : option X) (none_s : string) : option_wrapper X := val, none_s
-- The size of the "vectors" for a `fin n' → X`, for `has_repr` definitions /-- The homomorphism from ``R ⨅ i, I i`` to ``Π i, R I i`` featured in the Chinese
variables {m' n' : }  Remainder Theorem. -/
def chineseMap (I : ι Ideal R) : (R i, I i) +* Π i, R I i :=
 Ideal.Quotient.lift ( i, I i) (Pi.ringHom fun i : ι Ideal.Quotient.mk (I i))
 (by simp [ RingHom.mem_ker, ker_Pi_Quotient_mk])
/-- lemma chineseMap_mk (I : ι Ideal R) (x : R) :
For a "vector" `X^n'` represented by the type `Π n' : , fin n' → X`, where  chineseMap I (Quotient.mk _ x) = fun i : ι Ideal.Quotient.mk (I i) x :=
the `X` has a `has_repr` instance itself, we can provide a `has_repr` for the "vector".  rfl
This definition is used for displaying rows of the playfield, when it is defined
via a `matrix`, likely through notation.
-/
def vec_repr : Π {n' : }, (fin n' X) string :=
λ _ v, string.intercalate ", " ((vector.of_fn v).to_list.map repr)
instance vec_repr_instance : has_repr (fin n' X) := vec_repr theorem isCoprime_Inf {I : Ideal R} {J : ι Ideal R} {s : Finset ι}
 (hf : j s, IsCoprime I (J j)) : IsCoprime I ( j s, J j) := by
 classical
 simp_rw [isCoprime_iff_add] at *
 induction s using Finset.induction with
 | empty =>
 simp
 | @insert i s _ hs =>
 rw [Finset.iInf_insert, inf_comm, one_eq_top, eq_top_iff, one_eq_top]
 set K := j s, J j
 calc
 1 = I + K := (hs fun j hj hf j (Finset.mem_insert_of_mem hj)).symm
 _ = I + K * (I + J i) := by rw [hf i (Finset.mem_insert_self i s), mul_one]
 _ = (1 + K) * I + K * J i := by ring
 _ I + K J i := by gcongr ; apply mul_le_left ; apply mul_le_inf
/--
For a `matrix` `X^(m' × n')` where the `X` has a `has_repr` instance itself,
we can provide a `has_repr` for the matrix, using `vec_repr` for each of the rows of the matrix.
This definition is used for displaying the playfield, when it is defined
via a `matrix`, likely through notation.
-/
def matrix_repr : Π {m' n'}, matrix (fin m') (fin n') X string :=
λ _ _ M, string.intercalate ";\n" ((vector.of_fn M).to_list.map repr)
instance matrix_repr_instance : class Ring₃ (R : Type) extends AddGroup₃ R, Monoid₃ R, MulZeroClass R where
 has_repr (matrix (fin n') (fin m') X) := matrix_repr  /-- Multiplication is left distributive over addition -/
 left_distrib : a b c : R, a * (b + c) = a * b + a * c
 /-- Multiplication is right distributive over addition -/
 right_distrib : a b c : R, (a + b) * c = a * c + b * c
instance {R : Type} [Ring₃ R] : AddCommGroup₃ R :=
{ Ring₃.toAddGroup₃ with
 add_comm := by
 sorry }
end repr end repr

View File

@@ -1,67 +1,82 @@
import data.matrix.notation import MIL.Common
import data.vector2 import Mathlib.Topology.Instances.Real.Defs
/-! open Set Filter Topology
Helpers that don't currently fit elsewhere... variable {α : Type*}
variable (s t : Set )
variable (ssubt : s t)
variable {α : Type*} (s : Set (Set α))
-- Apostrophes are allowed in variable names
variable (f'_x x' : )
variable (bangwI' jablu'DI' QaQqu' nay' Ghay'cha' he' : )
-/ -- In the next example we could use `tauto` in each proof instead of knowing the lemmas
example {α : Type*} (s : Set α) : Filter α :=
{ sets := { t | s t }
univ_sets := subset_univ s
sets_of_superset := fun hU hUV Subset.trans hU hUV
inter_sets := fun hU hV subset_inter hU hV }
lemma split_eq {m n : Type*} (x : m × n) (p p' : m × n) :
p = x p' = x (x p x p') := by tauto
-- For `playfield`s, the piece type and/or piece index type.
variables (X : Type*)
variables [has_repr X]
namespace chess.utils namespace chess.utils
section repr section repr
/-- @[class] structure One₂ (α : Type) where
An auxiliary wrapper for `option X` that allows for overriding the `has_repr` instance /-- The element one -/
for `option`, and rather, output just the value in the `some` and a custom provided one : α
`string` for `none`.
-/
structure option_wrapper :=
(val : option X)
(none_s : string)
instance wrapped_option_repr : has_repr (option_wrapper X) := structure StandardTwoSimplex where
λ val, s, (option.map has_repr.repr val).get_or_else s x :
y :
z :
x_nonneg : 0 x
y_nonneg : 0 y
z_nonneg : 0 z
sum_eq : x + y + z = 1
variables {X} #check Pi.ringHom
/-- #check ker_Pi_Quotient_mk
Construct an `option_wrapper` term from a provided `option X` and the `string` #eval 1 + 1
that will override the `has_repr.repr` for `none`.
-/
def option_wrap (val : option X) (none_s : string) : option_wrapper X := val, none_s
-- The size of the "vectors" for a `fin n' → X`, for `has_repr` definitions /-- The homomorphism from ``R ⨅ i, I i`` to ``Π i, R I i`` featured in the Chinese
variables {m' n' : } Remainder Theorem. -/
def chineseMap (I : ι Ideal R) : (R i, I i) +* Π i, R I i :=
Ideal.Quotient.lift ( i, I i) (Pi.ringHom fun i : ι Ideal.Quotient.mk (I i))
(by simp [ RingHom.mem_ker, ker_Pi_Quotient_mk])
/-- lemma chineseMap_mk (I : ι Ideal R) (x : R) :
For a "vector" `X^n'` represented by the type `Π n' : , fin n' → X`, where chineseMap I (Quotient.mk _ x) = fun i : ι Ideal.Quotient.mk (I i) x :=
the `X` has a `has_repr` instance itself, we can provide a `has_repr` for the "vector". rfl
This definition is used for displaying rows of the playfield, when it is defined
via a `matrix`, likely through notation.
-/
def vec_repr : Π {n' : }, (fin n' X) string :=
λ _ v, string.intercalate ", " ((vector.of_fn v).to_list.map repr)
instance vec_repr_instance : has_repr (fin n' X) := vec_repr theorem isCoprime_Inf {I : Ideal R} {J : ι Ideal R} {s : Finset ι}
(hf : j s, IsCoprime I (J j)) : IsCoprime I ( j s, J j) := by
classical
simp_rw [isCoprime_iff_add] at *
induction s using Finset.induction with
| empty =>
simp
| @insert i s _ hs =>
rw [Finset.iInf_insert, inf_comm, one_eq_top, eq_top_iff, one_eq_top]
set K := j s, J j
calc
1 = I + K := (hs fun j hj hf j (Finset.mem_insert_of_mem hj)).symm
_ = I + K * (I + J i) := by rw [hf i (Finset.mem_insert_self i s), mul_one]
_ = (1 + K) * I + K * J i := by ring
_ I + K J i := by gcongr ; apply mul_le_left ; apply mul_le_inf
/--
For a `matrix` `X^(m' × n')` where the `X` has a `has_repr` instance itself,
we can provide a `has_repr` for the matrix, using `vec_repr` for each of the rows of the matrix.
This definition is used for displaying the playfield, when it is defined
via a `matrix`, likely through notation.
-/
def matrix_repr : Π {m' n'}, matrix (fin m') (fin n') X string :=
λ _ _ M, string.intercalate ";\n" ((vector.of_fn M).to_list.map repr)
instance matrix_repr_instance : class Ring₃ (R : Type) extends AddGroup₃ R, Monoid₃ R, MulZeroClass R where
has_repr (matrix (fin n') (fin m') X) := matrix_repr /-- Multiplication is left distributive over addition -/
left_distrib : a b c : R, a * (b + c) = a * b + a * c
/-- Multiplication is right distributive over addition -/
right_distrib : a b c : R, (a + b) * c = a * c + b * c
instance {R : Type} [Ring₃ R] : AddCommGroup₃ R :=
{ Ring₃.toAddGroup₃ with
add_comm := by
sorry }
end repr end repr