numbers with units (tested)

This commit is contained in:
Umur Ozkul 2022-05-23 08:13:51 +02:00
parent 4dd79eb018
commit 4628140069
6 changed files with 176 additions and 95 deletions

View File

@ -251,6 +251,13 @@ describe("Peggy parse", () => {
"{(::map (::$_constructArray_$ (1 2 3)) {|:x| {(::add :x 1)}})}",
)
})
describe("unit", () => {
testParse("1m", "{(::multiply 1 (::$valueOfUnit 'm'))}")
testParse(
"1m+2cm",
"{(::add (::multiply 1 (::$valueOfUnit 'm')) (::multiply 2 (::$valueOfUnit 'cm')))}",
)
})
})
describe("parsing new line", () => {

View File

@ -217,4 +217,8 @@ describe("Peggy to Expression", () => {
(),
)
})
describe("unit", () => {
testToExpression("1m", "(:$$_block_$$ (:multiply 1 (:$valueOfUnit 'm')))", ~v="1", ())
})
})

View File

@ -129,6 +129,23 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
)
}
let doValueOfUnit = (aUnit: string) =>
switch aUnit {
| "nm" => 0.000000001->EvNumber->Ok
| "um" => 0.000001->EvNumber->Ok
| "mm" => 0.001->EvNumber->Ok
| "cm" => 0.01->EvNumber->Ok
| "dm" => 0.1->EvNumber->Ok
| "m" => 1.->EvNumber->Ok
| "dam" => 10.->EvNumber->Ok
| "hm" => 100.->EvNumber->Ok
| "km" => 1000.->EvNumber->Ok
| "Mm" => 1000000.->EvNumber->Ok
| "Gm" => 1000000000.->EvNumber->Ok
| "Tm" => 1000000000000.->EvNumber->Ok
| _ => REUnitNotFound(aUnit)->Error
}
switch call {
| ("$_atIndex_$", [EvArray(aValueArray), EvNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex)
| ("$_atIndex_$", [EvRecord(dict), EvString(sIndex)]) => recordAtIndex(dict, sIndex)
@ -137,6 +154,7 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
| ("$_exportBindings_$", [EvRecord(externalBindings)]) => doExportBindings(externalBindings)
| ("$_setBindings_$", [EvRecord(externalBindings), EvSymbol(symbol), value]) =>
doSetBindings(externalBindings, symbol, value)
| ("$valueOfUnit", [EvString(aUnit)]) => doValueOfUnit(aUnit)
| ("inspect", [value, EvString(label)]) => inspectLabel(value, label)
| ("inspect", [value]) => inspect(value)
| ("keep", [EvArray(aValueArray), EvLambda(aLambdaValue)]) =>

View File

@ -4,18 +4,19 @@ type errorValue =
| REArrayIndexNotFound(string, int)
| REAssignmentExpected
| REDistributionError(DistributionTypes.error)
| REOperationError(Operation.operationError)
| REExpectedType(string)
| REExpressionExpected
| REFunctionExpected(string)
| REFunctionNotFound(string)
| REJavaScriptExn(option<string>, option<string>) // Javascript Exception
| REMacroNotFound(string)
| RENotAFunction(string)
| REOperationError(Operation.operationError)
| RERecordPropertyNotFound(string, string)
| RESymbolNotFound(string)
| RESyntaxError(string)
| RETodo(string) // To do
| REExpectedType(string)
| REUnitNotFound(string)
type t = errorValue
@ -52,4 +53,5 @@ let errorToString = err =>
| RESyntaxError(desc) => `Syntax Error: ${desc}`
| RETodo(msg) => `TODO: ${msg}`
| REExpectedType(typeName) => `Expected type: ${typeName}`
| REUnitNotFound(unitName) => `Unit not found: ${unitName}`
}

View File

@ -538,32 +538,42 @@ function peg$parse(input, options) {
var peg$f27 = function (characters) {
return nodeString(characters.join(""));
};
var peg$f28 = function () {
return nodeInteger(parseInt(text()));
var peg$f28 = function (number, unit) {
if (unit === null) {
return number;
} else {
return makeFunctionCall("multiply", [
number,
makeFunctionCall("$valueOfUnit", [nodeString(unit.value)]),
]);
}
};
var peg$f29 = function () {
return nodeFloat(parseFloat(text()));
return nodeInteger(parseInt(text()));
};
var peg$f30 = function () {
return nodeFloat(parseFloat(text()));
};
var peg$f31 = function () {
return nodeBoolean(text() === "true");
};
var peg$f31 = function (args, statements, finalExpression) {
var peg$f32 = function (args, statements, finalExpression) {
statements.push(finalExpression);
return nodeLambda(args, nodeBlock(statements));
};
var peg$f32 = function (args, finalExpression) {
var peg$f33 = function (args, finalExpression) {
return nodeLambda(args, nodeBlock([finalExpression]));
};
var peg$f33 = function () {
var peg$f34 = function () {
return makeFunctionCall("$_constructArray_$", [nodeExpression([])]);
};
var peg$f34 = function (args) {
var peg$f35 = function (args) {
return makeFunctionCall("$_constructArray_$", [nodeExpression(args)]);
};
var peg$f35 = function (args) {
var peg$f36 = function (args) {
return makeFunctionCall("$_constructRecord_$", [nodeExpression(args)]);
};
var peg$f36 = function (key, value) {
var peg$f37 = function (key, value) {
return nodeKeyValue(key, value);
};
@ -738,7 +748,7 @@ function peg$parse(input, options) {
function peg$parsestart() {
var s0, s1, s2, s3, s4;
var key = peg$currPos * 67 + 0;
var key = peg$currPos * 68 + 0;
var cached = peg$resultsCache[key];
if (cached) {
@ -771,7 +781,7 @@ function peg$parse(input, options) {
function peg$parsezeroOMoreArgumentsBlockOrExpression() {
var s0;
var key = peg$currPos * 67 + 1;
var key = peg$currPos * 68 + 1;
var cached = peg$resultsCache[key];
if (cached) {
@ -793,7 +803,7 @@ function peg$parse(input, options) {
function peg$parseouterBlock() {
var s0, s1, s2, s3, s4;
var key = peg$currPos * 67 + 2;
var key = peg$currPos * 68 + 2;
var cached = peg$resultsCache[key];
if (cached) {
@ -846,7 +856,7 @@ function peg$parse(input, options) {
function peg$parseinnerBlockOrExpression() {
var s0, s1;
var key = peg$currPos * 67 + 3;
var key = peg$currPos * 68 + 3;
var cached = peg$resultsCache[key];
if (cached) {
@ -874,7 +884,7 @@ function peg$parse(input, options) {
function peg$parsequotedInnerBlock() {
var s0, s1, s2, s3, s4, s5, s6;
var key = peg$currPos * 67 + 4;
var key = peg$currPos * 68 + 4;
var cached = peg$resultsCache[key];
if (cached) {
@ -991,7 +1001,7 @@ function peg$parse(input, options) {
function peg$parsearray_statements() {
var s0, s1, s2, s3, s4;
var key = peg$currPos * 67 + 5;
var key = peg$currPos * 68 + 5;
var cached = peg$resultsCache[key];
if (cached) {
@ -1046,7 +1056,7 @@ function peg$parse(input, options) {
function peg$parsestatement() {
var s0;
var key = peg$currPos * 67 + 6;
var key = peg$currPos * 68 + 6;
var cached = peg$resultsCache[key];
if (cached) {
@ -1068,7 +1078,7 @@ function peg$parse(input, options) {
function peg$parseletStatement() {
var s0, s1, s2, s3, s4, s5;
var key = peg$currPos * 67 + 7;
var key = peg$currPos * 68 + 7;
var cached = peg$resultsCache[key];
if (cached) {
@ -1109,7 +1119,7 @@ function peg$parse(input, options) {
function peg$parsedefunStatement() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
var key = peg$currPos * 67 + 8;
var key = peg$currPos * 68 + 8;
var cached = peg$resultsCache[key];
if (cached) {
@ -1186,7 +1196,7 @@ function peg$parse(input, options) {
function peg$parseassignmentOp() {
var s0, s1;
var key = peg$currPos * 67 + 9;
var key = peg$currPos * 68 + 9;
var cached = peg$resultsCache[key];
if (cached) {
@ -1221,7 +1231,7 @@ function peg$parse(input, options) {
function peg$parsearray_parameters() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 10;
var key = peg$currPos * 68 + 10;
var cached = peg$resultsCache[key];
if (cached) {
@ -1300,7 +1310,7 @@ function peg$parse(input, options) {
function peg$parseexpression() {
var s0;
var key = peg$currPos * 67 + 11;
var key = peg$currPos * 68 + 11;
var cached = peg$resultsCache[key];
if (cached) {
@ -1325,7 +1335,7 @@ function peg$parse(input, options) {
function peg$parseifthenelse() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
var key = peg$currPos * 67 + 12;
var key = peg$currPos * 68 + 12;
var cached = peg$resultsCache[key];
if (cached) {
@ -1439,7 +1449,7 @@ function peg$parse(input, options) {
function peg$parseternary() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
var key = peg$currPos * 67 + 13;
var key = peg$currPos * 68 + 13;
var cached = peg$resultsCache[key];
if (cached) {
@ -1513,7 +1523,7 @@ function peg$parse(input, options) {
function peg$parselogicalAdditive() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 14;
var key = peg$currPos * 68 + 14;
var cached = peg$resultsCache[key];
if (cached) {
@ -1578,7 +1588,7 @@ function peg$parse(input, options) {
function peg$parselogicalAdditiveOp() {
var s0, s1;
var key = peg$currPos * 67 + 15;
var key = peg$currPos * 68 + 15;
var cached = peg$resultsCache[key];
if (cached) {
@ -1613,7 +1623,7 @@ function peg$parse(input, options) {
function peg$parselogicalMultiplicative() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 16;
var key = peg$currPos * 68 + 16;
var cached = peg$resultsCache[key];
if (cached) {
@ -1678,7 +1688,7 @@ function peg$parse(input, options) {
function peg$parselogicalMultiplicativeOp() {
var s0, s1;
var key = peg$currPos * 67 + 17;
var key = peg$currPos * 68 + 17;
var cached = peg$resultsCache[key];
if (cached) {
@ -1713,7 +1723,7 @@ function peg$parse(input, options) {
function peg$parseequality() {
var s0, s1, s2, s3, s4, s5;
var key = peg$currPos * 67 + 18;
var key = peg$currPos * 68 + 18;
var cached = peg$resultsCache[key];
if (cached) {
@ -1757,7 +1767,7 @@ function peg$parse(input, options) {
function peg$parseequalityOp() {
var s0, s1;
var key = peg$currPos * 67 + 19;
var key = peg$currPos * 68 + 19;
var cached = peg$resultsCache[key];
if (cached) {
@ -1803,7 +1813,7 @@ function peg$parse(input, options) {
function peg$parserelational() {
var s0, s1, s2, s3, s4, s5;
var key = peg$currPos * 67 + 20;
var key = peg$currPos * 68 + 20;
var cached = peg$resultsCache[key];
if (cached) {
@ -1847,7 +1857,7 @@ function peg$parse(input, options) {
function peg$parserelationalOp() {
var s0, s1;
var key = peg$currPos * 67 + 21;
var key = peg$currPos * 68 + 21;
var cached = peg$resultsCache[key];
if (cached) {
@ -1915,7 +1925,7 @@ function peg$parse(input, options) {
function peg$parseadditive() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 22;
var key = peg$currPos * 68 + 22;
var cached = peg$resultsCache[key];
if (cached) {
@ -1980,7 +1990,7 @@ function peg$parse(input, options) {
function peg$parseadditiveOp() {
var s0, s1;
var key = peg$currPos * 67 + 23;
var key = peg$currPos * 68 + 23;
var cached = peg$resultsCache[key];
if (cached) {
@ -2048,7 +2058,7 @@ function peg$parse(input, options) {
function peg$parsemultiplicative() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 24;
var key = peg$currPos * 68 + 24;
var cached = peg$resultsCache[key];
if (cached) {
@ -2113,7 +2123,7 @@ function peg$parse(input, options) {
function peg$parsemultiplicativeOp() {
var s0, s1;
var key = peg$currPos * 67 + 25;
var key = peg$currPos * 68 + 25;
var cached = peg$resultsCache[key];
if (cached) {
@ -2181,7 +2191,7 @@ function peg$parse(input, options) {
function peg$parsepower() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 26;
var key = peg$currPos * 68 + 26;
var cached = peg$resultsCache[key];
if (cached) {
@ -2246,7 +2256,7 @@ function peg$parse(input, options) {
function peg$parsepowerOp() {
var s0, s1;
var key = peg$currPos * 67 + 27;
var key = peg$currPos * 68 + 27;
var cached = peg$resultsCache[key];
if (cached) {
@ -2292,7 +2302,7 @@ function peg$parse(input, options) {
function peg$parsecredibleInterval() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 28;
var key = peg$currPos * 68 + 28;
var cached = peg$resultsCache[key];
if (cached) {
@ -2377,7 +2387,7 @@ function peg$parse(input, options) {
function peg$parsecredibleIntervalOp() {
var s0, s1;
var key = peg$currPos * 67 + 29;
var key = peg$currPos * 68 + 29;
var cached = peg$resultsCache[key];
if (cached) {
@ -2412,7 +2422,7 @@ function peg$parse(input, options) {
function peg$parsechainFunctionCall() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 30;
var key = peg$currPos * 68 + 30;
var cached = peg$resultsCache[key];
if (cached) {
@ -2515,7 +2525,7 @@ function peg$parse(input, options) {
function peg$parsechainedFunction() {
var s0, s1, s2, s3, s4, s5, s6;
var key = peg$currPos * 67 + 31;
var key = peg$currPos * 68 + 31;
var cached = peg$resultsCache[key];
if (cached) {
@ -2627,7 +2637,7 @@ function peg$parse(input, options) {
function peg$parseunary() {
var s0, s1, s2, s3;
var key = peg$currPos * 67 + 32;
var key = peg$currPos * 68 + 32;
var cached = peg$resultsCache[key];
if (cached) {
@ -2667,7 +2677,7 @@ function peg$parse(input, options) {
function peg$parseunaryOperator() {
var s0, s1;
var key = peg$currPos * 67 + 33;
var key = peg$currPos * 68 + 33;
var cached = peg$resultsCache[key];
if (cached) {
@ -2724,7 +2734,7 @@ function peg$parse(input, options) {
function peg$parseindexedValue() {
var s0;
var key = peg$currPos * 67 + 34;
var key = peg$currPos * 68 + 34;
var cached = peg$resultsCache[key];
if (cached) {
@ -2749,7 +2759,7 @@ function peg$parse(input, options) {
function peg$parsecollectionElement() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
var key = peg$currPos * 67 + 35;
var key = peg$currPos * 68 + 35;
var cached = peg$resultsCache[key];
if (cached) {
@ -3051,7 +3061,7 @@ function peg$parse(input, options) {
function peg$parsearray_functionArguments() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 36;
var key = peg$currPos * 68 + 36;
var cached = peg$resultsCache[key];
if (cached) {
@ -3130,7 +3140,7 @@ function peg$parse(input, options) {
function peg$parserecordElement() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
var key = peg$currPos * 67 + 37;
var key = peg$currPos * 68 + 37;
var cached = peg$resultsCache[key];
if (cached) {
@ -3246,7 +3256,7 @@ function peg$parse(input, options) {
function peg$parseatom() {
var s0, s1, s2, s3, s4, s5;
var key = peg$currPos * 67 + 38;
var key = peg$currPos * 68 + 38;
var cached = peg$resultsCache[key];
if (cached) {
@ -3306,7 +3316,7 @@ function peg$parse(input, options) {
function peg$parsebasicValue() {
var s0;
var key = peg$currPos * 67 + 39;
var key = peg$currPos * 68 + 39;
var cached = peg$resultsCache[key];
if (cached) {
@ -3328,7 +3338,7 @@ function peg$parse(input, options) {
function peg$parsebasicLiteral() {
var s0;
var key = peg$currPos * 67 + 40;
var key = peg$currPos * 68 + 40;
var cached = peg$resultsCache[key];
if (cached) {
@ -3339,14 +3349,11 @@ function peg$parse(input, options) {
s0 = peg$parsestring();
if (s0 === peg$FAILED) {
s0 = peg$parsefloat();
s0 = peg$parsenumber();
if (s0 === peg$FAILED) {
s0 = peg$parseinteger();
s0 = peg$parseboolean();
if (s0 === peg$FAILED) {
s0 = peg$parseboolean();
if (s0 === peg$FAILED) {
s0 = peg$parsedollarIdentifier();
}
s0 = peg$parsedollarIdentifier();
}
}
}
@ -3359,7 +3366,7 @@ function peg$parse(input, options) {
function peg$parseidentifier() {
var s0, s1, s2, s3, s4;
var key = peg$currPos * 67 + 41;
var key = peg$currPos * 68 + 41;
var cached = peg$resultsCache[key];
if (cached) {
@ -3447,7 +3454,7 @@ function peg$parse(input, options) {
function peg$parsedollarIdentifier() {
var s0, s1, s2, s3, s4;
var key = peg$currPos * 67 + 42;
var key = peg$currPos * 68 + 42;
var cached = peg$resultsCache[key];
if (cached) {
@ -3535,7 +3542,7 @@ function peg$parse(input, options) {
function peg$parsestring() {
var s0, s1, s2, s3, s4;
var key = peg$currPos * 67 + 43;
var key = peg$currPos * 68 + 43;
var cached = peg$resultsCache[key];
if (cached) {
@ -3676,10 +3683,44 @@ function peg$parse(input, options) {
return s0;
}
function peg$parsenumber() {
var s0, s1, s2;
var key = peg$currPos * 68 + 44;
var cached = peg$resultsCache[key];
if (cached) {
peg$currPos = cached.nextPos;
return cached.result;
}
s0 = peg$currPos;
s1 = peg$parsefloat();
if (s1 === peg$FAILED) {
s1 = peg$parseinteger();
}
if (s1 !== peg$FAILED) {
s2 = peg$parseidentifier();
if (s2 === peg$FAILED) {
s2 = null;
}
peg$savedPos = s0;
s0 = peg$f28(s1, s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
return s0;
}
function peg$parseinteger() {
var s0, s1, s2, s3, s4;
var key = peg$currPos * 67 + 44;
var key = peg$currPos * 68 + 45;
var cached = peg$resultsCache[key];
if (cached) {
@ -3740,7 +3781,7 @@ function peg$parse(input, options) {
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f28();
s0 = peg$f29();
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -3769,7 +3810,7 @@ function peg$parse(input, options) {
function peg$parsefloat() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 45;
var key = peg$currPos * 68 + 46;
var cached = peg$resultsCache[key];
if (cached) {
@ -3898,7 +3939,7 @@ function peg$parse(input, options) {
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f29();
s1 = peg$f30();
}
s0 = s1;
peg$silentFails--;
@ -3917,7 +3958,7 @@ function peg$parse(input, options) {
function peg$parsefloatExponent() {
var s0, s1, s2, s3, s4;
var key = peg$currPos * 67 + 46;
var key = peg$currPos * 68 + 47;
var cached = peg$resultsCache[key];
if (cached) {
@ -3979,7 +4020,7 @@ function peg$parse(input, options) {
function peg$parsed() {
var s0;
var key = peg$currPos * 67 + 47;
var key = peg$currPos * 68 + 48;
var cached = peg$resultsCache[key];
if (cached) {
@ -4006,7 +4047,7 @@ function peg$parse(input, options) {
function peg$parseboolean() {
var s0, s1;
var key = peg$currPos * 67 + 48;
var key = peg$currPos * 68 + 49;
var cached = peg$resultsCache[key];
if (cached) {
@ -4039,7 +4080,7 @@ function peg$parse(input, options) {
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f30();
s1 = peg$f31();
}
s0 = s1;
peg$silentFails--;
@ -4058,7 +4099,7 @@ function peg$parse(input, options) {
function peg$parsevalueConstructor() {
var s0;
var key = peg$currPos * 67 + 49;
var key = peg$currPos * 68 + 50;
var cached = peg$resultsCache[key];
if (cached) {
@ -4086,7 +4127,7 @@ function peg$parse(input, options) {
function peg$parselambda() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12;
var key = peg$currPos * 67 + 50;
var key = peg$currPos * 68 + 51;
var cached = peg$resultsCache[key];
if (cached) {
@ -4161,7 +4202,7 @@ function peg$parse(input, options) {
}
if (s12 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f31(s5, s9, s10);
s0 = peg$f32(s5, s9, s10);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -4242,7 +4283,7 @@ function peg$parse(input, options) {
}
if (s11 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f32(s5, s9);
s0 = peg$f33(s5, s9);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -4277,7 +4318,7 @@ function peg$parse(input, options) {
function peg$parsearrayConstructor() {
var s0, s1, s2, s3, s4, s5;
var key = peg$currPos * 67 + 51;
var key = peg$currPos * 68 + 52;
var cached = peg$resultsCache[key];
if (cached) {
@ -4310,7 +4351,7 @@ function peg$parse(input, options) {
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f33();
s0 = peg$f34();
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -4346,7 +4387,7 @@ function peg$parse(input, options) {
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f34(s3);
s0 = peg$f35(s3);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -4376,7 +4417,7 @@ function peg$parse(input, options) {
function peg$parsearray_elements() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 52;
var key = peg$currPos * 68 + 53;
var cached = peg$resultsCache[key];
if (cached) {
@ -4455,7 +4496,7 @@ function peg$parse(input, options) {
function peg$parserecordConstructor() {
var s0, s1, s2, s3, s4, s5;
var key = peg$currPos * 67 + 53;
var key = peg$currPos * 68 + 54;
var cached = peg$resultsCache[key];
if (cached) {
@ -4491,7 +4532,7 @@ function peg$parse(input, options) {
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f35(s3);
s0 = peg$f36(s3);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -4520,7 +4561,7 @@ function peg$parse(input, options) {
function peg$parsearray_recordArguments() {
var s0, s1, s2, s3, s4, s5, s6, s7;
var key = peg$currPos * 67 + 54;
var key = peg$currPos * 68 + 55;
var cached = peg$resultsCache[key];
if (cached) {
@ -4599,7 +4640,7 @@ function peg$parse(input, options) {
function peg$parsekeyValuePair() {
var s0, s1, s2, s3, s4, s5;
var key = peg$currPos * 67 + 55;
var key = peg$currPos * 68 + 56;
var cached = peg$resultsCache[key];
if (cached) {
@ -4626,7 +4667,7 @@ function peg$parse(input, options) {
s5 = peg$parseexpression();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f36(s1, s5);
s0 = peg$f37(s1, s5);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -4648,7 +4689,7 @@ function peg$parse(input, options) {
function peg$parse_() {
var s0, s1;
var key = peg$currPos * 67 + 56;
var key = peg$currPos * 68 + 57;
var cached = peg$resultsCache[key];
if (cached) {
@ -4678,7 +4719,7 @@ function peg$parse(input, options) {
function peg$parse_nl() {
var s0, s1;
var key = peg$currPos * 67 + 57;
var key = peg$currPos * 68 + 58;
var cached = peg$resultsCache[key];
if (cached) {
@ -4714,7 +4755,7 @@ function peg$parse(input, options) {
function peg$parse__() {
var s0, s1;
var key = peg$currPos * 67 + 58;
var key = peg$currPos * 68 + 59;
var cached = peg$resultsCache[key];
if (cached) {
@ -4750,7 +4791,7 @@ function peg$parse(input, options) {
function peg$parse__nl() {
var s0, s1;
var key = peg$currPos * 67 + 59;
var key = peg$currPos * 68 + 60;
var cached = peg$resultsCache[key];
if (cached) {
@ -4792,7 +4833,7 @@ function peg$parse(input, options) {
function peg$parsestatementSeparator() {
var s0, s1, s2, s3;
var key = peg$currPos * 67 + 60;
var key = peg$currPos * 68 + 61;
var cached = peg$resultsCache[key];
if (cached) {
@ -4860,7 +4901,7 @@ function peg$parse(input, options) {
function peg$parsecommentOrNewLine() {
var s0, s1, s2;
var key = peg$currPos * 67 + 61;
var key = peg$currPos * 68 + 62;
var cached = peg$resultsCache[key];
if (cached) {
@ -4891,7 +4932,7 @@ function peg$parse(input, options) {
function peg$parsefinalComment() {
var s0, s1, s2, s3, s4;
var key = peg$currPos * 67 + 62;
var key = peg$currPos * 68 + 63;
var cached = peg$resultsCache[key];
if (cached) {
@ -4967,7 +5008,7 @@ function peg$parse(input, options) {
function peg$parsewhiteSpaceCharactersOrComment() {
var s0;
var key = peg$currPos * 67 + 63;
var key = peg$currPos * 68 + 64;
var cached = peg$resultsCache[key];
if (cached) {
@ -4989,7 +5030,7 @@ function peg$parse(input, options) {
function peg$parsedelimitedComment() {
var s0, s1, s2, s3;
var key = peg$currPos * 67 + 64;
var key = peg$currPos * 68 + 65;
var cached = peg$resultsCache[key];
if (cached) {
@ -5067,7 +5108,7 @@ function peg$parse(input, options) {
function peg$parsewhiteSpaceCharacters() {
var s0;
var key = peg$currPos * 67 + 65;
var key = peg$currPos * 68 + 66;
var cached = peg$resultsCache[key];
if (cached) {
@ -5094,7 +5135,7 @@ function peg$parse(input, options) {
function peg$parsenewLine() {
var s0, s1;
var key = peg$currPos * 67 + 66;
var key = peg$currPos * 68 + 67;
var cached = peg$resultsCache[key];
if (cached) {

View File

@ -248,8 +248,7 @@ basicValue = valueConstructor / basicLiteral
basicLiteral
= string
/ float
/ integer
/ number
/ boolean
/ dollarIdentifier
@ -263,6 +262,16 @@ string 'string'
= characters:("'" @([^'])* "'") {return nodeString(characters.join(''))}
/ characters:('"' @([^"])* '"') {return nodeString(characters.join(''))}
number = number:(float / integer) unit:identifier?
{
if (unit === null)
{ return number }
else
{ return makeFunctionCall('multiply',
[number, makeFunctionCall('$valueOfUnit', [nodeString(unit.value)])])
}
}
integer 'integer'
= d+ !"\." ![e]i
{ return nodeInteger(parseInt(text()))}