ShowWrapped.icl 2.57 KB
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1
2
3
4
5
implementation module ShowWrapped

import StdEnv
import Wrap

6
7
8
9
ShowParentheses
	:==	True
Don`tShowParentheses
	:==	False
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
10

11
12
13
14
15
16
showWrapped :: WrappedNode -> [{#Char}]
showWrapped node
	=	show Don`tShowParentheses node

show :: Bool WrappedNode -> [{#Char}]
show _ (WrappedInt i)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
17
	=	[toString i]
18
show _ (WrappedChar c)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
19
	=	["\'" +++ toString c +++ "\'"]
20
show _ (WrappedBool b)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
21
	=	[toString b]
22
show _ (WrappedReal r)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
23
	=	[toString r]
24
25
26
show _ (WrappedFile _)
	=	["File"]
show _ (WrappedString s)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
27
	=	["\"" +++ s +++ "\""]
28
29
30
31
32
33
34
35
36
37
38
39
40
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)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
41
	| size args == 2
42
		=	["[" : flatten [show Don`tShowParentheses args.[0] : showTail args.[1]]] ++ ["]"]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
43
	where
44
45
		showTail :: WrappedNode -> [[{#Char}]]
		showTail (WrappedOther WrappedDescriptorCons args)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
46
			| size args == 2
47
48
				=	[[", "], show Don`tShowParentheses args.[0] : showTail args.[1]]
		showTail (WrappedOther WrappedDescriptorNil args)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
49
50
			| size args == 0
				=	[]
51
52
53
54
55
56
		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
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
57
58
59
60
61
		=	["(" : application] ++ [")"]
	// otherwise
		=	application
	where
		application
62
			=	flatten (separate [" "] [[showDescriptor descriptor] : [show ShowParentheses arg \\ arg <-: args]])
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
63

64
65
showDescriptor :: WrappedDescriptor -> {#Char}
showDescriptor (WrappedDescriptorOther id)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
66
	=	toString id
67
showDescriptor WrappedDescriptorNil
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
68
	=	"[]"
69
showDescriptor WrappedDescriptorCons
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
70
	=	"[:]"
71
showDescriptor WrappedDescriptorTuple
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
72
73
	=	"(..)"

74
75
76
77
78
79
80
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])] ++ ["}"]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
81

82
83
84
85
separate :: a [a] -> [a]
separate separator [a : t=:[b : _]]
	=	[a, separator : separate separator t]
separate _ l
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
86
87
88
89
	=	l

instance toString File
where
90
	toString :: File -> {#Char}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
91
92
	toString _
		=	"File"