corenova / yang-js

YANG parser and composer
Apache License 2.0
56 stars 18 forks source link

length in a union #102

Closed jcourington closed 5 years ago

jcourington commented 5 years ago

Thank you very much for the quick responses on these issues. My models compile after this issue!

typedef t_A {
  type union {
    type string P
      length 4;
      pattern '[a-fA-F0-9]*';
    }
    type string {
      length 6;
      pattern '[a-fA-F0-9]*';
    }
  }
}

results in

ExpressionError: [submodule()/grouping()/leaf()/type(t_A)/type(string)] constraint violation for 'length' - cannot define more than once
    at Function.Element.error (/home/src/node_modules/yang-js/lib/element.js:60:15)
    at Function.Expression.error (/home/src/node_modules/yang-js/lib/expression.js:191:40)
    at Function.Element.merge (/home/src/node_modules/yang-js/lib/element.js:339:24)
    at Function.Yang.merge (/home/src/node_modules/yang-js/lib/yang.js:352:39)
    at Function.Element.update (/home/src/node_modules/yang-js/lib/element.js:402:21)
    at Function.Expression.update (/home/src/node_modules/yang-js/lib/expression.js:184:41)
    at Function.Element.update (/home/src/node_modules/yang-js/lib/element.js:407:16)
    at Function.Expression.update (/home/srcnode_modules/yang-js/lib/expression.js:184:41)
    at Function.Element.update (/home/src/node_modules/yang-js/lib/element.js:407:16)
    at Function.Expression.update (/home/src/node_modules/yang-js/lib/expression.js:184:41)
sekur commented 5 years ago

Hi @jcourington - unfortunately there isn't a quick fix for this issue due to the way current parser uses the tag to internally cache key lookup mappings.

However, here's a workaround that should satisfy your intended typedef:

typedef alpha-numeric-string {
  type string {
    pattern '[a-fA-F0-9]*';
  }
}
typedef fixed-string-4 {
  type alpha-numeric-string {
    length 4;
  } 
}
typedef fixed-string-6 {
  type alpha-numeric-string {
    length 6;
  }
}
typedef t_A {
  type union {
    type fixed-string-4;
    type fixed-string-6;
  }
}

I'll leave this issue open since we should properly handle the exception case for type that can have multiple duplicate tag values.

jcourington commented 5 years ago

Hi Peter,

I have figured out containers. I see now that there is an array of leafs under a container. I can access everything in my model. I really appreciate your help working through everything.

Let me know if this example could help others...

Thank you,

Jeff


From: Peter K. Lee notifications@github.com Sent: Friday, May 24, 2019 5:44 PM To: corenova/yang-js Cc: jcourington; Mention Subject: Re: [corenova/yang-js] length in a union (#102)

Hi @jcouringtonhttps://github.com/jcourington - unfortunately there isn't a quick fix for this issue due to the way current parser uses the tag to internally cache key lookup mappings.

However, here's a workaround that should satisfy your intended typedef:

typedef alpha-numeric-string { type string { pattern '[a-fA-F0-9]*'; } } typedef fixed-string-4 { type alpha-numeric-string { length 4; } } typedef fixed-string-6 { type alpha-numeric-string { length 6; } } typedef t_A { type union { type fixed-string-4; type fixed-string-6; } }

I'll leave this issue open since we should properly handle the exception case for type that can have multiple duplicate tag values.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/corenova/yang-js/issues/102?email_source=notifications&email_token=ACGGR2TI7EWBTEK3AM6KQHLPXBOSPA5CNFSM4HPOPGR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWGT7YY#issuecomment-495796195, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACGGR2SAA6QU26A7P4S5ZRLPXBOSPANCNFSM4HPOPGRQ.

sekur commented 5 years ago

@jcourington - my initial assessment on this issue was incorrect. I've added testcases for this scenario and it doesn't appear that this is an issue related to tag merge inside typedef. The tag merge constraint only applies to data nodes container, list, leaf, leaf-list.

I suspect something related to parsing with { compile: false } since when we process type we perform implicit compile()... but this is just a guess at this point.

I'll close this issue for now, but please let me know if this issue persists for you.