Skip to content
This repository was archived by the owner on Feb 22, 2025. It is now read-only.

Refactor the "Pyramid of Doom" out of all the AST node construct classes. #33

Open
Atlinx opened this issue Aug 6, 2021 · 0 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest
Milestone

Comments

@Atlinx
Copy link
Member

Atlinx commented Aug 6, 2021

Inside of the construct classes instead of chaining expect functions like

var label = parser.expect_token("keyword", "label")
if parser.is_success(label):
    var identifier = parser.expect("identifier")
    if parser.is_success(identifier):
        var expression = parser.expect("expression")
        if parser.is_success(expression):
            ...
        else:
            return expression
    else:
        return identifier
else:
    return label

they can be replaced with

var label = parser.expect_token("keyword", "label")
if not parser.is_success(label):
    return label

var identifier = parser.expect("identifier")
if not parser.is_success(identifier):
    return identifier

var expression = parser.expect("expression")
if not parser.is_success(expression):
    return expression

...

Notice how just by switching the is_success() to a not is_success() check we can break apart the "Pyramid of Doom"

@Atlinx Atlinx added enhancement New feature or request good first issue Good for newcomers labels Aug 6, 2021
@Atlinx Atlinx added this to the v1.2.0 milestone Aug 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest
Projects
None yet
Development

No branches or pull requests

1 participant