Expand description
This crate uses an earley parser (Dokearley) to parse input from a dokedef.
It also parses said dokedef, and can highlight it.
use dokearley::Dokearley;
// An input dokedef file.
let grammar = r#"
ItemEffect: "deal {amount:Int} damage" -> Damage
ItemEffect: "heal for {amount:Int}" -> Heal
ItemEffect: "apply {status:String}" -> ApplyStatus
Target: "self" -> Target { kind: "self" }
Target: "an ally" -> Target { kind: "ally" }
Target: "all enemies" -> Target { kind: "enemies" }
"#;
// Build the parser from the dokedef.
let parser = Dokearley::from_dokedef(grammar).expect("invalid grammar");
// Get a result from an input statement, and a <Start> Nonterminal, which tries to parse the input as a <Start>
let result = parser.parse("heal for 7", "ItemEffect").unwrap();
dbg!(result);
//
// Resource {
// typ: "TargetedEffect",
// fields: {
// "target": Resource { typ: "Target", fields: {"kind": String("self")}},
// "effect": Resource { typ: "Heal", fields: {"amount": Integer(7)} }}
// }Modules§
- grammar_
parser dokedefparser for the grammars, including highlighting utilities.
Structs§
Enums§
- Dokearley
Error - Errors for parsing grammar files or the input
- Value
- The output value type of any grammar, compatible with most games engines. Resources can map to custom Resources in Godot, or to ScriptableObjects in unity. They can be nested.