FHIR Chat · contains keyword in the FHIRPath grammar · fhirpath

Stream: fhirpath

Topic: contains keyword in the FHIRPath grammar


view this post on Zulip Steve Munini (May 23 2018 at 15:16):

I'm using the FHIRPath grammar from http://hl7.org/fhirpath/2018May/grammar.html, and working with the SearchParameter FHIRPath expressions in search-parameters.xml. They are working great except for this one:

ValueSet.expansion.contains.code

I'm getting this error using Antlr 4.3, generating Java:

line 1:19 no viable alternative at input 'contains'

If I remove the following line from the grammar, it works just fine. I don't think that "contains" is used in any SearchParameter FHIR expressions:

    | expression ('in' | 'contains') expression                 #membershipExpression

The problem appears to be with the keyword "contains" in the FHIRPath expression.

Has anyone else run into this problem with the grammar?

view this post on Zulip Grahame Grieve (May 23 2018 at 17:22):

it's certainly valid because contains is an element in the ValueSet resource

view this post on Zulip Bryn Rhodes (May 23 2018 at 19:32):

If the model has an element that is named the same as a keyword in the language, use a quoted identifier to access the element, so "contains"

view this post on Zulip Grahame Grieve (May 23 2018 at 19:34):

This was something we did not appreciate when we wrote the spec, and it's currently wrong if you're correct. But I don't think you are. field.contains is not ambiguous

view this post on Zulip Grahame Grieve (May 23 2018 at 19:35):

(as in, the FHIRPath spec is wrong)

view this post on Zulip Bryn Rhodes (May 23 2018 at 22:19):

Not sure I'm following. Are you saying the spec is wrong for having contains as a keyword?

view this post on Zulip Grahame Grieve (May 23 2018 at 22:20):

well, no, but if having that means you can't use xx.contains, then some examples are wrong. And I don't know whether I would have agreed to symbols containing words if I realised that was the case

view this post on Zulip Grahame Grieve (May 23 2018 at 22:20):

we don't publish a list of words...

view this post on Zulip Bryn Rhodes (May 23 2018 at 22:22):

True, we don't have a list of keywords, and we should, there are several:

view this post on Zulip Bryn Rhodes (May 23 2018 at 22:22):

But they are defined as such in the grammar.

view this post on Zulip Bryn Rhodes (May 23 2018 at 22:25):

div, mod, is, as, in, contains, and, or, xor, implies, and the date/time precision keywords (year, month, day, etc.)

view this post on Zulip Bryn Rhodes (May 23 2018 at 22:26):

If the implementations don't do this though, then I agree, the spec is wrong

view this post on Zulip Grahame Grieve (May 23 2018 at 22:27):

well, the spec doesn't put "" around them in the examples.

view this post on Zulip Grahame Grieve (May 23 2018 at 22:27):

and I don't see why we should unless there's actual ambiguity.

view this post on Zulip Bryn Rhodes (May 23 2018 at 22:29):

I agree, and I also agree that xx.contains isn't ambiguous, it couldn't possibly be a keyword because it's clearly part of a path. I think the Antlr parser chokes on this though, and as far as I've been able to determine, the workaround is to put the keywords in the indentifier rule. We've already actually done this with is and as, for example.

view this post on Zulip Grahame Grieve (May 23 2018 at 22:30):

well, can we fix the grammar then?

view this post on Zulip Bryn Rhodes (May 23 2018 at 22:31):

I'll take a look and see if i can figure out a better way to convince Antlr it's not ambiguous.

view this post on Zulip Bryn Rhodes (May 23 2018 at 22:31):

Worst case, yes, we can add all the keywords to the identifier rule.

view this post on Zulip Grahame Grieve (May 23 2018 at 22:32):

ok great.

view this post on Zulip Steve Munini (May 24 2018 at 01:18):

Thanks Bryn and Grahame for looking into this.


Last updated: Apr 12 2022 at 19:14 UTC