Merge pull request #865 from quantified-uncertainty/reducer-void
Reducer: void type
This commit is contained in:
commit
4055d1e93c
|
@ -200,6 +200,12 @@ export const SquiggleItem: React.FC<SquiggleItemProps> = ({
|
||||||
{expression.value.toDateString()}
|
{expression.value.toDateString()}
|
||||||
</VariableBox>
|
</VariableBox>
|
||||||
);
|
);
|
||||||
|
case "void":
|
||||||
|
return (
|
||||||
|
<VariableBox heading="Void" showTypes={showTypes}>
|
||||||
|
{"Void"}
|
||||||
|
</VariableBox>
|
||||||
|
);
|
||||||
case "timeDuration": {
|
case "timeDuration": {
|
||||||
return (
|
return (
|
||||||
<VariableBox heading="Time Duration" showTypes={showTypes}>
|
<VariableBox heading="Time Duration" showTypes={showTypes}>
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
open Jest
|
||||||
|
open Reducer_Peggy_TestHelpers
|
||||||
|
|
||||||
|
describe("Peggy void", () => {
|
||||||
|
//literal
|
||||||
|
testToExpression("()", "{()}", ~v="()", ())
|
||||||
|
testToExpression(
|
||||||
|
"fn()=1",
|
||||||
|
"{(:$_let_$ :fn (:$$_lambda_$$ [_] {1}))}",
|
||||||
|
~v="@{fn: lambda(_=>internal code)}",
|
||||||
|
(),
|
||||||
|
)
|
||||||
|
testToExpression("fn()=1; fn()", "{(:$_let_$ :fn (:$$_lambda_$$ [_] {1})); (:fn ())}", ~v="1", ())
|
||||||
|
testToExpression(
|
||||||
|
"fn(a)=(); call fn(1)",
|
||||||
|
"{(:$_let_$ :fn (:$$_lambda_$$ [a] {()})); (:$_let_$ :_ {(:fn 1)})}",
|
||||||
|
~v="@{_: (),fn: lambda(a=>internal code)}",
|
||||||
|
(),
|
||||||
|
)
|
||||||
|
})
|
|
@ -31,6 +31,7 @@
|
||||||
"format:prettier": "prettier --write .",
|
"format:prettier": "prettier --write .",
|
||||||
"format": "yarn format:rescript && yarn format:prettier",
|
"format": "yarn format:rescript && yarn format:prettier",
|
||||||
"prepack": "yarn build && yarn test && yarn bundle",
|
"prepack": "yarn build && yarn test && yarn bundle",
|
||||||
|
"all:rescript": "yarn build:rescript && yarn test:rescript && yarn format:rescript",
|
||||||
"all": "yarn build && yarn bundle && yarn test"
|
"all": "yarn build && yarn bundle && yarn test"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|
|
@ -120,6 +120,10 @@ function createTsExport(
|
||||||
x: expressionValue,
|
x: expressionValue,
|
||||||
environment: environment
|
environment: environment
|
||||||
): squiggleExpression {
|
): squiggleExpression {
|
||||||
|
switch (x) {
|
||||||
|
case "EvVoid":
|
||||||
|
return tag("void", "");
|
||||||
|
default: {
|
||||||
switch (x.tag) {
|
switch (x.tag) {
|
||||||
case "EvArray":
|
case "EvArray":
|
||||||
// genType doesn't convert anything more than 2 layers down into {tag: x, value: x}
|
// genType doesn't convert anything more than 2 layers down into {tag: x, value: x}
|
||||||
|
@ -153,7 +157,8 @@ function createTsExport(
|
||||||
return tag("number", x.value);
|
return tag("number", x.value);
|
||||||
case "EvRecord":
|
case "EvRecord":
|
||||||
// genType doesn't support records, so we have to do the raw conversion ourself
|
// genType doesn't support records, so we have to do the raw conversion ourself
|
||||||
let result: tagged<"record", { [key: string]: squiggleExpression }> = tag(
|
let result: tagged<"record", { [key: string]: squiggleExpression }> =
|
||||||
|
tag(
|
||||||
"record",
|
"record",
|
||||||
_.mapValues(x.value, (x: unknown) =>
|
_.mapValues(x.value, (x: unknown) =>
|
||||||
convertRawToTypescript(x as rescriptExport, environment)
|
convertRawToTypescript(x as rescriptExport, environment)
|
||||||
|
@ -173,8 +178,10 @@ function createTsExport(
|
||||||
case "EvTypeIdentifier":
|
case "EvTypeIdentifier":
|
||||||
return tag("typeIdentifier", x.value);
|
return tag("typeIdentifier", x.value);
|
||||||
case "EvType":
|
case "EvType":
|
||||||
let typeResult: tagged<"type", { [key: string]: squiggleExpression }> =
|
let typeResult: tagged<
|
||||||
tag(
|
"type",
|
||||||
|
{ [key: string]: squiggleExpression }
|
||||||
|
> = tag(
|
||||||
"type",
|
"type",
|
||||||
_.mapValues(x.value, (x: unknown) =>
|
_.mapValues(x.value, (x: unknown) =>
|
||||||
convertRawToTypescript(x as rescriptExport, environment)
|
convertRawToTypescript(x as rescriptExport, environment)
|
||||||
|
@ -194,3 +201,5 @@ function createTsExport(
|
||||||
return moduleResult;
|
return moduleResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -131,7 +131,8 @@ export type squiggleExpression =
|
||||||
| tagged<"record", { [key: string]: squiggleExpression }>
|
| tagged<"record", { [key: string]: squiggleExpression }>
|
||||||
| tagged<"type", { [key: string]: squiggleExpression }>
|
| tagged<"type", { [key: string]: squiggleExpression }>
|
||||||
| tagged<"typeIdentifier", string>
|
| tagged<"typeIdentifier", string>
|
||||||
| tagged<"module", { [key: string]: squiggleExpression }>;
|
| tagged<"module", { [key: string]: squiggleExpression }>
|
||||||
|
| tagged<"void", string>;
|
||||||
|
|
||||||
export { lambdaValue };
|
export { lambdaValue };
|
||||||
|
|
||||||
|
|
|
@ -82,3 +82,5 @@ let eIdentifier = (name: string): expression =>
|
||||||
|
|
||||||
let eTypeIdentifier = (name: string): expression =>
|
let eTypeIdentifier = (name: string): expression =>
|
||||||
name->BInternalExpressionValue.IEvTypeIdentifier->BExpressionT.EValue
|
name->BInternalExpressionValue.IEvTypeIdentifier->BExpressionT.EValue
|
||||||
|
|
||||||
|
let eVoid: expression = BInternalExpressionValue.IEvVoid->BExpressionT.EValue
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
}}
|
}}
|
||||||
|
|
||||||
start
|
start
|
||||||
// = _nl start:typeExpression _nl finalComment? {return start}
|
|
||||||
= _nl start:outerBlock _nl finalComment? {return start}
|
= _nl start:outerBlock _nl finalComment? {return start}
|
||||||
|
|
||||||
zeroOMoreArgumentsBlockOrExpression = innerBlockOrExpression / lambda
|
zeroOMoreArgumentsBlockOrExpression = innerBlockOrExpression / lambda
|
||||||
|
@ -39,6 +38,12 @@ statement
|
||||||
= letStatement
|
= letStatement
|
||||||
/ defunStatement
|
/ defunStatement
|
||||||
/ typeStatement
|
/ typeStatement
|
||||||
|
/ voidStatement
|
||||||
|
|
||||||
|
voidStatement
|
||||||
|
= "call" _nl value:zeroOMoreArgumentsBlockOrExpression
|
||||||
|
{ var variable = h.nodeIdentifier("_", location());
|
||||||
|
return h.nodeLetStatement(variable, value); }
|
||||||
|
|
||||||
letStatement
|
letStatement
|
||||||
= variable:identifier _ assignmentOp _nl value:zeroOMoreArgumentsBlockOrExpression
|
= variable:identifier _ assignmentOp _nl value:zeroOMoreArgumentsBlockOrExpression
|
||||||
|
@ -54,6 +59,8 @@ defunStatement
|
||||||
array_parameters
|
array_parameters
|
||||||
= head:dollarIdentifier tail:(_ ',' _nl @dollarIdentifier)*
|
= head:dollarIdentifier tail:(_ ',' _nl @dollarIdentifier)*
|
||||||
{ return [head, ...tail]; }
|
{ return [head, ...tail]; }
|
||||||
|
/ ""
|
||||||
|
{ return [h.nodeIdentifier("_", location())]; }
|
||||||
|
|
||||||
expression = ifthenelse / ternary / logicalAdditive
|
expression = ifthenelse / ternary / logicalAdditive
|
||||||
|
|
||||||
|
@ -172,6 +179,8 @@ collectionElement
|
||||||
array_functionArguments
|
array_functionArguments
|
||||||
= head:expression tail:(_ ',' _nl @expression)*
|
= head:expression tail:(_ ',' _nl @expression)*
|
||||||
{ return [head, ...tail]; }
|
{ return [head, ...tail]; }
|
||||||
|
/ ""
|
||||||
|
{return [h.nodeVoid()];}
|
||||||
|
|
||||||
atom
|
atom
|
||||||
= '(' _nl expression:expression _nl ')' {return expression}
|
= '(' _nl expression:expression _nl ')' {return expression}
|
||||||
|
@ -185,6 +194,10 @@ basicLiteral
|
||||||
/ boolean
|
/ boolean
|
||||||
/ dollarIdentifierWithModule
|
/ dollarIdentifierWithModule
|
||||||
/ dollarIdentifier
|
/ dollarIdentifier
|
||||||
|
/ voidLiteral
|
||||||
|
|
||||||
|
voidLiteral 'void'
|
||||||
|
= "()" {return h.nodeVoid();}
|
||||||
|
|
||||||
dollarIdentifierWithModule 'identifier'
|
dollarIdentifierWithModule 'identifier'
|
||||||
= head:$moduleIdentifier
|
= head:$moduleIdentifier
|
||||||
|
@ -195,7 +208,7 @@ dollarIdentifierWithModule 'identifier'
|
||||||
modifiers.unshift(head)
|
modifiers.unshift(head)
|
||||||
modifiers.push(final)
|
modifiers.push(final)
|
||||||
let modifiedIdentifier = modifiers.join('.')
|
let modifiedIdentifier = modifiers.join('.')
|
||||||
return h.nodeIdentifier(modifiedIdentifier)
|
return h.nodeIdentifier(modifiedIdentifier, location())
|
||||||
}
|
}
|
||||||
|
|
||||||
identifier 'identifier'
|
identifier 'identifier'
|
||||||
|
|
|
@ -34,6 +34,7 @@ type nodeModuleIdentifier = {...node, "value": string}
|
||||||
type nodeString = {...node, "value": string}
|
type nodeString = {...node, "value": string}
|
||||||
type nodeTernary = {...node, "condition": node, "trueExpression": node, "falseExpression": node}
|
type nodeTernary = {...node, "condition": node, "trueExpression": node, "falseExpression": node}
|
||||||
type nodeTypeIdentifier = {...node, "value": string}
|
type nodeTypeIdentifier = {...node, "value": string}
|
||||||
|
type nodeVoid = node
|
||||||
|
|
||||||
type peggyNode =
|
type peggyNode =
|
||||||
| PgNodeBlock(nodeBlock)
|
| PgNodeBlock(nodeBlock)
|
||||||
|
@ -50,6 +51,7 @@ type peggyNode =
|
||||||
| PgNodeString(nodeString)
|
| PgNodeString(nodeString)
|
||||||
| PgNodeTernary(nodeTernary)
|
| PgNodeTernary(nodeTernary)
|
||||||
| PgNodeTypeIdentifier(nodeTypeIdentifier)
|
| PgNodeTypeIdentifier(nodeTypeIdentifier)
|
||||||
|
| PgNodeVoid(nodeVoid)
|
||||||
|
|
||||||
external castNodeBlock: node => nodeBlock = "%identity"
|
external castNodeBlock: node => nodeBlock = "%identity"
|
||||||
external castNodeBoolean: node => nodeBoolean = "%identity"
|
external castNodeBoolean: node => nodeBoolean = "%identity"
|
||||||
|
@ -65,6 +67,7 @@ external castNodeModuleIdentifier: node => nodeModuleIdentifier = "%identity"
|
||||||
external castNodeString: node => nodeString = "%identity"
|
external castNodeString: node => nodeString = "%identity"
|
||||||
external castNodeTernary: node => nodeTernary = "%identity"
|
external castNodeTernary: node => nodeTernary = "%identity"
|
||||||
external castNodeTypeIdentifier: node => nodeTypeIdentifier = "%identity"
|
external castNodeTypeIdentifier: node => nodeTypeIdentifier = "%identity"
|
||||||
|
external castNodeVoid: node => nodeVoid = "%identity"
|
||||||
|
|
||||||
exception UnsupportedPeggyNodeType(string) // This should never happen; programming error
|
exception UnsupportedPeggyNodeType(string) // This should never happen; programming error
|
||||||
let castNodeType = (node: node) =>
|
let castNodeType = (node: node) =>
|
||||||
|
@ -83,6 +86,7 @@ let castNodeType = (node: node) =>
|
||||||
| "String" => node->castNodeString->PgNodeString
|
| "String" => node->castNodeString->PgNodeString
|
||||||
| "Ternary" => node->castNodeTernary->PgNodeTernary
|
| "Ternary" => node->castNodeTernary->PgNodeTernary
|
||||||
| "TypeIdentifier" => node->castNodeTypeIdentifier->PgNodeTypeIdentifier
|
| "TypeIdentifier" => node->castNodeTypeIdentifier->PgNodeTypeIdentifier
|
||||||
|
| "Void" => node->castNodeVoid->PgNodeVoid
|
||||||
| _ => raise(UnsupportedPeggyNodeType(node["type"]))
|
| _ => raise(UnsupportedPeggyNodeType(node["type"]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +120,7 @@ let rec pgToString = (peggyNode: peggyNode): string => {
|
||||||
" " ++
|
" " ++
|
||||||
toString(node["falseExpression"]) ++ ")"
|
toString(node["falseExpression"]) ++ ")"
|
||||||
| PgNodeTypeIdentifier(node) => `#${node["value"]}`
|
| PgNodeTypeIdentifier(node) => `#${node["value"]}`
|
||||||
|
| PgNodeVoid(_node) => "()"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
and toString = (node: node): string => node->castNodeType->pgToString
|
and toString = (node: node): string => node->castNodeType->pgToString
|
||||||
|
|
|
@ -48,5 +48,6 @@ let rec fromNode = (node: Parse.node): expression => {
|
||||||
)
|
)
|
||||||
| PgNodeTypeIdentifier(nodeTypeIdentifier) =>
|
| PgNodeTypeIdentifier(nodeTypeIdentifier) =>
|
||||||
ExpressionBuilder.eTypeIdentifier(nodeTypeIdentifier["value"])
|
ExpressionBuilder.eTypeIdentifier(nodeTypeIdentifier["value"])
|
||||||
|
| PgNodeVoid(_) => ExpressionBuilder.eVoid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,3 +213,7 @@ export function nodeTernary(
|
||||||
export function nodeTypeIdentifier(typeValue: string) {
|
export function nodeTypeIdentifier(typeValue: string) {
|
||||||
return { type: "TypeIdentifier", value: typeValue };
|
return { type: "TypeIdentifier", value: typeValue };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function nodeVoid() {
|
||||||
|
return { type: "Void" };
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ type rec externalExpressionValue =
|
||||||
| EvTypeIdentifier(string)
|
| EvTypeIdentifier(string)
|
||||||
| EvModule(record)
|
| EvModule(record)
|
||||||
| EvType(record)
|
| EvType(record)
|
||||||
|
| EvVoid
|
||||||
and record = Js.Dict.t<externalExpressionValue>
|
and record = Js.Dict.t<externalExpressionValue>
|
||||||
and externalBindings = record
|
and externalBindings = record
|
||||||
and lambdaValue = {
|
and lambdaValue = {
|
||||||
|
@ -63,6 +64,7 @@ let rec toString = aValue =>
|
||||||
| EvTimeDuration(t) => DateTime.Duration.toString(t)
|
| EvTimeDuration(t) => DateTime.Duration.toString(t)
|
||||||
| EvType(t) => `type${t->toStringRecord}`
|
| EvType(t) => `type${t->toStringRecord}`
|
||||||
| EvTypeIdentifier(id) => `#${id}`
|
| EvTypeIdentifier(id) => `#${id}`
|
||||||
|
| EvVoid => `()`
|
||||||
}
|
}
|
||||||
and toStringRecord = aRecord => {
|
and toStringRecord = aRecord => {
|
||||||
let pairs =
|
let pairs =
|
||||||
|
|
|
@ -23,6 +23,7 @@ type rec t =
|
||||||
| IEvTimeDuration(float)
|
| IEvTimeDuration(float)
|
||||||
| IEvType(map)
|
| IEvType(map)
|
||||||
| IEvTypeIdentifier(string)
|
| IEvTypeIdentifier(string)
|
||||||
|
| IEvVoid
|
||||||
and map = Belt.Map.String.t<t>
|
and map = Belt.Map.String.t<t>
|
||||||
and nameSpace = NameSpace(Belt.Map.String.t<t>)
|
and nameSpace = NameSpace(Belt.Map.String.t<t>)
|
||||||
and lambdaValue = {
|
and lambdaValue = {
|
||||||
|
@ -60,6 +61,7 @@ let rec toString = aValue =>
|
||||||
| IEvType(aMap) => aMap->toStringMap
|
| IEvType(aMap) => aMap->toStringMap
|
||||||
| IEvTimeDuration(t) => DateTime.Duration.toString(t)
|
| IEvTimeDuration(t) => DateTime.Duration.toString(t)
|
||||||
| IEvTypeIdentifier(id) => `#${id}`
|
| IEvTypeIdentifier(id) => `#${id}`
|
||||||
|
| IEvVoid => `()`
|
||||||
}
|
}
|
||||||
and toStringMap = aMap => {
|
and toStringMap = aMap => {
|
||||||
let pairs =
|
let pairs =
|
||||||
|
@ -92,6 +94,7 @@ let toStringWithType = aValue =>
|
||||||
| IEvTimeDuration(_) => `Date::${toString(aValue)}`
|
| IEvTimeDuration(_) => `Date::${toString(aValue)}`
|
||||||
| IEvType(_) => `Type::${toString(aValue)}`
|
| IEvType(_) => `Type::${toString(aValue)}`
|
||||||
| IEvTypeIdentifier(_) => `TypeIdentifier::${toString(aValue)}`
|
| IEvTypeIdentifier(_) => `TypeIdentifier::${toString(aValue)}`
|
||||||
|
| IEvVoid => `Void`
|
||||||
}
|
}
|
||||||
|
|
||||||
let argsToString = (args: array<t>): string => {
|
let argsToString = (args: array<t>): string => {
|
||||||
|
@ -135,6 +138,7 @@ type internalExpressionValueType =
|
||||||
| EvtTimeDuration
|
| EvtTimeDuration
|
||||||
| EvtType
|
| EvtType
|
||||||
| EvtTypeIdentifier
|
| EvtTypeIdentifier
|
||||||
|
| EvtVoid
|
||||||
|
|
||||||
type functionCallSignature = CallSignature(string, array<internalExpressionValueType>)
|
type functionCallSignature = CallSignature(string, array<internalExpressionValueType>)
|
||||||
type functionDefinitionSignature =
|
type functionDefinitionSignature =
|
||||||
|
@ -158,6 +162,7 @@ let valueToValueType = value =>
|
||||||
| IEvTimeDuration(_) => EvtTimeDuration
|
| IEvTimeDuration(_) => EvtTimeDuration
|
||||||
| IEvType(_) => EvtType
|
| IEvType(_) => EvtType
|
||||||
| IEvTypeIdentifier(_) => EvtTypeIdentifier
|
| IEvTypeIdentifier(_) => EvtTypeIdentifier
|
||||||
|
| IEvVoid => EvtVoid
|
||||||
}
|
}
|
||||||
|
|
||||||
let externalValueToValueType = (value: ExternalExpressionValue.t) =>
|
let externalValueToValueType = (value: ExternalExpressionValue.t) =>
|
||||||
|
@ -203,6 +208,7 @@ let valueTypeToString = (valueType: internalExpressionValueType): string =>
|
||||||
| EvtTimeDuration => `Duration`
|
| EvtTimeDuration => `Duration`
|
||||||
| EvtType => `Type`
|
| EvtType => `Type`
|
||||||
| EvtTypeIdentifier => `TypeIdentifier`
|
| EvtTypeIdentifier => `TypeIdentifier`
|
||||||
|
| EvtVoid => `Void`
|
||||||
}
|
}
|
||||||
|
|
||||||
let functionCallSignatureToString = (functionCallSignature: functionCallSignature): string => {
|
let functionCallSignatureToString = (functionCallSignature: functionCallSignature): string => {
|
||||||
|
@ -232,6 +238,7 @@ let rec toExternal = (iev: t): ExternalExpressionValue.t => {
|
||||||
| IEvType(v) => v->mapToExternal->EvType
|
| IEvType(v) => v->mapToExternal->EvType
|
||||||
| IEvTypeIdentifier(v) => EvTypeIdentifier(v)
|
| IEvTypeIdentifier(v) => EvTypeIdentifier(v)
|
||||||
| IEvBindings(v) => v->nameSpaceToTypeScriptBindings->EvModule
|
| IEvBindings(v) => v->nameSpaceToTypeScriptBindings->EvModule
|
||||||
|
| IEvVoid => EvVoid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
and mapToExternal = v =>
|
and mapToExternal = v =>
|
||||||
|
@ -271,6 +278,7 @@ let rec toInternal = (ev: ExternalExpressionValue.t): t => {
|
||||||
| EvTimeDuration(v) => IEvTimeDuration(v)
|
| EvTimeDuration(v) => IEvTimeDuration(v)
|
||||||
| EvType(v) => v->recordToInternal->IEvType
|
| EvType(v) => v->recordToInternal->IEvType
|
||||||
| EvTypeIdentifier(v) => IEvTypeIdentifier(v)
|
| EvTypeIdentifier(v) => IEvTypeIdentifier(v)
|
||||||
|
| EvVoid => IEvVoid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
and recordToInternal = v =>
|
and recordToInternal = v =>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user