@@ -66,10 +66,18 @@ impl Combine<Option<Position>> for Option<Position> {
6666/// `AstNode` represents a node in our BF AST.
6767#[ derive( PartialEq , Eq , Debug , Clone ) ]
6868pub enum AstNode {
69- /// The `+` and `-` instructions in BF. `amount` may not be 1 or -1
70- /// after simplifying e.g. `++`.
69+ /// The `+` and `-` instructions in BF.
7170 Increment {
71+ /// The amount to increment the current BF cell by.
72+ ///
73+ /// `amount` can have values other than 1 and -1 after
74+ /// simplification, e.g. `++` is simplified to a single
75+ /// Increment with an amount of 2.
7276 amount : BfValue ,
77+ /// The offset of the affected BF cell relative to the current
78+ /// BF cell pointer.
79+ ///
80+ /// For example, `>+<` is an increment at offset 1.
7381 offset : isize ,
7482 position : Option < Position > ,
7583 } ,
@@ -80,13 +88,9 @@ pub enum AstNode {
8088 position : Option < Position > ,
8189 } ,
8290 /// The `,` instruction in BF.
83- Read {
84- position : Option < Position > ,
85- } ,
91+ Read { position : Option < Position > } ,
8692 /// The `.` instruction in BF.
87- Write {
88- position : Option < Position > ,
89- } ,
93+ Write { position : Option < Position > } ,
9094 /// A loop in BF, such as `[>]`.
9195 Loop {
9296 body : Vec < AstNode > ,
@@ -98,6 +102,10 @@ pub enum AstNode {
98102 /// is equivalent to setting the BF cell to zero.
99103 Set {
100104 amount : BfValue ,
105+ /// The offset of the affected BF cell relative to the current
106+ /// BF cell pointer.
107+ ///
108+ /// For example, `>[-]<` is `Set { amount: 0, offset: 1}`.
101109 offset : isize ,
102110 position : Option < Position > ,
103111 } ,
0 commit comments