groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Laforge <glafo...@gmail.com>
Subject Re: About refining regex literal syntax
Date Mon, 22 Oct 2018 20:34:36 GMT
Damn, MG will tell me again I'm reacting negatively to Daniel's ideas
but... :-)

Interestingly, the multiline support in regex was kind of a highlight of
Groovy's support of regexes as they allowed making more readable regular
expressions.
If you have it, have a look at some of the examples in Groovy in Action
which highlighted this.

The most intuitive human parsing here is certainly (m / ab) then (c / d),
and not the command chain expression, and indeed the parser currently
parses it as the intuitive human approach.

Command chain expressions would have been parsed though if indeed we had
use the triple (single/double) quote syntax, which would also be an
intuitive human parsing.

Expecting the parse to be a command chain with the slashy strings would
seem counter intuitive to me.

So call me resistant to change if you will MG ;-) but I quite like the
current behavior.

Guillaume

On Mon, Oct 22, 2018 at 8:00 PM Daniel.Sun <sunlan@apache.org> wrote:

> Hi all,
>
>       Groovy regex literal allows new lines, i.e. 0D0A, which introduces
> some ambiguity and breaks consistency in syntax. Let's have a look at some
> examples:
>
> 1)  Ambiguity example:
> ```
> m /ab
> c/ d
> ```
> This can be parsed as a command chain expression or parsed as two
> arithmetic
> expressions.
>
> 2)  Consistency breaking in syntax
> Single line:
> 'abc'
> "abc"
>
> Multiple lines:
> '''
> abc
> '''
> """
> abc
> """
> /
> abc
> /
> $/
> abc
> /$
>
>       As you can see, both two version of regex literal can span multiple
> lines...
>
>       I propose to forbidden new lines in one version of regex literal
> since
> Groovy 3.0.0:
>
> Single line:
> 'abc'
> "abc"
> /abc/
>
> Multiple lines:
> '''
> abc
> '''
> """
> abc
> """
> $/
> abc
> /$
>
>       Any thoughts?
>
> Cheers,
> Daniel.Sun
>
>
>
>
> -----
> Daniel Sun
> Apache Groovy committer
> Blog: http://blog.sunlan.me
> Twitter: @daniel_sun
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>


-- 
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Blog: http://glaforge.appspot.com/
Twitter: @glaforge <http://twitter.com/glaforge>

Mime
View raw message