From c1c043ef9aab2cbb02f4eba46c15d2d1fbb87550 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 2 Feb 2023 14:39:41 +0100 Subject: Add basic vim support --- example.snug | 79 ++++++++++++++++++++++++++++++++++++++++++++++ example.txt | 79 ---------------------------------------------- vim-snug/ftdetect/snug.vim | 1 + vim-snug/ftplugin/snug.vim | 26 +++++++++++++++ vim-snug/syntax/snug.vim | 39 +++++++++++++++++++++++ 5 files changed, 145 insertions(+), 79 deletions(-) create mode 100644 example.snug delete mode 100644 example.txt create mode 100644 vim-snug/ftdetect/snug.vim create mode 100644 vim-snug/ftplugin/snug.vim create mode 100644 vim-snug/syntax/snug.vim diff --git a/example.snug b/example.snug new file mode 100644 index 0000000..33d4dab --- /dev/null +++ b/example.snug @@ -0,0 +1,79 @@ +(data Tuple (a b) ( + (Tuple a b))) +(data List (a) ( + Nil + (Cons a (List a)))) +(type String (List Char)) + +(data TypeIdent ((TI String))) +(data TypeVarIdent ((TVI String))) +(data ConstructorIdent ((CI String))) +(data SymbolIdent ((SI String))) + +(data Type ( + (Type TypeIdent) + (TypeVar TypeVarIdent) + (TypeApp Type Type))) + +(data ConstructorDef ( + (ConstructorDef ConstructorIdent (List Type)))) + +(data BasicValue ( + (BVInt Int) + (BVChar Char))) + +(data Pattern ( + Wildcard + (BasicValuePattern BasicValue) + (IdentPattern SymbolIdent) + (ConstructorPattern ConstructorIdent (List Pattern)))) + +(data CaseAlternative ( + (CaseAlternative Pattern Expression))) + +(data Expression ( + (BasicValue BasicValue) + (Symbol SymbolIdent) + (Case Expression (List CaseAlternative)) + (ExpApp Expression Expression))) + +(data Definition ( + (DataDef TypeIdent (List TypeVarIdent) (List ConstructorDef)) + (FunDef SymbolIdent (List (Tuple SymbolIdent Type)) Type Expression))) + +(fun list_ast () : Definition : + DataDef + (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil)))) + (Cons (Cons 'a' Nil) Nil) + (Cons (ConstructorDef (Cons 'N' (Cons 'i' (Cons 'l' Nil))) Nil) + (Cons (ConstructorDef (Cons 'C' (Cons 'o' (Cons 'n' (Cons 's' Nil)))) (Cons (TypeVar (Cons 'a' Nil)) (Cons (TypeApp (Type (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))) (TypeVar (Cons 'a' Nil))) Nil))) + Nil))) +(fun length_acc_ast () : Definition : + FunDef + (Cons 'l' (Cons 'e' (Cons 'n' (Cons 'g' (Cons 't' (Cons 'h' (Cons '_' (Cons 'a' (Cons 'c' (Cons 'c' Nil)))))))))) + (Cons (Tuple (Cons 'n' Nil) (Type (Cons 'I' (Cons 'n' (Cons 't' Nil))))) + (Cons (Tuple (Cons 'x' (Cons 's' Nil)) (TypeApp (Type (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))) (TypeVar (Cons 'a' Nil)))) + Nil)) + (Type (Cons 'I' (Cons 'n' (Cons 't' Nil)))) + (Case (Symbol (Cons 'x' (Cons 's' Nil))) + (Cons (CaseAlternative + (ConstructorPattern (Cons 'N' (Cons 'i' (Cons 'l' Nil))) Nil) + (Symbol (Cons 'n' Nil))) + (Cons (CaseAlternative + (ConstructorPattern (Cons 'C' (Cons 'o' (Cons 'n' (Cons 's' Nil)))) (Cons Wildcard (Cons (IdentPattern (Cons 'x' (Cons 's' Nil))) Nil))) + (ExpApp (ExpApp (Symbol (Cons 'l' (Cons 'e' (Cons 'n' (Cons 'g' (Cons 't' (Cons 'h' (Cons '_' (Cons 'a' (Cons 'c' (Cons 'c' Nil))))))))))) (ExpApp (ExpApp (Cons '+' Nil) (Cons 'n' Nil)) (BasicValue (BVInt 1)))) (Cons 'x' (Cons 's' Nil)))) + Nil)))) + +(# +(fun length ((xs : List a)) : Int : + length_acc 0 xs) +(fun length_acc ((n : Int) (xs : List a)) : Int : + case xs ( + (Nil -> n) + (Cons _ xs -> length_acc (+ n 1) xs))) +#) + +(fun testb ((x : Int) (y : Char)) : Tuple Int Char : + Tuple x y) +(fun test () : Tuple Int Char : + testb 37 'a') diff --git a/example.txt b/example.txt deleted file mode 100644 index 33d4dab..0000000 --- a/example.txt +++ /dev/null @@ -1,79 +0,0 @@ -(data Tuple (a b) ( - (Tuple a b))) -(data List (a) ( - Nil - (Cons a (List a)))) -(type String (List Char)) - -(data TypeIdent ((TI String))) -(data TypeVarIdent ((TVI String))) -(data ConstructorIdent ((CI String))) -(data SymbolIdent ((SI String))) - -(data Type ( - (Type TypeIdent) - (TypeVar TypeVarIdent) - (TypeApp Type Type))) - -(data ConstructorDef ( - (ConstructorDef ConstructorIdent (List Type)))) - -(data BasicValue ( - (BVInt Int) - (BVChar Char))) - -(data Pattern ( - Wildcard - (BasicValuePattern BasicValue) - (IdentPattern SymbolIdent) - (ConstructorPattern ConstructorIdent (List Pattern)))) - -(data CaseAlternative ( - (CaseAlternative Pattern Expression))) - -(data Expression ( - (BasicValue BasicValue) - (Symbol SymbolIdent) - (Case Expression (List CaseAlternative)) - (ExpApp Expression Expression))) - -(data Definition ( - (DataDef TypeIdent (List TypeVarIdent) (List ConstructorDef)) - (FunDef SymbolIdent (List (Tuple SymbolIdent Type)) Type Expression))) - -(fun list_ast () : Definition : - DataDef - (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil)))) - (Cons (Cons 'a' Nil) Nil) - (Cons (ConstructorDef (Cons 'N' (Cons 'i' (Cons 'l' Nil))) Nil) - (Cons (ConstructorDef (Cons 'C' (Cons 'o' (Cons 'n' (Cons 's' Nil)))) (Cons (TypeVar (Cons 'a' Nil)) (Cons (TypeApp (Type (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))) (TypeVar (Cons 'a' Nil))) Nil))) - Nil))) -(fun length_acc_ast () : Definition : - FunDef - (Cons 'l' (Cons 'e' (Cons 'n' (Cons 'g' (Cons 't' (Cons 'h' (Cons '_' (Cons 'a' (Cons 'c' (Cons 'c' Nil)))))))))) - (Cons (Tuple (Cons 'n' Nil) (Type (Cons 'I' (Cons 'n' (Cons 't' Nil))))) - (Cons (Tuple (Cons 'x' (Cons 's' Nil)) (TypeApp (Type (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))) (TypeVar (Cons 'a' Nil)))) - Nil)) - (Type (Cons 'I' (Cons 'n' (Cons 't' Nil)))) - (Case (Symbol (Cons 'x' (Cons 's' Nil))) - (Cons (CaseAlternative - (ConstructorPattern (Cons 'N' (Cons 'i' (Cons 'l' Nil))) Nil) - (Symbol (Cons 'n' Nil))) - (Cons (CaseAlternative - (ConstructorPattern (Cons 'C' (Cons 'o' (Cons 'n' (Cons 's' Nil)))) (Cons Wildcard (Cons (IdentPattern (Cons 'x' (Cons 's' Nil))) Nil))) - (ExpApp (ExpApp (Symbol (Cons 'l' (Cons 'e' (Cons 'n' (Cons 'g' (Cons 't' (Cons 'h' (Cons '_' (Cons 'a' (Cons 'c' (Cons 'c' Nil))))))))))) (ExpApp (ExpApp (Cons '+' Nil) (Cons 'n' Nil)) (BasicValue (BVInt 1)))) (Cons 'x' (Cons 's' Nil)))) - Nil)))) - -(# -(fun length ((xs : List a)) : Int : - length_acc 0 xs) -(fun length_acc ((n : Int) (xs : List a)) : Int : - case xs ( - (Nil -> n) - (Cons _ xs -> length_acc (+ n 1) xs))) -#) - -(fun testb ((x : Int) (y : Char)) : Tuple Int Char : - Tuple x y) -(fun test () : Tuple Int Char : - testb 37 'a') diff --git a/vim-snug/ftdetect/snug.vim b/vim-snug/ftdetect/snug.vim new file mode 100644 index 0000000..07343d1 --- /dev/null +++ b/vim-snug/ftdetect/snug.vim @@ -0,0 +1 @@ +au BufNewFile,BufRead *.snug set filetype=snug diff --git a/vim-snug/ftplugin/snug.vim b/vim-snug/ftplugin/snug.vim new file mode 100644 index 0000000..c385573 --- /dev/null +++ b/vim-snug/ftplugin/snug.vim @@ -0,0 +1,26 @@ +" Vim plugin for snug development +" Language: Snug functional programing language +" Maintainer: Camil Staps +" License: This file is placed in the public domain. + +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +let s:cpo_save = &cpo +set cpo&vim + +let b:undo_ftplugin = "setlocal com< cms< fo< sua<" + +setlocal comments=sr:(#,m:\ ,ex:#) +setlocal commentstring=(#\ %s\ #) + +setlocal formatoptions-=t formatoptions+=cro + +setlocal suffixesadd=.snug + +let &cpo = s:cpo_save +unlet s:cpo_save + +" vim: expandtab shiftwidth=2 tabstop=2 diff --git a/vim-snug/syntax/snug.vim b/vim-snug/syntax/snug.vim new file mode 100644 index 0000000..0353f63 --- /dev/null +++ b/vim-snug/syntax/snug.vim @@ -0,0 +1,39 @@ +" Snug syntax file +" Language: Snug functional programing language +" Maintainer: Camil Staps +" License: This file is placed in the public domain. + +if exists("b:current_syntax") + finish +endif + +let s:cpo_save = &cpo +set cpo&vim + +syn keyword snugKeyword case data fun type + +syn keyword snugTodo TODO FIXME XXX BUG NB contained containedin=snugComment + +syn match snugChar /'[^'\\]'/ display +syn match snugInt /\d\+/ display + +syn match snugDelimiter /\v[\[\]\(\):;=,]/ display + +syn match snugIdentifier /^[_a-zA-Z]\+/ display + +syn region snugComment start="(#" end="#)" contains=@Spell,snugComment display + +hi def link snugKeyword Keyword +hi def link snugChar Character +hi def link snugInt Number +hi def link snugDelimiter Delimiter +hi def link snugIdentifier Identifier +hi def link snugTodo Todo +hi def link snugComment Comment + +syntax sync ccomment snugComment + +let b:current_syntax = 'snug' + +let &cpo = s:cpo_save +unlet s:cpo_save -- cgit v1.2.3