Mercurial > projects > dil
comparison src/TypeRules.d @ 806:bcb74c9b895c
Moved out files in the trunk folder to the root.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 09 Mar 2008 00:12:19 +0100 |
parents | trunk/src/TypeRules.d@f51305056196 |
children | 451ede0105e0 |
comparison
equal
deleted
inserted
replaced
805:a3fab8b74a7d | 806:bcb74c9b895c |
---|---|
1 /++ | |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
5 module TypeRules; | |
6 | |
7 import cmd.Generate : xml_escape; | |
8 | |
9 import TypeRulesData; | |
10 import common; | |
11 | |
12 static const string[] basicTypes = [ | |
13 "char"[], "wchar", "dchar", "bool", | |
14 "byte", "ubyte", "short", "ushort", | |
15 "int", "uint", "long", "ulong", | |
16 /+"cent", "ucent",+/ | |
17 "float", "double", "real", | |
18 "ifloat", "idouble", "ireal", | |
19 "cfloat", "cdouble", "creal"/+, "void"+/ | |
20 ]; | |
21 | |
22 static const string[] unaryExpressions = [ | |
23 "!x", | |
24 "&x", | |
25 "~x", | |
26 "+x", | |
27 "-x", | |
28 "++x", | |
29 "--x", | |
30 "x++", | |
31 "x--", | |
32 ]; | |
33 | |
34 static const string[] binaryExpressions = [ | |
35 "x!<>=y", | |
36 "x!<>y", | |
37 "x!<=y", | |
38 "x!<y", | |
39 "x!>=y", | |
40 "x!>y", | |
41 "x<>=y", | |
42 "x<>y", | |
43 | |
44 "x=y", "x==y", "x!=y", | |
45 "x<=y", "x<y", | |
46 "x>=y", "x>y", | |
47 "x<<=y", "x<<y", | |
48 "x>>=y","x>>y", | |
49 "x>>>=y", "x>>>y", | |
50 "x|=y", "x||y", "x|y", | |
51 "x&=y", "x&&y", "x&y", | |
52 "x+=y", "x+y", | |
53 "x-=y", "x-y", | |
54 "x/=y", "x/y", | |
55 "x*=y", "x*y", | |
56 "x%=y", "x%y", | |
57 "x^=y", "x^y", | |
58 "x~=y", | |
59 "x~y", | |
60 "x,y" | |
61 ]; | |
62 | |
63 void genHTMLTypeRulesTables() | |
64 { | |
65 Stdout( | |
66 `<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">`\n | |
67 `<html>`\n | |
68 `<head>`\n | |
69 ` <meta http-equiv="Content-Type" content="text/html; charset=utf-8">`\n | |
70 ` <link href="" rel="stylesheet" type="text/css">`\n | |
71 ` <style type="text/css">`\n | |
72 ` .E { color: darkred; } /* Error */`\n | |
73 ` .R { font-size: 0.8em; } /* Result */`\n | |
74 ` .X { color: darkorange; }`\n | |
75 ` .Y { color: darkblue; }`\n | |
76 ` </style>`\n | |
77 `</head>`\n | |
78 `<body>`\n | |
79 `<p>These tables show what the type results of certain expressions are.</p>`\n | |
80 ); | |
81 | |
82 Stdout.format("<table>\n<tr><th colspan=\"{}\">Unary Expressions</th></tr>\n", unaryExpressions.length); | |
83 Stdout("<tr><td><!--typecol--></td>"); | |
84 foreach (unaryExpression; unaryExpressions) | |
85 Stdout.format("<td>{}</td>", { | |
86 if (unaryExpression[0] == 'x') | |
87 return `<span class="X">x</span>` ~ xml_escape(unaryExpression[1..$]); | |
88 else | |
89 return xml_escape(unaryExpression[0..$-1]) ~ `<span class="X">x</span>`; | |
90 }()); | |
91 Stdout("</tr>\n"); | |
92 foreach (i, basicType; basicTypes) | |
93 { | |
94 Stdout.format("<tr>\n"`<td class="X">{}</td>`, basicType); | |
95 foreach (expResults; unaryExpsResults) | |
96 { | |
97 auto result = expResults[i]; | |
98 Stdout.format(`<td class="R">{}</td>`, result[0] == 'E' ? `<span class="E">Error</span>`[] : result); | |
99 } | |
100 Stdout("\n<tr>\n"); | |
101 } | |
102 Stdout("</table>\n"); | |
103 | |
104 foreach (i, expResults; binaryExpsResults) | |
105 { | |
106 auto binaryExpression = binaryExpressions[i]; | |
107 binaryExpression = `<span class="X">x</span> ` ~ | |
108 xml_escape(binaryExpression[1..$-1]) ~ | |
109 ` <span class="Y">y</span>`; | |
110 Stdout.format("<table>\n<tr><th colspan=\"{}\">{}</th></tr>\n", basicTypes.length, binaryExpression); | |
111 Stdout.format("<tr><td><!--typecol--></td>"); | |
112 foreach (basicType; basicTypes) | |
113 Stdout.format(`<td class="Y">{}</td>`, basicType); | |
114 Stdout("\n<tr>\n"); | |
115 foreach (j, results; expResults) | |
116 { | |
117 Stdout.format("<tr>\n"`<td class="X">{}</td>`, basicTypes[j]); | |
118 foreach (result; results) | |
119 Stdout.format(`<td class="R">{}</td>`, result[0] == 'E' ? `<span class="E">Error</span>`[] : result); | |
120 Stdout("\n<tr>\n"); | |
121 } | |
122 Stdout("</table>\n"); | |
123 } | |
124 | |
125 Stdout( | |
126 "\n</body>" | |
127 "\n</html>" | |
128 ); | |
129 } |