You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Foo constructor () {
< stuff in here >
}
This is meant to be parsed in the grammar as a class declaration, with a primary_constructor. Indeed, we see it parsed as such with the current grammar:
The reason for this ends up being that the newline induces an opportunity for an automatic semicolon, so the token stream looks like:
PUBLIC CLASS "Foo" SEMICOLON CONSTRUCTOR ( ) ...
This makes the parser think that, since a class_declaration can have many optional things, that the public class Foo is a standalone class (with not very many things in it), and the thing that follows it is a call expression of constructor on a lambda or something, I think.
Expected behavior:
The above example should correctly parse to a single class declaration, with a primary constructor, as opposed to two top-level entities. This could be done by suppressing the insertion of the automatic semicolon in such a spot (which may require refactoring and heavier state being carried in the external scanner), or some grammar-level hacking.
Let me know what you think! I am trying to add better support for Kotlin in an open-source static analysis tool, Semgrep (https://github.com/returntocorp/semgrep), and this is blocking my ability to do so.
The text was updated successfully, but these errors were encountered:
Current behavior:
Suppose that I had a class that looked like this:
This is meant to be parsed in the grammar as a class declaration, with a
primary_constructor
. Indeed, we see it parsed as such with the current grammar:If I add a newline, however:
it parses as something different.
The reason for this ends up being that the newline induces an opportunity for an automatic semicolon, so the token stream looks like:
This makes the parser think that, since a
class_declaration
can have many optional things, that thepublic class Foo
is a standalone class (with not very many things in it), and the thing that follows it is a call expression ofconstructor
on a lambda or something, I think.Expected behavior:
The above example should correctly parse to a single class declaration, with a primary constructor, as opposed to two top-level entities. This could be done by suppressing the insertion of the automatic semicolon in such a spot (which may require refactoring and heavier state being carried in the external scanner), or some grammar-level hacking.
Let me know what you think! I am trying to add better support for Kotlin in an open-source static analysis tool, Semgrep (https://github.com/returntocorp/semgrep), and this is blocking my ability to do so.
The text was updated successfully, but these errors were encountered: