This modules exposes the internal structures of the package.
Its intended to be used in combination with some preprocessing.
The expressions always return a string
Print - just return the given stringInsert - look up the key and insert a generated string according to the definition of the key.The definition specifies how the strings gets generated
Choose - Choose a random sentence out of a list.Let - Generate the sentence one. Then use the sentence over and over again.With - Generate the sentence according to the sub-grammar.Decoder for the Syntax.
import Dict
input : String
input =
"""{ "origin" : [ "Hello \\\\\\\\ World \\\\#", "#statement# and #statement#" ]
, "statement" :
{ "origin" : "my #myPet# is the #complement#"
, "myPet": "#pet#"
, "pet" : ["cat","dog"]
, "complement" : ["smartest #myPet# in the world","fastest #myPet# that i know of"]
}
}"""
output : Syntax
output =
Dict.fromList
[ ( "origin"
, Choose
[ [Print "Hello ", Print "\\", Print " World ",Print "#"]
, [Insert "statement", Print " and ", Insert "statement"]
]
)
, ( "statement"
, Dict.fromList
[ ( "origin"
, Let [ Print "my ", Insert "myPet", Print " is the ", Insert "complement"]
)
, ( "myPet",Let [Insert "pet"])
, ( "pet", Choose [[Print "cat"],[Print "dog"]])
, ( "complement"
, Choose
[ [ Print "smartest ", Insert "myPet", Print " in the world"]
, [ Print "fastest ", Insert "myPet", Print " that i know of"]
]
)
]
|> With
)
]
input |> fromString
--> Ok outputThe origin is the starting point for the generated story.
originString : String
originString =
"origin"
The Syntax is just a dictionary of keys and their definition.