From cb30c64aada718c479791468f8babbcd3576cbf5 Mon Sep 17 00:00:00 2001 From: sai-neetha Date: Wed, 20 Mar 2024 15:55:54 +0100 Subject: ODLUX Update ODLUX Update Issue-ID: CCSDK-3999 Change-Id: I6f95cd65cabe08b27a1ff71eacb7c57aa318c376 Signed-off-by: sai-neetha (cherry picked from commit 5418ff6a08cd2482cf76aed8def6592623253229) Signed-off-by: sai-neetha --- .../apps/configurationApp/src/yang/whenParser.ts | 58 +++++++++++++++++++++- .../apps/configurationApp/src/yang/yangParser.ts | 20 ++++---- 2 files changed, 67 insertions(+), 11 deletions(-) (limited to 'sdnr/wt/odlux/apps/configurationApp/src/yang') diff --git a/sdnr/wt/odlux/apps/configurationApp/src/yang/whenParser.ts b/sdnr/wt/odlux/apps/configurationApp/src/yang/whenParser.ts index fa2968c9c..4956b13a9 100644 --- a/sdnr/wt/odlux/apps/configurationApp/src/yang/whenParser.ts +++ b/sdnr/wt/odlux/apps/configurationApp/src/yang/whenParser.ts @@ -3,6 +3,7 @@ enum WhenTokenType { OR = 'OR', NOT = 'NOT', EQUALS = 'EQUALS', + NOT_EQUALS = 'NOT_EQUALS', COMMA = 'COMMA', STRING = 'STRING', FUNCTION = 'FUNCTION', @@ -17,9 +18,31 @@ type Token = { value: string; }; -const isAlpha = (char: string) => /[a-z]/i.test(char); +const isAlpha = (char: string) => { + if (!char) return false; + const code = char.charCodeAt(0); + return (code >= 65 && code <= 90) || (code >= 97 && code <= 122); +}; + +const isAlphaNumeric = (char: string) => { + if (!char) return false; + const code = char.charCodeAt(0); + return ( + isAlpha(char) || + (code >= 48 && code <= 57) || + code === 95 || // underscore + code === 45 || // hyphen + code === 47 || // slash + code === 58 || // colon + code === 46 // dot + ); +}; -const isAlphaNumeric = (char: string) => /[A-Za-z0-9_\-/:\.]/i.test(char); +const isOperator = (char: string) => { + if (!char) return false; + const code = char.charCodeAt(0); + return code === 33 || code === 38 || code === 124 || code === 61; +}; const lex = (input: string) : Token[] => { let tokens = [] as any[]; @@ -110,6 +133,7 @@ const lex = (input: string) : Token[] => { continue; } + if (isAlphaNumeric(char)) { let value = ''; while (isAlphaNumeric(char)) { @@ -120,6 +144,36 @@ const lex = (input: string) : Token[] => { tokens.push({ type: WhenTokenType.IDENTIFIER, value }); continue; } + + if (isOperator(char)) { + let value = ''; + while (isOperator(char)) { + value += char; + char = input[++current]; + } + + switch (value) { + case '&&': + tokens.push({ type: WhenTokenType.AND }); + break; + case '||': + tokens.push({ type: WhenTokenType.OR }); + break; + case '!': + tokens.push({ type: WhenTokenType.NOT }); + break; + case '==': + tokens.push({ type: WhenTokenType.EQUALS }); + break; + case '!=': + tokens.push({ type: WhenTokenType.NOT_EQUALS }); + break; + default: + throw new TypeError(`I don't know what this operator is: ${value}`); + } + continue; + } + throw new TypeError(`I don't know what this character is: ${char}`); } return tokens; diff --git a/sdnr/wt/odlux/apps/configurationApp/src/yang/yangParser.ts b/sdnr/wt/odlux/apps/configurationApp/src/yang/yangParser.ts index 85eeb41a4..14e3468ac 100644 --- a/sdnr/wt/odlux/apps/configurationApp/src/yang/yangParser.ts +++ b/sdnr/wt/odlux/apps/configurationApp/src/yang/yangParser.ts @@ -491,7 +491,12 @@ export class YangParser { } public postProcess() { - + // process all type refs + this._typeRefToResolve.forEach(cb => { + try { cb(); } catch (error) { + console.warn(error.message); + } + }); /** * This is to fix the issue for sequential execution of modules based on their child and parent relationship * We are sorting the module object based on their augment status @@ -580,7 +585,7 @@ export class YangParser { const identity = module.identities[idKey]; if (identity.base != null) { const base = this.resolveIdentity(identity.base, module); - base.children?.push(identity); + base?.children?.push(identity); } else { baseIdentities.push(identity); } @@ -596,12 +601,6 @@ export class YangParser { } }); - this._typeRefToResolve.forEach(cb => { - try { cb(); } catch (error) { - console.warn(error.message); - } - }); - this._modulesToResolve.forEach(cb => { try { cb(); } catch (error) { console.warn(error.message); @@ -622,8 +621,11 @@ export class YangParser { } }); + const knownViews: ViewSpecification[] = []; // resolve readOnly const resolveReadOnly = (view: ViewSpecification, parentConfig: boolean) => { + if (knownViews.includes(view)) return; + knownViews.push(view); // update view config view.config = view.config && parentConfig; @@ -1622,4 +1624,4 @@ export class YangParser { : module.identities[identityName]; } -} \ No newline at end of file +} -- cgit 1.2.3-korg