IHTSDO / snomed-expression-constraint-language

Formal syntax and valid examples for each version of ECL
http://snomed.org/ecl
Other
3 stars 3 forks source link

Possible unreachable conjunction / disjunction refinement rules in the ANTLR grammar? #5

Closed martingall87 closed 1 year ago

martingall87 commented 1 year ago

Hi,

I've been investigating the SNOMED ECL ANTLR grammar for use with a language other than Java. Whilst experimenting with the ANTLR tooling, I've observed that the following rules may not be reachable in the grammar:

Link to rules

The subrefinement rule appears to be greedy in the eclrefinement rule they are used in. All conjunction / disjunction combinations I've tried seem to just use the conjunctionattributeset/disjunctionattributeset rules.

Example below using the latest ANTLR grammar in ANTLR Lab:

ECL:

<  404684003 |Clinical finding| :
          363698007 |Finding site|  = <<  39057004 |Pulmonary valve structure|  AND
          116676008 |Associated morphology|  = <<  415582006 |Stenosis|  AND
          42752001 |Due to|  = <<  445238008 |Malignant carcinoid tumor|

Parse Hierarchy:

image

Are there scenarios that do use these two rules or could the grammar be simplified?

martingall87 commented 1 year ago

Also similar situation with the following rule:

subRefinement = eclAttributeSet / eclAttributeGroup / "(" ws eclRefinement ws ")"

the "(" ws eclRefinement ws ")" component of the rule does not seem to be used because the eclattributeset rule is greedy.

For example:

ECL:

<  19829001 |Disorder of lung| :
         (116676008 |Associated morphology|  =  79654002 |Edema|)

Parse Hierarchy:

image
kaicode commented 1 year ago

Hi @martingall87, thanks for the question. The conjunctionrefinementset and disjunctionrefinementset elements are only needed when using conjunction or disjunction with attribute groups, these use curly braces { }.

For example:

* : * = *, { * = * }

Or something like:

< 131148009 |Bleeding (finding)| : 
     { 363698007 |Finding site (attribute)| = << 422897007 |Vascular structure of stomach (body structure)|, 
       116676008 |Associated morphology (attribute)| = 50960005 |Hemorrhage (morphologic abnormality)| },
      42752001 |Due to (attribute)| = << 312131008 |Viral infection of the digestive tract (disorder)|

If no attribute groups are needed then I think you are correct that the conjunctionrefinementset element will not be used.

I hope that helps. See ECL Guide Attribute Groups

martingall87 commented 1 year ago

Thank you so much for your reply @kaicode. Apologies I completely missed the dependency on the Attribute Groups so that makes sense!

kaicode commented 1 year ago

No worries at all, I'm glad you asked. It was good to check! Cheers.