Skip to content

Instantly share code, notes, and snippets.

@Anderssorby
Created September 9, 2020 20:24
Show Gist options
  • Save Anderssorby/8d8957f563c12bd7cba9c6ddf731a522 to your computer and use it in GitHub Desktop.
Save Anderssorby/8d8957f563c12bd7cba9c6ddf731a522 to your computer and use it in GitHub Desktop.
A syntax file for the Formality language tweaked from Haskell syntax
" Vim syntax file
" Language: Formality
" Maintainer: Anders Christiansen Sørby <anders@sorby.xyz>
" Last Change: August 16. 2020
"
" Version: 2.0
" Url:
"
" Remove any old syntax stuff hanging around
if version < 600
syn clear
elseif exists("b:current_syntax")
finish
endif
" (Qualified) identifiers (no default highlighting)
syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[A-Z][a-zA-Z0-9_']*\>"
syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[a-z][a-zA-Z0-9_']*\>"
" Infix operators--most punctuation characters and any (qualified) identifier
" enclosed in `backquotes`. An operator starting with : is a constructor,
" others are variables (e.g. functions).
syn match fmVarSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[-!#$%&\*\+/<=>\?@\\^|~.][-!#$%&\*\+/<=>\?@\\^|~:.]*"
syn match fmConSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=:[-!#$%&\*\+./<=>\?@\\^|~:]*"
syn match fmVarSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[a-z][a-zA-Z0-9_']*`"
syn match fmConSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[A-Z][a-zA-Z0-9_']*`"
" Reserved symbols--cannot be overloaded.
syn match fmDelimiter "(\|)\|\[\|\]\|,\|;\|_\|{\|}"
" Strings and constants
syn match fmSpecialChar contained "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)"
syn match fmSpecialChar contained "\\\(NUL\|SOH\|STX\|ETX\|EOT\|ENQ\|ACK\|BEL\|BS\|HT\|LF\|VT\|FF\|CR\|SO\|SI\|DLE\|DC1\|DC2\|DC3\|DC4\|NAK\|SYN\|ETB\|CAN\|EM\|SUB\|ESC\|FS\|GS\|RS\|US\|SP\|DEL\)"
syn match fmSpecialCharError contained "\\&\|'''\+"
syn region fmString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=fmSpecialChar
syn match fmCharacter "[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=fmSpecialChar,fmSpecialCharError
syn match fmCharacter "^'\([^\\]\|\\[^']\+\|\\'\)'" contains=fmSpecialChar,fmSpecialCharError
syn match fmNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>"
syn match fmFloat "\<[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>"
" Keyword definitions. These must be patters instead of keywords
" because otherwise they would match as keywords at the start of a
" "literate" comment (see lfm.vim).
syn match fmModule "\<module\>"
syn match fmImport "\<import\>.*"he=s+6 contains=fmImportMod,fmString,fmType,fmFunction
syn match fmImportMod contained "\<\(as\|qualified\|hiding\)\>"
syn match fmInfix "\<\(infix\|infixl\|infixr\)\>"
syn match fmStructure "\<\(class\|data\|deriving\|instance\|default\|where\)\>"
syn match fmTypedef "\<\(T\)\>"
syn match fmStatement "\<\(do\|var\|def\|as\|return\|bind\|case\|of\|let\|in\)\>"
syn match fmConditional "\<\(if\|then\|else\)\>"
" Haskell 2010 keywords
syn match fmForeign "\<foreign\>"
" Types from the standard prelude.
syn match fmType "\<\(Bool\|Maybe\|Either\|Ordering\)\>"
syn match fmType "\<\(Char\|String\|Nat\|Int\|Integer\|Float\|Double\|Rational\|IO\|List\)\>"
syn match fmType "\<\(ReadS\|ShowS\)\>"
syn match fmType "\<\(FilePath\|IOError\)\>"
" Classes from the standard prelude
syn match fmType "\<\(Eq\|Ord\|Enum\|Bounded\|Num\|Real\|Integral\|Fractional\|Floating\|RealFrac\|RealFloat\|Monad\|Functor\)\>"
syn match fmType "\<\(Show\|Read\)\>"
" Constants from the standard prelude.
syn match fmBoolean "\<\(true\|false\)\>"
syn match fmMaybe "\<\(Nothing\|Just\)\>"
syn match fmConstant "\<\(Left\|Right\)\>"
syn match fmOrdering "\<\(Equal\|LT\|EQ\|GT\)\>"
" Functions from the standard prelude.
syn match fmFunction "\<\(compare\|max\|min\)\>"
syn match fmFunction "\<\(succ\|pred\|toEnum\|fromEnum\|enumFrom\|enumFromThen\|enumFromTo\|enumFromThenTo\)\>"
syn match fmFunction "\<\(minBound\|maxBound\)\>"
syn match fmFunction "\<\(negate\|abs\|signum\|fromInteger\)\>"
syn match fmFunction "\<toRational\>"
syn match fmFunction "\<\(quot\|rem\|div\|mod\|quotRem\|divMod\|toInteger\)\>"
syn match fmFunction "\<\(recip\|fromRational\)\>"
syn match fmFunction "\<\(pi\|exp\|log\|sqrt\|logBase\|sin\|cos\|tan\|asin\|acos\|atan\|sinh\|cosh\|tanh\|asinh\|acosh\|atanh\)\>"
syn match fmFunction "\<\(properFraction\|truncate\|round\|ceiling\|floor\)\>"
syn match fmFunction "\<\(floatRadix\|floatDigits\|floatRange\|decodeFloat\|encodeFloat\|exponent\|significand\|scaleFloat\|isNaN\|isInfinite\|isDenormalized\|isIEEE\|isNegativeZero\|atan2\)\>"
syn match fmFunction "\<\(return\|fail\)\>"
syn match fmFunction "\<\(fmap\)\>"
syn match fmFunction "\<\(mapM\|mapM_\|sequence\|sequence_\)\>"
syn match fmFunction "\<\(maybe\|either\)\>"
syn match fmFunction "\<\(not\|otherwise\)\>"
syn match fmFunction "\<\(subtract\|even\|odd\|gcd\|lcm\)\>"
syn match fmFunction "\<\(fromIntegral\|realToFrac\)\>"
syn match fmFunction "\<\(fst\|snd\|curry\|uncurry\|id\|const\|flip\|until\)\>"
syn match fmFunction "\<\(asTypeOf\|error\|undefined\)\>"
syn match fmFunction "\<\(seq\)\>"
syn match fmFunction "\<\(map\|filter\|concat\|concatMap\)\>"
syn match fmFunction "\<\(head\|last\|tail\|init\|null\|length\)\>"
syn match fmFunction "\<\(foldl\|foldl1\|scanl\|scanl1\|foldr\|foldr1\|scanr\|scanr1\)\>"
syn match fmFunction "\<\(iterate\|repeat\|replicate\|cycle\)\>"
syn match fmFunction "\<\(take\|drop\|splitAt\|takeWhile\|dropWhile\|span\|break\)\>"
syn match fmFunction "\<\(lines\|words\|unlines\|unwords\|reverse\|and\|or\)\>"
syn match fmFunction "\<\(any\|all\|elem\|notElem\|lookup\)\>"
syn match fmFunction "\<\(sum\|product\|maximum\|minimum\)\>"
syn match fmFunction "\<\(zip\|zip3\|zipWith\|zipWith3\|unzip\|unzip3\)\>"
syn match fmFunction "\<\(readsPrec\|readList\)\>"
syn match fmFunction "\<\(showsPrec\|show\|showList\)\>"
syn match fmFunction "\<\(reads\|shows\|read\|lex\)\>"
syn match fmFunction "\<\(showChar\|showString\|readParen\|showParen\)\>"
syn match fmFunction "\<\(ioError\|userError\|catch\)\>"
syn match fmFunction "\<\(putChar\|putStr\|putStrLn\|print\)\>"
syn match fmFunction "\<\(getChar\|getLine\|getContents\|interact\)\>"
syn match fmFunction "\<\(readFile\|writeFile\|appendFile\|readIO\|readLn\)\>"
" Comments
syn match fmLineComment "//.*"
syn region fmBlockComment start="#" end="#" contains=fmBlockComment
syn region fmPragma start="{-#" end="#-}"
" Literate comments--any line not starting with '>' is a comment.
if exists("b:fm_literate_comments")
syn region fmLiterateComment start="^" end="^>"
endif
if !exists("fm_minlines")
let fm_minlines = 50
endif
exec "syn sync lines=" . fm_minlines
if version >= 508 || !exists("did_fm_syntax_inits")
if version < 508
let did_fm_syntax_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
hi link fmModule fmStructure
hi link fmImport Include
hi link fmImportMod fmImport
hi link fmForeign fmImport
hi link fmInfix PreProc
hi link fmStructure Structure
hi link fmStatement Statement
hi link fmConditional Conditional
hi link fmSpecialChar SpecialChar
hi link fmTypedef Typedef
hi link fmVarSym fmOperator
hi link fmConSym fmOperator
hi link fmOperator Operator
hi link fmSpecialCharError Error
hi link fmString String
hi link fmCharacter Character
hi link fmNumber Number
hi link fmFloat Float
hi link fmConditional Conditional
hi link fmLiterateComment fmComment
hi link fmBlockComment fmComment
hi link fmLineComment fmComment
hi link fmComment Comment
hi link fmPragma SpecialComment
hi link fmBoolean Boolean
hi link fmType Type
hi link fmForeignType Type
hi link fmFunction Function
hi link fmMaybe fmEnumConst
hi link fmOrdering fmEnumConst
hi link fmEnumConst Constant
hi link fmConstant Constant
hi link fmDebug Debug
delcommand HiLink
endif
let b:current_syntax = "formality"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment