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