]> gitweb.factorcode.org Git - factor.git/blob - misc/syntax-test.factor
misc/vim: better definition/declaration highlighting.
[factor.git] / misc / syntax-test.factor
1 #!/usr/bin/env foo
2
3 ! Comments
4
5     ! Normal comments
6     ! More comments
7
8     /* C
9     style 
10     comments */
11
12     /* comment */
13     /* multline ( x -- y )
14       2  comment */
15      6 /* something else */ 2 +
16
17 ! Imports
18
19     USING: vocabularies ... ;
20     USE: vocabulary
21     UNUSE: vocabulary
22     IN: vocabulary
23     FROM: vocab => words ... ;
24     EXCLUDE: vocab => words ... ;
25     QUALIFIED: vocab
26     QUALIFIED-WITH: vocab word-prefix
27     RENAME: word vocab => new-name
28     ALIAS: new-word existing-word
29     DEFER: word
30     FORGET: word
31     POSTPONE: word
32     SLOT: name
33
34 ! Classes
35
36     MIXIN: class
37     TUPLE: class slots ... ;
38     TUPLE: class < superclass slots ... ;
39     BUILTIN: class slots ... ;
40     INSTANCE: instance mixin
41     SINGLETON: class
42     SINGLETONS: words ... ;
43     PREDICATE: class < superclass predicate... ;
44
45 ! Examples
46
47     TUPLE: interval-map { array array read-only } ;
48     TUPLE: foo a b c ;
49     TUPLE: foo < bar d e f ;
50     BUILTIN: string { length array-capacity read-only initial: 0 } aux ;
51
52 ! Definitions
53
54     : word ( x -- ) drop ;
55     : word error drop ;
56     :: word ( x -- ) x drop ;
57     TYPED: word ( a b: class ... -- x: class y ... ) body ;
58     TYPED:: word ( a b: class ... -- x: class y ... ) body ;
59     MACRO: word ( inputs... -- ) definition... ) ;
60     MACRO:: word ( vars... -- outputs... ) definition... ) ;
61     M: object explain drop "an object" print ;
62     M: class generic definition... ;
63     M:: class generic ( vars... -- outputs... ) body... ;
64     M:: class generic error body... ;
65     GENERIC: word ( stack -- effect )
66     GENERIC: word
67         ( stack -- effect )
68     GENERIC: word
69 ( stack -- effect )
70     GENERIC: word ! comment
71         ( stack -- effect )
72     GENERIC: word drop ! 3rd token wrong
73     GENERIC: word ! next line wrong
74         drop
75     GENERIC: word
76 drop ! wrong
77     HOOK: word variable ( stack -- effect )
78     GENERIC#: word 1 ( stack -- effect )
79     GENERIC#: ! comment
80         word 1 ( stack -- effect )
81     GENERIC#: word 1 ( stack -- effect ) drop ! last token other
82     GENERIC#: word ! 2 should GENERIC# stack effect error
83         1 2 ( stack -- effect )
84     GENERIC#: word ! 2nd eff. should be independent of GENERIC#,
85         1 ! and 2 & 3 shouldn't GENERIC# highlight
86         ( stack -- effect ) ( independent -- effect ) 2 3
87     GENERIC#: word 1 ! comment
88         drop ! wrong
89     MATH: + ( x y -- z ) foldable flushable
90     C: <foo> foo
91     CONSTRUCTOR: <circle> circle ( radius -- obj ) ;
92     CONSTRUCTOR: <circle> circle ( radius -- obj ) definition...  ;
93
94 ! Private definitions
95
96 <PRIVATE
97
98     : word ( x -- ) drop ;
99     :: word ( x -- ) x drop ;
100     TYPED: word ( a b: class ... -- x: class y ... ) body ;
101     TYPED:: word ( a b: class ... -- x: class y ... ) body ;
102     MACRO: word ( inputs... -- ) definition... ) ;
103     MACRO:: word ( vars... -- outputs... ) definition... ) ;
104     M: class generic definition... ;
105     M:: class generic ( vars... -- outputs... ) body... ;
106     GENERIC: word ( stack -- effect )
107     HOOK: word variable ( stack -- effect )
108     GENERIC#: word 1 ( stack -- effect )
109     MATH: + ( x y -- z ) foldable flushable
110     C: <foo> foo
111     CONSTRUCTOR: <circle> circle ( radius -- obj ) ;
112     CONSTRUCTOR: <circle> circle ( radius -- obj ) definition...  ;
113
114 PRIVATE>
115
116 ! Alien
117
118     LIBRARY: name
119     TYPEDEF: old new
120     ENUM: type words... ;
121     ENUM: type < base-type words...
122     FUNCTION: return name ( parameters ) ;
123     FUNCTION-ALIAS: factor-name return name ( parameters ) ;
124
125 ! Symbols and literals
126
127     \ foo
128     $ foo
129     M\ foo bar
130
131     MAIN: word
132     CONSTANT: word value
133     SYMBOL: word
134     SYMBOLS: words ... ;
135
136 ! Math
137
138     1 2 +
139     3 4 -
140     5 6 *
141     7 8 /
142     32 2^
143     10 10^
144
145 ! Examples
146
147     [ 1 ] unless*
148     >boolean
149     <wrapper>
150     +@
151     H{ } assoc-empty?
152     5 >bignum
153     1 2 pick set-nth
154     5 f <array>
155     (clone)
156
157 ! Strings
158
159     ""
160     "test"
161     SBUF" foo"
162     SBUF" hello world "
163     "\s"
164     "\\foo"
165     "\"hello\""
166     "\a\b\e\f\n\r\t\s\v\s\0\\\""
167     "\x01\xaF\uffffff"
168
169     URL" http://google.com"
170     R" asdf"
171
172     """">json""""
173
174 ! Triple quote strings (old Factor)
175
176     """hello, world"""
177     """ hello, world """
178     """this is a
179     multiline string"""
180
181 ! Multiline strings
182
183     [=[this is a weird new string]=]
184
185 ! Containers
186
187     H{ { 1 2 } }
188     HS{ 1 2 3 }
189     { 4 5 6 }
190     V{ "asdf" 5 }
191     ${ 1 foo 3 }
192
193 ! Quotations
194
195     [ 2^ * ]
196     '[ _ sqrt ]
197     $[ 1 2 + ]
198
199 ! Tuples
200
201     T{ foo f 1 2 3 }
202     T{ foo { a 5 } }
203
204 ! Symbols are colored wrong:
205
206     : rock ( -- ) \ rock computer play. ;
207
208 ! SBUF is colored wrong:
209
210     SBUF" " clone swap [ " " append ] [ number>string append ] interleave
211
212 ! Update to new library words:
213
214     key? and assoc-empty? are not colored
215     tail* is not highlighted
216
217 ! IN poker, unicode characters:
218
219     t
220
221     f
222
223     CHAR: -
224     CHAR: a
225     CHAR: symbol-for-end-of-transmission
226     CHAR: snowman
227     CHAR: ☃
228
229     { CHAR: a CHAR: S }
230     { CHAR: b CHAR: D }
231     { CHAR: c CHAR: H }
232     { CHAR: d CHAR: C }
233
234 ! Bin
235
236     0b10101
237     0B10101
238
239 ! Oct
240
241     0o432
242     0O1234567
243     0o1234567
244     0o7
245
246 ! Hex
247
248     0xCAFEBABE
249     0XCAFEBABE
250     0x1AB4p30
251
252 ! Dec
253
254     1,000
255     10,000
256
257 ! Float
258
259     1e10
260     -1.5e-5
261
262
263 ! Weird numbers
264
265     1,234+56/78
266     +1/3
267     1+1/3
268     -1/3
269     -1-1/3
270     -1,234-1/34
271     1.
272     +1.5
273     -1.5e30
274     1.5e-30
275     1,000.1,2
276     NAN: CAFE1234 0,. ! third token wrong
277     0,. ! wrong, next line also wrong
278     0,.
279     NAN: ! ff 0xff comment
280         xCAFE1234 ! wrong
281         ff ! shouldn't match as a hex number
282     NAN: 0
283     drop
284     NAN: !
285         ! a 1 comment 1
286         f
287
288     NAN:
289 f,
290     NAN: ALKSJDflKJ ! XXX: should error
291
292 ! Not numbers
293
294     ,0.1
295     .
296     -.
297     1foo
298     1.5bar
299     +foo
300     -bar
301     *baz
302     qux*
303     /i
304     (1string)
305     ?1+
306
307 ! Comments in STRUCT: definitions
308 ! STRUCT: features like bitfields, etc.
309
310     STRUCT: foo
311     { a int initial: 0 } ! a comment
312     { b c-string }
313     { c char[4] }
314     { d void* }
315     { e int bits: 8 }
316     ;
317
318 ! Stack effects
319
320     ( -- )
321     ( x -- )
322     ( x -- x )
323     ( x x -- x )
324     ( x x -- x x )
325
326     ( quot: ( a -- b ) -- )
327     ( x quot: ( a -- b ) -- y )
328     ( ..a quot: ( ..a x -- ..b ) -- ..b )
329
330     ( x n -- (x)n )
331
332     ( p:
333 boolean -- q: boolean )
334     ( m: integer -- n: float )
335     ( :integer -- :float )
336
337     ( x -- y )
338
339 ! Weird stuff:
340
341     key?
342     key?thing
343     flushablething
344     flushable
345     <PRIVATEfoo
346     "asdf"foo
347
348 << 5 1 + . >> 1
349
350 : foo ( x -- y ) foo>> + ; inline
351
352 +@
353 +byte+
354
355 pair?
356 tail?
357
358 0.1
359 10,0.1
360 1.23
361 .1
362 -.1
363 -0.1
364 -0,1.1
365 1.
366
367 ! Numeral comma separator parsing (!: wrong, ~: other):
368   ! int
369   0 00 0,0 +0,0 -0,,0
370   /* ! */ ,0 ,00 0,, 00,, +,0 -,,0 +0, -0,, /* ~ */ , +, -,,
371
372   ! float
373   0,0e0 0e0,0 0,0e0,0 +0,0e+0,0 -0,0e-0,0
374   /* ~ */ e e, ,e ,e, +e -e +e, -e,
375   /* ~ */ +e -e +,e -,e +e+, -e-, +,e-,, -,,e+,
376   /* ~ */ +e -e +,e -,e +e+, -e-, +,e-,, -,,e+,
377   /* ! */ e0, -e,0 ,0e, 0,e, +,e0 -,e-0 0,e0 +0,0e+ -0,0e-,, 0e+ -0e-
378   /* ! */ +0e+0, -0e-,,0
379
380   ! float
381   0,0. .0,0 /* ! */ 0,. .,0 ,.0 0., ,0. .0,
382   +0,0.0 -0,0.0,0
383   0,0.0,0e0 0,0.0,0e0,0
384   0,0.0,0e+0,0 0,0.0,0e-0,0
385
386   ! ratio
387   /* ~ */ / /. +/ -/ ,/ /, 0/ /0
388   0/1 1/1 1/1. 1/0. 0/0. /* ! */ 0/0 1/0 1./1
389   1/2 +1/2 -1/2 +2/2 /* ! */ 1/+2 1/-2 1/+0 +2/+2
390   +1+1/2 -0-1/2 /* ! */ +1+2/2 +1+1/2. +0-1/2 -0+1/2
391
392 ! Regexp is colored wrong (on Github):
393
394 : using-line ( source -- vocabs )
395     R/ USING: [^;]* ;/s all-matching-subseqs ?first
396     [ { } ] [ " \n" split rest but-last ] if-empty ;