1 ! Copyright (C) 2004, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien arrays bit-arrays bit-vectors byte-arrays
4 byte-vectors definitions generic hashtables kernel math
5 namespaces parser sequences strings sbufs vectors words
6 quotations io assocs splitting classes.tuple generic.standard
7 generic.math classes io.files vocabs float-arrays float-vectors
8 classes.union classes.mixin classes.predicate classes.singleton
9 compiler.units combinators debugger ;
12 ! These words are defined as a top-level form, instead of with
13 ! defining parsing words, because during stage1 bootstrap, the
14 ! "syntax" vocabulary is copied from the host. When stage1
15 ! bootstrap completes, the host's syntax vocabulary is deleted
16 ! from the target, then this top-level form creates the
17 ! target's "syntax" vocabulary as one of the first things done
20 : define-delimiter ( name -- )
21 "syntax" lookup t "delimiter" set-word-prop ;
23 : define-syntax ( name quot -- )
24 >r "syntax" lookup dup r> define t "parsing" set-word-prop ;
27 { "]" "}" ";" ">>" } [ define-delimiter ] each
30 "Primitive definition is not supported" throw
34 "Call stack literals are not supported" throw
37 "!" [ lexer get next-line ] define-syntax
39 "#!" [ POSTPONE: ! ] define-syntax
41 "IN:" [ scan set-in ] define-syntax
43 "PRIVATE>" [ in get ".private" ?tail drop set-in ] define-syntax
46 POSTPONE: PRIVATE> in get ".private" append set-in
49 "USE:" [ scan use+ ] define-syntax
51 "USING:" [ ";" parse-tokens add-use ] define-syntax
53 "HEX:" [ 16 parse-base ] define-syntax
54 "OCT:" [ 8 parse-base ] define-syntax
55 "BIN:" [ 2 parse-base ] define-syntax
57 "f" [ f parsed ] define-syntax
58 "t" "syntax" lookup define-singleton-class
62 { [ dup length 1 = ] [ first ] }
63 { [ "\\" ?head ] [ next-escape drop ] }
64 [ name>char-hook get call ]
68 "\"" [ parse-string parsed ] define-syntax
71 lexer get skip-blank parse-string >sbuf parsed
75 lexer get skip-blank parse-string <pathname> parsed
78 "[" [ \ ] [ >quotation ] parse-literal ] define-syntax
79 "{" [ \ } [ >array ] parse-literal ] define-syntax
80 "V{" [ \ } [ >vector ] parse-literal ] define-syntax
81 "B{" [ \ } [ >byte-array ] parse-literal ] define-syntax
82 "?{" [ \ } [ >bit-array ] parse-literal ] define-syntax
83 "F{" [ \ } [ >float-array ] parse-literal ] define-syntax
84 "H{" [ \ } [ >hashtable ] parse-literal ] define-syntax
85 "T{" [ \ } [ >tuple ] parse-literal ] define-syntax
86 "W{" [ \ } [ first <wrapper> ] parse-literal ] define-syntax
88 "POSTPONE:" [ scan-word parsed ] define-syntax
89 "\\" [ scan-word literalize parsed ] define-syntax
90 "inline" [ word make-inline ] define-syntax
91 "foldable" [ word make-foldable ] define-syntax
92 "flushable" [ word make-flushable ] define-syntax
93 "delimiter" [ word t "delimiter" set-word-prop ] define-syntax
94 "parsing" [ word t "parsing" set-word-prop ] define-syntax
97 CREATE-WORD define-symbol
102 dup old-definitions get first delete-at
111 CREATE-GENERIC define-simple-generic
116 scan-word <standard-combination> define-generic
121 T{ math-combination } define-generic
125 CREATE-GENERIC scan-word
126 <hook-combination> define-generic
134 CREATE-CLASS parse-definition define-union-class
138 CREATE-CLASS define-mixin-class
143 scan-word scan-word 2dup add-mixin-instance
144 <mixin-instance> r> remember-definition
151 parse-definition define-predicate-class
156 dup save-location define-singleton-class
160 parse-tuple-definition define-tuple-class
165 scan-word dup check-tuple
166 [ boa ] curry define-inline
170 parse-tuple-definition
181 [ swap "declared-effect" set-word-prop ] [ drop ] if*
184 "MAIN:" [ scan-word in get vocab set-vocab-main ] define-syntax
187 [ \ >> parse-until >quotation ] with-compilation-unit
192 current-class get literalize parsed
193 current-generic get literalize parsed
194 \ (call-next-method) parsed
196 ] with-compilation-unit