Received: from mail4.protonmail.ch (mail4.protonmail.ch [185.70.40.27]) by mail.sr.ht (Postfix) with ESMTPS id 5CCA9400C5 for <~emersion/mrsh-dev@lists.sr.ht>; Mon, 28 Jan 2019 20:48:44 +0000 (UTC) Authentication-Results: mail.sr.ht; dkim=pass (1024-bit key) header.d=emersion.fr header.i=@emersion.fr header.b=jq/VpaMY Date: Mon, 28 Jan 2019 20:48:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emersion.fr; s=protonmail; t=1548708504; bh=i8ZajeDICRV+D7czBGcE6+7wkZOQkLT/5ZQWBVCPl1s=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References: Feedback-ID:From; b=jq/VpaMYAVk4cZ1Hsup7W0f5965T+vraONOobA9EhVnF8AtpwdoDI6Vkb+mwt+ywa Bf1SeHgMpTRXB3X3/LfrOzyKxqPqpoRn1DCzK1Q3sf7hdxSNwxZFkppwCYJ0gh7OA5 ugWMK8D8l2edMhdMOmEUU6odoZS5biMehmnsn5Yk= To: =?UTF-8?Q?Cristian_Adri=C3=A1n_Ontivero?= From: Simon Ser Cc: "~emersion/mrsh-dev@lists.sr.ht" <~emersion/mrsh-dev@lists.sr.ht> Reply-To: Simon Ser Subject: Re: [PATCH v2] Parse arithmetic expressions with shifts Message-ID: In-Reply-To: <20190125085755.5290-1-cristianontivero@gmail.com> References: <20190125085755.5290-1-cristianontivero@gmail.com> Feedback-ID: FsVprHBOgyvh0T8bxcZ0CmvJCosWkwVUg658e_lOUQMnA9qynD8O1lGeniuBDfPSkDAUuhiKfOIXUZBfarMyvA==:Ext:ProtonMail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch On Friday, January 25, 2019 9:57 AM, Cristian Adri=C3=A1n Ontivero wrote: > We introduce the function arithmetic_word() to parse arithmetic > expressions instead of reusing the general word(), and generalize > word_list() to receive a pointer to function, so that word_list() may be > used to parse a list of whatever type of word we need. > > This fixes #51, and enables properly parsing parenthesized expressions > inside arithmetic expressions, e.g. $(((2+1)-1)). > --- > > This is mostly a working proof of concept. There is (as might be expected= ) quite > a bit of similarity between word() and arithmetic_word(), but I think tha= t it > would be better in the long term to remove the "end" parameter, and have = a > couple of different *_word() functions that are called whenever appropria= te. > > As discussed, the alternative would be adding a mrsh_word_type parameter = to > word() and word_list(), but I think that this would eventually lead to a = word() > function with a lot of if-statements for each distinct context, and might= lead > to a more complex word() function (although preventing the repetition int= rinsic > to the *_word() functions alternative). > > What do you think? +1, I like it. Yeah, I agree, the `end` parameter should go away. Is there anything that prevents this from being merged? > > include/parser.h | 3 ++ > parser/word.c | 120 +++++++++++++++++++++++++++++++++++++++++++++-- > 2 files changed, 118 insertions(+), 5 deletions(-) > > diff --git a/include/parser.h b/include/parser.h > index 56e549f..d4b32b9 100644 > --- a/include/parser.h > +++ b/include/parser.h > @@ -63,6 +63,8 @@ struct mrsh_parser { > =09void *alias_user_data; > }; > > +typedef struct mrsh_word * (*word_fn)(struct mrsh_parser *, char end); Nitpick: the convention I've used so far is to use the `_func` prefix for function types.