From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/51568 Path: news.gmane.org!not-for-mail From: Renaud Aubin Newsgroups: gmane.comp.tex.context Subject: Re: Mark IV Syntax highlighting support Date: Thu, 02 Jul 2009 01:00:56 +0200 Message-ID: <4A4BEAA8.5080406@nibua-r.org> References: <4A494167.9010804@nibua-r.org> <4A49422E.40404@nibua-r.org> <20090630135807.GP1611@katherina.student.utwente.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040706040207050801030300" X-Trace: ger.gmane.org 1246489346 18747 80.91.229.12 (1 Jul 2009 23:02:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 1 Jul 2009 23:02:26 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Jul 02 01:02:19 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 1MM8ol-0005dL-44 for gctc-ntg-context-518@m.gmane.org; Thu, 02 Jul 2009 01:02:19 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id EF30F1FC67; Thu, 2 Jul 2009 01:02:17 +0200 (CEST) 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 12368-03; Thu, 2 Jul 2009 01:01:17 +0200 (CEST) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 85A341FBCC; Thu, 2 Jul 2009 01:01:17 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 772291FBCC for ; Thu, 2 Jul 2009 01:01:15 +0200 (CEST) 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 13411-03 for ; Thu, 2 Jul 2009 01:01:03 +0200 (CEST) Original-Received: from filter1-til.mf.surf.net (filter1-til.mf.surf.net [194.171.167.217]) by ronja.ntg.nl (Postfix) with ESMTP id 610A21FBBA for ; Thu, 2 Jul 2009 01:01:03 +0200 (CEST) Original-Received: from 26.mail-out.ovh.net (26.mail-out.ovh.net [91.121.27.225]) by filter1-til.mf.surf.net (8.13.8/8.13.8/Debian-3) with SMTP id n61N12in006400 for ; Thu, 2 Jul 2009 01:01:02 +0200 Original-Received: (qmail 3815 invoked by uid 503); 1 Jul 2009 23:01:23 -0000 Original-Received: from 2.mail-out.ovh.net (91.121.26.226) by 26.mail-out.ovh.net with SMTP; 1 Jul 2009 23:01:23 -0000 Original-Received: (qmail 11118 invoked by uid 503); 2 Jul 2009 00:27:50 -0000 Original-Received: from gw2.ovh.net (HELO mail182.ha.ovh.net) (213.251.189.202) by 2.mail-out.ovh.net with SMTP; 2 Jul 2009 00:27:50 -0000 Original-Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 1 Jul 2009 23:01:04 -0000 Original-Received: from cha78-4-88-178-141-145.fbx.proxad.net (HELO ?192.168.78.1?) (aubin@nibua-r.org@88.178.141.145) by ns0.ovh.net with SMTP; 1 Jul 2009 23:01:03 -0000 User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) In-Reply-To: <20090630135807.GP1611@katherina.student.utwente.nl> X-Ovh-Tracer-Id: 16910735126584890125 X-Ovh-Remote: 88.178.141.145 (cha78-4-88-178-141-145.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|H 0.5/N X-Ovh-Tracer-Id: 16916364625583608588 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=91.121.27.225; country=FR; region=A8; city=Chilly-mazarin; latitude=48.7000; longitude=2.3000; http://maps.google.com/maps?q=48.7000,2.3000&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 253965767 - 0dc183ffdd6e - 20090702 X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.217 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:51568 Archived-At: This is a multi-part message in MIME format. --------------040706040207050801030300 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Hi folks ! I have just finished a first draft of pret-xml.lua: - I need to improve its coverage (html); - DTD declaration is not yet managed; - I do nothing about re-indentation since I prefer to format my xml=20 sample by myself (by hand or using xmllint); - That's my first try to lua/luatex (after several months of Java...) so=20 my definitions (esp. for functions) is not clean at all (you have been=20 warned); I have done it the "trial/error" way without much design reflexion just=20 for fun (I'm on vacation)... I'm not sure it will be reusable... Take all your test files and please report issues (or give me advices)! ;= ) Thank you Matthijs! Regards, Renaud Matthijs Kooijman a =E9crit : > Hey all, > >> ./tex/texmf-context/tex/context/base/verb-.*\.lua ! > Actually, in newer versions (since a month or so), that's pret-*.lua. > >>> Where to start with this topic (current state in Mark IV, roadmap, ..= .) ? > I've been struggling with this a bit as well lately and found there was= next > to no documentation. I've managed to create my own pretty printer, and = tried > to update the docs a bit. See [1] and [2] on the wiki for more info. Th= ere are > still some details I don't get (why is there a line() hook, what is all= this > nesting stuff, etc.), so feel free to find out more and improve these p= ages! > > Gr. > > Matthijs > > [1]: http://wiki.contextgarden.net/Verbatim_text#Your_own_formatter > [2]: http://wiki.contextgarden.net/Custom_pretty_printer > > -----------------------------------------------------------------------= - > > _______________________________________________________________________= ____________ > If your question is of interest to others as well, please add an entry = to the Wiki! > > maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-= context > webpage : http://www.pragma-ade.nl / http://tex.aanhet.net > archive : https://foundry.supelec.fr/projects/contextrev/ > wiki : http://contextgarden.net > _______________________________________________________________________= ____________ --------------040706040207050801030300 Content-Type: text/x-lua; name="pret-xml.lua" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pret-xml.lua" if not modules then modules = { } end modules ['pret-xml'] = { version = 1.001, comment = "from pret-.*\.lua, http://wiki.contextgarden.net/Verbatim_text#Your_own_formatter and http://wiki.contextgarden.net/Custom_pretty_printer", author = "Renaud AUBIN", copyright = "to be defined", license = "to be defined" } local utf = unicode.utf8 local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues local utfbyte, utffind = utf.byte, utf.find local byte, sub, find, gfind, match = string.byte, string.sub, string.find, string.gfind, string.match local texsprint, texwrite = tex.sprint, tex.write local ctxcatcodes = tex.ctxcatcodes local change_state, finish_state = buffers.change_state, buffers.finish_state buffers.visualizers.xml = buffers.visualizers.xml or { } buffers.visualizers.xml.identifiers = buffers.visualizers.xml.identifiers or { } incomment = false local colors = { "prettyone", "prettytwo", "prettythree", "prettyfour", "prettyfive", "prettysix", "prettyseven" } local states = { ['namespace'] = 1, ['element'] = 2, ['attrname'] = 3, ['attrvalue'] = 4, ['prolog'] = 5, ['comment'] = 6, ['pi'] = 7 } local function flush_text(str) for c in utfcharacters(str) do if c == " " then texsprint(ctxcatcodes,"\\obs") else texwrite(c) end end end local function process_attribute(str) local name, value, state = "", "", 0 buffers.currentcolors = colors local name,value = match(str,"^(.-)=(\".-\")$") state = change_state(states['attrname'], state) flush_text(name) state = finish_state(state) texwrite("=") state = change_state(states['attrvalue'], state) flush_text(value) state = finish_state(state) end local function process_namespace(str) local state = 0 buffers.currentcolors = colors state = change_state(states['namespace'], state) flush_text(str) state = finish_state(state) texwrite(":") end local function process_element(str) local state = 0 buffers.currentcolors = colors state = change_state(states['element'], state) flush_text(str) state = finish_state(state) end local function process_comment(str) local state = 0 buffers.currentcolors = colors state = change_state(states['comment'], state) flush_text(str) state = finish_state(state) end function process_tag(str) local name, value, state = "", "", 0 buffers.currentcolors = colors if match(str,"^<%?xml.-%?>$") then local prolog = match(str,"^<%?xml(.-)%?>$") state = change_state(states['pi'], state) texwrite("") state = finish_state(state) elseif match(str,"^$") then process_comment(str) elseif match(str,"^<[%a_]%w-%s*/?>$") or match(str,"^$") then local btag, name, etag = match(str,"^()$") texwrite(btag) process_element(name) texwrite(etag) elseif match(str,"^<%a%w-:[%a_]%w-%s*/?>$") or match(str,"^$") then local btag, ns, name, etag = match(str,"^()$") texwrite(btag) process_namespace(ns) process_element(name) texwrite(etag) elseif match(str,"^<%a%w-:[%a_][%w%-]-%s.*/?>$") or match(str,"^$") then local btag, ns, name, attributes, etag = match(str,"^()$") texwrite(btag) process_namespace(ns) process_element(name) repeat attributes=recursive_processing(attributes) until attributes==nil texwrite(etag) elseif match(str,"^<[%a_]%w-%s.*/?>$") or match(str,"^$") then local btag, name, attributes, etag = match(str,"^()$") texwrite(btag) process_element(name) repeat attributes=recursive_processing(attributes) until attributes==nil texwrite(etag) end end function process_uncomplete_starttag(str) local name, value, state = "", "", 0 buffers.currentcolors = colors if match(str,"^<%a%w-:[%a_]%w-%s.*$") then local btag, ns, name, attributes = match(str,"^(<)(%a%w-):([%a_]%w-%s)(.*)$") texwrite(btag) process_namespace(ns) process_element(name) repeat attributes=recursive_processing(attributes) until attributes==nil elseif match(str,"^<[%a_]%w-%s.*$") then local btag, name, attributes = match(str,"^(<)([%a_]%w-%s)(.*)$") texwrite(btag) process_element(name) repeat attributes=recursive_processing(attributes) until attributes==nil end end function recursive_processing(str) local first, second, third, attribute = "", "", "", "" if match(str, "^(.-)(%-%->)(.*)$") then -- stop multiline comment first, second, third = match(str, "^(.-)(%-%->)(.*)$") process_comment(first..second) incomment = false return third elseif incomment then process_comment(str) elseif match(str, "^(.-)(%b<>)(.*)$") then -- standard tag first, second, third = match(str, "^(.-)(%b<>)(.*)$") repeat first=recursive_processing(first) until first==nil process_tag(second) return third elseif match(str, "^(.-)(<[%a_]%w-:?%w-[%s%c])(.*)$") then -- multiline starttag first, second, third = match(str, "^(.-)(<[%a_]%w-:?%w-[%s%c])(.*)$") repeat first=recursive_processing(first) until first==nil process_uncomplete_starttag(second) return third -- elseif match(str, "^(.-)(<%?xml)(.*)$") then -- TODO manage multiline prolog -- first, second, third = match(str, "^(.-)(<%?xml)(.*)$") -- return third elseif match(str, "^(.-)(