Skip to main content

Module parser

Module parser 

Source
Expand description

Parsing grammars from the Algorithmic Beauty of Plants

§The format

# Comments start with a hash.
# This describes plant 5 in fig 1.24 of ABOP (pg 25)
n = 6           # Number of derivation iterations. This is one more iteration than in ABOP
delta = 22.5    # The angle that the + and - tokens turn the "turtle" by.

initial: X      # The starting string

# And now the productions
Forward -> Forward Forward
X -> Forward + [ [ X ] - X ] - Forward [ - Forward X ] + X

§Parsing

If we have a string in the format given above, you can parse it like so:

use rusty_systems::interpretation::abop::parser::parse;

let (interpretation, system, initial_string) = parse(plant_string).unwrap();

The parse function returns the following:

Functions§

parse
Parses a string in a bespoke “plant” format. See the namespace namespace documentation for more information.
parse_file
Reads a file containing an L-System written in the library’s bespoke “plant” format.