1 ! Copyright (C) 2004, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays byte-arrays byte-vectors
4 classes.algebra.private classes.intersection classes.maybe
5 classes.mixin classes.parser classes.predicate
6 classes.singleton classes.tuple classes.tuple.parser
7 classes.union combinators compiler.units definitions
8 effects.parser generic generic.hook generic.math generic.parser
9 generic.standard hash-sets hashtables io.pathnames kernel lexer
10 math namespaces parser quotations sbufs sequences slots
11 source-files splitting strings strings.parser vectors
12 vocabs.parser words words.alias words.constant words.symbol ;
15 ! These words are defined as a top-level form, instead of with
16 ! defining parsing words, because during stage1 bootstrap, the
17 ! "syntax" vocabulary is copied from the host. When stage1
18 ! bootstrap completes, the host's syntax vocabulary is deleted
19 ! from the target, then this top-level form creates the
20 ! target's "syntax" vocabulary as one of the first things done
23 : define-delimiter ( name -- )
24 "syntax" lookup-word t "delimiter" set-word-prop ;
26 : define-core-syntax ( name quot -- )
27 [ dup "syntax" lookup-word [ ] [ no-word-error ] ?if ] dip
31 { "]" "}" ";" ">>" } [ define-delimiter ] each
34 "Primitive definition is not supported" throw
38 "Call stack literals are not supported" throw
41 "!" [ lexer get next-line ] define-core-syntax
43 "#!" [ POSTPONE: ! ] define-core-syntax
45 "IN:" [ scan-token set-current-vocab ] define-core-syntax
47 "<PRIVATE" [ begin-private ] define-core-syntax
49 "PRIVATE>" [ end-private ] define-core-syntax
51 "USE:" [ scan-token use-vocab ] define-core-syntax
53 "UNUSE:" [ scan-token unuse-vocab ] define-core-syntax
55 "USING:" [ ";" [ use-vocab ] each-token ] define-core-syntax
57 "QUALIFIED:" [ scan-token dup add-qualified ] define-core-syntax
59 "QUALIFIED-WITH:" [ scan-token scan-token add-qualified ] define-core-syntax
62 scan-token "=>" expect ";" parse-tokens add-words-from
66 scan-token "=>" expect ";" parse-tokens add-words-excluding
70 scan-token scan-token "=>" expect scan-token add-renamed-word
73 "NAN:" [ 16 scan-base <fp-nan> suffix! ] define-core-syntax
75 "f" [ f suffix! ] define-core-syntax
79 { [ dup length 1 = ] [ first ] }
80 { [ "\\" ?head ] [ next-escape >string "" assert= ] }
81 [ name>char-hook get call( name -- char ) ]
85 "\"" [ parse-multiline-string suffix! ] define-core-syntax
88 lexer get skip-blank parse-string >sbuf suffix!
92 lexer get skip-blank parse-string <pathname> suffix!
95 "[" [ parse-quotation suffix! ] define-core-syntax
96 "{" [ \ } [ >array ] parse-literal ] define-core-syntax
97 "V{" [ \ } [ >vector ] parse-literal ] define-core-syntax
98 "B{" [ \ } [ >byte-array ] parse-literal ] define-core-syntax
99 "BV{" [ \ } [ >byte-vector ] parse-literal ] define-core-syntax
100 "H{" [ \ } [ parse-hashtable ] parse-literal ] define-core-syntax
101 "T{" [ parse-tuple-literal suffix! ] define-core-syntax
102 "W{" [ \ } [ first <wrapper> ] parse-literal ] define-core-syntax
103 "HS{" [ \ } [ >hash-set ] parse-literal ] define-core-syntax
105 "POSTPONE:" [ scan-word suffix! ] define-core-syntax
106 "\\" [ scan-word <wrapper> suffix! ] define-core-syntax
107 "M\\" [ scan-word scan-word lookup-method <wrapper> suffix! ] define-core-syntax
108 "inline" [ word make-inline ] define-core-syntax
109 "recursive" [ word make-recursive ] define-core-syntax
110 "foldable" [ word make-foldable ] define-core-syntax
111 "flushable" [ word make-flushable ] define-core-syntax
112 "delimiter" [ word t "delimiter" set-word-prop ] define-core-syntax
113 "deprecated" [ word make-deprecated ] define-core-syntax
116 scan-new-word parse-definition define-syntax
120 scan-new-word define-symbol
124 ";" [ create-in [ reset-generic ] [ define-symbol ] bi ] each-token
128 ";" [ create-class-in define-singleton-class ] each-token
132 scan-token current-vocab create
133 [ fake-definition ] [ set-word ] [ undefined-def define ] tri
137 scan-new-word scan-word define-alias
141 scan-new-word scan-object define-constant
149 [ simple-combination ] (GENERIC:)
153 [ scan-number <standard-combination> ] (GENERIC:)
157 [ math-combination ] (GENERIC:)
161 [ scan-word <hook-combination> ] (GENERIC:)
169 scan-new-class parse-definition define-union-class
173 scan-new-class parse-definition define-intersection-class
177 scan-new-class define-mixin-class
182 scan-word scan-word 2dup add-mixin-instance
184 ] dip remember-definition
191 parse-definition define-predicate-class
195 scan-new-class define-singleton-class
199 parse-tuple-definition define-tuple-class
207 scan-token define-protocol-slot
211 scan-new-word scan-word define-boa-word
215 parse-tuple-definition
225 ")" parse-effect suffix!
230 [ current-vocab main<< ]
231 [ file get [ main<< ] [ drop ] if* ] bi
236 \ >> parse-until >quotation
237 ] with-nested-compilation-unit call( -- )
243 \ (call-next-method) suffix!
245 not-in-a-method-error
250 \ } [ <anonymous-union> <maybe> ] parse-literal
254 \ } [ <anonymous-union> <anonymous-complement> ] parse-literal
258 \ } [ <anonymous-intersection> ] parse-literal
262 \ } [ <anonymous-union> ] parse-literal
265 "initial:" "syntax" lookup-word define-symbol
267 "read-only" "syntax" lookup-word define-symbol
269 "call(" [ \ call-effect parse-call( ] define-core-syntax
271 "execute(" [ \ execute-effect parse-call( ] define-core-syntax
273 "<<<<<<<" [ version-control-merge-conflict ] define-core-syntax
274 "=======" [ version-control-merge-conflict ] define-core-syntax
275 ">>>>>>>" [ version-control-merge-conflict ] define-core-syntax
277 "<<<<<<" [ version-control-merge-conflict ] define-core-syntax
278 "======" [ version-control-merge-conflict ] define-core-syntax
279 ">>>>>>" [ version-control-merge-conflict ] define-core-syntax
280 ] with-compilation-unit