[{"name":"Tracery","comment":" Tracery is a text-generation language mostly used for twitter bots.\n\nSee [Tracery.io](www.tracery.io) for more information.\n\n@docs fromJson, run, runTo, toString\n\n","unions":[],"aliases":[],"values":[{"name":"fromJson","comment":" Turns a tracery json-string into a generator\n\n    import Json.Decode\n    import Random\n    import Result.Extra\n\n    generate : Int -> String -> String\n    generate seed json =\n        json\n            |> Tracery.fromJson\n            |> Result.Extra.unpack\n                Json.Decode.errorToString\n                (\\grammar ->\n                    Random.step (Tracery.run grammar) (Random.initialSeed seed)\n                        |> Tuple.first\n                )\n\nA tracery json is a object that has a `origin` field.\n\nThe `#` and `\\` characters need to be escaped.\n\n    \"\"\"\n    { \"origin\": \"The \\\\\\\\# and \\\\\\\\\\\\\\\\ characters need to be escaped.\"}\n    \"\"\"\n    |> generate 42\n    --> \"The # and \\\\ characters need to be escaped.\"\n\nIf you provide a list, tracer will tick an element at random.\n\n    \"\"\"\n    { \"origin\": [\"I like cats\",\"I like dogs\"]}\n    \"\"\"\n    |> generate 42\n    --> \"I like cats\"\n\nYou can reference other fields using `#..#`\n\n    \"\"\"\n    { \"origin\": [\"I have two pets: a #pet# and a #pet#\"]\n    , \"pet\": [\"cat\",\"dog\",\"fish\",\"parrot\"]\n    }\n    \"\"\"\n    |> generate 42\n    --> \"I have two pets: a dog and a cat\"\n\nYou can also save partially evaluated strings\n\n    \"\"\"\n    { \"origin\": [\"I both have a #myPet# and a #myPet#.\"]\n    , \"myPet\" : \"#petWithColor#\"\n    , \"petWithColor\" : [\"black #pet#\", \"white #pet#\", \"brown #pet#\"]\n    , \"pet\": [\"cat\",\"dog\",\"fish\",\"parrot\"]\n    }\n    \"\"\"\n    |> generate 41\n    --> \"I both have a white cat and a white parrot.\"\n\nDefinitions may also be recursive.\n\n    \"\"\"\n    { \"origin\": [\"I have #pets#\"]\n    , \"pets\": [\"a #pet#\",\"a #pet# and #pets#\"]\n    , \"pet\": [\"cat\",\"dog\",\"fish\",\"parrot\"]\n    }\n    \"\"\"\n    |> generate 20\n    --> \"I have a fish and a cat and a dog\"\n\nYou can define constants by providing a string instead of a list.\n\n    \"\"\"\n    { \"origin\": [\"My #favoritePet# is the best #favoritePet# in the world\"]\n    , \"favoritePet\" : \"#pet#\"\n    , \"pet\": [\"cat\",\"dog\",\"fish\",\"parrot\"]\n    }\n    \"\"\"\n    |> generate 42\n    --> \"My dog is the best dog in the world\"\n\nYou may define sub-definitions to organize your definitions.\n\n    \"\"\"\n    { \"origin\": [\"My #cat#\",\"My #dog#\"]\n    , \"cat\":\n      { \"origin\":\"cat is named #name#\"\n      , \"name\": [\"Cleopatra\",\"Cesar\"]\n      }\n    , \"dog\":\n      { \"origin\":\"dog is named #name#\"\n      , \"name\": [\"Athena\",\"Zeus\"]\n      }\n    }\n    \"\"\"\n    |> generate 42\n    --> \"My cat is named Cleopatra\"\n\n","type":"String.String -> Result.Result Json.Decode.Error Tracery.Grammar.Grammar"},{"name":"run","comment":" Runs a grammar until it ends.\n\nSome recursive definitions might take a long time.\n\nUse `runTo` if you want to avoid long waiting times.\n\n","type":"Tracery.Grammar.Grammar -> Random.Generator String.String"},{"name":"runTo","comment":" Runs a grammar until it reaches a key in the list.\n\n    import Json.Decode\n    import Random\n    import Result.Extra\n\n    generateTo : List String -> ({variable:String} -> String)-> Int -> String -> String\n    generateTo list fun seed json =\n        json\n            |> Tracery.fromJson\n            |> Result.Extra.unpack\n                Json.Decode.errorToString\n                (\\grammar ->\n                    Random.step (Tracery.runTo list grammar) (Random.initialSeed seed)\n                        |> Tuple.first\n                        |> toString fun\n                )\n\n    \"\"\"\n    { \"origin\": [\"A #color# #animal#\"]\n    , \"color\": [\"black\",\"white\",\"gray\"]\n    , \"animal\":\n      [ \"cat, looking at a #color# #animal#\"\n      , \"bird.\"\n      ]\n    }\n    \"\"\"\n    |> generateTo [\"animal\"] (\\{variable} -> \"dog.\") 42\n    --> \"A black dog.\"\n\n","type":"List.List String.String -> Tracery.Grammar.Grammar -> Random.Generator Tracery.Grammar.Grammar"},{"name":"toString","comment":" Will just write the current output.\n\nuse run or runTo, to actually compute something.\n\n","type":"({ variable : String.String } -> String.String) -> Tracery.Grammar.Grammar -> String.String"}],"binops":[]},{"name":"Tracery.Command","comment":" Commands are used to be able to pause the execution of a Grammar.\n\nBy modifying the commands in a grammar you can directly change how the program should run.\n\n@docs Command, simplify, toString\n\n@docs fillAll, fromExpressions, variables, onlyValues\n\n","unions":[{"name":"Command","comment":" Defines commands that the algorithm recognizes\n\n  - Print - print the expression to the output\n  - Define - Add a set of definitions\n  - Delete - Delete a set of definitions\n  - Save - saves the current value of the output as a constant and replaces it with a different value.\n\n","args":[],"cases":[["Print",["Tracery.Syntax.Expression"]],["Define",["Dict.Dict String.String Tracery.Syntax.Definition"]],["Delete",["List.List String.String"]],["Save",["{ asConstant : String.String, replaceWith : List.List Tracery.Command.Command }"]]]}],"aliases":[],"values":[{"name":"fillAll","comment":" replaces all variables\n","type":"(String.String -> Random.Generator (List.List Tracery.Command.Command)) -> List.List Tracery.Command.Command -> Random.Generator (List.List Tracery.Command.Command)"},{"name":"fromExpressions","comment":" Convert expressions to commands\n","type":"List.List Tracery.Syntax.Expression -> List.List Tracery.Command.Command"},{"name":"onlyValues","comment":" States if only values are in the list. This essentially means, that all processing has been done.\n","type":"List.List Tracery.Command.Command -> Basics.Bool"},{"name":"simplify","comment":" simplifies the commands.\n","type":"List.List Tracery.Command.Command -> List.List Tracery.Command.Command"},{"name":"toString","comment":" Turns the list of commands into a readable string\n","type":"(String.String -> String.String) -> List.List Tracery.Command.Command -> String.String"},{"name":"variables","comment":" Returns all variables.\n","type":"List.List Tracery.Command.Command -> List.List String.String"}],"binops":[]},{"name":"Tracery.Grammar","comment":" Creates a string generator based on a syntax.\n\n\n# Grammar\n\n@docs Grammar, fromDefinitions, toString\n\n\n# Generating\n\n@docs generateWhile, generateOutput, generateNext\n\n\n# Strategy\n\n@docs Strategy, defaultStrategy, noRecursionStrategy, onlyRecursionStrategy\n\n\n# Technical Utilities\n\n@docs toNext, withCommands, skip, rewind, end\n\n","unions":[],"aliases":[{"name":"Grammar","comment":"\n\n  - `next` - what needs to be generated next?\n  - `constants` - what\n  - `definitions` - the grammar rules (see Syntax)\n\n","args":[],"type":"{ output : List.List Tracery.Command.Command, stack : List.List Tracery.Command.Command, next : Maybe.Maybe Tracery.Command.Command, constants : Dict.Dict String.String (List.List Tracery.Command.Command), definitions : Dict.Dict String.String Tracery.Syntax.Definition }"},{"name":"Strategy","comment":" The strategy specifies the algorithm to choose an option\n","args":[],"type":"String.String -> List.List Tracery.Syntax.Expression -> Basics.Bool"}],"values":[{"name":"defaultStrategy","comment":" This strategy will choose any option\n","type":"String.String -> List.List Tracery.Syntax.Expression -> Basics.Bool"},{"name":"end","comment":" set the remaining commands as output\n","type":"Tracery.Grammar.Grammar -> Tracery.Grammar.Grammar"},{"name":"fromDefinitions","comment":" Turns Definitions into a Grammar.\n","type":"Dict.Dict String.String Tracery.Syntax.Definition -> Tracery.Grammar.Grammar"},{"name":"generateNext","comment":" Computes the command in `grammar.next`.\n\nAfterwards the next command gets loaded\n\n    import Dict\n    import Json.Decode\n    import Random exposing (Generator)\n    import Result.Extra\n    import Tracery.Syntax exposing (Definition(..), Expression(..))\n\n    andThenToString : ({ variable : String } -> String) -> Int -> (Grammar -> Generator Grammar) -> Grammar -> String\n    andThenToString fun seed gen grammar =\n        Random.step (gen grammar) (Random.initialSeed seed)\n            |> Tuple.first\n            |> toString fun\n\n    input : Grammar\n    input =\n        [ ( \"origin\", Choose [ [ Value \"A \", Variable \"animal\" ] ] )\n        , ( \"animal\"\n          , Choose\n                [ [ Value \"cat, looking at a \", Variable \"animal\" ]\n                , [ Value \"bird.\" ]\n                ]\n          )\n        ]\n            |> Dict.fromList\n            |> fromDefinitions\n\nusing this function, you can step through the computation\n\n    input\n    |> andThenToString (\\{variable} -> \"<\" ++ variable ++ \">.\") 42 (generateNext defaultStrategy)\n    --> \"A <animal>.\"\n\nThe second step does nothing (some steps only perform internal rearrangements)\n\n    input\n    |> andThenToString (\\{variable} -> \"<\" ++ variable ++ \">.\") 42\n        (\\g -> g\n            |> (generateNext defaultStrategy)\n            |> Random.andThen (generateNext defaultStrategy)\n        )\n    --> \"A <animal>.\"\n\nBut after a few more steps (and some rewinding), we get the result\n\n    input\n    |> andThenToString (\\{variable} -> \"dog.\") 42\n        (\\g -> g\n            |> (generateNext defaultStrategy)\n            |> Random.andThen (generateNext defaultStrategy)\n            |> Random.andThen (generateNext defaultStrategy)\n            |> Random.map rewind\n            |> Random.andThen (generateNext defaultStrategy)\n             |> Random.andThen (generateNext defaultStrategy)\n        )\n    --> \"A cat, looking at a dog.\"\n\n","type":"Tracery.Grammar.Strategy -> Tracery.Grammar.Grammar -> Random.Generator Tracery.Grammar.Grammar"},{"name":"generateOutput","comment":" Generates an output found in the resulting grammar.\n\nYou can use `generateCommands` instead, If you intend to get the output right away.\n\n","type":"(Tracery.Grammar.Grammar -> Basics.Bool) -> Tracery.Grammar.Strategy -> Tracery.Grammar.Grammar -> Random.Generator Tracery.Grammar.Grammar"},{"name":"generateWhile","comment":" Generates a string while a predicate is valid\n\n    import Dict\n    import Json.Decode\n    import Random exposing (Generator)\n    import Result.Extra\n    import Tracery.Syntax exposing (Definition(..), Expression(..))\n    import Set\n\n    andThenToString : ({ variable : String } -> String) -> Int -> (Grammar -> Generator Grammar) -> Grammar -> String\n    andThenToString fun seed gen grammar =\n        Random.step (gen grammar) (Random.initialSeed seed)\n            |> Tuple.first\n            |> toString fun\n\n    input : Grammar\n    input =\n        [ ( \"origin\", Choose [ [ Value \"A \", Variable \"animal\" ] ] )\n        , ( \"animal\"\n          , Choose\n                [ [ Value \"cat, looking at a \", Variable \"animal\" ]\n                , [ Value \"bird.\" ]\n                ]\n          )\n        ]\n            |> Dict.fromList\n            |> fromDefinitions\n\n    input\n    |> andThenToString (\\{variable} -> \"dog.\") 42 (generateWhile (\\_ -> True) defaultStrategy)\n    --> \"A cat, looking at a cat, looking at a cat, looking at a cat, looking at a bird.\"\n\n    input\n    |> andThenToString (\\{variable} -> \"dog.\") 42 (generateWhile (\\_ -> True) (noRecursionStrategy (Set.fromList [\"animal\"])))\n    --> \"A bird.\"\n\n","type":"(Tracery.Grammar.Grammar -> Basics.Bool) -> Tracery.Grammar.Strategy -> Tracery.Grammar.Grammar -> Random.Generator Tracery.Grammar.Grammar"},{"name":"noRecursionStrategy","comment":" This strategy will never choose a recursive option\n","type":"Set.Set String.String -> String.String -> List.List Tracery.Syntax.Expression -> Basics.Bool"},{"name":"onlyRecursionStrategy","comment":" This strategy will only chose recursive options\n","type":"Set.Set String.String -> String.String -> List.List Tracery.Syntax.Expression -> Basics.Bool"},{"name":"rewind","comment":" sets the output as input.\n","type":"Tracery.Grammar.Grammar -> Tracery.Grammar.Grammar"},{"name":"skip","comment":" Puts the current command on the output (without executing it) and then gets the next command.\n","type":"Tracery.Grammar.Grammar -> Tracery.Grammar.Grammar"},{"name":"toNext","comment":" Moves to the next command without executing anything.\n\n    toNext : Grammar -> Grammar\n    toNext grammar =\n        grammar |> withCommands grammar.stack\n\n","type":"Tracery.Grammar.Grammar -> Tracery.Grammar.Grammar"},{"name":"toString","comment":" Prints the Grammar\n","type":"({ variable : String.String } -> String.String) -> Tracery.Grammar.Grammar -> String.String"},{"name":"withCommands","comment":" Sets Commands of a Grammar.\n","type":"List.List Tracery.Command.Command -> Tracery.Grammar.Grammar -> Tracery.Grammar.Grammar"}],"binops":[]},{"name":"Tracery.Syntax","comment":" This modules exposes the internal structures of the package.\n\nIts intended to be used in combination with some preprocessing.\n\n@docs Expression, Definition\n@docs decoder, fromString, originString\n\n","unions":[{"name":"Definition","comment":" The definition specifies how the strings gets generated\n\n  - `Choose` - Choose a random sentence out of a list.\n  - `Let` - Generate the sentence one. Then use the sentence over and over again.\n  - `With` - Generate the sentence according to the sub-grammar.\n\n","args":[],"cases":[["Choose",["List.List (List.List Tracery.Syntax.Expression)"]],["Let",["List.List Tracery.Syntax.Expression"]],["With",["Dict.Dict String.String Tracery.Syntax.Definition"]]]},{"name":"Expression","comment":" The expressions always return a string\n\n  - `Value` - just return the given string\n  - `Variable` - look up the key and insert a generated string according to the definition of the key.\n\n","args":[],"cases":[["Value",["String.String"]],["Variable",["String.String"]]]}],"aliases":[],"values":[{"name":"decoder","comment":" Decoder for the Syntax.\n","type":"Json.Decode.Decoder (Dict.Dict String.String Tracery.Syntax.Definition)"},{"name":"fromString","comment":"\n\n    import Dict exposing (Dict)\n    import Tracery.Command exposing (Command(..))\n\n    input : String\n    input =\n       \"\"\"{ \"origin\" : [ \"Hello \\\\\\\\\\\\\\\\ World \\\\\\\\#\", \"#statement# and #statement#\" ]\n       , \"statement\" :\n         { \"origin\" : \"my #myPet# is the #complement#\"\n         , \"myPet\": \"#pet#\"\n         , \"pet\" : [\"cat\",\"dog\"]\n         , \"complement\" : [\"smartest #myPet# in the world\",\"fastest #myPet# that i know of\"]\n         }\n       }\"\"\"\n\n    output : Dict String Definition\n    output =\n        Dict.fromList\n            [ ( \"origin\"\n              , Choose\n                  [ [ (Value \"Hello \"),  (Value \"\\\\\"),  (Value \" World \"), (Value \"#\")]\n                  , [ (Variable \"statement\"),  (Value \" and \"),  (Variable \"statement\")]\n                  ]\n              )\n            , ( \"statement\"\n              , Dict.fromList\n                  [ ( \"origin\"\n                    , [  (Value \"my \")\n                      ,  (Variable \"myPet\")\n                      ,  (Value \" is the \")\n                      ,  (Variable \"complement\")\n                      ]\n                        |> Let\n                    )\n                  , ( \"myPet\",Let [ (Variable \"pet\")])\n                  , ( \"pet\", Choose [[ (Value \"cat\")],[ (Value \"dog\")]])\n                  , ( \"complement\"\n                    , Choose\n                        [ [  (Value \"smartest \"),  (Variable \"myPet\"),  (Value \" in the world\")]\n                        , [  (Value \"fastest \"),  (Variable \"myPet\"),  (Value \" that i know of\")]\n                        ]\n                    )\n                  ]\n                    |> With\n                )\n            ]\n\n    input |> fromString\n    --> Ok output\n\n","type":"String.String -> Result.Result Json.Decode.Error (Dict.Dict String.String Tracery.Syntax.Definition)"},{"name":"originString","comment":" The origin is the starting point for the generated story.\n\n    originString : String\n    originString =\n        \"origin\"\n\n","type":"String.String"}],"binops":[]}]