Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Parker committed May 31, 2020
1 parent 781055d commit 0d24fd1
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 38 deletions.
12 changes: 6 additions & 6 deletions README.md
@@ -1,6 +1,6 @@
# Sciline Editor
# TechniCalc Editor

Represents a math AST that can be converted to both MathML and an AST for Sciline Calculator
Represents a math AST that can be converted to both MathML and an AST for TechniCalc Calculator

## AST Representation

Expand Down Expand Up @@ -85,7 +85,7 @@ There is additionally a superscript element, `` `Superscript1 ``, which accepts

&#x25a1;<sup>&#x25a1;</sup>

However, in the case we are converting to MathML or a Sciline Calculator AST, and the superscript immediately precedes an element that accepts a superscript (the element is suffixed with an `S`), they are merged together, much like ligatures in fonts. If an element does not accept a superscript, it is left unaltered
However, in the case we are converting to MathML or a TechniCalc Calculator AST, and the superscript immediately precedes an element that accepts a superscript (the element is suffixed with an `S`), they are merged together, much like ligatures in fonts. If an element does not accept a superscript, it is left unaltered

1 &#x25a1;<sup>&#x25a1;</sup> &#x2192; 1<sup>&#x25a1;</sup>

Expand All @@ -111,9 +111,9 @@ Some elements have special insertion and deletion logic. For example, if you ins

The superscript encoding leads to a really natural eding experience. If you have one digit raised to a power, you could insert another digit between the the first and the superscript to move the superscript. You could also put brackets between, and the superscript is still maintained

### Convertion to MathML and Sciline Calculator AST
### Convertion to MathML and TechniCalc Calculator AST

For converting to either MathML or a Sciline Calculator AST, we first do a transformation to a node-based AST. For example, The fraction example above transforms to
For converting to either MathML or a TechniCalc Calculator AST, we first do a transformation to a node-based AST. For example, The fraction example above transforms to

```reason
type node('t) = `Frac({ fracNum: node('t), den: node('t), superscript: option(node('t)) })
Expand All @@ -140,7 +140,7 @@ A side note is that we never fully construct a node-based AST, as the reduction

### Indices

Every element of the elements array is addressable by a single index. This index is imporant for MathML, so we know where to put the cursor; and also in the conversion to a Sciline Calculator AST, as if there is a parsing error, we need to return the index
Every element of the elements array is addressable by a single index. This index is imporant for MathML, so we know where to put the cursor; and also in the conversion to a TechniCalc Calculator AST, as if there is a parsing error, we need to return the index

To handle this, the `~reduce` and `~map` functions are the start (`i`) and end index of the node (`i'`)

