ianlewis / lexparse

Experimental lexer/parser library written in Go
Apache License 2.0
0 stars 1 forks source link

feat: Add Parser node moving functions. lint fixes. Test cases. #11

Closed superfrink closed 5 months ago

superfrink commented 5 months ago
  1. 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'
  2. 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:

    '+'
    '1'
    '2'
    '*'

    After:

    '+'
    '1'
    '*'
    '2'

    Then adding '3' produces:

    '+'
    '1'
    '*'
    '2'
    '3'
codecov-commenter commented 5 months ago

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (f4c1c14) 63.48% compared to head (b815f1d) 83.56%. Report is 5 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/ianlewis/lexparse/pull/11/graphs/tree.svg?width=650&height=150&src=pr&token=PD7UEVGU5S&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ian+Lewis)](https://app.codecov.io/gh/ianlewis/lexparse/pull/11?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ian+Lewis) ```diff @@ Coverage Diff @@ ## main #11 +/- ## =========================================== + Coverage 63.48% 83.56% +20.08% =========================================== Files 3 3 Lines 293 365 +72 =========================================== + Hits 186 305 +119 + Misses 97 46 -51 - Partials 10 14 +4 ``` | [Files](https://app.codecov.io/gh/ianlewis/lexparse/pull/11?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ian+Lewis) | Coverage Δ | | |---|---|---| | [lexparse.go](https://app.codecov.io/gh/ianlewis/lexparse/pull/11?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ian+Lewis#diff-bGV4cGFyc2UuZ28=) | `0.00% <0.00%> (ø)` | | | [parser.go](https://app.codecov.io/gh/ianlewis/lexparse/pull/11?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ian+Lewis#diff-cGFyc2VyLmdv) | `90.76% <91.66%> (+90.76%)` | :arrow_up: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/ianlewis/lexparse/pull/11/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ian+Lewis)