FHIR Chat · Grammar question · cql

Stream: cql

Topic: Grammar question


view this post on Zulip Frank Adrian (Nov 07 2020 at 11:05):

In the .g4 grammar for CQL, the library statement's identifier is required to be a qualified identifier production and the ANTLR parser built from this grammar seems to accept a qualified identifier of the form X.Y.Z.libraryName. However, there are no examples in the CQL spec where the library name is shown to be anything other than a simple identifier and when I try to use a qualified identifier in language processors presumably built on this syntax, a syntax error is thrown when one tries to use a qualified identifier in this context. Why is a qualified identifier production specified instead of a library identifier or a simple identifier production in the grammar, if the end result is an error message anyway?

view this post on Zulip Bryn Rhodes (Nov 11 2020 at 00:59):

Hi @Frank Adrian, qualified library identifiers were introduced in CQL 1.3 to support namespacing, but the environment that's translating the CQL has to provide the namespace information (because you can't declare it in a CQL library, it's necessarily outside the CQL. It shouldn't give you an error though, can you give some more details on what error you are seeing?

view this post on Zulip Frank Adrian (Nov 11 2020 at 01:33):

What I'm seeing is an inconsistency in the documentation and the .g4
grammar.
The ANTLR grammar defines the libraryDefinition as:
libraryDefinition
: 'library' qualifiedIdentifier ('version' versionSpecifier)?
;
However, if you actually use a qualifiedIdentifier like
AQualifier.MyLibName in this context, the compiler throws an error
(Something about a syntax error at the "." which makes sense as there is no
valid semantic meaning for a library name that is qualified as the main
library name in the library declaration proper). This check seems to be
done somewhere in the semantic checking for the CQL compiler. My question
is whether or not this is the proper type of identifier production to be
used in this context in the grammar. The unqualified libraryIdentifier
production would work as well in this particular context and be clearer as
to what is accepted legally in the language. I might be missing some
semantic meaning of a library statement like "library AQualifier.MyLibrary
version '2'", but I don't think so as there are no examples like this in
the CQL standard and it's prohibited by something in the compiler anyway.
So what was the rationale behind using a qualifiedIdentifier in this
context rather than an unqualified libraryIdentifier? The code seems to go
through more work to limit the identifier in this context and,
grammar-wise, it's misleading at best.


Last updated: Apr 12 2022 at 19:14 UTC