Skip to content

Commit

Permalink
Highlight and indent Rewrite Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
whonore committed Sep 17, 2024
1 parent e9097cd commit 72c3411
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased ([main])

### Added
- Basic support for `Rewrite Rule` syntax highlighting and indentation.
(PR #373)

### Fixed
- Correctly execute commands containing quotes (e.g., `Coq Check a'`).
(PR #371)
Expand Down
4 changes: 3 additions & 1 deletion indent/coq.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ let s:bullet = '[-+*]\+)\@!'
let s:bulletline = '^\s*' . s:bullet
let s:match = '\<\%(lazy\|multi\)\?match\>'
let s:inductive = '\%(\%(Co\)\?Inductive\|Variant\)'
let s:rewrite = '\<Rewrite\_s\+Rule\>'
let s:vbar_cmd = '\%(' . s:inductive . '\|' . s:rewrite . '\)'
let s:lineend = '\s*$'

" Match syntax groups.
Expand Down Expand Up @@ -243,7 +245,7 @@ function! s:GetCoqIndent() abort
if l:currentline =~# '^\s*|[|}]\@!'
let l:match = s:indent_of_previous_pair(s:match, '', '\<end\>', 1, ['string', 'comment'])
let l:off = get(g:, 'coqtail_inductive_shift', 1) * &sw
return l:match != -1 ? l:match : s:indent_of_previous('^\s*' . s:inductive) + l:off
return l:match != -1 ? l:match : s:indent_of_previous('^\s*' . s:vbar_cmd) + l:off
endif

" current line begins with terminating '|}', '}', or ')'
Expand Down
5 changes: 4 additions & 1 deletion syntax/coq.vim
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ syn region coqBinderTypeParen contained contains=@coqTerm matchgroup=coqVernac
syn region coqBinderTypeCurly contained contains=@coqTerm matchgroup=coqVernacPunctuation start=":" end="}"

" Declarations
syn region coqDecl contains=coqIdent,coqDeclTerm,coqBinder matchgroup=coqVernacCmd start="\<\%(Axioms\?\|Conjectures\?\|Hypothes[ie]s\|Parameters\?\|Variables\?\|Context\)\>" matchgroup=coqVernacCmd end="\.\_s" keepend
syn region coqDecl contains=coqIdent,coqDeclTerm,coqBinder matchgroup=coqVernacCmd start="\<\%(Axioms\?\|Conjectures\?\|Hypothes[ie]s\|Parameters\?\|Variables\?\|Context\|Symbols\?\)\>" matchgroup=coqVernacCmd end="\.\_s" keepend
syn region coqDeclTerm contained contains=@coqTerm matchgroup=coqVernacPunctuation start=":" end=")"
syn region coqDeclTerm contained contains=@coqTerm matchgroup=coqVernacPunctuation start=":" end="\.\_s"

Expand Down Expand Up @@ -491,6 +491,9 @@ syn region elpiString contained start=+"+ skip=+\\"+ end=+"+ extend
syn match elpiMode contained "\<[io]:"
syn match elpiNumber contained "[0-9]\+"

" Rewrite Rules
syn region coqRewrite contains=coqIdent,coqVernacPunctuation,coqLtacContents matchgroup=coqVernacCmd start="\<Rewrite\_s\+Rule\>" end="\.\_s" keepend

" Various (High priority)
syn region coqComment containedin=ALLBUT,coqString contains=coqComment,coqTodo,@Spell start="(\*" end="\*)" extend keepend
syn keyword coqTodo contained TODO FIXME XXX NOTE
Expand Down
19 changes: 19 additions & 0 deletions tests/vim/indent.vader
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ Expect coq (indented-inductive-shift):
Execute (indent-inductive-shift-option-post):
unlet g:coqtail_inductive_shift

Given coq (rewrite):
Rewrite Rule pplus_rewrite :=
| ?n ++ 0 => ?n
| ?n ++ S ?m =>
S (?n ++ ?m)
| 0 ++ ?n => ?n
| S ?n ++ ?m => S (?n ++ ?m).

Do (indent-rewrite):
=ip

Expect coq (indented-rewrite):
Rewrite Rule pplus_rewrite :=
| ?n ++ 0 => ?n
| ?n ++ S ?m =>
S (?n ++ ?m)
| 0 ++ ?n => ?n
| S ?n ++ ?m => S (?n ++ ?m).

Given coq (match):
Definition f (b : bool) :=
match b with
Expand Down

0 comments on commit 72c3411

Please sign in to comment.