Skip to content

Commit

Permalink
make: fix enconding of hash and dollar signs
Browse files Browse the repository at this point in the history
Some tests were failing with Make 4.3.
  • Loading branch information
asarhaddon committed Jan 18, 2022
1 parent 790c490 commit 0382550
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion impls/make/printer.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ keyword_pr_str = $(COLON)$(patsubst $(__keyword)%,%,$(call str_decode,$($(1)_val

string_pr_str = $(if $(filter $(__keyword)%,$(call str_decode,$($(1)_value))),$(COLON)$(patsubst $(__keyword)%,%,$(call str_decode,$($(1)_value))),$(if $(2),"$(subst $(NEWLINE),$(ESC_N),$(subst $(DQUOTE),$(ESC_DQUOTE),$(subst $(SLASH),$(SLASH)$(SLASH),$(call str_decode,$($(1)_value)))))",$(call str_decode,$($(1)_value))))

function_pr_str = <$(if $(word 6,$(value $(1)_value)),$(wordlist 1,5,$(value $(1)_value))...,$(value $(1)_value))>
function_pr_str = <Function>

list_pr_str = ($(foreach v,$(call __get_obj_values,$(1)),$(call _pr_str,$(v),$(2))))

Expand Down
4 changes: 2 additions & 2 deletions impls/make/readline.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ __mal_readline_included := true
# have readline history.
READLINE_EOF :=
READLINE_HISTORY_FILE := $${HOME}/.mal-history
READLINE = $(eval __readline_temp := $(shell \
READLINE = $(eval __readline_temp := $(subst #,\#,$(subst $$,$$$$,$(shell \
history -r $(READLINE_HISTORY_FILE); \
read -u 0 -r -e -p $(if $(1),$(1),"user> ") line && \
history -s -- "$${line}" && \
echo "$${line}" || \
echo "__||EOF||__"; \
history -a $(READLINE_HISTORY_FILE) 2>/dev/null || \
true \
))$(if $(filter __||EOF||__,$(__readline_temp)),$(eval READLINE_EOF := yes),$(__readline_temp))
))))$(if $(filter __||EOF||__,$(__readline_temp)),$(eval READLINE_EOF := yes),$(__readline_temp))$(if $(DEBUG_READLINE),$(warning readline/$(__readline_temp)/))

endif
2 changes: 1 addition & 1 deletion impls/make/step2_eval.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $(strip \
$(foreach key,$($(1)_value),\
$(if $(call _contains?,$(2),$(key)),\
$(call _get,$(2),$(key)),\
$(call _error,'$(key)' not found in REPL_ENV ($(2))))),\
$(call _error,'$(key)' not found in REPL_ENV))),\
$(if $(call _list?,$(1)),\
$(call _smap,EVAL,$(1),$(2)),\
$(if $(call _vector?,$(1)),\
Expand Down
9 changes: 5 additions & 4 deletions impls/make/util.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ ESC_DQUOTE := $(SLASH)$(DQUOTE)
ESC_N := $(SLASH)n
SQUOTE := '# '
QQUOTE := `# `
SPACE :=
SPACE +=
SPACE := $(hopefully_undefined) $(hopefully_undefined)
MINUS := -
NUMBERS := 0 1 2 3 4 5 6 7 8 9
UNQUOTE := ~
Expand All @@ -35,7 +34,9 @@ define NEWLINE
endef
CARET := ^
ATSIGN := @
HASH := \#
_HASH := ©
# \u00ab
_LP := «
# \u00bb
Expand Down Expand Up @@ -86,12 +87,12 @@ _reverse = $(if $(1),$(call _reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstw
# str_encode: take a string and return an encoded version of it with
# every character separated by a space and special characters replaced
# with special Unicode characters
str_encode = $(strip $(eval __temp := $$(subst $$$$,$(_DOL) ,$$(subst $(SPLICE_UNQUOTE),$(_SUQ) ,$$(subst $$(LPAREN),$$(_LP) ,$$(subst $$(RPAREN),$$(_RP) ,$$(subst $$(LCURLY),$$(_LC) ,$$(subst $$(RCURLY),$$(_RC) ,$$(subst $$(NEWLINE),$$(_NL) ,$$(subst $$(SPACE),$(_SP) ,$$1)))))))))$(foreach a,$(gmsl_characters),$(eval __temp := $$(subst $$a,$$a$$(SPACE),$(__temp))))$(__temp))
str_encode = $(strip $(eval __temp := $$(subst $$$$,$(_DOL) ,$$(subst $(SPLICE_UNQUOTE),$(_SUQ) ,$$(subst $$(LPAREN),$$(_LP) ,$$(subst $$(RPAREN),$$(_RP) ,$$(subst $$(LCURLY),$$(_LC) ,$$(subst $$(RCURLY),$$(_RC) ,$$(subst $$(NEWLINE),$$(_NL) ,$$(subst $$(HASH),$(_HASH) ,$$(subst $$(SPACE),$(_SP) ,$$1))))))))))$(foreach a,$(gmsl_characters),$(eval __temp := $$(subst $$a,$$a$$(SPACE),$(__temp))))$(__temp))
# str_decode: take an encoded string an return an unencoded version of
# it by replacing the special Unicode charactes with the real
# characters and with all characters joined into a regular string
str_decode = $(subst $(_SP),$(SPACE),$(subst $(_NL),$(NEWLINE),$(subst $(_LC),$(LCURLY),$(subst $(_RC),$(RCURLY),$(subst $(_LP),$(LPAREN),$(subst $(_RP),$(RPAREN),$(subst $(_SUQ),$(SPLICE_UNQUOTE),$(subst $(_DOL),$$,$(strip $(call _join,$(1)))))))))))
str_decode = $(subst $(_SP),$(SPACE),$(subst $(_NL),$(NEWLINE),$(subst $(_LC),$(LCURLY),$(subst $(_RC),$(RCURLY),$(subst $(_LP),$(LPAREN),$(subst $(_RP),$(RPAREN),$(subst $(_SUQ),$(SPLICE_UNQUOTE),$(subst $(_DOL),$$,$(subst $(_HASH),$(HASH),$(strip $(call _join,$(1))))))))))))
# Read a whole file substituting newlines with $(_NL)
_read_file = $(subst $(_NL),$(NEWLINE),$(shell out=""; while read -r l; do out="$${out}$${l}$(_NL)"; done < $(1); echo "$$out"))
Expand Down

0 comments on commit 0382550

Please sign in to comment.