1 ! Copyright (C) 2004, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien arrays byte-arrays definitions generic
4 hashtables kernel math namespaces parser lexer sequences strings
5 strings.parser sbufs vectors words words.symbol words.constant
6 words.alias quotations io assocs splitting classes.tuple
7 generic.standard generic.math generic.parser classes
8 io.pathnames vocabs vocabs.parser classes.parser classes.union
9 classes.intersection classes.mixin classes.predicate
10 classes.singleton classes.tuple.parser compiler.units
11 combinators effects.parser slots ;
14 ! These words are defined as a top-level form, instead of with
15 ! defining parsing words, because during stage1 bootstrap, the
16 ! "syntax" vocabulary is copied from the host. When stage1
17 ! bootstrap completes, the host's syntax vocabulary is deleted
18 ! from the target, then this top-level form creates the
19 ! target's "syntax" vocabulary as one of the first things done
22 : define-delimiter ( name -- )
23 "syntax" lookup t "delimiter" set-word-prop ;
25 : define-syntax ( name quot -- )
26 [ dup "syntax" lookup [ dup ] [ no-word-error ] ?if ] dip
30 { "]" "}" ";" ">>" } [ define-delimiter ] each
33 "Primitive definition is not supported" throw
37 "Call stack literals are not supported" throw
40 "!" [ lexer get next-line ] define-syntax
42 "#!" [ POSTPONE: ! ] define-syntax
44 "IN:" [ scan set-in ] define-syntax
46 "PRIVATE>" [ in get ".private" ?tail drop set-in ] define-syntax
49 POSTPONE: PRIVATE> in get ".private" append set-in
52 "USE:" [ scan use+ ] define-syntax
54 "USING:" [ ";" parse-tokens add-use ] define-syntax
56 "QUALIFIED:" [ scan dup add-qualified ] define-syntax
58 "QUALIFIED-WITH:" [ scan scan add-qualified ] define-syntax
61 scan "=>" expect ";" parse-tokens swap add-words-from
65 scan "=>" expect ";" parse-tokens swap add-words-excluding
69 scan scan "=>" expect scan add-renamed-word
72 "HEX:" [ 16 parse-base ] define-syntax
73 "OCT:" [ 8 parse-base ] define-syntax
74 "BIN:" [ 2 parse-base ] define-syntax
76 "f" [ f parsed ] define-syntax
77 "t" "syntax" lookup define-singleton-class
81 { [ dup length 1 = ] [ first ] }
82 { [ "\\" ?head ] [ next-escape >string "" assert= ] }
83 [ name>char-hook get call ]
87 "\"" [ parse-string parsed ] define-syntax
90 lexer get skip-blank parse-string >sbuf parsed
94 lexer get skip-blank parse-string <pathname> parsed
97 "[" [ \ ] [ >quotation ] parse-literal ] define-syntax
98 "{" [ \ } [ >array ] parse-literal ] define-syntax
99 "V{" [ \ } [ >vector ] parse-literal ] define-syntax
100 "B{" [ \ } [ >byte-array ] parse-literal ] define-syntax
101 "H{" [ \ } [ >hashtable ] parse-literal ] define-syntax
102 "T{" [ parse-tuple-literal parsed ] define-syntax
103 "W{" [ \ } [ first <wrapper> ] parse-literal ] define-syntax
105 "POSTPONE:" [ scan-word parsed ] define-syntax
106 "\\" [ scan-word literalize parsed ] define-syntax
107 "inline" [ word make-inline ] define-syntax
108 "recursive" [ word make-recursive ] define-syntax
109 "foldable" [ word make-foldable ] define-syntax
110 "flushable" [ word make-flushable ] define-syntax
111 "delimiter" [ word t "delimiter" set-word-prop ] define-syntax
112 "parsing" [ word make-parsing ] define-syntax
115 CREATE-WORD define-symbol
120 [ create-in dup reset-generic define-symbol ] each
125 [ create-class-in define-singleton-class ] each
129 CREATE-WORD scan-word define-alias
133 CREATE scan-object define-constant
137 scan current-vocab create
138 dup old-definitions get [ delete-at ] with each
147 CREATE-GENERIC define-simple-generic
152 scan-word <standard-combination> define-generic
157 T{ math-combination } define-generic
161 CREATE-GENERIC scan-word
162 <hook-combination> define-generic
170 CREATE-CLASS parse-definition define-union-class
174 CREATE-CLASS parse-definition define-intersection-class
178 CREATE-CLASS define-mixin-class
183 scan-word scan-word 2dup add-mixin-instance
185 ] dip remember-definition
192 parse-definition define-predicate-class
196 CREATE-CLASS define-singleton-class
200 parse-tuple-definition define-tuple-class
204 scan define-protocol-slot
208 CREATE-WORD scan-word define-boa-word
212 parse-tuple-definition
223 word dup [ set-stack-effect ] [ 2drop ] if
227 "))" parse-effect parsed
230 "MAIN:" [ scan-word in get vocab (>>main) ] define-syntax
234 \ >> parse-until >quotation
235 ] with-nested-compilation-unit call
241 \ (call-next-method) parsed
243 not-in-a-method-error
247 "initial:" "syntax" lookup define-symbol
249 "read-only" "syntax" lookup define-symbol
250 ] with-compilation-unit