Skip to content

Instantly share code, notes, and snippets.

@michalbcz
Last active November 11, 2022 07:38

Revisions

  1. michalbcz revised this gist Nov 11, 2022. No changes.
  2. michalbcz revised this gist Nov 11, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions slashy_string_ending_with_backslash_issue.groovy
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,8 @@ import groovy.io.*
    // from statement below any GString with interpolation or comments doesn't work (ie. cannot be compiled)
    def dir = new File(/C:\Users\/)
    def statementWorks = 1+1
    println statementWorks
    def expressionWorks = 1+1
    println expressionWorks
    println "GString without interpolation works"
    println 'String works'
  3. michalbcz created this gist Nov 11, 2022.
    29 changes: 29 additions & 0 deletions slashy_string_ending_with_backslash_issue.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    /*
    Example what happened when you use backslash in Slashy string (https://groovy-lang.org/syntax.html#_slashy_string)
    Note: there is a note that you are not supposed to do that in https://groovy-lang.org/syntax.html#_special_cases
    "A consequence of slash escaping is that a slashy string can’t end with a backslash"
    */

    import groovy.io.*

    // def dir = new File(/C:\Users/) // WORKS (removed last slash)
    // def dir = new File("C:\\Users\\") // WORKS
    // def dir = new File("C:\\Users") // WORKS

    // from statement below any GString with interpolation or comments doesn't work (ie. cannot be compiled)
    def dir = new File(/C:\Users\/)
    def statementWorks = 1+1
    println statementWorks
    println "GString without interpolation works"
    println 'String works'
    dir.eachFile({ file ->
    "expression below is not working, remove it (commenting doesn't work either) and it starts to work"
    println "${file}"
    "working expressions"
    println file
    println "file"
    })