1"
2" Copyright 2017, NICTA
3"
4" This software may be distributed and modified according to the terms of
5" the GNU General Public License version 2. Note that NO WARRANTY is provided.
6" See "LICENSE_GPLv2.txt" for details.
7"
8" @TAG(NICTA_GPL)
9"
10
11" Vim syntax file
12" Language:		Cogent
13" Maintainer:		Zilin Chen <Zilin.Chen@data61.csiro.au>
14" Last Change:		10 Apr 2017
15" Original Author:	Zilin Chen <Zilin.Chen@data61.csiro.au>
16"
17"
18
19if exists("b:current_syntax")
20  finish
21endif
22 
23" Identifiers
24syn match cogentTypeId "\<[A-Z][a-zA-Z0-9_']*"
25syn match cogentVarDef "^[a-z_][a-zA-Z0-9_']*"
26syn match cogentFieldId "\<[a-z][a-zA-Z0-9_']*" contained nextgroup=cogentFieldColon skipwhite
27syn match cogentTag "[A-Z][a-zA-Z0-9_']*" contained nextgroup=cogentTypeId,cogentRecord,cogentVariant skipwhite
28
29" Definitions
30syn region cogentDefinition keepend start="^[a-z_][a-zA-Z0-9_']*\(.*=\|\s|\)"rs=s skip="\n\s" end="$" contains=cogentLetBang,cogentLineComment,cogentBlockComment,cogentBoolean,cogentSpecialChar,cogentCharacter,cogentString,cogentNumber,cogentOperator,cogentBar,cogentCaseArr,cogentSemiColon,cogentComma,cogentKeyword,cogentTypeId,cogentVarDef,cogentTakePut transparent
31syn match cogentLetBang "!\s*[a-z_][a-zA-Z0-9_']*" containedin=cogentDefinition contained
32syn region cogentTakePut start="{\|#{"rs=s end="}"re=e containedin=cogentDefinition contained contains=cogentLineComment,cogentBlockComment,cogentBoolean,cogentSpecialChar,cogentCharacter,cogentString,cogentNumber,cogentOperator,cogentBar,cogentCaseArr,cogentSemiColon,cogentComma,cogentKeyword,cogentTypeId,cogentTakePut,cogentOpenBrace,cogentCloseBrace,cogentLetBang transparent
33syn match cogentOpenBrace "{\|#{" containedin=cogentTakePut contained
34syn match cogentCloseBrace "}" containedin=cogenttakePut contained
35
36" Typedef's
37syn region cogentTypedef keepend matchgroup=Keyword start="^type\>" skip="\n\s" end="$" contains=cogentTypedefTypeId,cogentTypedefEq,cogentTypeType,cogentLineComment,cogentBlockComment transparent
38" syn keyword cogentTypedefTypeKw type nextgroup=cogentTypedefTypeId skipwhite contained
39syn match cogentTypedefTypeId "[A-Z][a-zA-Z0-9_']*" nextgroup=cogentTypedefEq skipwhite contained
40syn match cogentTypedefEq "=" nextgroup=cogentTypeType skipwhite contained
41
42" Type signatures
43syn region cogentTypeSig keepend matchgroup=Identifier start="^[a-z_][a-zA-Z0-9_']*\s*\(:\)\@=" skip="\n\s" end="$" contains=cogentTypeSigColon,cogentTypeType,cogentLineComment,cogentBlockComment transparent
44" syn match cogentTypeSigVarId "^[a-z][a-zA-Z0-9_']*" nextgroup=cogentTypeSigColon skipwhite contained
45syn match cogentTypeSigColon ":" nextgroup=cogentTypeType skipwhite contained
46
47syn region cogentTypeType start="." keepend skip="\n\s" end="$" contains=cogentKindSig,cogentTypeId,cogentRecord,cogentVariant,cogentAllT,cogentArrowT,cogentUnitT,cogentTakeT,cogentBangT,cogentUnboxT,cogentLineComment,cogentBlockComment transparent contained
48
49syn region cogentKindSig matchgroup=PreProc start="\<all\>" keepend skip="\n\s" matchgroup=NONE end="\." contains=cogentInKind,cogentKinds,cogentLineComment,cogentBlockComment transparent contained
50
51
52" Type constructors
53syn region cogentRecord start="{" end="}" contains=cogentKindSig,cogentFieldId,cogentTypeId,cogentFieldColon,cogentRecord,cogentVariant,cogentUnitT,cogentArrowT,cogentBangT,cogentUnboxT,cogentTakeT,cogentLineComment,cogentBlockComment transparent contained
54syn region cogentVariant start="<" end=">" contains=cogentVariantBar,cogentTag,cogentTypeId,cogentRecord,cogentVariant,cogentUnitT,cogentAllT,cogentArrowT,cogentBangT,cogentUnboxT,cogentTakeT,cogentLineComment,cogentBlockComment transparent contained
55syn match cogentUnitT "()" contained
56syn match cogentArrowT "->" contained
57syn match cogentBangT "!" contained
58syn match cogentUnboxT "#" contained
59syn keyword cogentTakeT take put contained
60syn match cogentInKind ":<" contained
61syn match cogentKinds "[DES]" contained nextgroup=cogentComma,cogentCloseParens,cogentDot
62syn match cogentVariantBar "|" contained
63
64syn match cogentCloseParens ")"
65syn match cogentDot "\."
66
67syn match cogentFieldColon contained ":"
68
69" " Constants
70" syn match cogentBoolean "\<\(True\|False\)\>"
71" syn match cogentSpecialChar "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)"
72" syn match cogentCharacter "[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=cogentSpecialChar
73" syn match cogentCharacter "^'\([^\\]\|\\[^']\+\|\\'\)'" contains=cogentSpecialChar
74" syn region cogentString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=cogentSpecialChar
75" syn match cogentNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>"
76
77" Delimiter
78syn match cogentBar "|"
79syn match cogentCaseArr "\m\(->\|=>\|\~>\)"
80syn match cogentSemiColon ";"
81syn match cogentComma ","
82
83" Operators
84syn match cogentOperator "[+\-*/%><]\([^+\-*/%><]\|\n\)"he=s+1
85syn match cogentOperator ">=\|<=\|==\|/=\|&&\|||\|\.&\.\|\.|\.\|\.\^\.\|>>\|<<"
86syn keyword cogentOperator not complement
87
88" Keywords
89" syn keyword cogentType type
90" syn keyword cogentInclude include
91syn keyword cogentKeyword and in if then else let
92
93" Comments
94syn keyword cogentDev contained TODO FIXME XXX NOTE ASSERT containedin=cogentLineComment,cogentBlockComment
95
96syn match   cogentLineComment      "--.*$" contains=cogentDev
97syn region  cogentBlockComment     start="{-"  end="-}" contains=cogentBlockComment,cogentDev
98
99" Include
100syn match  cogentIncludeLine display "^include\>\s*["<]" contains=cogentIncludeStr
101syn region cogentIncludeStr display start=+"+ skip=+\\\\\|\\+ end=+"+
102syn match  cogentIncludeStr display contained "<[^>]*>" containedin=cogentIncludeLine
103
104
105command -nargs=+ HiLink hi def link <args>
106
107HiLink cogentType			    Keyword
108HiLink cogentInclude			Keyword
109HiLink cogentKeyword			Keyword
110HiLink cogentDev				Todo
111
112HiLink cogentTypdefTypeKw		Keyword
113HiLink cogentTypdefTypeId		Type
114
115HiLink cogentTypeSigVarId		Identifier
116
117HiLink cogentTypeId             Type
118HiLink cogentTakeT		        PreProc
119HiLink cogentUnitT              PreProc
120HiLink cogentArrowT		    	PreProc
121HiLink cogentBangT              PreProc
122HiLink cogentUnboxT		    	PreProc
123HiLink cogentInKind		    	PreProc
124HiLink cogentVariantBar	        PreProc
125
126HiLink cogentKinds			    PreProc
127
128HiLink cogentLetBang			PreProc
129
130HiLink cogentOpenBrace		    Keyword
131HiLink cogentCloseBrace     	Keyword
132
133HiLink cogentVarDef		        Identifier
134
135HiLink cogentBoolean			Boolean
136HiLink cogentSpecialChar	    SpecialChar
137HiLink cogentCharacter		    Character
138HiLink cogentString			    String
139HiLink cogentNumber			    Number
140
141HiLink cogentOperator			Special
142
143" HiLink cogentFieldId			Tag
144HiLink cogentTag				Tag
145
146HiLink cogentBlockComment		Comment
147HiLink cogentLineComment        Comment
148
149HiLink cogentIncludeStr         String
150HiLink cogentIncludeLine        Keyword
151
152delcommand HiLink
153
154
155let b:current_syntax = "cogent"
156