factor/core/syntax/syntax.factor

207 lines
5.6 KiB
Factor
Raw Normal View History

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-04-30 17:11:55 -04:00
USING: alien arrays bit-arrays byte-arrays byte-vectors
2008-04-20 01:18:27 -04:00
definitions generic hashtables kernel math
2008-01-30 02:10:58 -05:00
namespaces parser sequences strings sbufs vectors words
quotations io assocs splitting classes.tuple generic.standard
2008-04-20 01:18:27 -04:00
generic.math classes io.files vocabs float-arrays
2008-05-10 19:09:05 -04:00
classes.union classes.intersection 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
[
{ "]" "}" ";" ">>" } [ define-delimiter ] each
2007-09-20 18:09:08 -04: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
"<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
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
"\"" [ 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
"?{" [ \ } [ >bit-array ] parse-literal ] define-syntax
"F{" [ \ } [ >float-array ] parse-literal ] define-syntax
"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
] define-syntax
"DEFER:" [
scan in get create
2007-12-24 17:18:26 -05:00
dup old-definitions get first delete-at
set-word
] define-syntax
":" [
2008-02-26 19:40:32 -05:00
(:) define
] define-syntax
"GENERIC:" [
2008-03-16 03:43:00 -04:00
CREATE-GENERIC define-simple-generic
] define-syntax
"GENERIC#" [
2008-03-16 03:43:00 -04:00
CREATE-GENERIC
scan-word <standard-combination> define-generic
] define-syntax
"MATH:" [
2008-03-16 03:43:00 -04:00
CREATE-GENERIC
T{ math-combination } define-generic
] define-syntax
"HOOK:" [
2008-03-16 03:43:00 -04:00
CREATE-GENERIC scan-word
<hook-combination> define-generic
] define-syntax
"M:" [
2008-03-16 03:43:00 -04:00
(M:) define
] 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
"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
"PREDICATE:" [
CREATE-CLASS
2008-03-26 19:23:19 -04:00
scan "<" assert=
scan-word
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
"TUPLE:" [
2008-03-26 18:07:50 -04:00
parse-tuple-definition define-tuple-class
] define-syntax
"C:" [
2008-03-16 03:43:00 -04:00
CREATE-WORD
scan-word dup check-tuple
[ 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
"(" [
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
"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
] define-syntax
] with-compilation-unit