Merge branch 'generic-units' into Umur-reducer-dev

packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js
This commit is contained in:
Umur Ozkul 2022-05-23 18:02:21 +02:00
commit 0124181bce
3 changed files with 4754 additions and 2 deletions

View File

@ -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", () => {

View File

@ -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()))}