lukehutch / pikaparser

The Pika Parser reference implementation
MIT License
141 stars 12 forks source link

parseASTNodes: nextNodeLabel is always null...? #14

Closed psfblair closed 4 years ago

psfblair commented 4 years ago

From what my IDE can tell, and as far as I can see, nextNodeLabel is never anything but null here, so the clause never gets relabeled. This is MetaGrammar.java line 318:

    /** Recursively parse a list of AST nodes. */
    private static List<Clause> parseASTNodes(List<ASTNode> astNodes) {
        List<Clause> clauses = new ArrayList<>(astNodes.size());
        String nextNodeLabel = null;
        for (int i = 0; i < astNodes.size(); i++) {
            var astNode = astNodes.get(i);
            // Create a Clause from the ASTNode
            var clause = parseASTNode(astNode);
            if (nextNodeLabel != null) {
                // Label the Clause with the preceding label, if present
                clause = ast(nextNodeLabel, clause);
                nextNodeLabel = null;
            }
            clauses.add(clause);
        }
        return clauses;
    }
lukehutch commented 4 years ago

Good catch, that was dead code, left behind during some refactoring work. The unreachable code is redundant with this code, which handles the AST node label:

        case LABEL_AST:
            clause = ast(astNode.getFirstChild().getText(), parseASTNode(astNode.getSecondChild().getFirstChild()));
            break;