ridencww / goldengine

Java implementation of Devin Cook's GOLD Parser engine
Other
35 stars 14 forks source link

generateTree(true) conflicts with reduction execution #24

Closed Pranavgulati closed 8 months ago

Pranavgulati commented 5 years ago

The execution doesn't occur using the rule handlers if generateTree(true) is done. Is this intentional for some reason ? if not then it will be nice to have both the tree and the reductions to be executed.

According to my hypothesis the following is the problem code in GOLDParser.class:

    /**
     * Base parser builds a tree of Reduction objects
     * Override to process reductions
     * @return Boolean to indicate if processing should stop (true) or continue (false). 
     */
    protected boolean processReduction() {
        if (!generateTree && ruleHandlers.size() > 0) {
            try {
                Reduction reduction = createInstance();
                setCurrentReduction(reduction);
            } catch (Throwable t) {
                addErrorMessage(t.getMessage());
                return true;
            }
        }
        return false;
    }

I think it can be corrected by doing the following:

    /**
     * Base parser builds a tree of Reduction objects
     * Override to process reductions
     * @return Boolean to indicate if processing should stop (true) or continue (false). 
     */
    protected boolean processReduction() {
        if ( ruleHandlers.size() > 0) {
            try {
                Reduction reduction = createInstance();
                setCurrentReduction(reduction);
            } catch (Throwable t) {
                addErrorMessage(t.getMessage());
                return true;
            }
        }
        return false;
    }
ridencww commented 5 years ago

There was a reason, but it has been so long ago, I can't recall what the reason was. Possibly something to do with the engine state after generating the tree interferes with code execution. I will have to have a look this weekend. It is a simple enough matter to make your suggested change and see if the existing tests pass.

I also want to have a look at some of the other open issues and see if it is practical for me to address.

Pranavgulati commented 5 years ago

Yes I tried the suggested change and Yes it has something to do with the parser state because of which only either works. I am currently using a workaround that re-parses the source but I will see if i can work on a solution any time soon.

Thanks for your quick reply and active particiaption !! Also thanks for contributing in making this engine, This was probably a very huge effort and i strongly appreciate it !!!!!

Cheers !