Expand Down
6 changes: 3 additions & 3 deletions bsconfig.json
@@ -1,5 +1,5 @@
{
"name": "sciline-editor",
"name": "technicalc-editor",
"version": "0.1.0",
"sources": {
"dir": "src",
Expand All @@ -10,10 +10,10 @@
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": ["sciline-calculator"],
"bs-dependencies": ["technicalc-calculator"],
"warnings": {
"error": "+101"
},
"namespace": true,
"namespace": "TechniCalcEditor",
"refmt": 3
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -19,7 +19,7 @@
"bs-platform": "^8.0.0-dev.1",
"esm": "^3.2.22",
"jest": "^24.9.0",
"sciline-calculator": "https://github.com/jacobp100/sciline-calculator"
"technicalc-calculator": "https://github.com/jacobp100/technicalc-calculator"
},
"dependencies": {}
}
2 changes: 1 addition & 1 deletion src/AST/AST_ReduceMap.re
Expand Up @@ -7,7 +7,7 @@ type atom('a) = {
superscript: option(superscript('a)),
};
type customAtom('a) = {
customAtomValue: ScilineCalculator.Encoding.encoding,
customAtomValue: TechniCalcCalculator.Encoding.encoding,
mml: string,
superscript: option(superscript('a)),
};
Expand Down
6 changes: 3 additions & 3 deletions src/AST/AST_Types.re
Expand Up @@ -20,11 +20,11 @@ type func =
| Im
| Gamma;
type unitConversion = {
fromUnits: ScilineCalculator.Unit_Types.units,
toUnits: ScilineCalculator.Unit_Types.units,
fromUnits: TechniCalcCalculator.Unit_Types.units,
toUnits: TechniCalcCalculator.Unit_Types.units,
};
type customAtom = {
value: ScilineCalculator.Encoding.encoding,
value: TechniCalcCalculator.Encoding.encoding,
mml: string,
};
type table = {
Expand Down
9 changes: 5 additions & 4 deletions src/Mml/Mml_Units.re
@@ -1,4 +1,4 @@
let unitMmlSymbol = (unit: ScilineCalculator.Unit_Types.unitType) =>
let unitMmlSymbol = (unit: TechniCalcCalculator.Unit_Types.unitType) =>
switch (unit) {
/* Time */
| Second => "s"
Expand Down Expand Up @@ -114,22 +114,23 @@ let unitMmlSymbol = (unit: ScilineCalculator.Unit_Types.unitType) =>
| Fahrenheit => "&#x00B0;F"
};

let unitToMml = (unit: ScilineCalculator.Unit_Types.unitType) =>
let unitToMml = (unit: TechniCalcCalculator.Unit_Types.unitType) =>
switch (unit) {
/* Work around :( */
| Angstrom => "<mi mathvariant=\"normal\">A</mi>"
| _ => "<mi mathvariant=\"normal\">" ++ unitMmlSymbol(unit) ++ "</mi>"
};

let unitPowerToMml = ((unit, power): ScilineCalculator.Unit_Types.unitPower) =>
let unitPowerToMml =
((unit, power): TechniCalcCalculator.Unit_Types.unitPower) =>
switch (power) {
| 1 => unitToMml(unit)
| _ =>
let powerMml = "<mn>" ++ string_of_int(power) ++ "</mn>";
"<msup>" ++ unitToMml(unit) ++ powerMml ++ "</msup>";
};

let unitPowersToMml = (units: ScilineCalculator.Unit_Types.units) => {
let unitPowersToMml = (units: TechniCalcCalculator.Unit_Types.units) => {
let unitsMmlList =
Belt.Array.map(units, unitPowerToMml)->Belt.List.fromArray;
String.concat("<mspace width=\"0.1em\" />", unitsMmlList);
Expand Down
2 changes: 1 addition & 1 deletion src/Value/Value.re
@@ -1,6 +1,6 @@
open AST_ReduceMap;

module AST = ScilineCalculator.AST_Types;
module AST = TechniCalcCalculator.AST_Types;

let parse = (elements: array(AST_Types.t)) => {
let error = ref(None);
Expand Down
2 changes: 1 addition & 1 deletion src/Value/Value_Builders.re
Expand Up @@ -2,7 +2,7 @@ open AST_ReduceMap;
open AST_Types;
open Value_Types;

module AST = ScilineCalculator.AST_Types;
module AST = TechniCalcCalculator.AST_Types;

let withSuperscript = (value, superscript) =>
switch (superscript) {
Expand Down
2 changes: 1 addition & 1 deletion src/Value/Value_NumberParser.re
@@ -1,7 +1,7 @@
open AST_ReduceMap;
open Value_Types;

module AST = ScilineCalculator.AST_Types;
module AST = TechniCalcCalculator.AST_Types;

let numberIsValidForBase = (base, atomNucleus) =>
switch (base, atomNucleus) {
Expand Down
4 changes: 2 additions & 2 deletions src/Value/Value_Types.re
@@ -1,6 +1,6 @@
open AST_ReduceMap;

type node = ScilineCalculator.AST_Types.t;
type node = TechniCalcCalculator.AST_Types.t;

type funcitionLike =
| GenericFunction(AST_Types.func)
Expand All @@ -11,4 +11,4 @@ type funcitionLike =
type partialNode =
| Resolved(node)
| Unresolved(t(node), int)
| UnresolvedFunction(funcitionLike, int);
| UnresolvedFunction(funcitionLike, int);
14 changes: 7 additions & 7 deletions src/__tests__/ValueNumbers.re
Expand Up @@ -2,12 +2,12 @@ open Jest;

let parseEval = v =>
switch (Value.parse(v)) {
| `Ok(v) => Some(ScilineCalculator.AST.eval(v))
| `Ok(v) => Some(TechniCalcCalculator.AST.eval(v))
| _ => None
};

let ofInt = ScilineCalculator.Types.ofInt;
let ofString = ScilineCalculator.Types.ofString;
let ofInt = TechniCalcCalculator.Types.ofInt;
let ofString = TechniCalcCalculator.Types.ofString;

test("Parses numbers", (.) => {
parseEval([|`DigitS("1"), `DigitS("2"), `DigitS("3")|])
Expand Down Expand Up @@ -104,7 +104,7 @@ test("Parses magnitudes", (.) => {
});

test("Parses imaginary units", (.) => {
let mulI = ScilineCalculator.Value.(mul(i));
let mulI = TechniCalcCalculator.Value.(mul(i));

parseEval([|`DigitS("2"), `ImaginaryUnitS|])
->expect
Expand Down Expand Up @@ -154,9 +154,9 @@ test("Parses imaginary units", (.) => {
});

test("Angles", (.) => {
let pi = ScilineCalculator.Value.pi;
let mul = ScilineCalculator.Value.mul;
let div = ScilineCalculator.Value.div;
let pi = TechniCalcCalculator.Value.pi;
let mul = TechniCalcCalculator.Value.mul;
let div = TechniCalcCalculator.Value.div;

parseEval([|`DigitS("1"), `Degree|])
->expect
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/ValueTest.re
Expand Up @@ -3,11 +3,11 @@ open AST_Types;

let parseEval = v =>
switch (Value.parse(v)) {
| `Ok(v) => Some(ScilineCalculator.AST.eval(v))
| `Ok(v) => Some(TechniCalcCalculator.AST.eval(v))
| _ => None
};

let ofString = ScilineCalculator.Types.ofString;
let ofString = TechniCalcCalculator.Types.ofString;

test("Parses with bodmas", (.) => {
parseEval([|`DigitS("1"), `Sub, `DigitS("2"), `Add, `DigitS("3")|])
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Expand Up @@ -3481,12 +3481,6 @@ sax@^1.2.4:
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==

"sciline-calculator@https://github.com/jacobp100/sciline-calculator":
version "0.1.0"
resolved "https://github.com/jacobp100/sciline-calculator#45610d2656405c93fd2833ddda406588378f97d0"
dependencies:
decimal.js "^10.2.0"

"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0, semver@^5.6.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
Expand Down Expand Up @@ -3773,6 +3767,12 @@ symbol-tree@^3.2.2:
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==

"technicalc-calculator@https://github.com/jacobp100/technicalc-calculator":
version "0.1.0"
resolved "https://github.com/jacobp100/technicalc-calculator#9a32c3c71414db707428d8f84050c03cbb3f948e"
dependencies:
decimal.js "^10.2.0"

test-exclude@^5.2.3:
version "5.2.3"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-5.2.3.tgz#c3d3e1e311eb7ee405e092dac10aefd09091eac0"
Expand Down

0 comments on commit 0d24fd1

Please sign in to comment.