all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Doug Lewan <dougl@shubertticketing.com>
To: Thorsten Jolitz <tjolitz@googlemail.com>,
	"help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: RE: Nested Regexp's
Date: Tue, 18 Sep 2012 18:43:06 +0000	[thread overview]
Message-ID: <155DEC68569B714B86C2C7075F5EDA982690086F@DAKIYA1.pegasus.local> (raw)
In-Reply-To: <87627bp9m6.fsf@googlemail.com>

> -----Original Message-----
> From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org
> [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.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
> 
> 
> Hi List,
> 
> 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 therefore to structure them like programs.

Here's how I define the REs that I think you want. (I assume that by "nested" you mean multiple.) I hope this helps.

,Doug

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defconst my-regex-plain-text 
  (concat "\\([[:space:]]*[^}]+\\)[[:space:]]*" ; Matches "123$%^ Чебурашка &*(0-="
	  )
  "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.")

;; 
;; Sunny day test code
;; 
(defconst test-plain-text (list "foo"
				"foo bar "
				"	foo bar baz bat"
				" --- 123$%^ Чебурашка &*(0-= --- "))
(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)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

> 
> This is the syntax:
> 
> ,--------------------
> | -{bar}  ; list item
> | !{foo}  ; bold
> `--------------------
> 
> These are examples of nesting bold text into list items:
> 
> ,-------------------------------------------------------------------
> | -{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}
> `-------------------------------------------------------------------
> 
> These are the regexps:
> 
> ,--------------------------------------------------
> | (defconst my-regex-list-item
> |   "\\(-{\\)\\([
> | ]*[^}]+\\)\\(}\\)"
> |   "Regular expression for matching a list item.")
> |
> | (defconst my-regex-bold
> |   "\\(!{\\)\\([
> | ]*[^}]+\\)\\(}\\)"
> |   "Regular expression for matching bold text.")
> `--------------------------------------------------
> 
> 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.
> 
> I would appreciate any hint about how to construct the list-item regexp
> in a way that it can contain nested bold terms.
> 
> --
> cheers,
> Thorsten
> 
> 




  reply	other threads:[~2012-09-18 18:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18 16:40 Nested Regexp's Thorsten Jolitz
2012-09-18 18:43 ` Doug Lewan [this message]
2012-09-18 23:28   ` Thorsten Jolitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=155DEC68569B714B86C2C7075F5EDA982690086F@DAKIYA1.pegasus.local \
    --to=dougl@shubertticketing.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=tjolitz@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.