1 ! Copyright (C) 2004, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien arrays byte-arrays byte-vectors
4 definitions generic hashtables kernel math namespaces parser
5 lexer sequences strings strings.parser sbufs vectors
6 words quotations io assocs splitting classes.tuple
7 generic.standard generic.math generic.parser classes io.files
8 vocabs 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 >r "syntax" lookup dup r> define t "parsing" set-word-prop ;
29 { "]" "}" ";" ">>" } [ define-delimiter ] each
32 "Primitive definition is not supported" throw
36 "Call stack literals are not supported" throw
39 "!" [ lexer get next-line ] define-syntax
41 "#!" [ POSTPONE: ! ] define-syntax
43 "IN:" [ scan set-in ] define-syntax
45 "PRIVATE>" [ in get ".private" ?tail drop set-in ] define-syntax
48 POSTPONE: PRIVATE> in get ".private" append set-in
51 "USE:" [ scan use+ ] define-syntax
53 "USING:" [ ";" parse-tokens add-use ] define-syntax
55 "HEX:" [ 16 parse-base ] define-syntax
56 "OCT:" [ 8 parse-base ] define-syntax
57 "BIN:" [ 2 parse-base ] define-syntax
59 "f" [ f parsed ] define-syntax
60 "t" "syntax" lookup define-singleton-class
64 { [ dup length 1 = ] [ first ] }
65 { [ "\\" ?head ] [ next-escape drop ] }
66 [ name>char-hook get call ]
70 "\"" [ parse-string parsed ] define-syntax
73 lexer get skip-blank parse-string >sbuf parsed
77 lexer get skip-blank parse-string <pathname> parsed
80 "[" [ \ ] [ >quotation ] parse-literal ] define-syntax
81 "{" [ \ } [ >array ] parse-literal ] define-syntax
82 "V{" [ \ } [ >vector ] parse-literal ] define-syntax
83 "B{" [ \ } [ >byte-array ] parse-literal ] define-syntax
84 "BV{" [ \ } [ >byte-vector ] parse-literal ] define-syntax
85 "H{" [ \ } [ >hashtable ] parse-literal ] define-syntax
86 "T{" [ parse-tuple-literal parsed ] define-syntax
87 "W{" [ \ } [ first <wrapper> ] parse-literal ] define-syntax
89 "POSTPONE:" [ scan-word parsed ] define-syntax
90 "\\" [ scan-word literalize parsed ] define-syntax
91 "inline" [ word make-inline ] define-syntax
92 "recursive" [ word make-recursive ] define-syntax
93 "foldable" [ word make-foldable ] define-syntax
94 "flushable" [ word make-flushable ] define-syntax
95 "delimiter" [ word t "delimiter" set-word-prop ] define-syntax
96 "parsing" [ word t "parsing" set-word-prop ] define-syntax
99 CREATE-WORD define-symbol
103 scan current-vocab create
104 dup old-definitions get [ delete-at ] with each
113 CREATE-GENERIC define-simple-generic
118 scan-word <standard-combination> define-generic
123 T{ math-combination } define-generic
127 CREATE-GENERIC scan-word
128 <hook-combination> define-generic
136 CREATE-CLASS parse-definition define-union-class
140 CREATE-CLASS parse-definition define-intersection-class
144 CREATE-CLASS define-mixin-class
149 scan-word scan-word 2dup add-mixin-instance
150 <mixin-instance> r> remember-definition
157 parse-definition define-predicate-class
161 CREATE-CLASS define-singleton-class
165 parse-tuple-definition define-tuple-class
169 scan define-protocol-slot
174 scan-word [ boa ] curry define-inline
178 parse-tuple-definition
189 word dup [ set-stack-effect ] [ 2drop ] if
193 "))" parse-effect parsed
196 "MAIN:" [ scan-word in get vocab (>>main) ] define-syntax
200 \ >> parse-until >quotation
201 ] with-nested-compilation-unit call
205 current-class get current-generic get
206 2dup [ word? ] both? [
207 [ literalize parsed ] bi@
208 \ (call-next-method) parsed
210 not-in-a-method-error
214 "initial:" "syntax" lookup define-symbol
216 "read-only" "syntax" lookup define-symbol
217 ] with-compilation-unit