factor: Add syntax.arity for new parser.

locals-and-roots
Doug Coleman 2016-06-07 23:34:12 -07:00
parent 516073cbd0
commit 2a19d0ca4e
6 changed files with 42 additions and 15 deletions

View File

@ -37,6 +37,7 @@ load-help? off
"vocabs.loader" require "vocabs.loader" require
"syntax" require "syntax" require
"syntax.arity" require
"bootstrap.layouts" require "bootstrap.layouts" require
! need this ! need this

View File

@ -15,8 +15,8 @@ in: bootstrap.syntax
"B{" "B{"
"BV{" "BV{"
"C:" "C:"
"CHAR:"
"char:" "char:"
"ARITY:"
"DEFER:" "DEFER:"
"defer:" "defer:"
"ERROR:" "ERROR:"
@ -36,7 +36,6 @@ in: bootstrap.syntax
"MATH:" "MATH:"
"MIXIN:" "MIXIN:"
"mixin:" "mixin:"
"NAN:"
"nan:" "nan:"
"POSTPONE\\" "POSTPONE\\"
"postpone\\" "postpone\\"
@ -64,7 +63,7 @@ in: bootstrap.syntax
"UNUSE:" "UNUSE:"
"unuse:" "unuse:"
"USING:" "USING:"
"qualified:" "QUALIFIED:"
"qualified:" "qualified:"
"QUALIFIED-WITH:" "QUALIFIED-WITH:"
"FROM:" "FROM:"

View File

@ -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

View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -82,7 +82,7 @@ in: bootstrap.syntax
"USING:" [ ";" [ use-vocab ] each-token ] define-core-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:" [ scan-token dup add-qualified ] define-core-syntax
"QUALIFIED-WITH:" [ scan-token scan-token ";" expect 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 scan-token scan-token "=>" expect scan-token ";" expect add-renamed-word
] define-core-syntax ] define-core-syntax
"NAN:" [ 16 scan-base <fp-nan> suffix! ] define-core-syntax
"nan:" [ 16 scan-base <fp-nan> suffix! ] define-core-syntax "nan:" [ 16 scan-base <fp-nan> suffix! ] define-core-syntax
"f" [ f 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:" [ "char:" [
lexer get parse-raw [ "token" throw-unexpected-eof ] unless* { lexer get parse-raw [ "token" throw-unexpected-eof ] unless* {
{ [ dup length 1 = ] [ first ] } { [ dup length 1 = ] [ first ] }
@ -140,7 +131,6 @@ in: bootstrap.syntax
"W{" [ \ } [ first <wrapper> ] parse-literal ] define-core-syntax "W{" [ \ } [ first <wrapper> ] parse-literal ] define-core-syntax
"HS{" [ \ } [ >hash-set ] 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 "postpone\\" [ scan-word suffix! ] define-core-syntax
"\\" [ scan-word <wrapper> suffix! ] define-core-syntax "\\" [ scan-word <wrapper> suffix! ] define-core-syntax
"M\\" [ scan-word scan-word lookup-method <wrapper> suffix! ] define-core-syntax "M\\" [ scan-word scan-word lookup-method <wrapper> suffix! ] define-core-syntax
@ -189,6 +179,7 @@ in: bootstrap.syntax
scan-token current-vocab create-word scan-token current-vocab create-word
[ fake-definition ] [ set-last-word ] [ undefined-def define ] tri [ fake-definition ] [ set-last-word ] [ undefined-def define ] tri
] define-core-syntax ] define-core-syntax
"defer:" [ "defer:" [
scan-token current-vocab create-word scan-token current-vocab create-word
[ fake-definition ] [ set-last-word ] [ undefined-def define ] tri [ fake-definition ] [ set-last-word ] [ undefined-def define ] tri
@ -315,6 +306,10 @@ in: bootstrap.syntax
[ current-source-file get [ main<< ] [ drop ] if* ] bi [ current-source-file get [ main<< ] [ drop ] if* ] bi
] define-core-syntax ] define-core-syntax
"ARITY:" [
scan-escaped-word scan-number "arity" set-word-prop
] define-core-syntax
"<<" [ "<<" [
[ [
\ >> parse-until >quotation \ >> parse-until >quotation

View File

@ -8,34 +8,40 @@ in: alien.syntax
SYNTAX: \ DLL" lexer get skip-blank parse-string dlopen suffix! ; SYNTAX: \ DLL" lexer get skip-blank parse-string dlopen suffix! ;
SYNTAX: \ ALIEN: 16 scan-base <alien> suffix! ;
SYNTAX: \ alien: 16 scan-base <alien> suffix! ; SYNTAX: \ alien: 16 scan-base <alien> suffix! ;
SYNTAX: BAD-ALIEN <bad-alien> suffix! ; SYNTAX: BAD-ALIEN <bad-alien> suffix! ;
SYNTAX: \ LIBRARY: scan-token current-library set ; SYNTAX: \ LIBRARY: scan-token current-library set ;
ARITY: \ LIBRARY: 1
SYNTAX: \ library: scan-token current-library set ; SYNTAX: \ library: scan-token current-library set ;
ARITY: \ library: 1
SYNTAX: \ FUNCTION: SYNTAX: \ FUNCTION:
(FUNCTION:) make-function define-inline ; (FUNCTION:) make-function define-inline ;
ARITY: \ FUNCTION: 4
SYNTAX: \ FUNCTION-ALIAS: SYNTAX: \ FUNCTION-ALIAS:
scan-token create-function scan-token create-function
(FUNCTION:) (make-function) define-inline ; (FUNCTION:) (make-function) define-inline ;
ARITY: \ FUNCTION-ALIAS: 4
SYNTAX: \ CALLBACK: SYNTAX: \ CALLBACK:
(CALLBACK:) define-inline ; (CALLBACK:) define-inline ;
SYNTAX: \ TYPEDEF: SYNTAX: \ TYPEDEF:
scan-c-type CREATE-C-TYPE ";" expect dup save-location typedef ; scan-c-type CREATE-C-TYPE ";" expect dup save-location typedef ;
ARITY: \ TYPEDEF: 2
SYNTAX: \ ENUM: SYNTAX: \ ENUM:
parse-enum (define-enum) ; parse-enum (define-enum) ;
SYNTAX: \ C-TYPE: SYNTAX: \ C-TYPE:
void CREATE-C-TYPE typedef ; void CREATE-C-TYPE typedef ;
ARITY: \ C-TYPE: 2
SYNTAX: \ c-type: SYNTAX: \ c-type:
void CREATE-C-TYPE typedef ; void CREATE-C-TYPE typedef ;
ARITY: \ c-type: 2
SYNTAX: \ &: SYNTAX: \ &:
scan-token current-library get '[ _ _ address-of ] append! ; scan-token current-library get '[ _ _ address-of ] append! ;