unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>
To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org
Subject: Re: [PATCH v4 2/9] parse-time-string: add a date/time parser to notmuch
Date: Mon, 15 Oct 2012 00:26:10 -0400	[thread overview]
Message-ID: <87hapw9x99.fsf@betacantrips.com> (raw)
In-Reply-To: <0296be2a3899653549b3f95e1aa1a4a0632e92e7.1350164594.git.jani@nikula.org>

Jani Nikula <jani@nikula.org> writes:

Hi! I commend you for your work and persistence. This represents a lot
of work and I think it's good enough to be merged. I would certainly
love to see "last" and "ago" supported but this patch series, and this
patch especially, is cumbersome enough that I'd really rather it be
merged before it gets any worse.

If this patch series isn't accepted, I'd suggest making a patch series
that makes a "null" date parser, which just takes strings of date
timestamps the way notmuch does now: "12345" -> (time_t) 12345. We're
going to need a date parser anyhow, so a patch series that sets up the
scaffolding -- separate directory, tests -- could be merged without the
actual parser. Then you'd have fewer patches to juggle the next time
around.

I agree with Tomi Ollila that whether the parser is built in bison or in
straight C, as this one is, isn't important. The difficult part of
parsing dates isn't the translation from text to parse tree; it's
dealing with all the semantic difficulty that comes YYMMDD versus DDMMYY
and the difference between "last week" and "last Thursday".

I have a few minor quibbles that I would be happy to see addressed after
this was merged, or not at all.

> +/* Parse a previously postponed number if one exists. */
> +static int parse_postponed_number (struct state *state, int v, int n, char d);
> +static int
> +handle_postponed_number (struct state *state, enum field next_field)
> +{
> +    int v = state->postponed_value;
> +    int n = state->postponed_length;
> +    char d = state->postponed_delim;
> +    int r;
> +
> +    if (!n)
> +	return 0;
> +
> +    state->postponed_value = 0;
> +    state->postponed_length = 0;
> +    state->postponed_delim = 0;

This could be refactored to be a call to get_postponed_number. Also, I'd
prefer parse_postponed_number be up here, closer to its sole caller (handle_postponed_number).

> +/*
> + * Postpone a number to be handled later. If one exists already,
> + * handle it first. n may be -1 to indicate a keyword that has no
> + * number length.
> + */
> +static int
> +set_postponed_number (struct state *state, int v, int n)
> +{
> +    int r;
> +    char d = state->delim;
> +
> +    /* Parse a previously postponed number, if any. */
> +    r = handle_postponed_number (state, TM_NONE);
> +    if (r)
> +	return r;

I would love a comment explaining under what circumstances this could
occur and what the caller is expected to do.

> +/*
> + * Accepted keywords.
> + */
> +static struct keyword keywords[] = {
> +    /* Weekdays. */
> +    { N_("sun|day"),	TM_ABS_WDAY,	0,	NULL },
> +    { N_("mon|day"),	TM_ABS_WDAY,	1,	NULL },

Maybe it's just my history with Python, but I'd prefer keywords, which
is a global and a constant, to be written in all caps (KEYWORDS).

> +/*
> + * Compare strings s and keyword. Return number of matching chars on
> + * match, 0 for no match. Match must be at least n chars, or all of
> + * keyword if n < 0, otherwise it's not a match. Use match_case for
> + * case sensitive matching.
> + */
> +static size_t
> +stringcmp (const char *s, const char *keyword, ssize_t n, bool match_case)
> +{

The name of this function makes it look uncomfortably like strcmp(3),
which has a very different calling semantics (specifically the -1, 0, 1
return value). I'd prefer a name like string_match_keyword.

Ethan

  reply	other threads:[~2012-10-15  4:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-13 22:09 [PATCH v4 0/9] notmuch search date:since..until query support Jani Nikula
2012-10-13 22:09 ` [PATCH v4 1/9] build: drop the -Wswitch-enum warning Jani Nikula
2012-10-13 22:09 ` [PATCH v4 2/9] parse-time-string: add a date/time parser to notmuch Jani Nikula
2012-10-15  4:26   ` Ethan Glasser-Camp [this message]
2012-10-17  7:48     ` Jani Nikula
2012-10-13 22:09 ` [PATCH v4 3/9] test: add new test tool parse-time for date/time parser Jani Nikula
2012-10-13 22:09 ` [PATCH v4 4/9] test: add smoke tests for the date/time parser module Jani Nikula
2012-10-13 22:09 ` [PATCH v4 5/9] build: build parse-time-string as part of the notmuch lib and static cli Jani Nikula
2012-10-13 22:09 ` [PATCH v4 6/9] lib: add date range query support Jani Nikula
2012-10-13 22:09 ` [PATCH v4 7/9] test: add tests for date:since..until range queries Jani Nikula
2012-10-13 22:09 ` [PATCH v4 8/9] man: document the " Jani Nikula
2012-10-13 22:09 ` [PATCH v4 9/9] NEWS: date range search support Jani Nikula

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hapw9x99.fsf@betacantrips.com \
    --to=ethan.glasser.camp@gmail.com \
    --cc=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).