is a match (since the braces are balanced) but{foo is awesome and so is {bar}}
will not. Pretty elementary, yes? OK, so here's my problem. I'm using this module in order to convert some code written in Curl into XML. Curl uses || to denote comments, like this:{foo is not {balanced}
my problem is that the comment often contains braces, and I of course don't want to end up with a situation where{center foo} ||this is comment
does not match. This results in everything after an extra { in comment being unmatched to the end of the input, since a matching } won't be found unless it's a random } in another comment. So my current (not so) brilliant thinking is that I will use a regex like this:|| an open brace looks like this { {beginning of a block {some function} end of a block}
So far so good, right? OK, so I run these regexes, then run the Text::Balanced routine, then after that is done I search for "endbrace" and "openbrace" and replace them appropriately. So this makes sense in my head, but it does not seem to work in actuality. I was hoping that, for example,$text =~ s/\|\|(.*?)\n/\<\!\-\-$1\-\-\>\n/g; #turn line comment form i +nto XML comment form $text =~ s/<\!\-\-(.*?)\}(.*?)\-\->/<\!\-\-$1 endbrace $2\-\->/gxs; #e +scape the end braces in comment so they needn't be balanced $text =~ s/<\!\-\-(.*?)\{(.*?)\-\->/<\!\-\-$1 openbrace $2\-\->/gxs; # +ditto for open braces
Would simply become the same block of code with <!-- in place of || and a --> at the end of each line. Actually, the change of comment indicators seems fine, but identifying each brace seems to be screwing up. Running the above code through my program I get||{paragraph The union of zero or more {glossary citation="type", typ +es } || may be denoted using {ONE-OF }. For example, the || {glossary type expression } {ctext {one-of int float } } {glossa +ry || citation="evaluate", evaluates } to a non- {glossary || representational type } that can be used to {glossary declare } a + {glossary || variable } that can hold either an {INT } or a {FLOAT }. }
The <> instead of {} is due to the Text::Balanced recognizing balanced braces, which indicates that my regexes are not working in all occurences. Specifically, they seem to match once per line of comment. Am I making some dumb mistake in my regexes? Is there a better way to get Text::Balanced to ignore braces in ||comment? Any suggestions/pointers much appreciated. Thanks!<!-- { paragraph The union of zero or more <glossary citation="type", + types } --> <!-- may be denoted using { ONE-OF } . For example, the--> <!-- { glossary type expression } <ctext> <one-of> int float </on +e-of> </ctext> <glossary-->> <!-- citation="evaluate", evaluates } to a non- { glossary--> <!-- representational type } that can be used to { glossary declar +e </glossary--> a <glossary-->> <!-- variable } that can hold either an { INT </glossary--> or a +<FLOAT> </FLOAT>. > -->
In reply to Problem with skipping comment by tshabet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |