aboutsummaryrefslogtreecommitdiff
path: root/frontend/ShowWrapped.icl
blob: 7254b4046ba843737bfc220e14cada8e33e64f22 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
implementation module ShowWrapped

import StdEnv
import Wrap

ShowParentheses
	:==	True
Don`tShowParentheses
	:==	False

showWrapped :: WrappedNode -> [{#Char}]
showWrapped node
	=	show Don`tShowParentheses node

show :: Bool WrappedNode -> [{#Char}]
show _ (WrappedInt i)
	=	[toString i]
show _ (WrappedChar c)
	=	["\'" +++ toString c +++ "\'"]
show _ (WrappedBool b)
	=	[toString b]
show _ (WrappedReal r)
	=	[toString r]
show _ (WrappedFile _)
	=	["File"]
show _ (WrappedString s)
	=	["\"" +++ s +++ "\""]
show _ (WrappedIntArray a)
	=	showBasicArray a
show _ (WrappedBoolArray a)
	=	showBasicArray a
show _ (WrappedRealArray a)
	=	showBasicArray a
show _ (WrappedFileArray a)
	=	showBasicArray a
show _ (WrappedArray a)
	=	["{" : flatten (separate [", "] [show Don`tShowParentheses el \\ el <-: a])] ++ ["}"]
show _ (WrappedRecord descriptor args)
	=	["{" : flatten (separate [" "] [[showDescriptor descriptor] : [show ShowParentheses arg \\ arg <-: args]])] ++ ["}"]
show _ (WrappedOther WrappedDescriptorCons args)
	| size args == 2
		=	["[" : flatten [show Don`tShowParentheses args.[0] : showTail args.[1]]] ++ ["]"]
	where
		showTail :: WrappedNode -> [[{#Char}]]
		showTail (WrappedOther WrappedDescriptorCons args)
			| size args == 2
				=	[[", "], show Don`tShowParentheses args.[0] : showTail args.[1]]
		showTail (WrappedOther WrappedDescriptorNil args)
			| size args == 0
				=	[]
		showTail node // abnormal list
			=	[[" : " : show Don`tShowParentheses node]]
show _ (WrappedOther WrappedDescriptorTuple args)
	=	["(" : flatten (separate [", "] [show Don`tShowParentheses arg \\ arg <-: args])] ++ [")"]
show parentheses (WrappedOther descriptor args)
	| parentheses && size args > 0
		=	["(" : application] ++ [")"]
	// otherwise
		=	application
	where
		application
			=	flatten (separate [" "] [[showDescriptor descriptor] : [show ShowParentheses arg \\ arg <-: args]])

showDescriptor :: WrappedDescriptor -> {#Char}
showDescriptor (WrappedDescriptorOther id)
	=	toString id
showDescriptor WrappedDescriptorNil
	=	"[]"
showDescriptor WrappedDescriptorCons
	=	"[:]"
showDescriptor WrappedDescriptorTuple
	=	"(..)"

showBasicArray :: {#a} -> [{#Char}] | toString, ArrayElem a
showBasicArray a
	=	["{" : separate ", " [toString el \\ el <-: a]] ++ ["}"]

showWrappedArray :: {WrappedNode} -> [{#Char}]
showWrappedArray a
	=	["{" : flatten (separate [", "] [show Don`tShowParentheses el \\ el <-: a])] ++ ["}"]

separate :: a [a] -> [a]
separate separator [a : t=:[b : _]]
	=	[a, separator : separate separator t]
separate _ l
	=	l

instance toString File
where
	toString :: File -> {#Char}
	toString _
		=	"File"