Merge pull request #578 from quantified-uncertainty/reducer-dev
Reducer: Add Units (reimplemented)
This commit is contained in:
commit
0d964865c3
|
@ -251,6 +251,10 @@ describe("Peggy parse", () => {
|
||||||
"{(::map (::$_constructArray_$ (1 2 3)) {|:x| {(::add :x 1)}})}",
|
"{(::map (::$_constructArray_$ (1 2 3)) {|:x| {(::add :x 1)}})}",
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
describe("unit", () => {
|
||||||
|
testParse("1m", "{(::fromUnit_m 1)}")
|
||||||
|
testParse("1m+2cm", "{(::add (::fromUnit_m 1) (::fromUnit_cm 2))}")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("parsing new line", () => {
|
describe("parsing new line", () => {
|
||||||
|
|
|
@ -4,18 +4,19 @@ type errorValue =
|
||||||
| REArrayIndexNotFound(string, int)
|
| REArrayIndexNotFound(string, int)
|
||||||
| REAssignmentExpected
|
| REAssignmentExpected
|
||||||
| REDistributionError(DistributionTypes.error)
|
| REDistributionError(DistributionTypes.error)
|
||||||
| REOperationError(Operation.operationError)
|
| REExpectedType(string)
|
||||||
| REExpressionExpected
|
| REExpressionExpected
|
||||||
| REFunctionExpected(string)
|
| REFunctionExpected(string)
|
||||||
| REFunctionNotFound(string)
|
| REFunctionNotFound(string)
|
||||||
| REJavaScriptExn(option<string>, option<string>) // Javascript Exception
|
| REJavaScriptExn(option<string>, option<string>) // Javascript Exception
|
||||||
| REMacroNotFound(string)
|
| REMacroNotFound(string)
|
||||||
| RENotAFunction(string)
|
| RENotAFunction(string)
|
||||||
|
| REOperationError(Operation.operationError)
|
||||||
| RERecordPropertyNotFound(string, string)
|
| RERecordPropertyNotFound(string, string)
|
||||||
| RESymbolNotFound(string)
|
| RESymbolNotFound(string)
|
||||||
| RESyntaxError(string)
|
| RESyntaxError(string)
|
||||||
| RETodo(string) // To do
|
| RETodo(string) // To do
|
||||||
| REExpectedType(string)
|
| REUnitNotFound(string)
|
||||||
|
|
||||||
type t = errorValue
|
type t = errorValue
|
||||||
|
|
||||||
|
@ -52,4 +53,5 @@ let errorToString = err =>
|
||||||
| RESyntaxError(desc) => `Syntax Error: ${desc}`
|
| RESyntaxError(desc) => `Syntax Error: ${desc}`
|
||||||
| RETodo(msg) => `TODO: ${msg}`
|
| RETodo(msg) => `TODO: ${msg}`
|
||||||
| REExpectedType(typeName) => `Expected type: ${typeName}`
|
| REExpectedType(typeName) => `Expected type: ${typeName}`
|
||||||
|
| REUnitNotFound(unitName) => `Unit not found: ${unitName}`
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,8 +248,7 @@ basicValue = valueConstructor / basicLiteral
|
||||||
|
|
||||||
basicLiteral
|
basicLiteral
|
||||||
= string
|
= string
|
||||||
/ float
|
/ number
|
||||||
/ integer
|
|
||||||
/ boolean
|
/ boolean
|
||||||
/ dollarIdentifier
|
/ dollarIdentifier
|
||||||
|
|
||||||
|
@ -263,6 +262,15 @@ string 'string'
|
||||||
= characters:("'" @([^'])* "'") {return nodeString(characters.join(''))}
|
= characters:("'" @([^'])* "'") {return nodeString(characters.join(''))}
|
||||||
/ characters:('"' @([^"])* '"') {return nodeString(characters.join(''))}
|
/ characters:('"' @([^"])* '"') {return nodeString(characters.join(''))}
|
||||||
|
|
||||||
|
number = number:(float / integer) unit:identifier?
|
||||||
|
{
|
||||||
|
if (unit === null)
|
||||||
|
{ return number }
|
||||||
|
else
|
||||||
|
{ return makeFunctionCall('fromUnit_'+unit.value, [number])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
integer 'integer'
|
integer 'integer'
|
||||||
= d+ !"\." ![e]i
|
= d+ !"\." ![e]i
|
||||||
{ return nodeInteger(parseInt(text()))}
|
{ return nodeInteger(parseInt(text()))}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user