aboutsummaryrefslogtreecommitdiff
path: root/frontend/ShowWrapped.icl
blob: 82b72a1bea75932c15275216822e62f3059b2b30 (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
implementation module ShowWrapped

import StdEnv
import Wrap

ShowWrapped :: WrappedNode -> [{#Char}]
ShowWrapped node
	=	Show False node

Show _ (WrappedInt i)
	=	[toString i]
Show _ (WrappedChar c)
	=	["\'" +++ toString c +++ "\'"]
Show _ (WrappedBool b)
	=	[toString b]
Show _ (WrappedReal r)
	=	[toString r]
Show _ (WrappedFile f)
	=	[toString f]
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 False el \\ el <-: a])] ++ ["}"]
Show _ (WrappedRecord descriptor args)
	=	["{" : flatten (Separate [" "] [[ShowDescriptor descriptor] : [Show True arg \\ arg <-: args]])] ++ ["}"]
Show _ (WrappedOther WrappedDescriptorCons args)
	| size args == 2
	=	["[" : flatten [Show False args.[0] : ShowTail args.[1]]] ++ ["]"]
	where
		ShowTail (WrappedOther WrappedDescriptorCons args)
			| size args == 2
				=	[[", "], Show False args.[0] : ShowTail args.[1]]
		ShowTail (WrappedOther WrappedDescriptorNil args)
			| size args == 0
				=	[]
		ShowTail graph // abnormal list
			=	[[" : " : Show False graph]]
Show _ (WrappedOther WrappedDescriptorTuple args)
	=	["(" : flatten (Separate [", "] [Show False arg \\ arg <-: args])] ++ [")"]
Show pars (WrappedOther descriptor args)
	| pars && size args > 0
		=	["(" : application] ++ [")"]
	// otherwise
		=	application
	where
		application
			=	flatten (Separate [" "] [[ShowDescriptor descriptor] : [Show True arg \\ arg <-: args]])

ShowDescriptor (WrappedDescriptorOther id)
	=	toString id
ShowDescriptor WrappedDescriptorNil
	=	"[]"
ShowDescriptor WrappedDescriptorCons
	=	"[:]"
ShowDescriptor WrappedDescriptorTuple
	=	"(..)"

ShowBasicArray a
	=	["{" : Separate ", " [toString el \\ el <-: a]] ++ ["}"]
ShowWrappedArray a
	=	["{" : flatten (Separate [", "] [Show False 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"