cleaned all trailing white space from source files.
[sdk] / samples / eC / ecas / ecas.ec
1 // ecas -- By Joey Adams
2 import "ecere"
3 import "expression"
4
5 class Form1 : Window
6 {
7    text = "Simple Parser";
8    background = activeBorder;
9    borderStyle = sizable;
10    hasMaximize = true;
11    hasMinimize = true;
12    hasClose = true;
13    size = { 576, 432 };
14    anchor = { horz = -3, vert = -4 };
15
16    bool OnCreate(void)
17    {
18
19       return true;
20    }
21
22    bool OnKeyHit(Key key, unichar ch)
23    {
24       if (ch=='\r')
25          DoParse(true);
26
27       return true;
28    }
29
30    void DoParse(bool simplify) {
31       EditBoxStream s;
32       CASDictionary dict {};
33       Expression expr {};
34       Expression exprCopy;
35       outputTree.Clear();
36       s = {editBox=outputTree};
37       if (expr.FromString(inputString.contents, dict)) {
38          statusLabel.SetText("Parse successful");
39          if (simplify)
40             expr.Simplify(dict);
41       }
42       else
43          statusLabel.SetText("Invalid expression");
44       expr.DebugPrint(s, dict, 0, null);
45       s.Printf("\nCopy:\n");
46       exprCopy = expr.Copy(null);
47       delete expr;
48       exprCopy.DebugPrint(s, dict, 0, null);
49       delete s;
50       delete dict;
51       delete exprCopy;
52    }
53
54    Button parseButton
55    {
56       this, text = "Parse", size = { 75, 30 }, position = { 10, 40 };
57
58       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
59       {
60          DoParse(false);
61          return true;
62       }
63    };
64    Button simplifyButton
65    {
66       this, text = "Simplify", size = { 75, 30 }, position = { 90, 40 };
67
68       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
69       {
70          DoParse(true);
71          return true;
72       }
73    };
74
75    bool TypeButton(Button button, int x, int y, Modifiers mods) {
76       inputString.Activate();
77       inputString.Deselect();
78       inputString.AddS(button.text);
79       inputString.Update(null);
80    }
81    Label statusLabel { this, size = { 274, 21 }, position = { 250, 45 } };
82    Button ebutton { this, text = constant_string[e], NotifyClicked = TypeButton, size = { 20, 20 }, position = { 170, 45 } };
83    Button ibutton { this, text = constant_string[i], NotifyClicked = TypeButton, size = { 20, 20 }, position = { 195, 45 } };
84    Button pibutton { this, text = constant_string[pi], NotifyClicked = TypeButton, size = { 20, 20 }, position = { 220, 45 } };
85    EditBox outputTree { this, font = { "Courier New", 10 }, size = { 286, 219 }, position = { 10, 80 }, hasHorzScroll = true, true, readOnly = true, true };
86    EditBox inputString { this, text = "inputString", size = { 350, 19 }, position = { 10, 10 } };
87
88    void OnResize(int width, int height)
89    {
90       inputString.size.w = clientSize.w-20;
91       //parseButton.position.x = (clientSize.w-parseButton.size.w)/2;
92       statusLabel.size.w = clientSize.w-statusLabel.position.x-10;
93       outputTree.size.w = clientSize.w-20;
94       outputTree.size.h = clientSize.h-outputTree.position.y-10;
95    }
96 }
97
98 Form1 form1 {};