Christopher Smith created GROOVY-10152:
------------------------------------------

             Summary: 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


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}



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

Reply via email to