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
Forums
Escaping substitution in strings
29 posts
• Page 2 of 3 • 1, 2, 3
Re: Escaping substitution in strings
- Attachments
-
- escSubst1.patch
- (7.31 KiB) Downloaded 593 times
- hopscc
- Posts: 632
- Location: New Plymouth, Taranaki, New Zealand
Re: Escaping substitution in strings
I'll take a look this week. Thanks.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Escaping substitution in strings
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
Best regards as always,
Steve
- Steve
- Posts: 9
Re: Escaping substitution in strings
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
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
Good changes.
Theres one edge case it misses - escaped escape
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
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
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.
Cases added. Bug fixed.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Escaping substitution in strings
and finally... heres a patch to remove the mostly duplicated code in each of the new
StringTokenDef subclasses match methods
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
I'm unable to apply this patch:
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
- 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
29 posts
• Page 2 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 10 guests