Forums

Escaping substitution in strings

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Re: Escaping substitution in strings

Postby hopscc » Mon Apr 28, 2008 8:08 am

Heres another patch for escaped substitution in strings - this one using a TokenDef subclass and an extension to the straight re matching
Its a little more widespread than desirable due the .Net Match class being immutable and not exposing a public constructor -
I had to wrap it and change the baseclass return type and consequent changes
Attachments
escSubst1.patch
(7.31 KiB) Downloaded 592 times
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Escaping substitution in strings

Postby Charles » Mon Apr 28, 2008 9:53 am

I'll take a look this week. Thanks.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Escaping substitution in strings

Postby Steve » Wed Apr 30, 2008 7:21 am

Would it be possible to offer an alternative syntax that is a little more unique than [ ]? For instance, in Boo I believe the syntax was ${ }, which was unique enough that I never had any problems. The current syntax that Cobra uses seems to occur quite frequently unfortunately.

Best regards as always,


Steve
Steve
 
Posts: 9

Re: Escaping substitution in strings

Postby Charles » Thu May 01, 2008 9:15 am

Let's start with the escaping of brackets with \ and raw strings, and go from there.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Escaping substitution in strings

Postby Charles » Fri May 09, 2008 12:37 am

In development, you can now escape a square bracket with a backslash to prevent Cobra from interpreting it as a substitution expression:
assert 'foo \[bar]' == r'foo [bar]'
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Escaping substitution in strings

Postby hopscc » Fri May 09, 2008 5:46 am

Good changes.
Theres one edge case it misses - escaped escape
Code: Select all
    a=99
    assert "s2:a=\\[a]" == r"s2:a=\99"
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Escaping substitution in strings

Postby hopscc » Fri May 09, 2008 5:47 am

Heres the test file
Attachments
063-esc-string-subst.cobra
(2.03 KiB) Downloaded 571 times
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Escaping substitution in strings

Postby Charles » Sun May 11, 2008 2:39 pm

Thanks, these are good test cases. I even had them in my workspace already from when you first posted them, but in my last work session, I forgot about them!

Cases added. Bug fixed.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Escaping substitution in strings

Postby hopscc » Wed May 14, 2008 5:49 am

and finally... heres a patch to remove the mostly duplicated code in each of the new
StringTokenDef subclasses match methods
Attachments
rmdupcode.patch
(3.24 KiB) Downloaded 583 times
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Escaping substitution in strings

Postby Charles » Tue Jun 03, 2008 1:24 am

I'm unable to apply this patch:
Code: Select all
patch -p0 -i rmdupcode.patch 
patching file CobraTokenizer.cobra
patch: **** malformed patch at line 14: @@ -743,6 +773,25 @@

I tried on Windows and then on Mac with the same result. The command "patch -p0 -i <file>" has worked in the past and I'm not sure what is wrong.

Did you use the "svn di" command as explained at http://cobra-language.com/trac/cobra/wiki/HowToSubmitAPatch. If so, what version of svn are you on?

I could do this small patch by hand, but let's find out what's going wrong.

-Chuck
Charles
 
Posts: 2515
Location: Los Angeles, CA

PreviousNext

Return to Discussion

Who is online

Users browsing this forum: No registered users and 8 guests