From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Doug Lewan Newsgroups: gmane.emacs.help Subject: RE: Nested Regexp's Date: Tue, 18 Sep 2012 18:43:06 +0000 Message-ID: <155DEC68569B714B86C2C7075F5EDA982690086F@DAKIYA1.pegasus.local> References: <87627bp9m6.fsf@googlemail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1347993758 2733 80.91.229.3 (18 Sep 2012 18:42:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 18 Sep 2012 18:42:38 +0000 (UTC) To: Thorsten Jolitz , "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Sep 18 20:42:42 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TE2kr-0002j5-Kg for geh-help-gnu-emacs@m.gmane.org; Tue, 18 Sep 2012 20:42:41 +0200 Original-Received: from localhost ([::1]:47894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TE2kn-0007pI-Gc for geh-help-gnu-emacs@m.gmane.org; Tue, 18 Sep 2012 14:42:37 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TE2kh-0007oq-Go for help-gnu-emacs@gnu.org; Tue, 18 Sep 2012 14:42:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TE2kd-0000MS-D7 for help-gnu-emacs@gnu.org; Tue, 18 Sep 2012 14:42:31 -0400 Original-Received: from mailhost.shubertorg.com ([207.246.209.200]:23381 helo=webmail.shubertorg.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TE2kd-0000MG-9O for help-gnu-emacs@gnu.org; Tue, 18 Sep 2012 14:42:27 -0400 Original-Received: from dakiya1.pegasus.local ([::1]) by DAKIYA1.pegasus.local ([::1]) with mapi id 14.01.0339.001; Tue, 18 Sep 2012 14:43:06 -0400 Thread-Topic: Nested Regexp's Thread-Index: AQHNlcCnCP/Fnnnry0SAwpi3weU1+ZeQbV6A In-Reply-To: <87627bp9m6.fsf@googlemail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.0.21.202] X-detected-operating-system: by eggs.gnu.org: Windows XP/2000 (RFC1323+, w+, tstamp-) X-Received-From: 207.246.209.200 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:86824 Archived-At: > -----Original Message----- > From: help-gnu-emacs-bounces+dougl=3Dshubertticketing.com@gnu.org > [mailto:help-gnu-emacs-bounces+dougl=3Dshubertticketing.com@gnu.org] On > Behalf Of Thorsten Jolitz > Sent: Tuesday, 2012 September 18 12:41 > To: help-gnu-emacs@gnu.org > Subject: Nested Regexp's >=20 >=20 > Hi List, >=20 > I'm somehow stuck with a regexp I need for fontification purposes. Thorsten, It helps me a lot to think of regular expressions like programs and therefo= re to structure them like programs. Here's how I define the REs that I think you want. (I assume that by "neste= d" you mean multiple.) I hope this helps. ,Doug ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defconst my-regex-plain-text=20 (concat "\\([[:space:]]*[^}]+\\)[[:space:]]*" ; Matches "123$%^ =FE=C5=C2= =D5=D2=C1=DB=CB=C1 &*(0-=3D" ) "Regular expression defining what 'plain text' is.") (defconst my-regex-bold-text (concat "\\(!{\\)" my-regex-plain-text "\\(}\\)") "Regular expression defining what 'bold text' is.") (defconst my-regex-text (concat "\\(" my-regex-plain-text "\\|" my-regex-bold-text "\\)") "Regular expression defining what 'text'. Text is a mix of plain text and bold text.") (defconst my-regex-list-item (concat "\\(-{\\)" my-regex-text "+" "\\(}\\)") "Regular expression defining what a 'list item' is.") ;;=20 ;; Sunny day test code ;;=20 (defconst test-plain-text (list "foo" "foo bar " " foo bar baz bat" " --- 123$%^ =FE=C5=C2=D5=D2=C1=DB=CB=C1 &*(0-=3D --- ")) (defconst test-bold-text (mapcar (lambda (text) (concat "!{" text "}")) test-plain-text)) (defconst test-list-item (mapcar (lambda (list-text) (concat "-{" list-text "}")) (append test-plain-text test-bold-text))) (mapc (lambda (test-spec) (let ((re (car test-spec)) (test-data (cdr test-spec))) (mapc (lambda (item) (if (string-match re item) (message "PASS -- [[%s]] matches [[%s]]" re item) (message "FAIL -- [[%s]] DIDN'T match [[%s]]" re item)) (sit-for 1)) test-data))) (list (cons my-regex-plain-text test-plain-text) (cons my-regex-bold-text test-bold-text) (cons my-regex-list-item test-list-item))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >=20 > This is the syntax: >=20 > ,-------------------- > | -{bar} ; list item > | !{foo} ; bold > `-------------------- >=20 > These are examples of nesting bold text into list items: >=20 > ,------------------------------------------------------------------- > | -{foo bar foo bar} ; fontified as list item > | -{!{bold} foo bar} ; bold fontified, list item text not > | -{foo bar ; fontified as list item > | foo bar} > | -{foo bar !{hello ; 'hello bold' fontified, list item > text not > | bold} foo bar} > `------------------------------------------------------------------- >=20 > These are the regexps: >=20 > ,-------------------------------------------------- > | (defconst my-regex-list-item > | "\\(-{\\)\\([ > | ]*[^}]+\\)\\(}\\)" > | "Regular expression for matching a list item.") > | > | (defconst my-regex-bold > | "\\(!{\\)\\([ > | ]*[^}]+\\)\\(}\\)" > | "Regular expression for matching bold text.") > `-------------------------------------------------- >=20 > Now I would need to construct a 'my-regex-list-item' that allows for > one > or several nested 'bold' terms, with each the list item and the bold > term > possibly including line-breaks. The result should actually show the > whole list item in the assigned color, and the bold terms in the same > color, but bold. >=20 > I would appreciate any hint about how to construct the list-item regexp > in a way that it can contain nested bold terms. >=20 > -- > cheers, > Thorsten >=20 >=20