plsql: add dockerfile. Lots of cleanup/renaming.
[jackhill/mal.git] / make / printer.mk
1 #
2 # mal (Make a Lisp) printer
3 #
4
5 ifndef __mal_printer_included
6 __mal_printer_included := true
7
8 _TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
9 include $(_TOP_DIR)util.mk
10 include $(_TOP_DIR)types.mk
11
12 # return a printable form of the argument, the second parameter is
13 # 'print_readably' which backslashes quotes in string values
14 _pr_str = $(if $(1),$(foreach ot,$(call _obj_type,$(1)),$(if $(call _EQ,make,$(ot)),$(call _error,_pr_str failed on $(1)),$(call $(ot)_pr_str,$(1),$(2)))),)
15
16 # Like _pr_str but takes multiple values in first argument, the second
17 # parameter is 'print_readably' which backslashes quotes in string
18 # values, the third parameter is the delimeter to use between each
19 # _pr_str'd value
20 _pr_str_mult = $(call _pr_str,$(word 1,$(1)),$(2))$(if $(word 2,$(1)),$(3)$(call _pr_str_mult,$(wordlist 2,$(words $(1)),$(1)),$(2),$(3)),)
21
22
23 # Type specific printing
24
25 nil_pr_str = nil
26 true_pr_str = true
27 false_pr_str = false
28
29 number_pr_str = $(call int_decode,$($(1)_value))
30
31 symbol_pr_str = $($(1)_value)
32
33 keyword_pr_str = $(COLON)$(patsubst $(__keyword)%,%,$(call str_decode,$($(1)_value)))
34
35 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))))
36
37 function_pr_str = <$(if $(word 6,$(value $(1)_value)),$(wordlist 1,5,$(value $(1)_value))...,$(value $(1)_value))>
38
39 list_pr_str = ($(foreach v,$(call __get_obj_values,$(1)),$(call _pr_str,$(v),$(2))))
40
41 vector_pr_str = [$(foreach v,$(call __get_obj_values,$(1)),$(call _pr_str,$(v),$(2)))]
42
43 hash_map_pr_str = {$(foreach v,$(call __get_obj_values,$(1)),$(foreach vval,$(foreach hcode,$(word 3,$(subst _, ,$(1))),$(patsubst $(1)_%,%,$(v:%_value=%))),$(if $(filter $(__keyword)%,$(vval)),$(patsubst $(__keyword)%,$(COLON)%,$(vval)),"$(vval)")) $(call _pr_str,$($(v)),$(2)))}
44
45 atom_pr_str = (atom $(call _pr_str,$($(1)_value),$(2)))
46
47 endif