A helper module for easily creating entities.
Example syntax:
PLAYER.fear=1
TORCH.item.illumination=7.current_location=PLAYER
CAVE.location.dark
Syntax is <entity id>.<props>
, given:
'_', '-', ':', '#' or '+'
.'_', ':' and '#'
. Tags are specified just as a key. Stats and links have a key then a '='
then an int or entity id respectively.(By convention, entity ids are capitalized and prop keys are snake case.)
Note that RuleParser
relies on some of the parsers in this module.
Result NarrativeEngine.Syntax.Helpers.ParseErrors (NarrativeEngine.Core.WorldModel.WorldModel a)
The result of parsing a collection of entity syntax strings.
Result String ( NarrativeEngine.Core.WorldModel.ID
, NarrativeEngine.Core.WorldModel.NarrativeComponent a
}
The result of parsing an entity syntax string, which includes both the entity id and a narrative component.
In general you should use parseMany
at the top level of you application, and either use the result as your initial world model in your Model, or display the errors with NarrativeEngine.Syntax.Helpers.parseErrorsView
.
a -> NarrativeEngine.Core.WorldModel.NarrativeComponent {} -> NarrativeEngine.Core.WorldModel.NarrativeComponent a
A function for "merging" extra fields into a NarrativeComponent {}
.
parseMany : ExtendFn a -> List ( String, a ) -> ParsedWorldModel a
Parses a list of "entity definition" syntax strings into a world model. The list of entities are tuples of the "entity definition" syntax for parsing, and the extra fields for that entity. You also need to provide an "extend function" to "merge" extra fields with the standard entity fields.
parseEntity : ExtendFn a -> ( String, a ) -> ParsedEntity a
Parses a single "entity definition" syntax string along with a record of additional fields. The extend function is used to "merge" the additional fields into the standard entity record. (You can use always identity
if you don't have any extra fields).
idParser : Parser NarrativeEngine.Core.WorldModel.ID
IDs must start with a letter, then optionally have more letters, digits, or special characters.
numberParser : Parser Basics.Int
Parses Ints.
Can't use Parser.int
directly because a "." can follow a number in entity strings ("ID.a_stat=1.a_tag"), and int
doesn't allow a digit followed by a ".". This also handles negatives.
propertyNameParser : Parser String
A parser for valid property names