Should a parser type be a struct or class?
Meta
jared771 at gmail.com
Thu Jun 18 19:28:54 UTC 2020
On Wednesday, 17 June 2020 at 11:50:27 UTC, Per Nordlöw wrote:
> Should a range-compliant aggregate type realizing a parser be
> encoded as a struct or class? In dmd `Lexer` and `Parser` are
> both classes.
>
> In general how should I reason about whether an aggregate type
> should be encoded as a struct or class?
IMO it doesn't need to be. However, it's worth saying that range
semantics aren't a great fit for parsers - at least that's been
my experience. Parsers need to be able to "synchronize" to
recover from syntax errors, which does not fit into the range API
very well. You can probably fit it in somewhere in popFront or
front or empty, as your implementation permits, but I find it's
just easier to forego the range interface and implement whatever
primitives you need; *then* you can add a range interface over
top that models the output of the parser as a range of
expressions, or whatever you want.
More information about the Digitalmars-d-learn
mailing list