From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30559 invoked by alias); 19 Feb 2015 07:41:24 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 30495 invoked by uid 89); 19 Feb 2015 07:41:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: aibo.runbox.com Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 19 Feb 2015 07:41:21 +0000 Received: from [10.9.9.206] (helo=mailfront02.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1YOLja-0006nn-00; Thu, 19 Feb 2015 08:41:18 +0100 Received: from 70-36-239-115.dsl.dynamic.fusionbroadband.com ([70.36.239.115] helo=toshie.bothner.com) by mailfront02.runbox.com with esmtpsa (uid:757155 ) (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) id 1YOLjY-0001DR-Ja; Thu, 19 Feb 2015 08:41:16 +0100 Message-ID: <54E59398.6020105@bothner.com> Date: Thu, 19 Feb 2015 07:41:00 -0000 From: Per Bothner User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: mikel evins , Kawa mailing list Subject: Re: How to customize the reader and printer in a language implementation References: <0BC303A6-82BC-4811-86C8-280F1593A9FF@me.com> In-Reply-To: <0BC303A6-82BC-4811-86C8-280F1593A9FF@me.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-q1/txt/msg00043.txt.bz2 On 02/18/2015 07:51 PM, mikel evins wrote: > What's the right way to arrange for Kawa to use an output format > that's not in the formats array in Shell.java? I want to use my own > printer with the Bard implementation. I assume you've written an implementation of either AbstractFormat or Consumer So you want to give it a name, so it can be selected by the --output-format switch. How would you do that? Right now there isn't anyway, except to modify the formats array in Shell.java. One way to fix that is to add a registerFormat method, which would act similar to registerLanguage in gnu/expr/Language.java. The problem is you'd have to write your own main program to call registerFormat before clling repl.main. For example see gnu.jemacs.lang.ELisp#main. This means you can't do something like: $ java kawa.repl -output-format my-new-format A better way to be able to extend new formats while still using kawa.repl is to use Java's "service provide" mechanism. See java.util.ServiceLoader. We could define an interface kawa.OutputFormatProvider: public interface OutputFormatProvider { public Object[][] getProvidedFormats(); } or maybe better: public interface OutputFormatProvider { /** Return null if this OutputFormatProvider does not provide a format * with the given name. */ Consumer getOutputConsumer(String name, OutPort out); } Then you add a new format you'd add a file META-INF/services/kawa.OutputFormatProvider to your .jar, which contains the name of one or more OutputFormatProvider sub-classes. Patches welcome ... > While I'm asking, I may as well also ask about the right way to > customize the reader to handle alternative syntax for certain value > expressions. For example, I want to read expressions like "{...}" as > finite maps, and "[...]" as persistent sequences. In that case I suggest creating a new Language class. If it's very similar to Scheme except for a few modest changes make it extend kawa.standard.Scheme. Then you can override the createReadTable method. > I'd also like to > arrange for a different surface syntax for character objects. Character values are evil. You shouldn't make it easier to work with characters directly - they're too low-level and little or no useful semantic meaning. Instead people should work with strings. IMNSHO. -- --Per Bothner per@bothner.com http://per.bothner.com/