Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
╚ Groups Home
Nested Regexp's
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Thorsten Jolitz  
View profile  
 More options Sep 18 2012, 1:10 pm
Newsgroups: gnu.emacs.help
From: Thorsten Jolitz <tjol...@googlemail.com>
Date: Tue, 18 Sep 2012 18:40:49 +0200
Local: Tues, Sep 18 2012 12:40 pm
Subject: Nested Regexp's

Hi List,

I'm somehow stuck with a regexp I need for fontification purposes.

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Doug Lewan  
View profile  
 More options Sep 18 2012, 2:42 pm
Newsgroups: gnu.emacs.help
From: Doug Lewan <do...@shubertticketing.com>
Date: Tue, 18 Sep 2012 18:43:06 +0000
Local: Tues, Sep 18 2012 2:43 pm
Subject: RE: Nested Regexp's

> -----Original Message-----
> From: help-gnu-emacs-bounces+dougl=shubertticketing....@gnu.org
> [mailto:help-gnu-emacs-bounces+dougl=shubertticketing....@gnu.org] On
> Behalf Of Thorsten Jolitz
> Sent: Tuesday, 2012 September 18 12:41
> To: help-gnu-em...@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)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thorsten Jolitz  
View profile  
 More options Sep 18 2012, 7:25 pm
Newsgroups: gnu.emacs.help
From: Thorsten Jolitz <tjol...@googlemail.com>
Date: Wed, 19 Sep 2012 01:28:47 +0200
Local: Tues, Sep 18 2012 7:28 pm
Subject: Re: Nested Regexp's

Doug Lewan <do...@shubertticketing.com> writes:

Hi Doug,

> 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.

thank you very much, very helpfull, exactly what I needed to tackle the
problem!

--
cheers,
Thorsten


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »