aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/apps/configurationApp/src/yang
diff options
context:
space:
mode:
authorsai-neetha <sai-neetha.phulmali@highstreet-technologies.com>2024-03-20 15:55:54 +0100
committersai-neetha <sai-neetha.phulmali@highstreet-technologies.com>2024-03-21 13:02:37 +0100
commitcb30c64aada718c479791468f8babbcd3576cbf5 (patch)
tree7e74b1249086589fedc4d71f00ded65f5e5fd56b /sdnr/wt/odlux/apps/configurationApp/src/yang
parent907af9b57aa0db3ace5dc8fdaef9fb84c1392ec9 (diff)
ODLUX Update
ODLUX Update Issue-ID: CCSDK-3999 Change-Id: I6f95cd65cabe08b27a1ff71eacb7c57aa318c376 Signed-off-by: sai-neetha <sai-neetha.phulmali@highstreet-technologies.com> (cherry picked from commit 5418ff6a08cd2482cf76aed8def6592623253229) Signed-off-by: sai-neetha <sai-neetha.phulmali@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/odlux/apps/configurationApp/src/yang')
-rw-r--r--sdnr/wt/odlux/apps/configurationApp/src/yang/whenParser.ts58
-rw-r--r--sdnr/wt/odlux/apps/configurationApp/src/yang/yangParser.ts20
2 files changed, 67 insertions, 11 deletions
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
+}