From c64f6f2357727af3269409914fdebe6f4337ddd4 Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Sun, 6 Feb 2022 22:04:42 +0100 Subject: [PATCH] make: trivial --- impls/make/gmsl.mk | 4 ---- impls/make/printer.mk | 4 ++-- impls/make/reader.mk | 56 +++++++++++++++++++++---------------------- impls/make/util.mk | 25 +++---------------- 4 files changed, 33 insertions(+), 56 deletions(-) diff --git a/impls/make/gmsl.mk b/impls/make/gmsl.mk index adfb953582..a6374fa05f 100644 --- a/impls/make/gmsl.mk +++ b/impls/make/gmsl.mk @@ -55,8 +55,4 @@ gmsl_characters += 0 1 2 3 4 5 6 7 8 9 gmsl_characters += ` ~ ! @ \# $$ % ^ & * ( ) - _ = + gmsl_characters += { } [ ] \ : ; ' " < > , . / ? | -gmsl_pairmap = $(strip \ - $(if $2$3,$(call $1,$(word 1,$2),$(word 1,$3)) \ - $(call gmsl_pairmap,$1,$(wordlist 2,$(words $2),$2),$(wordlist 2,$(words $3),$3)))) - endif diff --git a/impls/make/printer.mk b/impls/make/printer.mk index 55abd96f06..0187424d7f 100644 --- a/impls/make/printer.mk +++ b/impls/make/printer.mk @@ -33,8 +33,8 @@ symbol_pr_str = $(_symbol_val) keyword_pr_str = $(encoded_colon)$(_keyword_val) string_pr_str = $(if $2\ - ,"$(subst $(_NL),$(ESC_N),$(rem \ - )$(subst $(DQUOTE),$(ESC_DQUOTE),$(rem \ + ,"$(subst $(_NL),$(encoded_slash)n,$(rem \ + )$(subst ",$(encoded_slash)",$(rem \ )$(subst $(encoded_slash),$(encoded_slash)$(encoded_slash),$(rem \ )$(_string_val))))"$(rem \ else \ diff --git a/impls/make/reader.mk b/impls/make/reader.mk index eff3ad9d96..602464ccd6 100755 --- a/impls/make/reader.mk +++ b/impls/make/reader.mk @@ -11,7 +11,7 @@ include $(_TOP_DIR)types.mk READER_DEBUG ?= -_TOKEN_DELIMS := $(SEMI) $(COMMA) $(DQUOTE) $(QQUOTE) $(_SP) $(_NL) { } $(_LP) $(_RP) $(LBRACKET) $(RBRACKET) +_TOKEN_DELIMS := ; , " ` $(_SP) $(_NL) { } $(_LP) $(_RP) [ ] #`" reader_init = $(eval __reader_temp := $(str_encode)) reader_next = $(firstword $(__reader_temp)) @@ -20,21 +20,21 @@ reader_log = $(if $(READER_DEBUG),$(info READER: $1 from $(__reader_temp))) define READ_NUMBER $(call reader_log,number)$(rem \ -)$(if $(filter $(NUMBERS),$(reader_next))\ +)$(if $(filter 0 1 2 3 4 5 6 7 8 9,$(reader_next))\ ,$(reader_next)$(reader_drop)$(call READ_NUMBER)) endef define READ_STRING $(call reader_log,string)$(rem \ -)$(if $(filter $(DQUOTE),$(reader_next))\ - ,$(reader_drop)$(rem \ +)$(if $(filter ",$(reader_next))\ + ,$(reader_drop)$(rem "\ ),$(if $(filter $(encoded_slash),$(reader_next))\ ,$(reader_drop)$(rem \ )$(if $(filter n,$(reader_next)),$(_NL),$(reader_next))$(rem \ )$(reader_drop)$(call READ_STRING)$(rem \ ),$(if $(reader_next)\ ,$(reader_next)$(reader_drop)$(call READ_STRING)$(rem \ -),$(call _error,Expected '$(DQUOTE)'$(COMMA) got EOF)))) +),$(call _error,Expected '"'$(COMMA) got EOF)))) endef define READ_SYMBOL @@ -56,7 +56,7 @@ $(call reader_log,until $1)$(rem \ endef define READ_COMMENT -$(call reader_log,read comment)$(rem \ +$(call reader_log,comment)$(rem \ )$(if $(filter-out $(_NL),$(reader_next))\ ,$(reader_drop)$(call READ_COMMENT)) endef @@ -64,8 +64,8 @@ endef define READ_SPACES $(call reader_log,spaces)$(rem \ )$(if $(filter $(_SP) $(_NL) $(COMMA),$(reader_next))\ - ,$(reader_drop)$(call READ_SPACES),$(rem \ -)$(if $(filter $(SEMI),$(reader_next))\ + ,$(reader_drop)$(call READ_SPACES)$(rem \ +),$(if $(filter ;,$(reader_next))\ ,$(READ_COMMENT))) endef @@ -74,39 +74,39 @@ $(call reader_log,form)$(rem \ )$(READ_SPACES)$(rem \ )$(if $(filter-out undefined,$(flavor READ_FORM_$(reader_next)))\ ,$(call READ_FORM_$(reader_next)$(reader_drop))$(rem \ -),$(if $(reader_next)\ - ,$(foreach sym,$(READ_SYMBOL)\ +),$(foreach sym,$(READ_SYMBOL)\ ,$(if $(filter false nil true,$(sym))\ ,$(__$(sym))$(rem \ - ),$(call _symbol,$(sym))))$(rem \ -),$(call _error,expected a form, found EOF))) + ),$(call _symbol,$(sym))))) endef +READ_FORM_ = $(call _error,expected a form$(COMMA) found EOF) + # Reader macros -READ_FORM_$(ATSIGN) = $(call list,$(call _symbol,deref) $(call READ_FORM)) -READ_FORM_$(SQUOTE) = $(call list,$(call _symbol,quote) $(call READ_FORM)) -READ_FORM_$(QQUOTE) = $(call list,$(call _symbol,quasiquote) $(call READ_FORM)) -READ_FORM_$(CARET) = $(call list,$(call _symbol,with-meta) $(foreach m,\ +READ_FORM_@ = $(call list,$(call _symbol,deref) $(call READ_FORM)) +READ_FORM_' = $(call list,$(call _symbol,quote) $(call READ_FORM))#' +READ_FORM_` = $(call list,$(call _symbol,quasiquote) $(call READ_FORM))#` +READ_FORM_^ = $(call list,$(call _symbol,with-meta) $(foreach m,\ $(call READ_FORM),$(call READ_FORM) $m)) -READ_FORM_$(UNQUOTE) = $(call list,$(if $(filter $(ATSIGN),$(reader_next))\ +READ_FORM_~ = $(call list,$(if $(filter @,$(reader_next))\ ,$(reader_drop)$(call _symbol,splice-unquote)$(rem \ ),$(call _symbol,unquote)) $(call READ_FORM)) # Lists, vectors and maps # _map_new accepts a leading space, list and vector require )strip. -READ_FORM_$(LCURLY) = $(call _map_new,,$(strip $(call READ_UNTIL,$(RCURLY)))) -READ_FORM_$(_LP) = $(call list,$(strip $(call READ_UNTIL,$(_RP)))) -READ_FORM_$(LBRACKET) = $(call vector,$(strip $(call READ_UNTIL,$(RBRACKET)))) -READ_FORM_$(RCURLY) = $(call _error,Unexpected '$(RCURLY)') -READ_FORM_$(_RP) = $(call _error,Unexpected '$(_RP)') -READ_FORM_$(RBRACKET) = $(call _error,Unexpected '$(RBRACKET)') +READ_FORM_{ = $(call _map_new,,$(strip $(call READ_UNTIL,}))) +READ_FORM_$(_LP) = $(call list,$(strip $(call READ_UNTIL,$(_RP)))) +READ_FORM_[ = $(call vector,$(strip $(call READ_UNTIL,]))) +READ_FORM_} = $(call _error,Unexpected '}') +READ_FORM_$(_RP) = $(call _error,Unexpected '$(_RP)') +READ_FORM_] = $(call _error,Unexpected ']') # Numbers -define READ_FORM_$(MINUS) -$(if $(filter $(NUMBERS),$(reader_next))\ - ,$(call _number,$(MINUS)$(READ_NUMBER))$(rem \ - ),$(call _symbol,$(MINUS)$(READ_SYMBOL))) +define READ_FORM_- +$(if $(filter 0 1 2 3 4 5 6 7 8 9,$(reader_next))\ + ,$(call _number,-$(READ_NUMBER))$(rem \ + ),$(call _symbol,-$(READ_SYMBOL))) endef READ_FORM_0 = $(call _number,0$(READ_NUMBER)) READ_FORM_1 = $(call _number,1$(READ_NUMBER)) @@ -120,7 +120,7 @@ READ_FORM_8 = $(call _number,8$(READ_NUMBER)) READ_FORM_9 = $(call _number,9$(READ_NUMBER)) # Strings -READ_FORM_$(DQUOTE) = $(call _string,$(call str_decode,$(READ_STRING))) +READ_FORM_" = $(call _string,$(call str_decode,$(READ_STRING)))#" # Keywords READ_FORM_$(encoded_colon) = $(call _keyword,$(READ_SYMBOL)) diff --git a/impls/make/util.mk b/impls/make/util.mk index 77139a1add..898e9ed28d 100644 --- a/impls/make/util.mk +++ b/impls/make/util.mk @@ -14,32 +14,17 @@ encoded_slash := λ raw_hash := \# encoded_hash := η -SEMI := ; COMMA := , COLON := : -LCURLY := { -RCURLY := } LPAREN := ( RPAREN := ) -LBRACKET := [ -RBRACKET := ] -DQUOTE := "# " SLASH := $(strip \ ) -ESC_DQUOTE := $(encoded_slash)$(DQUOTE) -ESC_N := $(encoded_slash)n -SQUOTE := '# ' -QQUOTE := `# ` SPACE := SPACE := $(SPACE) $(SPACE) -MINUS := - -NUMBERS := 0 1 2 3 4 5 6 7 8 9 -UNQUOTE := ~ define NEWLINE endef -CARET := ^ -ATSIGN := @ # \u00ab _LP := « @@ -51,8 +36,6 @@ _SP := § _DOL := Ş ## \u00b6 _NL := ¶ -## \u00a8 -###_EDQ := ¨ # @@ -117,13 +100,11 @@ print = $(info $(str_decode_nospace)) _rest = $(wordlist 2,$(words $1),$1) _rest2 = $(wordlist 3,$(words $1),$1) -# Evaluate $3 repeatedly with $k and $v set to key/value pairs from $1. +# Evaluate $2 repeatedly with $k and $v set to key/value pairs from $1. define _foreach2 -$(if $1\ - ,$(foreach k,$(firstword $1)\ +$(foreach k,$(firstword $1)\ ,$(foreach v,$(word 2,$1)\ - ,$(eval $2)))$(rem \ - )$(call _foreach2,$(_rest2),$2)) + ,$(eval $2)$(call _foreach2,$(_rest2),$2))) endef endif