From 2a19d0ca4e936b6c885d1eaefb2c7c3e4fd084ec Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 7 Jun 2016 23:34:12 -0700 Subject: [PATCH] factor: Add syntax.arity for new parser. --- core/bootstrap/stage1.factor | 1 + core/bootstrap/syntax.factor | 5 ++--- core/syntax/arity/arity.factor | 25 +++++++++++++++++++++++++ core/syntax/arity/authors.txt | 1 + core/syntax/syntax.factor | 17 ++++++----------- language/alien/syntax/syntax.factor | 8 +++++++- 6 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 core/syntax/arity/arity.factor create mode 100644 core/syntax/arity/authors.txt diff --git a/core/bootstrap/stage1.factor b/core/bootstrap/stage1.factor index 70aaacf5d4..df3684d187 100644 --- a/core/bootstrap/stage1.factor +++ b/core/bootstrap/stage1.factor @@ -37,6 +37,7 @@ load-help? off "vocabs.loader" require "syntax" require + "syntax.arity" require "bootstrap.layouts" require ! need this diff --git a/core/bootstrap/syntax.factor b/core/bootstrap/syntax.factor index 4979f6db37..44530d05b3 100644 --- a/core/bootstrap/syntax.factor +++ b/core/bootstrap/syntax.factor @@ -15,8 +15,8 @@ in: bootstrap.syntax "B{" "BV{" "C:" - "CHAR:" "char:" + "ARITY:" "DEFER:" "defer:" "ERROR:" @@ -36,7 +36,6 @@ in: bootstrap.syntax "MATH:" "MIXIN:" "mixin:" - "NAN:" "nan:" "POSTPONE\\" "postpone\\" @@ -64,7 +63,7 @@ in: bootstrap.syntax "UNUSE:" "unuse:" "USING:" - "qualified:" + "QUALIFIED:" "qualified:" "QUALIFIED-WITH:" "FROM:" diff --git a/core/syntax/arity/arity.factor b/core/syntax/arity/arity.factor new file mode 100644 index 0000000000..140f89fe22 --- /dev/null +++ b/core/syntax/arity/arity.factor @@ -0,0 +1,25 @@ +! Copyright (C) 2016 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: ; +in: syntax.arity + +ARITY: \ IN: 1 +ARITY: \ USE: 1 +ARITY: \ UNUSE: 1 +ARITY: \ SYMBOL: 1 +ARITY: \ SINGLETON: 1 +ARITY: \ B: 1 + + +ARITY: \ ALIAS: 2 +ARITY: \ C: 2 +ARITY: \ CONSTANT: 2 +ARITY: \ INSTANCE: 2 + +ARITY: \ GENERIC: 2 +ARITY: \ PRIMITIVE: 2 + + +ARITY: \ GENERIC# 3 +ARITY: \ HOOK: 3 + diff --git a/core/syntax/arity/authors.txt b/core/syntax/arity/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/core/syntax/arity/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/core/syntax/syntax.factor b/core/syntax/syntax.factor index 41472beabe..aba2b98c6c 100644 --- a/core/syntax/syntax.factor +++ b/core/syntax/syntax.factor @@ -82,7 +82,7 @@ in: bootstrap.syntax "USING:" [ ";" [ use-vocab ] each-token ] define-core-syntax - "qualified:" [ scan-token dup add-qualified ] define-core-syntax + "QUALIFIED:" [ scan-token dup add-qualified ] define-core-syntax "qualified:" [ scan-token dup add-qualified ] define-core-syntax "QUALIFIED-WITH:" [ scan-token scan-token ";" expect add-qualified ] define-core-syntax @@ -99,19 +99,10 @@ in: bootstrap.syntax scan-token scan-token "=>" expect scan-token ";" expect add-renamed-word ] define-core-syntax - "NAN:" [ 16 scan-base suffix! ] define-core-syntax "nan:" [ 16 scan-base suffix! ] define-core-syntax "f" [ f suffix! ] define-core-syntax - "CHAR:" [ - lexer get parse-raw [ "token" throw-unexpected-eof ] unless* { - { [ dup length 1 = ] [ first ] } - { [ "\\" ?head ] [ next-escape >string "" assert= ] } - [ name>char-hook get call( name -- char ) ] - } cond suffix! - ] define-core-syntax - "char:" [ lexer get parse-raw [ "token" throw-unexpected-eof ] unless* { { [ dup length 1 = ] [ first ] } @@ -140,7 +131,6 @@ in: bootstrap.syntax "W{" [ \ } [ first ] parse-literal ] define-core-syntax "HS{" [ \ } [ >hash-set ] parse-literal ] define-core-syntax - "POSTPONE\\" [ scan-word suffix! ] define-core-syntax "postpone\\" [ scan-word suffix! ] define-core-syntax "\\" [ scan-word suffix! ] define-core-syntax "M\\" [ scan-word scan-word lookup-method suffix! ] define-core-syntax @@ -189,6 +179,7 @@ in: bootstrap.syntax scan-token current-vocab create-word [ fake-definition ] [ set-last-word ] [ undefined-def define ] tri ] define-core-syntax + "defer:" [ scan-token current-vocab create-word [ fake-definition ] [ set-last-word ] [ undefined-def define ] tri @@ -315,6 +306,10 @@ in: bootstrap.syntax [ current-source-file get [ main<< ] [ drop ] if* ] bi ] define-core-syntax + "ARITY:" [ + scan-escaped-word scan-number "arity" set-word-prop + ] define-core-syntax + "<<" [ [ \ >> parse-until >quotation diff --git a/language/alien/syntax/syntax.factor b/language/alien/syntax/syntax.factor index 78182649c6..271045d17a 100755 --- a/language/alien/syntax/syntax.factor +++ b/language/alien/syntax/syntax.factor @@ -8,34 +8,40 @@ in: alien.syntax SYNTAX: \ DLL" lexer get skip-blank parse-string dlopen suffix! ; -SYNTAX: \ ALIEN: 16 scan-base suffix! ; SYNTAX: \ alien: 16 scan-base suffix! ; SYNTAX: BAD-ALIEN suffix! ; SYNTAX: \ LIBRARY: scan-token current-library set ; +ARITY: \ LIBRARY: 1 SYNTAX: \ library: scan-token current-library set ; +ARITY: \ library: 1 SYNTAX: \ FUNCTION: (FUNCTION:) make-function define-inline ; +ARITY: \ FUNCTION: 4 SYNTAX: \ FUNCTION-ALIAS: scan-token create-function (FUNCTION:) (make-function) define-inline ; +ARITY: \ FUNCTION-ALIAS: 4 SYNTAX: \ CALLBACK: (CALLBACK:) define-inline ; SYNTAX: \ TYPEDEF: scan-c-type CREATE-C-TYPE ";" expect dup save-location typedef ; +ARITY: \ TYPEDEF: 2 SYNTAX: \ ENUM: parse-enum (define-enum) ; SYNTAX: \ C-TYPE: void CREATE-C-TYPE typedef ; +ARITY: \ C-TYPE: 2 SYNTAX: \ c-type: void CREATE-C-TYPE typedef ; +ARITY: \ c-type: 2 SYNTAX: \ &: scan-token current-library get '[ _ _ address-of ] append! ;