From 1067371e7b38aede62d773f4b23e7904b85f9b1c Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Thu, 12 Jul 2012 10:14:25 +0100 Subject: [PATCH] Re: [PATCH v4 1/3] Add support for structured output formatters. --- 53/e0710596c08ef4c0756d1200b0c075bc1be430 | 219 ++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 53/e0710596c08ef4c0756d1200b0c075bc1be430 diff --git a/53/e0710596c08ef4c0756d1200b0c075bc1be430 b/53/e0710596c08ef4c0756d1200b0c075bc1be430 new file mode 100644 index 000000000..a769449d5 --- /dev/null +++ b/53/e0710596c08ef4c0756d1200b0c075bc1be430 @@ -0,0 +1,219 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 594D8431FC9 + for ; Thu, 12 Jul 2012 02:14:35 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id mcpx+Y2e0J9b for ; + Thu, 12 Jul 2012 02:14:34 -0700 (PDT) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 67C2C431FC7 + for ; Thu, 12 Jul 2012 02:14:34 -0700 (PDT) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1SpFTg-0001A2-BR; Thu, 12 Jul 2012 10:14:30 +0100 +Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] + helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1SpFTf-000139-Vu; Thu, 12 Jul 2012 10:14:28 +0100 +From: Mark Walters +To: craven@gmx.net, notmuch@notmuchmail.org +Subject: Re: [PATCH v4 1/3] Add support for structured output formatters. +In-Reply-To: <1342079004-5300-2-git-send-email-craven@gmx.net> +References: <87d34hsdx8.fsf@awakening.csail.mit.edu> + <1342079004-5300-1-git-send-email-craven@gmx.net> + <1342079004-5300-2-git-send-email-craven@gmx.net> +User-Agent: Notmuch/0.13.2+61~gf708609 (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Thu, 12 Jul 2012 10:14:25 +0100 +Message-ID: <87sjcxtk7i.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 94.192.233.223 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: d142ed23e5c2bb358bdbbe3f3c369ec6 (of first 20000 bytes) +X-SpamAssassin-Score: -1.8 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.8 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay + * domain + * 0.5 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 12 Jul 2012 09:14:35 -0000 + + +Hi + +this definitely looks nice. I have a couple of suggestions for the +comments: + +On Thu, 12 Jul 2012, craven@gmx.net wrote: +> This patch adds a new type sprinter_t, which is used for structured +> formatting, e.g. JSON or S-Expressions. The structure printer is the +> code from Austin Clements (id:87d34hsdx8.fsf@awakening.csail.mit.edu). +> +> The structure printer contains the following function pointers: +> +> /* start a new map/dictionary structure. +> */ +> void (*begin_map) (struct sprinter *); +> +> /* start a new list/array structure +> */ +> void (*begin_list) (struct sprinter *); +> +> /* end the last opened list or map structure +> */ +> void (*end) (struct sprinter *); +> +> /* print one string/integer/boolean/null element (possibly inside a +> * list or map +> */ +> void (*string) (struct sprinter *, const char *); +> void (*integer) (struct sprinter *, int); +> void (*boolean) (struct sprinter *, notmuch_bool_t); +> void (*null) (struct sprinter *); +> +> /* print the key of a map's key/value pair. +> */ +> void (*map_key) (struct sprinter *, const char *); +> +> /* print a frame delimiter (such as a newline or extra whitespace) +> */ +> void (*frame) (struct sprinter *); +> +> The printer can (and should) use internal state to insert delimiters and +> syntax at the correct places. +> +> Example: +> +> format->begin_map(format); +> format->map_key(format, "foo"); +> format->begin_list(format); +> format->integer(format, 1); +> format->integer(format, 2); +> format->integer(format, 3); +> format->end(format); +> format->map_key(format, "bar"); +> format->begin_map(format); +> format->map_key(format, "baaz"); +> format->string(format, "hello world"); +> format->end(format); +> format->end(format); +> +> would output JSON as follows: +> +> {"foo": [1, 2, 3], "bar": { "baaz": "hello world"}} +> --- +> sprinter.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ +> 1 file changed, 49 insertions(+) +> create mode 100644 sprinter.h +> +> diff --git a/sprinter.h b/sprinter.h +> new file mode 100644 +> index 0000000..1dad9a0 +> --- /dev/null +> +++ b/sprinter.h +> @@ -0,0 +1,49 @@ +> +#ifndef NOTMUCH_SPRINTER_H +> +#define NOTMUCH_SPRINTER_H +> + +> +/* for notmuch_bool_t */ +> +#include "notmuch-client.h" +> + +> +/* Structure printer interface */ +> +typedef struct sprinter +> +{ +> + /* start a new map/dictionary structure. +> + */ +> + void (*begin_map) (struct sprinter *); +> + +> + /* start a new list/array structure +> + */ +> + void (*begin_list) (struct sprinter *); +> + +> + /* end the last opened list or map structure +> + */ +> + void (*end) (struct sprinter *); +> + +> + /* print one string/integer/boolean/null element (possibly inside a +> + * list or map +> + */ + +I think this should say that it also prints any separator necessary. + +> + void (*string) (struct sprinter *, const char *); +> + void (*integer) (struct sprinter *, int); +> + void (*boolean) (struct sprinter *, notmuch_bool_t); +> + void (*null) (struct sprinter *); +> + +> + /* print the key of a map's key/value pair. +> + */ +> + void (*map_key) (struct sprinter *, const char *); +> + +> + /* print a frame delimiter (such as a newline or extra whitespace) +> + */ +> + void (*frame) (struct sprinter *); + +I think this should say that the intention is that this only prints +non-syntactic stuff. + +Best wishes + +Mark + + +> +} sprinter_t; +> + +> +/* Create a new structure printer that emits JSON */ +> +struct sprinter * +> +sprinter_json_new(const void *ctx, FILE *stream); +> + +> +/* A dummy structure printer that signifies that standard text output is +> + * to be used instead of any structured format. +> + */ +> +struct sprinter * +> +sprinter_text; +> + +> +#endif // NOTMUCH_SPRINTER_H +> -- +> 1.7.11.1 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2