Re: regexp for scheme blocks in lilypond language

Lorenzo Bettini <[email protected]> Sun, 22 Jan 2012 12:22:16 +0100
Newsgroups gmane.comp.gnu.source-highlight.general
Message-ID <[email protected]>
On 01/22/2012 12:20 PM, Federico Bruni wrote:
> Il 21/01/2012 15:24, Lorenzo Bettini ha scritto:
>>> Thanks, this should be the direction, but it's not so easy.
>>> First, the doc says:
>>>
>>> "Note that, in order for a delimited language element to be nested, its
>>> starting and ending elements must be different"
>>>
>>> I may be wrong, but I would add: they also have to be specular.
>>> In my case delimiters are not specular.
>>
>> no, that's not requested :)
>> note that end delimiter may refer to start delimiter (using the regex
>> syntax for referring the matched part of another expression); this is
>> the case for lua.lang where nested comments can have different syntax
>> and the delimiter has to match the starting delimiter and refers to it
>> (with this respect, source-highlight is pretty powerful, but I may be
>> biased ;)
>
> thanks, but I'm still far away from understanding
>
> can you give me some pointer/keyword which can help me understanding the
> following regexp (in particular, I can't understand (=*) and @{1})?
>
> environment comment delim `--\[(=*)\[` "]" + @{1} + "]" multiline nested
> begin
> include "url.lang"
> environment comment delim "[[" "]]" multiline nested begin
> include "url.lang"
> end
> end

it says that the starting delimiter is

`--\[(=*)\[`

while the end delimiter is

"]" + @{1} + "]"

(please have a look at the documentation to understand the difference 
among ", ', ` )

the starting delimiter searches for elements of the shape

--[[, --[=[, --[==[

etc. ( (=*) is just a regular expression that matches any multiple 
occurrence of =, even none)

the end delimiter uses the feature I was talking about

"]" + @{1} + "]"

in particular @{1} refers to the first grouped matched string of the 
start delimiter, i.e., in this example (=*)  (as I said, take a look at 
the implementation concerning ` ` which keeps grouped regular expressions).

This means that if the starting delimiter matched --[[ then the end 
delimiter will try to match ]] ; if the starting delimiter matched --[=[ 
then the end delimiter will try to match ]=] ; if the starting delimiter 
matched --[==[ then the end delimiter will try to match ]==] ; and so on...

pretty powerful, isn't it? O:)

The inner

environment comment delim "[[" "]]" multiline nested begin
         include "url.lang"
   end

will try to match only comments [[ ]] because, if I remember correctly, 
in Lua inside a comment --[[ ]] you can only have [[ ]] comments...

is that clearer now?

cheers
	Lorenzo

-- 
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net