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