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 "BV{" [ \ } [ >byte-vector ] parse-literal ] define-syntax
83 "?{" [ \ } [ >bit-array ] parse-literal ] define-syntax
84 "?V{" [ \ } [ >bit-vector ] parse-literal ] define-syntax
85 "F{" [ \ } [ >float-array ] parse-literal ] define-syntax
86 "FV{" [ \ } [ >float-vector ] parse-literal ] define-syntax
87 "H{" [ \ } [ >hashtable ] parse-literal ] define-syntax
88 "T{" [ \ } [ >tuple ] parse-literal ] define-syntax
89 "W{" [ \ } [ first <wrapper> ] parse-literal ] define-syntax
91 "POSTPONE:" [ scan-word parsed ] define-syntax
92 "\\" [ scan-word literalize parsed ] define-syntax
93 "inline" [ word make-inline ] define-syntax
94 "foldable" [ word make-foldable ] define-syntax
95 "flushable" [ word make-flushable ] define-syntax
96 "delimiter" [ word t "delimiter" set-word-prop ] define-syntax
97 "parsing" [ word t "parsing" set-word-prop ] define-syntax
100 CREATE-WORD define-symbol
105 dup old-definitions get first delete-at
114 CREATE-GENERIC define-simple-generic
119 scan-word <standard-combination> define-generic
124 T{ math-combination } define-generic
128 CREATE-GENERIC scan-word
129 <hook-combination> define-generic
137 CREATE-CLASS parse-definition define-union-class
141 CREATE-CLASS define-mixin-class
146 scan-word scan-word 2dup add-mixin-instance
147 <mixin-instance> r> remember-definition
154 parse-definition define-predicate-class
159 dup save-location define-singleton-class
163 parse-tuple-definition define-tuple-class
168 scan-word dup check-tuple
169 [ boa ] curry define-inline
173 parse-tuple-definition
184 [ swap "declared-effect" set-word-prop ] [ drop ] if*
187 "MAIN:" [ scan-word in get vocab set-vocab-main ] define-syntax
190 [ \ >> parse-until >quotation ] with-compilation-unit
195 current-class get literalize parsed
196 current-generic get literalize parsed
197 \ (call-next-method) parsed
199 ] with-compilation-unit