congo-cc / congo-parser-generator

The CongoCC Parser Generator, the Next Generation of JavaCC 21, which in turn was the next generation of JavaCC
https://discuss.congocc.org/
Other
37 stars 11 forks source link

Sync upstream changes. #196

Closed vsajip closed 4 months ago

revusky commented 3 months ago

Thanks for doing this, Vinay. By the way, it later dawned on me that I could have resolved the test failure by simply having the injection only apply when generating Java code, i.e.

#if __java__
INJECT IfStatement :
{
    public Node getElseBlock() {
      Node result = getLastChild();
      Token tok = (Token) result.previousSibling();
      if (tok.getType() == TokenType.ELSE) return result;
      return null;
      }
}
#endif

That said, it is better if the various API that is generated for Java also works in the other languages -- at least to the extent possible. I had originally written the above injection as:

INJECT IfStatement :
{
    public Node getElseBlock() {
        Node elseTok = firstChildOfType(TokenType.ELSE);
        return elseTok == null ? null : elseTok.nextSibling();
    }
}

And it was failing to translate firstChildOfType into C#. Actually, I suspect that the only reason the Python tests did not also fail was because Python leaves a lot of resolution to run-time, and the method was never being called. But in C# it was a compile-time failure.