From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/77198 Path: news.gmane.org!not-for-mail From: Pontus Lurcock Newsgroups: gmane.comp.tex.context Subject: Re: Check brackets and parentheses Date: Fri, 6 Jul 2012 08:38:44 +0100 Message-ID: <20120706073844.GN9970@rae.vm.bytemark.co.uk> References: <64C3576E-DF3A-470B-82C9-295690C44AB8@gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="R3G7APHDIzY6R/pk" X-Trace: dough.gmane.org 1341560338 12355 80.91.229.3 (6 Jul 2012 07:38:58 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 6 Jul 2012 07:38:58 +0000 (UTC) To: ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Fri Jul 06 09:38:57 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sn37v-0004rv-F6 for gctc-ntg-context-518@m.gmane.org; Fri, 06 Jul 2012 09:38:55 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id DC1801023F; Fri, 6 Jul 2012 09:38:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id j9qmT6-AWU5S; Fri, 6 Jul 2012 09:38:47 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id B36B0101E5; Fri, 6 Jul 2012 09:38:47 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 758DC101E5 for ; Fri, 6 Jul 2012 09:38:46 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Sa5D3qqmlwqY for ; Fri, 6 Jul 2012 09:38:45 +0200 (CEST) Original-Received: from filter1-til.mf.surf.net (filter1-til.mf.surf.net [194.171.167.217]) by balder.ntg.nl (Postfix) with ESMTP id C5D811018E for ; Fri, 6 Jul 2012 09:38:45 +0200 (CEST) Original-Received: from rae.talvi.net (mail.talvi.net [IPv6:2001:41c8:1:5986::10]) by filter1-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q667ciUx012696 for ; Fri, 6 Jul 2012 09:38:45 +0200 Original-Received: from pont by rae.talvi.net with local (Exim 4.72) (envelope-from ) id 1Sn37k-0006PZ-FR for ntg-context@ntg.nl; Fri, 06 Jul 2012 08:38:44 +0100 Content-Disposition: inline In-Reply-To: <64C3576E-DF3A-470B-82C9-295690C44AB8@gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Bayes-Prob: 0.6116 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=2001:41c8:1:5986::10; country=GB X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0RHuTCISx - b1308a54f0ad - 20120706 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.13 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 Xref: news.gmane.org gmane.comp.tex.context:77198 Archived-At: --R3G7APHDIzY6R/pk Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu 05 Jul 2012, Gilbert Houtekamer wrote: > I sometimes find myself looking for misplaced and missing brackets for a = long time, as context may given errors about a completely different locatio= n. >=20 > For example this one took me a while > \goto{\url[localhost20381}[url(localhost20381)] > =20 > (missing ] after this localhost20381). >=20 > Is there a SciTE or Notepad++ or command line script that anyone wrote to= help with this? It can be more or less sophisticated, but I found that mi= ssing / mismatched { [ ] } give the most confusing errors. =20 I wrote the attached Python script a while ago to catch cases like this, where an opening bracket accidentally =E2=80=98contains=E2=80=99 the = whole rest of the file. The script just keeps a running count of the nesting level, and gives the number of the last line where the nesting level was zero. Usually the offending bracket is at or very close to that line. It does that same for \start... and \stop..., in a very stupid=20 way (i.e. just counts them without identifying them, wouldn't catch e.g. \startonething \stopsomeotherthing). Hope it's helpful, Pont --R3G7APHDIzY6R/pk Content-Type: text/x-python; charset=us-ascii Content-Disposition: attachment; filename="brace-lint.py" #!/usr/bin/python import sys '''Count opening and closing braces in a file.''' def count(filename, opening, closing): print opening, closing f = open(sys.argv[1], 'r') braces = 0 i = 1 last_zero = -1 for line in f.readlines(): braces += line.count(opening) braces -= line.count(closing) if braces==0: last_zero = i i += 1 f.close() print last_zero count(sys.argv[1], '{', '}') count(sys.argv[1], '[', ']') count(sys.argv[1], '\\start', '\\stop') --R3G7APHDIzY6R/pk Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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 : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --R3G7APHDIzY6R/pk--