TypeFox / yang-lsp

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

BinaryOperation serialize is not correct. #151

Closed huyuwen closed 4 years ago

huyuwen commented 5 years ago

We loaded a simple module first.

module ma {
    yang-version 1.1;
    prefix ma;
    description "Test";
        container c1 {
             leaf l1 {
                 type string;
             }
        }
}

Now we try to add length statement to l1's type by using code.

        Type strType = ... // Get from leaf node...
    Literal start = YangFactory.eINSTANCE.createLiteral();
    start.setValue("1");
    Literal end = YangFactory.eINSTANCE.createLiteral();
    end.setValue("255");
    BinaryOperation bopt = YangFactory.eINSTANCE.createBinaryOperation();
    bopt.setOperator("..");
    bopt.setLeft(start);
    bopt.setRight(end);
    Length length = YangFactory.eINSTANCE.createLength();
    length.setExpression(bopt);
    strType.getSubstatements().add(length);

When we get the serialization result, it looks like the following format.

...
        type string {
               length 1 .. 255;
        }
...

This kind of format of length is not accept by pyang. So we think the valid serlization result should be one of the two followings.

  1. length 1..255 // There has no space between left_value, operator and right_value
  2. length '1 .. 255' // Or use qoute to wrapp the whole expression of length, or similar statement.
huyuwen commented 5 years ago

Maybe here is the code, where the space comes from. https://github.com/theia-ide/yang-lsp/blob/306fcd791c8234a9eddd1811682367a69ad07ab2/yang-lsp/io.typefox.yang/src/main/java/io/typefox/yang/formatting2/YangFormatter.xtend#L557