]> gitweb.factorcode.org Git - factor.git/blob - misc/syntax-test.factor
misc/vim: change stack effects to not highlight when required
[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 ( x -- ) x drop ;
53     TYPED: word ( a b: class ... -- x: class y ... ) body ;
54     TYPED:: word ( a b: class ... -- x: class y ... ) body ;
55     MACRO: word ( inputs... -- ) definition... ) ;
56     MACRO:: word ( vars... -- outputs... ) definition... ) ;
57     M: class generic (definition) ... ;
58     M:: class generic ( vars... -- outputs... ) body... ;
59     GENERIC: word ( stack -- effect )
60     HOOK: word variable ( stack -- effect )
61     GENERIC#: word 1 ( stack -- effect )
62     MATH: + ( x y -- z ) foldable flushable
63     SLOT: name
64     C: <foo> foo
65
66 ! Private definitions
67
68 <PRIVATE
69
70     : word ( x -- ) drop ;
71     :: word ( x -- ) x drop ;
72     TYPED: word ( a b: class ... -- x: class y ... ) body ;
73     TYPED:: word ( a b: class ... -- x: class y ... ) body ;
74     MACRO: word ( inputs... -- ) definition... ) ;
75     MACRO:: word ( vars... -- outputs... ) definition... ) ;
76     M: class generic (definition) ... ;
77     M:: class generic ( vars... -- outputs... ) body... ;
78     GENERIC: word ( stack -- effect )
79     HOOK: word variable ( stack -- effect )
80     GENERIC#: word 1 ( stack -- effect )
81     MATH: + ( x y -- z ) foldable flushable
82     SLOT: name
83     C: <foo> foo
84
85 PRIVATE>
86
87 ! Alien
88
89     LIBRARY: name
90     TYPEDEF: old new
91     ENUM: type words... ;
92     ENUM: type < base-type words...
93     FUNCTION: return name ( parameters ) ;
94     FUNCTION-ALIAS: factor-name return name ( parameters ) ;
95
96 ! Symbols and literals
97
98     \ foo
99     $ foo
100     M\ foo bar
101
102     MAIN: word
103     CONSTANT: word value
104     SYMBOL: word
105     SYMBOLS: words ... ;
106
107     C: <foo> foo
108
109 ! Math
110
111     1 2 +
112     3 4 -
113     5 6 *
114     7 8 /
115     32 2^
116     10 10^
117
118 ! Examples
119
120     [ 1 ] unless*
121     >boolean
122     <wrapper>
123     +@
124     H{ } assoc-empty?
125     5 >bignum
126     1 2 pick set-nth
127     5 f <array>
128     (clone)
129
130 ! Strings
131
132     ""
133     "test"
134     SBUF" foo"
135     SBUF" hello world "
136     "\s"
137     "\\foo"
138     "\"hello\""
139     "\a\b\e\f\n\r\t\s\v\s\0\\\""
140     "\x01\xaF\uffffff"
141
142     URL" http://google.com"
143     R" asdf"
144
145     """">json""""
146
147 ! Triple quote strings (old Factor)
148
149     """hello, world"""
150     """ hello, world """
151     """this is a
152     multiline string"""
153
154 ! Multiline strings
155
156     [=[this is a weird new string]=]
157
158 ! Containers
159
160     H{ { 1 2 } }
161     HS{ 1 2 3 }
162     { 4 5 6 }
163     V{ "asdf" 5 }
164     ${ 1 foo 3 }
165
166 ! Quotations
167
168     [ 2^ * ]
169     '[ _ sqrt ]
170     $[ 1 2 + ]
171
172 ! Tuples
173
174     T{ foo f 1 2 3 }
175     T{ foo { a 5 } }
176
177 ! Symbols are colored wrong:
178
179     : rock ( -- ) \ rock computer play. ;
180
181 ! SBUF is colored wrong:
182
183     SBUF" " clone swap [ " " append ] [ number>string append ] interleave
184
185 ! Update to new library words:
186
187     key? and assoc-empty? are not colored
188     tail* is not highlighted
189
190 ! IN poker, unicode characters:
191
192     t
193
194     f
195
196     CHAR: -
197     CHAR: a
198     CHAR: symbol-for-end-of-transmission
199     CHAR: snowman
200
201     { CHAR: a CHAR: S }
202     { CHAR: b CHAR: D }
203     { CHAR: c CHAR: H }
204     { CHAR: d CHAR: C }
205
206 ! New number literals:
207
208     0xCAFEBABE
209     0o432
210     0b10101
211     1,000
212     10,000
213     1e10
214     -1.5e-5
215
216 ! Weird numbers
217
218     1,234+56/78
219     +1/3
220     1+1/3
221     -1/3
222     -1-1/3
223     -1,234-1/34
224     1.
225     +1.5
226     -1.5e30
227     1.5e-30
228     1,000.1,2
229     0xCAFEBABE
230     0x1AB4p30
231     0b10101
232     0o1234567
233     NAN: CAFE1234
234     NAN: 0
235
236 ! Not numbers
237
238     1foo
239     1.5bar
240     +foo
241     -bar
242     *baz
243     qux*
244     /i
245     (1string)
246     ?1+
247
248 ! Comments in STRUCT: definitions
249 ! STRUCT: features like bitfields, etc.
250
251     STRUCT: foo
252     { a int initial: 0 } ! a comment
253     { b c-string }
254     { c char[4] }
255     { d void* }
256     { e int bits: 8 }
257     ;
258
259 ! Stack effects
260
261     ( -- )
262     ( x -- )
263     ( x -- x )
264     ( x x -- x )
265     ( x x -- x x )
266
267     ( quot: ( a -- b ) -- )
268     ( x quot: ( a -- b ) -- y )
269     ( ..a quot: ( ..a x -- ..b ) -- ..b )
270
271     ( x n -- (x)n )
272
273     ( m: integer -- n: float )
274     ( :integer -- :float )
275
276     ( x -- y )
277
278 ! Weird stuff:
279
280     key?
281     key?thing
282     flushablething
283     flushable
284     <PRIVATEfoo
285
286     "asdf"foo
287
288 << 5 1 + . >> 1
289
290 : foo ( x -- y ) foo>> + ; inline
291
292 +@
293 +byte+
294
295 pair?
296 tail?
297
298 0.1
299 ,0.1 ! wrong
300 10,0.1
301 1.23
302 .1
303 -.1
304 -0.1
305 -0,1.1
306 1.
307 .  ! wrong
308 -. ! wrong
309
310 ! Regexp is colored wrong (on Github):
311
312 : using-line ( source -- vocabs )
313     R/ USING: [^;]* ;/s all-matching-subseqs ?first
314     [ { } ] [ " \n" split rest but-last ] if-empty ;