Added two functions to move nodes around in a parse tree.
RotateLeft() is used to move the current node into the position of it's parent. This is useful to make the input 1 - 2 - 3 be parsed as (1 - 2) - 3 instead of as 1 - (2 - 3). Before calling RotateLeft() the tree wold look like:
'-' (first '-')
'1'
'2'
'-' (second '-')
After:
'-' (second '-')
'-' (first '-')
'1'
'2'
Then adding '3' produces:
'-' (second '-')
'-' (first '-')
'1'
'2'
'3'
AdoptSibling() is used to move the current node's previous sibling from the parent's children to the current node's children. This is useful for input with more than one operator in a row like 1 + 2 * 3. Before calling AdoptSibling() the tree would look like:
parser.go
.parser_test.go
.RotateLeft()
is used to move the current node into the position of it's parent. This is useful to make the input1 - 2 - 3
be parsed as(1 - 2) - 3
instead of as1 - (2 - 3)
. Before callingRotateLeft()
the tree wold look like:After:
Then adding '3' produces:
AdoptSibling()
is used to move the current node's previous sibling from the parent's children to the current node's children. This is useful for input with more than one operator in a row like1 + 2 * 3
. Before callingAdoptSibling()
the tree would look like:After:
Then adding '3' produces: