Stream: fhirpath
Topic: contains keyword in the FHIRPath grammar
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?
Grahame Grieve (May 23 2018 at 17:22):
it's certainly valid because contains is an element in the ValueSet resource
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"
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
Grahame Grieve (May 23 2018 at 19:35):
(as in, the FHIRPath spec is wrong)
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?
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
Grahame Grieve (May 23 2018 at 22:20):
we don't publish a list of words...
Bryn Rhodes (May 23 2018 at 22:22):
True, we don't have a list of keywords, and we should, there are several:
Bryn Rhodes (May 23 2018 at 22:22):
But they are defined as such in the grammar.
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.)
Bryn Rhodes (May 23 2018 at 22:26):
If the implementations don't do this though, then I agree, the spec is wrong
Grahame Grieve (May 23 2018 at 22:27):
well, the spec doesn't put "" around them in the examples.
Grahame Grieve (May 23 2018 at 22:27):
and I don't see why we should unless there's actual ambiguity.
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.
Grahame Grieve (May 23 2018 at 22:30):
well, can we fix the grammar then?
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.
Bryn Rhodes (May 23 2018 at 22:31):
Worst case, yes, we can add all the keywords to the identifier rule.
Grahame Grieve (May 23 2018 at 22:32):
ok great.
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