| 
									
										
										
										
											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-07-02 03:03:30 -04:00
										 |  |  | USING: alien arrays byte-arrays byte-vectors | 
					
						
							| 
									
										
										
										
											2008-06-25 04:25:08 -04:00
										 |  |  | definitions generic hashtables kernel math namespaces parser | 
					
						
							|  |  |  | lexer sequences strings strings.parser sbufs vectors | 
					
						
							|  |  |  | words quotations io assocs splitting classes.tuple | 
					
						
							|  |  |  | generic.standard generic.math generic.parser classes io.files | 
					
						
							| 
									
										
										
										
											2008-07-02 03:03:30 -04:00
										 |  |  | vocabs classes.parser classes.union | 
					
						
							| 
									
										
										
										
											2008-06-25 04:25:08 -04:00
										 |  |  | classes.intersection classes.mixin classes.predicate | 
					
						
							|  |  |  | classes.singleton classes.tuple.parser compiler.units | 
					
						
							| 
									
										
										
										
											2008-06-28 03:36:20 -04:00
										 |  |  | combinators debugger effects.parser slots ;
 | 
					
						
							| 
									
										
										
										
											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 ] } | 
					
						
							| 
									
										
										
										
											2008-04-11 13:53:22 -04:00
										 |  |  |             [ name>char-hook get call ] | 
					
						
							| 
									
										
										
										
											2008-02-15 20:32:14 -05:00
										 |  |  |         } 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-04-30 17:11:55 -04:00
										 |  |  |     "BV{" [ \ } [ >byte-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 | 
					
						
							| 
									
										
										
										
											2008-07-18 20:22:59 -04:00
										 |  |  |     "recursive" [ word make-recursive ] define-syntax | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "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:" [ | 
					
						
							| 
									
										
										
										
											2008-05-28 20:43:01 -04:00
										 |  |  |         scan current-vocab create | 
					
						
							| 
									
										
										
										
											2008-05-28 20:34:18 -04:00
										 |  |  |         dup old-definitions get [ delete-at ] with each
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-10 19:09:05 -04:00
										 |  |  |     "INTERSECTION:" [ | 
					
						
							|  |  |  |         CREATE-CLASS parse-definition define-intersection-class | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "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-05-10 19:20:50 -04:00
										 |  |  |         CREATE-CLASS 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-28 03:36:20 -04:00
										 |  |  |     "SLOT:" [ | 
					
						
							|  |  |  |         scan define-protocol-slot | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "C:" [ | 
					
						
							| 
									
										
										
										
											2008-03-16 03:43:00 -04:00
										 |  |  |         CREATE-WORD | 
					
						
							| 
									
										
										
										
											2008-06-30 02:44:58 -04:00
										 |  |  |         scan-word [ boa ] curry define-inline | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     ] 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
										 |  |  | 
 | 
					
						
							|  |  |  |     "(" [ | 
					
						
							| 
									
										
										
										
											2008-06-11 03:58:38 -04:00
										 |  |  |         ")" parse-effect | 
					
						
							| 
									
										
										
										
											2008-06-11 19:53:56 -04:00
										 |  |  |         word dup [ set-stack-effect ] [ 2drop ] if
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  |     "((" [ | 
					
						
							|  |  |  |         "))" parse-effect parsed | 
					
						
							|  |  |  |     ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  |     "MAIN:" [ scan-word in get vocab set-vocab-main ] define-syntax | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-15 22:35:03 -05:00
										 |  |  |     "<<" [ | 
					
						
							| 
									
										
										
										
											2008-05-28 20:34:18 -04:00
										 |  |  |         [ | 
					
						
							|  |  |  |             \ >> parse-until >quotation | 
					
						
							|  |  |  |         ] with-nested-compilation-unit call
 | 
					
						
							| 
									
										
										
										
											2008-01-15 22:35:03 -05:00
										 |  |  |     ] define-syntax | 
					
						
							| 
									
										
										
										
											2008-04-02 22:27:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     "call-next-method" [ | 
					
						
							| 
									
										
										
										
											2008-04-26 19:55:26 -04:00
										 |  |  |         current-class get current-generic get
 | 
					
						
							|  |  |  |         2dup [ word? ] both? [ | 
					
						
							|  |  |  |             [ literalize parsed ] bi@
 | 
					
						
							|  |  |  |             \ (call-next-method) parsed | 
					
						
							|  |  |  |         ] [ | 
					
						
							|  |  |  |             not-in-a-method-error | 
					
						
							|  |  |  |         ] if
 | 
					
						
							| 
									
										
										
										
											2008-04-02 22:27:49 -04:00
										 |  |  |     ] define-syntax | 
					
						
							| 
									
										
										
										
											2008-06-28 03:36:20 -04:00
										 |  |  |      | 
					
						
							|  |  |  |     "initial:" "syntax" lookup define-symbol | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2008-06-30 02:44:58 -04:00
										 |  |  |     "read-only" "syntax" lookup define-symbol | 
					
						
							| 
									
										
										
										
											2007-12-21 21:18:24 -05:00
										 |  |  | ] with-compilation-unit |