Re: [PATCH v3 2/5] config: split do_event() into start and flush operations
- From
- Jonathan Tan <jonathantanmy@google.com>
- Date
- Oct 23, 2023, 18:05 UTC
- Message-ID
- <20231023180555.986240-1-jonathantanmy@google.com>
- In-Reply-To
- <8a1463c223497fca2fd3f11a54db5d7e52d1d08a.1695330852.git.steadmon@google.com>
Josh Steadmon <steadmon@google.com> writes:
Show 6 quoted lines
> +static void start_event(struct config_source *cs, enum config_event_t type,
> + struct parse_event_data *data)
> +{
> + data->previous_type = type;
> + data->previous_offset = get_corrected_offset(cs, type);
> +}It's a pity that get_corrected_offset() has to be called twice (once here and once below) but I think that's the best we can do given how the code is laid out (and I can't think of a better code layout either).
> +static int flush_event(struct config_source *cs, enum config_event_t type, > + struct parse_event_data *data)
One thing confusing here is that the "type" is not what's being flushed, but used to change details about how we flush. Technically all we need is is_whitespace_type and is_eof_type, but that's clumsier to code. I think the best we can do is add some documentation to this function, maybe 'Flush the event started by a prior start_event(), if one exists. The type of the event being flushed is not "type" but the type that was passed to the prior start_event(); "type" here may merely change how the flush is performed' or something like that.
Show 14 quoted lines
> +{
> + if (!data->opts || !data->opts->event_fn)
> + return 0;
> +
> + if (type == CONFIG_EVENT_WHITESPACE &&
> + data->previous_type == type)
> + return 0;
>
> if (data->previous_type != CONFIG_EVENT_EOF &&
> data->opts->event_fn(data->previous_type, data->previous_offset,
> - offset, cs, data->opts->event_fn_data) < 0)
> + get_corrected_offset(cs, type), cs,
> + data->opts->event_fn_data) < 0)
> return -1;Another confusing point here is how EOF is used both to mean "start_event() was never called" and a true EOF. I think for now it's best to just document this where we define CONFIG_EVENT_EOF.