j-mie6 / parsley

A fast and modern parser combinator library for Scala
https://j-mie6.github.io/parsley/
BSD 3-Clause "New" or "Revised" License
173 stars 15 forks source link

Add indexed Visitor classes for LazyParsley #206

Closed MF42-DZH closed 1 year ago

MF42-DZH commented 1 year ago

This PR adds the abstract classes LazyParsleyIVisitor and an abstract subclass GenericLazyParsleyIVisitor into the deep-embedding frontend. They are used for processing trees of LazyParsley parsers without needing to use manual exhaustive matching on LazyParsley types, which can be tedious to maintain if new LazyParsley subclasses are added. These visitors are also indexed, to preserve the generic return types of parsers while minimising uses of .asInstanceOf[X].

However, all LazyParsley instances now have an additional requirement for a method, visit, which when given a visitor instance and a context argument, must call its respective visit method within the visitor. If a new LazyParsley subclass is added, a new visit method must be added to LazyParsleyIVisitor (and if it conforms to either Singleton, Unary, Binary or Ternary, a respective default override must be added to GenericLazyParsleyIVisitor) so that all parser analytics that use the visitors are forced to update their implementations to handle this new parser class.

j-mie6 commented 1 year ago

Just line lengths now left to fix :)

codeclimate[bot] commented 1 year ago

Code Climate has analyzed commit 2364448d and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 95.8% (50% is the threshold).

This pull request will bring the total coverage in the repository to 91.9% (0.2% change).

View more on Code Climate.

MF42-DZH commented 1 year ago

Indentation to 4-space and underscores removed from visitor method names

These should both be done (if I haven't missed any!), and some of the shortened names have been restored to the original names from the class parameters.