From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/46990 Path: news.gmane.org!not-for-mail From: Hans Hagen Newsgroups: gmane.comp.tex.context Subject: Re: lua questions Date: Fri, 23 Jan 2009 12:13:15 +0100 Message-ID: <4979A64B.1080906@wxs.nl> References: <8FF223F7-EFDC-43BD-8765-CBB15A03DBAD@uni-bonn.de> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1232709286 16730 80.91.229.12 (23 Jan 2009 11:14:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Jan 2009 11:14:46 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Fri Jan 23 12:15:58 2009 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by lo.gmane.org with esmtp (Exim 4.50) id 1LQK10-0004bp-AZ for gctc-ntg-context-518@m.gmane.org; Fri, 23 Jan 2009 12:15:58 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 67F3A1FE4E; Fri, 23 Jan 2009 12:14:34 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 09844-06; Fri, 23 Jan 2009 12:13:31 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 18F0B1FE36; Fri, 23 Jan 2009 12:13:31 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 74ABF1FE35 for ; Fri, 23 Jan 2009 12:13:29 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 14679-04 for ; Fri, 23 Jan 2009 12:13:15 +0100 (CET) Original-Received: from filter2-ams.mf.surf.net (filter2-ams.mf.surf.net [192.87.102.70]) by ronja.ntg.nl (Postfix) with ESMTP id 1D2A01FA2B for ; Fri, 23 Jan 2009 12:13:15 +0100 (CET) Original-Received: from mail.pragma-ade.net (dsl-083-247-100-017.solcon.nl [83.247.100.17]) by filter2-ams.mf.surf.net (8.13.8/8.13.8/Debian-3) with ESMTP id n0NBDD7R032659 for ; Fri, 23 Jan 2009 12:13:13 +0100 Original-Received: from [10.100.1.100] (unverified [10.100.1.100]) by controller-1 (SurgeMail 3.9e) with ESMTP id 5450-1840426 for ; Fri, 23 Jan 2009 12:13:13 +0100 User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) In-Reply-To: <8FF223F7-EFDC-43BD-8765-CBB15A03DBAD@uni-bonn.de> X-Originating-IP: 10.100.1.100 X-Authenticated-User: hagen@controller-1 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=83.247.100.17; country=NL; region=16; city=Dronten; latitude=52.5333; longitude=5.7167; http://maps.google.com/maps?q=52.5333,5.7167&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 169579201 - 9324995a0e63 X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.70 X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.11 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:46990 Archived-At: Thomas A. Schmitz wrote: > Hi all, > = > this is a bit OT and should probably go to a lua list, but since some = > people here are very proficient in lua and I feel less embarrassed about = > noob questions here... I have a half-functioning python script to = > convert entries from a classics database into the bibtex format. I want = > to rewrite it in lua and make it more functional. Three little = > problems/questions: > = > 1. I found a script to convert Roman numerals via lpeg here: = > http://lua-users.org/wiki/LpegRecipes but it uses the syntax lpeg.Ca = > which my lpeg doesn't recognize and which I can't find in the lpeg = > manual. According to a talk by Roberto Ierusalimschy, "lpeg.Ca(patt) - = > "accumulates" the nested captures." = > (http://www.inf.puc-rio.br/~roberto/lpeg/slides-lpeg-workshop2008.pdf) = > Is this obsolete, has it been replaced by anything? here is a variant that implements a function (and does not use the env = trick) do local add =3D function (x,y) return x+y end local P,Ca,Cc=3D lpeg.P,lpeg.Ca,lpeg.Cc local symbols =3D { = I=3D1,V=3D5,X=3D10,L=3D50,C=3D100,D=3D500,M=3D1000,IV=3D4,IX=3D9,XL=3D40,CD= =3D400,CM=3D900} local adders =3D { } for s,n in pairs(symbols) do adders[s] =3D P(s)*Cc(n)/add end local MS =3D adders.M^0 local CS =3D = (adders.D*adders.C^(-4)+adders.CD+adders.CM+adders.C^(-4))^(-1) local XS =3D (adders.L*adders.X^(-4)+adders.XL+adders.X^(-4))^(-1) local IS =3D = (adders.V*adders.I^(-4)+adders.IX+adders.IV+adders.I^(-4))^(-1) local p =3D Ca(Cc(0)*MS*CS*XS*IS) function string:romantonumber() return p:match(self:upper()) end end print(string.romantonumber("MMIX")) print(string.romantonumber("MMIIIX")) just run such script using mtxrun --script yourscript.lua as luatex (texlua) has the latest lpeg built in) > 2. How can I check if a string begins with a class of words "(Der |Die = > |Das |The |An )" etc. and strip these words from the string? I do it = > with a compiled regexp in python, but "Programming in lua" has this to = > say: "Unlike some other systems, in Lua a modifier can only be applied = > to a character class; there is no way to group patterns under a = > modifier. For instance, there is no pattern that matches an optional = > word (unless the word has only one letter). Usually you can circumvent = > this limitation using some of the advanced techniques that we will see = > later." I haven't found these techniques yet. local stripped =3D { "Der", "Die", "Das" } local p =3D lpeg.P(false) for k, v in ipairs(stripped) do p =3D p + lpeg.P(v) end local w =3D p * " " local stripper =3D lpeg.Cs(((w/"") + lpeg.C(1))^0) lpeg.print(stripper) str =3D "Germans somehow always talk about Der Thomas and Der Hans" print(stripper:match(str)) > 3. How can I compare strings with utf8 characters? My naive approach > if string.find(record, "R=E9sum=E9") > doesn't appear to work (while the same method does work if the string = > has only ASCII characters). since lua is 8 bit clean utf should just work ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- ___________________________________________________________________________= ________ If your question is of interest to others as well, please add an entry to t= he Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-cont= ext webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________= ________