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