usethesource / rascal

The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
http://www.rascal-mpl.org
Other
406 stars 78 forks source link

removal of the implicit "filtering" feature during parse tree construction #1484

Closed jurgenvinju closed 3 years ago

jurgenvinju commented 3 years ago

This is a proposal to change the behavior of the Rascal parse function in ParseTree. Not enough for a complete amendment proposal in my view. But perhaps we can escalate this later if others deem this necessary.

Please help in this discussion @PaulKlint @tvdstorm @DavyLandman

This latter feature is highly problematic:

An optimal solution would be that the # operator produces also a reified set of normalizing functions which are applicable in the given compile-time scope, but that would require serializable functions to work, and some other features which Rascal does not have yet. Also it is questionable if these functions are logically belonging to a "reified grammar".

An intermediate solution is to add a keyword parameter to each parse function, which contains a set of references to normalization functions. That way the user can "reifiy" the normalizations functions and pass them to the parser explicitly. The same normalizing functionality would be obtained at a slight cost of changing all calls to parser functions:

parse(input, src, normalizers={amb, \ifStatement, \whileStatement})

Your thoughts pls.

jurgenvinju commented 3 years ago

Additional benefit: if parse functions do not need to call rascal functions then the IFunction which is generated by IRascalValueFactory.parser does not have to lock the interpreter anymore. This is beneficial for the code complexity of the parser function and also for parallel calls to the parser (which happens in Eclipse and the LSP a lot while typing).

jurgenvinju commented 3 years ago

reminder: we do need post-parse filtering during tree construction to bring tree construction for ambiguous-grammars-which are-disambiguated-by-post-parse-filtering down to O(n^3) as opposed to in O(n^p). (p the length of the longest production minus 1). Namely, we can apply disambiguations on the binarized SPPF level like this instead of on the non-binarized Rascal Tree representation.

DavyLandman commented 3 years ago

I'm fine with moving it to a parameter of parse.

The only place where I know it's used is in the standard libraries java8 grammar. It's used to disambiguate actually ambigu type-aliases in java, but also for some left-overs from the sdf source.

jurgenvinju commented 3 years ago

This was done. Filtering is no longer an implicit side-by-side effect but a parameter of the parse function.