My experience with Sealed Types and Data-Oriented Programming
Nathan Reynolds
numeralnathan at gmail.com
Sun Sep 11 04:04:54 UTC 2022
I'm glad it worked so well. I was dubious since you are parsing English.
In general, I like to keep the parsing logic in the class of the resulting
object. This way each class deals with the specifics for that class. The
downside is that some logic may be duplicated.
On Sat, Sep 10, 2022, 10:52 PM David Alayachew <davidalayachew at gmail.com>
wrote:
> Hello Nathan,
>
> > It's been a while. One parser I used allowed for writing a grammar. It
> then parsed the grammar and turned it into Java code. The grammar specified
> how to hook the generated Java code into code that hooked into the rest of
> the Java code. If the grammar became out of sync with the rest of the Java
> code, then the build process would flag errors in the grammar.
>
> What a powerful solution. And I definitely see where you are coming from
> now. Your solution goes in a completely different direction - rather than
> trying to bend Java into 2 directions at once (being both genericized and
> able to handle dynamically created rules), you have instead made Java the
> landing point. You just create rules, and then hardcode them into plain
> java code.
>
> > Instead of "of()", use "parse()". The name is more descriptive
>
> Agreed.
>
> I gave your original suggestion (or rather, my interpretation of it) a
> shot, and I have to say I quite liked the results! I took one of my
> permitted subclasses, and refactored it to no longer have an alternative
> constructor, but to instead, use the new ::parse method. It was nice
> because then I could keep all of the regex logic inside of the record and
> not expose it to the outside world needlessly. Furthermore, it made cycling
> through all of the classes to find a viable match much easier. Instead of
> having a Map<Pattern, Function<List<String>, Parseable>>, I instead have a
> Set<Function<String, Parseable>>.
>
> Thank you again for all of your help and guidance!
> David Alayachew
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20220910/7777e353/attachment.htm>
More information about the amber-dev
mailing list