-
Notifications
You must be signed in to change notification settings - Fork 0
/
edition.js
94 lines (72 loc) · 3.7 KB
/
edition.js
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
93
94
/*
Fōrmulæ symbolic package. Module for edition.
Copyright (C) 2015-2023 Laurence R. Ugalde
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
'use strict';
export class Symbolic extends Formulae.Package {}
Symbolic.editionSymbol = function() {
let s = "";
do {
s = prompt(Symbolic.messages.enterSymbol, s);
}
while (s == "");
if (s == null) return;
let newExpression = Formulae.createExpression("Symbolic.Symbol");
newExpression.set("Name", s);
Formulae.sExpression.replaceBy(newExpression);
Formulae.sHandler.prepareDisplay();
Formulae.sHandler.display();
Formulae.setSelected(Formulae.sHandler, newExpression, false);
}
Symbolic.actionSymbol = {
isAvailableNow: () => Formulae.sHandler.type != Formulae.ROW_OUTPUT,
getDescription: () => "Change the name of the symbol...",
doAction: () => {
let s = Formulae.sExpression.get("Name");
do {
s = prompt(Symbolic.messages.updateSymbol, s);
}
while (s == "");
if (s == null) return;
Formulae.sExpression.set("Name", s);
Formulae.sHandler.prepareDisplay();
Formulae.sHandler.display();
Formulae.setSelected(Formulae.sHandler, Formulae.sExpression, false);
}
};
Symbolic.editionFunction = function() {
let functionExpression = Formulae.createExpression("Symbolic.Function");
Formulae.sExpression.replaceBy(functionExpression);
functionExpression.addChild(Formulae.sExpression);
let listExpression = Formulae.createExpression("List.List");
functionExpression.addChild(listExpression);
let nullExpression = Formulae.createExpression("Null");
listExpression.addChild(nullExpression);
Formulae.sHandler.prepareDisplay();
Formulae.sHandler.display();
Formulae.setSelected(Formulae.sHandler, nullExpression, false);
}
Symbolic.setEditions = function() {
Formulae.addEdition(this.messages.pathSymbolic, null, this.messages.leafSymbol, Formulae.editionSymbol = () => Symbolic.editionSymbol());
Formulae.addEdition(this.messages.pathSymbolic, null, this.messages.leafAssignment, () => Expression.binaryEdition ("Symbolic.Assignment", false));
Formulae.addEdition(this.messages.pathSymbolic, null, this.messages.leafLocal, () => Expression.wrapperEdition("Symbolic.Local"));
Formulae.addEdition(this.messages.pathSymbolic, null, this.messages.leafUndefine, () => Expression.wrapperEdition("Symbolic.Undefine"));
Formulae.addEdition(this.messages.pathSymbolic, null, this.messages.leafFunction, Formulae.editionFunction = () => Symbolic.editionFunction());
Formulae.addEdition(this.messages.pathSymbolic, null, this.messages.leafReturn, () => Expression.wrapperEdition("Symbolic.Return"));
Formulae.addEdition(this.messages.pathSymbolic, null, this.messages.leafLambda, () => Expression.binaryEdition ("Symbolic.Lambda", false));
Formulae.addEdition(this.messages.pathSymbolic, null, this.messages.leafLambdaApplication, () => Expression.binaryEdition ("Symbolic.LambdaApplication", false));
Formulae.addEdition(this.messages.pathSymbolic, null, this.messages.leafLambdaBuilder, () => Expression.binaryEdition ("Symbolic.LambdaBuilder", false));
};
Symbolic.setActions = function() {
Formulae.addAction("Symbolic.Symbol", Symbolic.actionSymbol);
};