| 
									
										
										
										
											2008-01-30 02:10:58 -05:00
										 |  |  | ! Copyright (C) 2004, 2008 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-01-30 02:10:58 -05:00
										 |  |  | USING: alien arrays bit-arrays bit-vectors byte-arrays | 
					
						
							|  |  |  | byte-vectors definitions generic hashtables kernel math | 
					
						
							|  |  |  | namespaces parser sequences strings sbufs vectors words | 
					
						
							| 
									
										
										
										
											2008-03-29 04:34:48 -04:00
										 |  |  | quotations io assocs splitting classes.tuple generic.standard | 
					
						
							| 
									
										
										
										
											2008-01-30 02:10:58 -05:00
										 |  |  | generic.math classes io.files vocabs float-arrays float-vectors | 
					
						
							| 
									
										
										
										
											2008-04-02 16:41:29 -04:00
										 |  |  | classes.union classes.mixin classes.predicate classes.singleton | 
					
						
							|  |  |  | compiler.units combinators debugger ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: bootstrap.syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! These words are defined as a top-level form, instead of with | 
					
						
							|  |  |  | ! defining parsing words, because during stage1 bootstrap, the | 
					
						
							|  |  |  | ! "syntax" vocabulary is copied from the host. When stage1 | 
					
						
							|  |  |  | ! bootstrap completes, the host's syntax vocabulary is deleted | 
					
						
							|  |  |  | ! from the target, then this top-level form creates the | 
					
						
							|  |  |  | ! target's "syntax" vocabulary as one of the first things done | 
					
						
							|  |  |  | ! in stage2. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : define-delimiter ( name -- )
 | 
					
						
							|  |  |  |     "syntax" lookup t "delimiter" set-word-prop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : define-syntax ( name quot -- )
 | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  |     >r "syntax" lookup dup r> define t "parsing" set-word-prop ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  | [ | 
					
						
							|  |  |  |     { "]" "}" ";" ">>" } [ define-delimiter ] each
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "PRIMITIVE:" [ | 
					
						
							|  |  |  |         "Primitive definition is not supported" throw
 | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "CS{" [ | 
					
						
							|  |  |  |         "Call stack literals are not supported" throw
 | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "!" [ lexer get next-line ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "#!" [ POSTPONE: ! ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "IN:" [ scan set-in ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "PRIVATE>" [ in get ".private" ?tail drop set-in ] define-syntax | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "<PRIVATE" [ | 
					
						
							|  |  |  |         POSTPONE: PRIVATE> in get ".private" append set-in | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "USE:" [ scan use+ ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "USING:" [ ";" parse-tokens add-use ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "HEX:" [ 16 parse-base ] define-syntax | 
					
						
							|  |  |  |     "OCT:" [ 8 parse-base ] define-syntax | 
					
						
							|  |  |  |     "BIN:" [ 2 parse-base ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "f" [ f parsed ] define-syntax | 
					
						
							| 
									
										
										
										
											2008-04-02 17:32:10 -04:00
										 |  |  |     "t" "syntax" lookup define-singleton-class | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-15 20:32:14 -05:00
										 |  |  |     "CHAR:" [ | 
					
						
							|  |  |  |         scan { | 
					
						
							|  |  |  |             { [ dup length 1 = ] [ first ] } | 
					
						
							|  |  |  |             { [ "\\" ?head ] [ next-escape drop ] } | 
					
						
							|  |  |  |             { [ t ] [ name>char-hook get call ] } | 
					
						
							|  |  |  |         } cond parsed | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "\"" [ parse-string parsed ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "SBUF\"" [ | 
					
						
							|  |  |  |         lexer get skip-blank parse-string >sbuf parsed | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "P\"" [ | 
					
						
							|  |  |  |         lexer get skip-blank parse-string <pathname> parsed | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "[" [ \ ] [ >quotation ] parse-literal ] define-syntax | 
					
						
							|  |  |  |     "{" [ \ } [ >array ] parse-literal ] define-syntax | 
					
						
							|  |  |  |     "V{" [ \ } [ >vector ] parse-literal ] define-syntax | 
					
						
							|  |  |  |     "B{" [ \ } [ >byte-array ] parse-literal ] define-syntax | 
					
						
							| 
									
										
										
										
											2008-01-30 02:10:58 -05:00
										 |  |  |     "BV{" [ \ } [ >byte-vector ] parse-literal ] define-syntax | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "?{" [ \ } [ >bit-array ] parse-literal ] define-syntax | 
					
						
							| 
									
										
										
										
											2008-01-30 02:10:58 -05:00
										 |  |  |     "?V{" [ \ } [ >bit-vector ] parse-literal ] define-syntax | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "F{" [ \ } [ >float-array ] parse-literal ] define-syntax | 
					
						
							| 
									
										
										
										
											2008-01-30 02:10:58 -05:00
										 |  |  |     "FV{" [ \ } [ >float-vector ] parse-literal ] define-syntax | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "H{" [ \ } [ >hashtable ] parse-literal ] define-syntax | 
					
						
							|  |  |  |     "T{" [ \ } [ >tuple ] parse-literal ] define-syntax | 
					
						
							|  |  |  |     "W{" [ \ } [ first <wrapper> ] parse-literal ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "POSTPONE:" [ scan-word parsed ] define-syntax | 
					
						
							|  |  |  |     "\\" [ scan-word literalize parsed ] define-syntax | 
					
						
							|  |  |  |     "inline" [ word make-inline ] define-syntax | 
					
						
							|  |  |  |     "foldable" [ word make-foldable ] define-syntax | 
					
						
							|  |  |  |     "flushable" [ word make-flushable ] define-syntax | 
					
						
							|  |  |  |     "delimiter" [ word t "delimiter" set-word-prop ] define-syntax | 
					
						
							|  |  |  |     "parsing" [ word t "parsing" set-word-prop ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "SYMBOL:" [ | 
					
						
							| 
									
										
										
										
											2008-03-16 03:43:00 -04:00
										 |  |  |         CREATE-WORD define-symbol | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "DEFER:" [ | 
					
						
							|  |  |  |         scan in get create | 
					
						
							| 
									
										
										
										
											2007-12-24 17:18:26 -05:00
										 |  |  |         dup old-definitions get first delete-at
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |         set-word | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ":" [ | 
					
						
							| 
									
										
										
										
											2008-02-26 19:40:32 -05:00
										 |  |  |         (:) define | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "GENERIC:" [ | 
					
						
							| 
									
										
										
										
											2008-03-16 03:43:00 -04:00
										 |  |  |         CREATE-GENERIC define-simple-generic | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "GENERIC#" [ | 
					
						
							| 
									
										
										
										
											2008-03-16 03:43:00 -04:00
										 |  |  |         CREATE-GENERIC | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |         scan-word <standard-combination> define-generic | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "MATH:" [ | 
					
						
							| 
									
										
										
										
											2008-03-16 03:43:00 -04:00
										 |  |  |         CREATE-GENERIC | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |         T{ math-combination } define-generic | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "HOOK:" [ | 
					
						
							| 
									
										
										
										
											2008-03-16 03:43:00 -04:00
										 |  |  |         CREATE-GENERIC scan-word | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |         <hook-combination> define-generic | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "M:" [ | 
					
						
							| 
									
										
										
										
											2008-03-16 03:43:00 -04:00
										 |  |  |         (M:) define | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "UNION:" [ | 
					
						
							|  |  |  |         CREATE-CLASS parse-definition define-union-class | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "MIXIN:" [ | 
					
						
							|  |  |  |         CREATE-CLASS define-mixin-class | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-04 21:10:49 -05:00
										 |  |  |     "INSTANCE:" [ | 
					
						
							|  |  |  |         location >r | 
					
						
							|  |  |  |         scan-word scan-word 2dup add-mixin-instance | 
					
						
							|  |  |  |         <mixin-instance> r> remember-definition | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     "PREDICATE:" [ | 
					
						
							|  |  |  |         CREATE-CLASS | 
					
						
							| 
									
										
										
										
											2008-03-26 19:23:19 -04:00
										 |  |  |         scan "<" assert=
 | 
					
						
							|  |  |  |         scan-word | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |         parse-definition define-predicate-class | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-02 14:11:55 -04:00
										 |  |  |     "SINGLETON:" [ | 
					
						
							| 
									
										
										
										
											2008-04-02 16:41:29 -04:00
										 |  |  |         scan create-class-in | 
					
						
							|  |  |  |         dup save-location define-singleton-class | 
					
						
							| 
									
										
										
										
											2008-04-02 14:11:55 -04:00
										 |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "TUPLE:" [ | 
					
						
							| 
									
										
										
										
											2008-03-26 18:07:50 -04:00
										 |  |  |         parse-tuple-definition define-tuple-class | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "C:" [ | 
					
						
							| 
									
										
										
										
											2008-03-16 03:43:00 -04:00
										 |  |  |         CREATE-WORD | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |         scan-word dup check-tuple | 
					
						
							|  |  |  |         [ construct-boa ] curry define-inline | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-19 20:15:43 -04:00
										 |  |  |     "ERROR:" [ | 
					
						
							| 
									
										
										
										
											2008-03-26 18:07:50 -04:00
										 |  |  |         parse-tuple-definition | 
					
						
							|  |  |  |         pick save-location | 
					
						
							|  |  |  |         define-error-class | 
					
						
							| 
									
										
										
										
											2008-03-19 20:15:43 -04:00
										 |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-09 16:57:59 -05:00
										 |  |  |     "FORGET:" [ | 
					
						
							| 
									
										
										
										
											2008-03-27 20:52:53 -04:00
										 |  |  |         scan-object forget | 
					
						
							| 
									
										
										
										
											2008-01-09 16:57:59 -05:00
										 |  |  |     ] define-syntax | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     "(" [ | 
					
						
							|  |  |  |         parse-effect word | 
					
						
							|  |  |  |         [ swap "declared-effect" set-word-prop ] [ drop ] if*
 | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "MAIN:" [ scan-word in get vocab set-vocab-main ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-15 22:35:03 -05:00
										 |  |  |     "<<" [ | 
					
						
							|  |  |  |         [ \ >> parse-until >quotation ] with-compilation-unit | 
					
						
							|  |  |  |         call
 | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  | ] with-compilation-unit |