TypeFox / yang-lsp

A Language Server for YANG
http://www.yang-central.org
Apache License 2.0
51 stars 13 forks source link

Multiple list keys serializes without enclosing quotes #202

Closed andreasjakobik closed 3 years ago

andreasjakobik commented 3 years ago

Hello,

When creating multiple keys to a list and then serialize to a file, the key names should be enclosed in quotes for statement to be syntactically correct.

Here is result from serialization:

       list a11 {
            key first-name last-name state mocy-ref;
        }

Pyang complains on above: unterminated statement definition for keyword "key"

Expectation is:

       list a11 {
            key "first-name last-name state mocy-ref";
        }

(Or single quotes should be fine too.)

The keys are created programatically using the following snippet of code:

            var Key key = substatementsOfType(Key)?.head
            if (key === null) {
                key = YangFactory.eINSTANCE.createKey();
                substatements.add(0, key)
            }
            for (Leaf keyLeaf : validKeyLeafs) {
                if (key.references?.filter[node == keyLeaf].nullOrEmpty) {
                    val KeyReference keyRef = YangFactory.eINSTANCE.createKeyReference();
                    keyRef.setNode(keyLeaf);
                    key.getReferences().add(keyRef);
                } else {
                    LOGGER.warn(keyLeaf.name + " is key of " + it.name + " already, skip add key")
                }
            }

Thanks, Andreas

dhuebner commented 3 years ago

Fixed in master