You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Christopher Smith (Jira)" <ji...@apache.org> on 2021/06/28 03:37:00 UTC

[jira] [Updated] (GROOVY-10152) Parrot can't parse closure

     [ https://issues.apache.org/jira/browse/GROOVY-10152?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christopher Smith updated GROOVY-10152:
---------------------------------------
    Description: 
I have this "cleanup" method in an ETL project. The intent is to call a static method returning {{Try<String>}} that attempts to normalize a phone number, then check whether we had an error processing any of them; if so, return a failure, but if success, replace the existing phone numbers with the normalized ones and return the record.

{code:groovy}
    static Try<IdentityRecord> normalizePhones(IdentityRecord record) {
        Map<String, Try<String>> normalized = record.phones.collectEntries { ctx, number ->
            [ctx, PhoneRules.normalize(number)]
        }

        return normalized.entrySet().stream()
            .filter { it.value.failure }
            .findFirst()
            .map { Try.failure(new ValidationException("${it.key}: ${it.value.cause.message}")) }
            .orElseGet {
                record.phones = normalized.collectEntries { ctx, tr -> ctx, tr.value }
                Try.success(record)
            }
    }
{code}

Parrot is giving me a generic parse error on the closure for the {{orElseGet}} call, and I can't figure out why. Commenting out the assignment statement removes the error (but of course prevents the intended modification). Adding {{_ ->}} does not change the error, and neither does inserting semicolons in various places.

{code}
Groovy:Unexpected input: '{'
{code}

Update: It appears that my attempted more-minimal workaround still triggers the problem:

{code:groovy}
    static void groovy10152(IdentityRecord record, Map<String, String> normalized) {
        normalized.collectEntries { ctx, tr -> ctx, tr.value }
    }
{code}

results in the same error at the opening of the closure:

{code}
Groovy:Unexpected input: '{'
{code}

  was:
I have this "cleanup" method in an ETL project. The intent is to call a static method returning {{Try<String>}} that attempts to normalize a phone number, then check whether we had an error processing any of them; if so, return a failure, but if success, replace the existing phone numbers with the normalized ones and return the record.

{code:groovy}
    static Try<IdentityRecord> normalizePhones(IdentityRecord record) {
        Map<String, Try<String>> normalized = record.phones.collectEntries { ctx, number ->
            [ctx, PhoneRules.normalize(number)]
        }

        return normalized.entrySet().stream()
            .filter { it.value.failure }
            .findFirst()
            .map { Try.failure(new ValidationException("${it.key}: ${it.value.cause.message}")) }
            .orElseGet {
                record.phones = normalized.collectEntries { ctx, tr -> ctx, tr.value }
                Try.success(record)
            }
    }
{code}

Parrot is giving me a generic parse error on the closure for the {{orElseGet}} call, and I can't figure out why. Commenting out the assignment statement removes the error (but of course prevents the intended modification). Adding {{_ ->}} does not change the error, and neither does inserting semicolons in various places.

{code}
Groovy:Unexpected input: '{'
{code}


> Parrot can't parse closure
> --------------------------
>
>                 Key: GROOVY-10152
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10152
>             Project: Groovy
>          Issue Type: Bug
>          Components: parser-antlr4
>    Affects Versions: 3.0.8
>            Reporter: Christopher Smith
>            Priority: Major
>
> I have this "cleanup" method in an ETL project. The intent is to call a static method returning {{Try<String>}} that attempts to normalize a phone number, then check whether we had an error processing any of them; if so, return a failure, but if success, replace the existing phone numbers with the normalized ones and return the record.
> {code:groovy}
>     static Try<IdentityRecord> normalizePhones(IdentityRecord record) {
>         Map<String, Try<String>> normalized = record.phones.collectEntries { ctx, number ->
>             [ctx, PhoneRules.normalize(number)]
>         }
>         return normalized.entrySet().stream()
>             .filter { it.value.failure }
>             .findFirst()
>             .map { Try.failure(new ValidationException("${it.key}: ${it.value.cause.message}")) }
>             .orElseGet {
>                 record.phones = normalized.collectEntries { ctx, tr -> ctx, tr.value }
>                 Try.success(record)
>             }
>     }
> {code}
> Parrot is giving me a generic parse error on the closure for the {{orElseGet}} call, and I can't figure out why. Commenting out the assignment statement removes the error (but of course prevents the intended modification). Adding {{_ ->}} does not change the error, and neither does inserting semicolons in various places.
> {code}
> Groovy:Unexpected input: '{'
> {code}
> Update: It appears that my attempted more-minimal workaround still triggers the problem:
> {code:groovy}
>     static void groovy10152(IdentityRecord record, Map<String, String> normalized) {
>         normalized.collectEntries { ctx, tr -> ctx, tr.value }
>     }
> {code}
> results in the same error at the opening of the closure:
> {code}
> Groovy:Unexpected input: '{'
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)