StubbleOrg / Stubble

Trimmed down {{mustache}} templates in .NET
Other
399 stars 58 forks source link

[Question/Discussion] Rework of the Parser to support more information on its output #139

Open ProIcons opened 1 year ago

ProIcons commented 1 year ago

Would you be open on a Parser that doesn't throw Exceptions but instead returns ParsingResults with the MustacheTemplate inside it, and the ParserContext. And in case of a failure the ParsingFailure and the state of the Processor up until this point to be included?

Then on the Rendering Side of things, the possible exceptions could be unwrapped and be thrown.

I'm considering into using your Parser for a LanguageServer I'm making to provide IntelliSense for Monaco Editors for Mustache. Exceptions are heavy, so I was thinking if you're open on this idea on converting your parser to support returning this Structure and exiting early when a failure happens, without the throwing of an exception.

This could be achieved in two ways; the first approach would be for all the Inline/Block parsers to return a Struct/Class object with the result of their processing. This however would throw an exception on an unhandled issue. The second approach would be to use LanguageExt and utilized their monads which can be used to catch an exception as early as possible and wrap it in a Try<>, Unit, Either<,> or whatever else. This minimizes the impact of the exception throwing.