|
I don't know, if that would belong to you, but nevetheless, I'd like to mention it here. I have the following source-code: BufferedReader br = new BufferedReader(row.getCharacterStream(2)) /* br.eachLine { line -> if (modify.isSelected() && line.contains("import namespace")) { String location1 = line.find("schemaLocation=\".*\"") String location2 = location1.replaceAll("\".*/", "\"") line = line.replaceAll(location1, location2) } sb.append(line) sb.append("\n") } fieldContent = sb.toString() */ and the documented part starts from the /* (of course...) but only till the regex in the location1.replaceAll("\".*/ That ends in an error in eclipse and the source could not be compiled. I'm currently using: Groovy-Eclipse plugin Version: 2.6.0.xx-20111212-0900-e37-RELEASE Best regards, Susanne. -- Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de |
|
I thnik you have to escape the \
String location2 = location1.replaceAll("\".*\/", "\\"") should work On Thu, Feb 9, 2012 at 2:19 PM, Susanne Jaeckel <[hidden email]> wrote:
|
|
Hello Sebastien,
thanks for your reply, but the problem is a bit earlier at the ".*/" part of the regex. My little bit refined code is now: br.eachLine { line -> if (modify.isSelected() && line.contains("import namespace")) { line = line.replaceAll("(schemaLocation=\")[^\"]*/", '$1') } sb.append(line + "\n") } The code works, but I could not comment it out with /* ... */, only with // on each line. And if I try to escape the slash in [^\"]*/ like [^\"*]\/, I get the error-message: Groovy: unexpected char: '\' @ line x, column y Best regards, Susanne.
-- Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de |
|
Suzanne,
I think this might be a groovy issue, not an eclipse plugin issue. I saved your example code to a file, and tried to run it with groovy: > groovy -v
Groovy Version: 1.8.4 JVM: 1.6.0_26 > type suzanne.groovy
BufferedReader br = new BufferedReader(row.getCharacterStream(2))
/* br.eachLine { line -> if (modify.isSelected() && line.contains("import namespace")) {
String location1 = line.find("schemaLocation=\".*\"") String location2 = location1.replaceAll("\".*/", "\"")
line = line.replaceAll(location1, location2) }
sb.append(line) sb.append("\n")
} fieldContent = sb.toString() */
> groovy suzanne.groovy org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\Documents and Settings\Administrator\My Documents\A Place to run Anything\suzanne.groovy: 7: unexpected char: '\' @ line 7, column 79. ocation1.replaceAll("\".*/", "\"")
^ 1 error
>
So it seems the parser doesn't understand that your */ is quoted. Hope that's helpful, Danny On Thu, Feb 9, 2012 at 8:34 AM, Susanne Jaeckel <[hidden email]> wrote:
Danny Yarbrough, N9JDY Plainfield, IL |
|
Thanks for pointing this out, but this is not a bug in the parser.
Since the entire block is commented out, there is no way for the parser to know that the first */ is part of a quoted string (since strings don't exist in comments). This is why it is always safer to use line comments instead of block comments for commenting out code. On Thu, Feb 9, 2012 at 6:50 AM, Danny Yarbrough <[hidden email]> wrote: > Suzanne, > > I think this might be a groovy issue, not an eclipse plugin issue. > > I saved your example code to a file, and tried to run it with groovy: > >> groovy -v > Groovy Version: 1.8.4 JVM: 1.6.0_26 > >> type suzanne.groovy > BufferedReader br = new > BufferedReader(row.getCharacterStream(2)) > > /* > br.eachLine { line -> > if (modify.isSelected() && line.contains("import > namespace")) { > String location1 = > line.find("schemaLocation=\".*\"") > String location2 = location1.replaceAll("\".*/", > "\"") > line = line.replaceAll(location1, location2) > } > sb.append(line) > sb.append("\n") > } > fieldContent = sb.toString() > */ > >> groovy suzanne.groovy > org.codehaus.groovy.control.MultipleCompilationErrorsException: startup > failed: > C:\Documents and Settings\Administrator\My Documents\A Place to run > Anything\suzanne.groovy: 7: unexpected char: '\' @ line 7, column 79. > ocation1.replaceAll("\".*/", "\"") > ^ > > 1 error > > >> > > So it seems the parser doesn't understand that your */ is quoted. > > Hope that's helpful, > > Danny > > > On Thu, Feb 9, 2012 at 8:34 AM, Susanne Jaeckel <[hidden email]> wrote: >> >> Hello Sebastien, >> >> thanks for your reply, but the problem is a bit earlier at the ".*/" part >> of the regex. >> >> My little bit refined code is now: >> >> br.eachLine { line -> >> if (modify.isSelected() && line.contains("import >> namespace")) { >> line = >> line.replaceAll("(schemaLocation=\")[^\"]*/", '$1') >> } >> sb.append(line + "\n") >> } >> >> The code works, but I could not comment it out with /* ... */, only with >> // on each line. >> >> And if I try to escape the slash in [^\"]*/ like [^\"*]\/, I get the >> error-message: >> Groovy: unexpected char: '\' @ line x, column y >> >> Best regards, >> Susanne. >> >> -------- Original-Nachricht -------- >> Datum: Thu, 9 Feb 2012 14:27:36 +0100 >> Von: Sebastien Blanc <[hidden email]> >> An: [hidden email] >> Betreff: Re: [groovy-eclipse-plugin-user] Parsing mistake in the >> groovy-eclipse plugin? >> >> I thnik you have to escape the \ >> >> String location2 = location1.replaceAll("\".*\/", "\\"") >> should work >> >> >> On Thu, Feb 9, 2012 at 2:19 PM, Susanne Jaeckel <[hidden email]> wrote: >>> >>> Dear groovy-eclipse plugin developer, >>> >>> I don't know, if that would belong to you, but nevetheless, I'd like to >>> mention it here. >>> >>> I have the following source-code: >>> >>> BufferedReader br = new >>> BufferedReader(row.getCharacterStream(2)) >>> >>> /* >>> br.eachLine { line -> >>> if (modify.isSelected() && line.contains("import >>> namespace")) { >>> String location1 = >>> line.find("schemaLocation=\".*\"") >>> String location2 = >>> location1.replaceAll("\".*/", "\"") >>> line = line.replaceAll(location1, location2) >>> } >>> sb.append(line) >>> sb.append("\n") >>> } >>> fieldContent = sb.toString() >>> */ >>> >>> and the documented part starts from the /* (of course...) but only till >>> the regex in the location1.replaceAll("\".*/ >>> >>> That ends in an error in eclipse and the source could not be compiled. >>> >>> I'm currently using: >>> Groovy-Eclipse plugin >>> Version: 2.6.0.xx-20111212-0900-e37-RELEASE >>> >>> Best regards, >>> Susanne. >>> >>> >>> >>> -- >>> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir >>> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de >> >> >> >> >> >> -- >> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir >> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de > > > > > -- > Danny Yarbrough, N9JDY > Plainfield, IL --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Yeah, I kind of made it sound like I thought it was a groovy bug, didn't I :-) Not my intention.
Suzanne, in case you aren't aware, it's easy in Eclipse to // comment out a block of code by first highlighting the block, and then pressing Ctrl+/ . This will put a // in the first column (might be configurable? not sure) of each line in the selection. Doing Ctrl+/ again removes the // from the highlighted block.
Saves you the trouble of typing it at the beginning of every line. (if Ctrl-/ has been redefined in your environment, your mileage may vary :-) Good luck!
Danny On Thu, Feb 9, 2012 at 10:32 AM, Andrew Eisenberg <[hidden email]> wrote: Thanks for pointing this out, but this is not a bug in the parser. Danny Yarbrough, N9JDY Plainfield, IL |
|
Thanks a lot for all your responses! :-)
The explanation makes really sense. Seems, that I never tried to comment some code with regexes before, even in other languages... ;-) Have a nice Weekend! Susanne.
-- Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de |
| Powered by Nabble | Edit this page |
