]> gitweb.factorcode.org Git - factor.git/blob - misc/vim/syntax/factor.vim
Solution to Project Euler problem 65
[factor.git] / misc / vim / syntax / factor.vim
1
2 " Vim syntax file
3 " Language: factor
4 " Maintainer: Alex Chapman <chapman.alex@gmail.com>
5 " Last Change: 2009 May 19
6 " To run: USE: html.templates.fhtml "resource:misc/factor.vim.fgen" <fhtml> call-template
7
8 " For version 5.x: Clear all syntax items
9 " For version 6.x: Quit when a syntax file was already loaded
10 if version < 600
11     syntax clear
12 elseif exists("b:current_syntax")
13     finish
14 endif
15
16 " factor is case sensitive.
17 syn case match
18
19 " make all of these characters part of a word (useful for skipping over words with w, e, and b)
20 if version >= 600
21     setlocal iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
22 else
23     set iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
24 endif
25
26 syn cluster factorCluster contains=factorComment,factorKeyword,factorRepeat,factorConditional,factorBoolean,factorCompileDirective,factorString,factorSbuf,@factorNumber,@factorNumErr,factorDelimiter,factorChar,factorCharErr,factorBackslash,@factorWordOps,factorAlien,factorTuple
27
28 syn match factorTodo /\(TODO\|FIXME\|XXX\):\=/ contained
29 syn match factorComment /\<#! .*/ contains=factorTodo
30 syn match factorComment /\<! .*/ contains=factorTodo
31
32 syn cluster factorDefnContents contains=@factorCluster,factorStackEffect,factorLiteralStackEffect,factorArray0,factorQuotation0
33
34 syn region factorDefn matchgroup=factorDefnDelims start=/\<\(SYNTAX\|\(MACRO\|MEMO\)\?:\?\):\s\+\S\+\>/ end=/\<;\>/ contains=@factorDefnContents
35 syn region factorMethod matchgroup=factorMethodDelims start=/\<M::\?\s\+\S\+\s\+\S\+\>/ end=/\<;\>/ contains=@factorDefnContents
36 syn region factorGeneric matchgroup=factorGenericDelims start=/\<GENERIC:\s\+\S\+\>/ end=/$/ contains=factorStackEffect
37 syn region factorGenericN matchgroup=factorGenericNDelims start=/\<GENERIC#\s\+\S\+\s\+\d\+\>/ end=/$/ contains=factorStackEffect
38
39 syn region factorPrivateDefn matchgroup=factorPrivateDefnDelims start=/\<\(SYNTAX\|\(MACRO\|MEMO\)\?:\?\):\s\+\S\+\>/ end=/\<;\>/ contains=@factorDefnContents contained
40 syn region factorPrivateMethod matchgroup=factorPrivateMethodDelims start=/\<M::\?\s\+\S\+\s\+\S\+\>/ end=/\<;\>/ contains=@factorDefnContents contained
41 syn region factorPGeneric matchgroup=factorPGenericDelims start=/\<GENERIC:\s\+\S\+\>/ end=/$/ contains=factorStackEffect contained
42 syn region factorPGenericN matchgroup=factorPGenericNDelims start=/\<GENERIC#\s\+\S\+\s\+\d\+\>/ end=/$/ contains=factorStackEffect
43
44 syn region None matchgroup=factorPrivate start=/\<<PRIVATE\>/ end=/\<PRIVATE>\>/ contains=@factorDefnContents,factorPrivateDefn,factorPrivateMethod,factorPGeneric,factorPGenericN
45
46
47 syn keyword factorBoolean boolean f general-t t
48 syn keyword factorCompileDirective inline foldable recursive
49
50 syn keyword factorKeyword or tuck 2bi 2tri while wrapper nip 4dip wrapper? bi* callstack>array both? hashcode die dupd callstack callstack? 3dup tri@ pick curry build ?execute 3bi prepose >boolean ?if clone eq? tri* ? = swapd call-clear 2over 2keep 3keep clear 2dup when not tuple? dup 2bi* 2tri* call tri-curry object bi@ do unless* if* loop bi-curry* drop when* assert= retainstack assert? -rot execute 2bi@ 2tri@ boa with either? 3drop bi curry? datastack until 3dip over 3curry roll tri-curry* swap tri-curry@ 2nip and throw set-retainstack bi-curry (clone) hashcode* compose spin 2dip if 3tri unless compose? tuple keep 2curry equal? set-datastack assert tri 2drop most <wrapper> boolean? identity-tuple? null new set-callstack dip bi-curry@ rot -roll xor identity-tuple boolean
51 syn keyword factorKeyword ?at assoc? assoc-clone-like assoc= delete-at* assoc-partition extract-keys new-assoc value? assoc-size map>assoc push-at assoc-like key? assoc-intersect assoc-refine update assoc-union assoc-combine at* assoc-empty? at+ set-at assoc-all? assoc-subset? assoc-hashcode change-at assoc-each assoc-diff zip values value-at rename-at inc-at enum? at cache assoc>map <enum> assoc assoc-map enum value-at* remove-all assoc-map-as >alist assoc-filter-as substitute-here clear-assoc assoc-stack maybe-set-at substitute assoc-filter 2cache delete-at assoc-find keys assoc-any? unzip
52 syn keyword factorKeyword case execute-effect no-cond no-case? 3cleave>quot 2cleave cond>quot wrong-values? no-cond? cleave>quot no-case case>quot 3cleave wrong-values to-fixed-point alist>quot case-find cond cleave call-effect 2cleave>quot recursive-hashcode linear-case-quot spread spread>quot
53 syn keyword factorKeyword byte-array>bignum sgn >bignum next-float number= each-integer next-power-of-2 ?1+ fp-special? imaginary-part mod recip float>bits rational >float number? 2^ bignum? integer fixnum? neg fixnum sq bignum fp-snan? fp-infinity? denominator (all-integers?) times find-last-integer (each-integer) bit? * + fp-bitwise= - fp-qnan? / power-of-2? >= bitand find-integer complex <fp-nan> < log2 > integer? real number bits>double double>bits bitor 2/ zero? rem fp-nan-payload all-integers? (find-integer) real-part prev-float align bits>float float? shift float fp-nan? abs bitxor ratio? even? <= /mod odd? >integer ratio rational? bitnot real? >fixnum complex? /i numerator /f
54 syn keyword factorKeyword append assert-sequence= find-last-from trim-head-slice clone-like 3sequence assert-sequence? map-as filter-here last-index-from reversed index-from cut* pad-tail (indices) concat-as remq but-last snip trim-tail nths nth 2pusher sequence slice? <slice> partition remove-nth tail-slice empty? tail* if-empty find-from virtual-sequence? member? set-length delq drop-prefix unclip iota unclip-last-slice bounds-error? sequence-hashcode-step map start midpoint@ rest-slice prepend fourth sift delete sigma new-sequence follow like delete-nth first4 1sequence reverse slice unless-empty padding virtual@ repetition? set-last index 4sequence max-length set-second immutable-sequence first2 first3 replicate-as reduce-index unclip-slice supremum insert-nth trim-tail-slice tail 3append short count suffix concat flip filter sum immutable? 2sequence map-integers delete-all start* indices snip-slice check-slice sequence? head map-find reduce append-as reverse-here sequence= halves collapse-slice interleave 2map binary-reduce virtual-seq slice-error? product bounds-check? bounds-check harvest immutable find produce remove pad-head last replicate set-fourth shorten reversed? map-find-last 3map-as 2unclip-slice shorter? 3map find-last head-slice pop* 2map-as tail-slice* but-last-slice 2map-reduce iota? accumulate each pusher cut-slice new-resizable each-index head-slice* 2reverse-each sequence-hashcode memq? pop set-nth ?nth <flat-slice> second change-each join when-empty accumulator immutable-sequence? <reversed> all? 3append-as virtual-sequence subseq? push-either new-like length last-index push-if 2all? lengthen assert-sequence copy map-reduce move third first 3each tail? set-first prefix bounds-error any? <repetition> trim-slice exchange surround 2reduce cut change-nth min-length set-third produce-as push-all head? delete-slice rest sum-lengths 2each head* infimum glue slice-error subseq replace-slice push repetition map-index trim-head unclip-last mismatch trim
55 syn keyword factorKeyword global +@ change set-namestack change-global init-namespaces on off set-global namespace set with-scope bind with-variable inc dec counter initialize namestack get get-global make-assoc
56 syn keyword factorKeyword <array> 2array 3array pair >array 1array 4array pair? array resize-array array?
57 syn keyword factorKeyword +character+ bad-seek-type? readln stream-seek read print with-output-stream contents write1 stream-write1 stream-copy stream-element-type with-input-stream stream-print stream-read stream-contents bl seek-output bad-seek-type nl stream-nl write flush stream-lines +byte+ stream-flush read1 seek-absolute? stream-read1 lines stream-readln stream-read-until each-line seek-end with-output-stream* seek-absolute with-streams seek-input seek-relative? input-stream stream-write read-partial seek-end? seek-relative error-stream read-until with-input-stream* with-streams* each-block output-stream stream-read-partial
58 syn keyword factorKeyword resize-string >string <string> 1string string string?
59 syn keyword factorKeyword vector? <vector> ?push vector >vector 1vector
60 syn keyword factorKeyword with-return restarts return-continuation with-datastack recover rethrow-restarts <restart> ifcc set-catchstack >continuation< cleanup ignore-errors restart? compute-restarts attempt-all-error error-thread continue <continuation> attempt-all-error? condition? <condition> throw-restarts error catchstack continue-with thread-error-hook continuation rethrow callcc1 error-continuation callcc0 attempt-all condition continuation? restart return
61
62
63 syn cluster factorReal          contains=factorInt,factorFloat,factorRatio,factorBinary,factorHex,factorOctal
64 syn cluster factorNumber        contains=@factorReal,factorComplex
65 syn cluster factorNumErr        contains=factorBinErr,factorHexErr,factorOctErr
66 syn match   factorInt           /\<-\=\d\+\>/
67 syn match   factorFloat         /\<-\=\d*\.\d\+\>/
68 syn match   factorRatio         /\<-\=\d*\.*\d\+\/-\=\d*\.*\d\+\>/
69 syn region  factorComplex       start=/\<C{\>/ end=/\<}\>/ contains=@factorReal
70 syn match   factorBinErr        /\<BIN:\s\+[01]*[^\s01]\S*\>/
71 syn match   factorBinary        /\<BIN:\s\+[01]\+\>/
72 syn match   factorHexErr        /\<HEX:\s\+\x*[^\x\s]\S*\>/
73 syn match   factorHex           /\<HEX:\s\+\x\+\>/
74 syn match   factorOctErr        /\<OCT:\s\+\o*[^\o\s]\S*\>/
75 syn match   factorOctal         /\<OCT:\s\+\o\+\>/
76
77 syn match   factorIn            /\<IN:\s\+\S\+\>/
78 syn match   factorUse           /\<USE:\s\+\S\+\>/
79 syn match   factorUnuse         /\<UNUSE:\s\+\S\+\>/
80
81 syn match   factorCharErr       /\<CHAR:\s\+\S\+/
82 syn match   factorChar          /\<CHAR:\s\+\\\=\S\>/
83
84 syn match   factorBackslash     /\<\\\>\s\+\S\+\>/
85
86 syn region  factorUsing         start=/\<USING:\>/       end=/;/
87 syn region  factorSingletons    start=/\<SINGLETONS:\>/  end=/;/
88 syn match   factorSymbol        /\<SYMBOL:\s\+\S\+\>/
89 syn region  factorSymbols       start=/\<SYMBOLS:\>/     end=/;/
90 syn region  factorConstructor2  start=/\<CONSTRUCTOR:\?/ end=/;/
91 syn region  factorTuple         start=/\<TUPLE:\>/ end=/\<;\>/
92
93 syn match   factorConstant      /\<CONSTANT:\s\+\S\+\>/
94 syn match   factorSingleton     /\<SINGLETON:\s\+\S\+\>/
95 syn match   factorPostpone      /\<POSTPONE:\s\+\S\+\>/
96 syn match   factorDefer         /\<DEFER:\s\+\S\+\>/
97 syn match   factorForget        /\<FORGET:\s\+\S\+\>/
98 syn match   factorMixin         /\<MIXIN:\s\+\S\+\>/
99 syn match   factorInstance      /\<INSTANCE:\s\+\S\+\s\+\S\+\>/
100 syn match   factorHook          /\<HOOK:\s\+\S\+\s\+\S\+\>/
101 syn match   factorMain          /\<MAIN:\s\+\S\+\>/
102 syn match   factorConstructor   /\<C:\s\+\S\+\s\+\S\+\>/
103 syn match   factorAlien         /\<ALIEN:\s\+\d\+\>/
104
105 syn cluster factorWordOps       contains=factorSymbol,factorPostpone,factorDefer,factorForget,factorMixin,factorInstance,factorHook,factorMain,factorConstructor
106
107
108 "TODO:
109 "misc:
110 " HELP:
111 " ARTICLE:
112 "literals:
113 " PRIMITIVE:
114
115 "C interface:
116 " FIELD:
117 " BEGIN-STRUCT:
118 " C-ENUM:
119 " FUNCTION:
120 " END-STRUCT
121 " DLL"
122 " TYPEDEF:
123 " LIBRARY:
124 " C-UNION:
125 "QUALIFIED:
126 "QUALIFIED-WITH:
127 "FROM:
128 "ALIAS:
129 "! POSTPONE: "
130 "#\ "
131
132 syn region factorString start=/"/ skip=/\\"/ end=/"/ oneline
133 syn region factorSbuf start=/SBUF" / skip=/\\"/ end=/"/ oneline
134
135 syn region factorMultiString matchgroup=factorMultiStringDelims start=/\<STRING:\s\+\S\+\>/ end=/^;$/ contains=factorMultiStringContents
136 syn match factorMultiStringContents /.*/ contained
137
138 "syn match factorStackEffectErr /\<)\>/
139 "syn region factorStackEffectErr start=/\<(\>/ end=/\<)\>/
140 "syn region factorStackEffect start=/\<(\>/ end=/\<)\>/ contained
141 syn match factorStackEffect /\<( .*--.* )\>/ contained
142 syn match factorLiteralStackEffect /\<(( .*--.* ))\>/
143
144 "adapted from lisp.vim
145 if exists("g:factor_norainbow") 
146     syn region factorQuotation matchgroup=factorDelimiter start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ matchgroup=factorDelimiter end=/\<\]\>/ contains=ALL
147 else
148     syn region factorQuotation0           matchgroup=hlLevel0 start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ end=/\<\]\>/ contains=@factorCluster,factorQuotation1,factorArray1
149     syn region factorQuotation1 contained matchgroup=hlLevel1 start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ end=/\<\]\>/ contains=@factorCluster,factorQuotation2,factorArray2
150     syn region factorQuotation2 contained matchgroup=hlLevel2 start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ end=/\<\]\>/ contains=@factorCluster,factorQuotation3,factorArray3
151     syn region factorQuotation3 contained matchgroup=hlLevel3 start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ end=/\<\]\>/ contains=@factorCluster,factorQuotation4,factorArray4
152     syn region factorQuotation4 contained matchgroup=hlLevel4 start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ end=/\<\]\>/ contains=@factorCluster,factorQuotation5,factorArray5
153     syn region factorQuotation5 contained matchgroup=hlLevel5 start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ end=/\<\]\>/ contains=@factorCluster,factorQuotation6,factorArray6
154     syn region factorQuotation6 contained matchgroup=hlLevel6 start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ end=/\<\]\>/ contains=@factorCluster,factorQuotation7,factorArray7
155     syn region factorQuotation7 contained matchgroup=hlLevel7 start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ end=/\<\]\>/ contains=@factorCluster,factorQuotation8,factorArray8
156     syn region factorQuotation8 contained matchgroup=hlLevel8 start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ end=/\<\]\>/ contains=@factorCluster,factorQuotation9,factorArray9
157     syn region factorQuotation9 contained matchgroup=hlLevel9 start=/\<\(\('\|\$\|\)\[\)\|\[\(let\||\)\>/ end=/\<\]\>/ contains=@factorCluster,factorQuotation0,factorArray0
158 endif
159
160 if exists("g:factor_norainbow") 
161     syn region factorArray    matchgroup=factorDelimiter start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/  matchgroup=factorDelimiter end=/\<}\>/ contains=ALL
162 else
163     syn region factorArray0           matchgroup=hlLevel0 start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/ end=/\<}\>/ contains=@factorCluster,factorArray1,factorQuotation1
164     syn region factorArray1 contained matchgroup=hlLevel1 start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/ end=/\<}\>/ contains=@factorCluster,factorArray2,factorQuotation2
165     syn region factorArray2 contained matchgroup=hlLevel2 start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/ end=/\<}\>/ contains=@factorCluster,factorArray3,factorQuotation3
166     syn region factorArray3 contained matchgroup=hlLevel3 start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/ end=/\<}\>/ contains=@factorCluster,factorArray4,factorQuotation4
167     syn region factorArray4 contained matchgroup=hlLevel4 start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/ end=/\<}\>/ contains=@factorCluster,factorArray5,factorQuotation5
168     syn region factorArray5 contained matchgroup=hlLevel5 start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/ end=/\<}\>/ contains=@factorCluster,factorArray6,factorQuotation6
169     syn region factorArray6 contained matchgroup=hlLevel6 start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/ end=/\<}\>/ contains=@factorCluster,factorArray7,factorQuotation7
170     syn region factorArray7 contained matchgroup=hlLevel7 start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/ end=/\<}\>/ contains=@factorCluster,factorArray8,factorQuotation8
171     syn region factorArray8 contained matchgroup=hlLevel8 start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/ end=/\<}\>/ contains=@factorCluster,factorArray9,factorQuotation9
172     syn region factorArray9 contained matchgroup=hlLevel9 start=/\<\(V\|H\|T\|W\|F\|B\|\$\)\?{\>/ end=/\<}\>/ contains=@factorCluster,factorArray0,factorQuotation0
173 endif
174
175 syn match factorBracketErr /\<\]\>/
176 syn match factorBracketErr /\<}\>/
177
178 syn sync lines=100
179
180 if version >= 508 || !exists("did_factor_syn_inits")
181     if version <= 508
182         let did_factor_syn_inits = 1
183         command -nargs=+ HiLink hi link <args>
184     else
185         command -nargs=+ HiLink hi def link <args>
186     endif
187
188     HiLink factorComment                Comment
189     HiLink factorStackEffect            Typedef
190     HiLink factorLiteralStackEffect     Typedef
191     HiLink factorTodo                   Todo
192     HiLink factorInclude                Include
193     HiLink factorRepeat                 Repeat
194     HiLink factorConditional            Conditional
195     HiLink factorKeyword                Keyword
196     HiLink factorOperator               Operator
197     HiLink factorBoolean                Boolean
198     HiLink factorDefnDelims             Typedef
199     HiLink factorMethodDelims           Typedef
200     HiLink factorGenericDelims          Typedef
201     HiLink factorGenericNDelims         Typedef
202     HiLink factorConstructor            Typedef
203     HiLink factorConstructor2           Typedef
204     HiLink factorPrivate                Special
205     HiLink factorPrivateDefnDelims      Special
206     HiLink factorPrivateMethodDelims    Special
207     HiLink factorPGenericDelims         Special
208     HiLink factorPGenericNDelims        Special
209     HiLink factorString                 String
210     HiLink factorSbuf                   String
211     HiLink factorMultiStringContents    String
212     HiLink factorMultiStringDelims      Typedef
213     HiLink factorBracketErr             Error
214     HiLink factorComplex                Number
215     HiLink factorRatio                  Number
216     HiLink factorBinary                 Number
217     HiLink factorBinErr                 Error
218     HiLink factorHex                    Number
219     HiLink factorHexErr                 Error
220     HiLink factorOctal                  Number
221     HiLink factorOctErr                 Error
222     HiLink factorFloat                  Float
223     HiLink factorInt                    Number
224     HiLink factorUsing                  Include
225     HiLink factorUse                    Include
226     HiLink factorUnuse                  Include
227     HiLink factorIn                     Define
228     HiLink factorChar                   Character
229     HiLink factorCharErr                Error
230     HiLink factorDelimiter              Delimiter
231     HiLink factorBackslash              Special
232     HiLink factorCompileDirective       Typedef
233     HiLink factorSymbol                 Define
234     HiLink factorConstant               Define
235     HiLink factorSingleton              Define
236     HiLink factorSingletons             Define
237     HiLink factorMixin                  Typedef
238     HiLink factorInstance               Typedef
239     HiLink factorHook                   Typedef
240     HiLink factorMain                   Define
241     HiLink factorPostpone               Define
242     HiLink factorDefer                  Define
243     HiLink factorForget                 Define
244     HiLink factorAlien                  Define
245     HiLink factorTuple                  Typedef
246
247     if &bg == "dark"
248         hi   hlLevel0 ctermfg=red         guifg=red1
249         hi   hlLevel1 ctermfg=yellow      guifg=orange1
250         hi   hlLevel2 ctermfg=green       guifg=yellow1
251         hi   hlLevel3 ctermfg=cyan        guifg=greenyellow
252         hi   hlLevel4 ctermfg=magenta     guifg=green1
253         hi   hlLevel5 ctermfg=red         guifg=springgreen1
254         hi   hlLevel6 ctermfg=yellow      guifg=cyan1
255         hi   hlLevel7 ctermfg=green       guifg=slateblue1
256         hi   hlLevel8 ctermfg=cyan        guifg=magenta1
257         hi   hlLevel9 ctermfg=magenta     guifg=purple1
258     else
259         hi   hlLevel0 ctermfg=red         guifg=red3
260         hi   hlLevel1 ctermfg=darkyellow  guifg=orangered3
261         hi   hlLevel2 ctermfg=darkgreen   guifg=orange2
262         hi   hlLevel3 ctermfg=blue        guifg=yellow3
263         hi   hlLevel4 ctermfg=darkmagenta guifg=olivedrab4
264         hi   hlLevel5 ctermfg=red         guifg=green4
265         hi   hlLevel6 ctermfg=darkyellow  guifg=paleturquoise3
266         hi   hlLevel7 ctermfg=darkgreen   guifg=deepskyblue4
267         hi   hlLevel8 ctermfg=blue        guifg=darkslateblue
268         hi   hlLevel9 ctermfg=darkmagenta guifg=darkviolet
269     endif
270
271     delcommand HiLink
272 endif
273
274 let b:current_syntax = "factor"
275
276 set sw=4
277 set sts=4
278 set expandtab
279 set autoindent " annoying?
280
281 " vim: syntax=vim
282