j-brant / SmaCC

MIT License
24 stars 16 forks source link

SmaCC Java: startingState for both interface and class declaration #10

Closed badetitou closed 5 years ago

badetitou commented 5 years ago

Hello (sorry it's again me 😬 ),

From the previous issue (#9), I've discovered that we cannot use the same startingState to parse a method in Java if the method is written in an Interface or in a Class

ex doesn't work:

JavaParser
        parse: '
public default void show() 
    { 
        System.out.println("Default TestInterface1"); 
    } 
 ' startingAt: JavaParser startingStateForclass_body_declaration.

I think I understand why the parser cannot do that (the grammar is different in an interface and in a class).

So, what do you think we should do in such a case? Using parse:startingAt:onError? And give to onError the block that will execute the parsing with another startingPoint?

If yes, I will propose a pull request to add interface_member_declaration as a startingPoint (or maybe we can specify a startingPoint without adding it at the begin of the "parser generator"). If no, I'm interesting about the solution 😃

j-brant commented 5 years ago

I added an additional starting state: JavaParser startingStateForclass_or_interface_body_declaration