From 10a674fe1d1a2ca1918b1f80c48ca94592821aa7 Mon Sep 17 00:00:00 2001 From: Jellyfrog Date: Thu, 22 Jan 2026 00:01:10 +0100 Subject: [PATCH] fix: tolerate lowercase type identifiers in SEQUENCE OF Add relaxed grammar option to handle MIB files that incorrectly use lowercase type identifiers in SEQUENCE OF declarations. Co-Authored-By: Claude Opus 4.5 --- pysmi/lexer/smi.py | 1 + pysmi/parser/dialect.py | 1 + pysmi/parser/smi.py | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/pysmi/lexer/smi.py b/pysmi/lexer/smi.py index 43455db..5fee7f6 100644 --- a/pysmi/lexer/smi.py +++ b/pysmi/lexer/smi.py @@ -534,6 +534,7 @@ def tokens(): "lowcaseIdentifier": [], "curlyBracesAroundEnterpriseInTrap": [], "noCells": [], + "lowcaseTypeIdentifier": [], } diff --git a/pysmi/parser/dialect.py b/pysmi/parser/dialect.py index cd7b7e6..650b9db 100644 --- a/pysmi/parser/dialect.py +++ b/pysmi/parser/dialect.py @@ -26,6 +26,7 @@ lowcaseIdentifier=True, curlyBracesAroundEnterpriseInTrap=True, noCells=True, + lowcaseTypeIdentifier=True, ) # Compatibility API diff --git a/pysmi/parser/smi.py b/pysmi/parser/smi.py index 5ae4273..5754afe 100644 --- a/pysmi/parser/smi.py +++ b/pysmi/parser/smi.py @@ -1420,6 +1420,15 @@ def p_CreationPart(self, p): p[0] = (p[1], p[3]) +# noinspection PyIncorrectDocstring +class LowcaseTypeIdentifier: + # common mistake - lowercase type identifier in SEQUENCE OF + @staticmethod + def p_row(self, p): + """row : fuzzy_lowercase_identifier""" + p[0] = ('row', p[1]) + + relaxedGrammar = { "supportSmiV1Keywords": [ SupportSmiV1Keywords.p_importedKeyword, @@ -1438,6 +1447,7 @@ def p_CreationPart(self, p): CurlyBracesInEnterprises.p_EnterprisePart, ], "noCells": [NoCells.p_CreationPart], + "lowcaseTypeIdentifier": [LowcaseTypeIdentifier.p_row], } @@ -1464,6 +1474,7 @@ def parserFactory(**grammarOptions): * lowcaseIdentifier - tolerate lowercase MIB identifiers * curlyBracesAroundEnterpriseInTrap - tolerate curly braces around enterprise ID in TRAP MACRO * noCells - tolerate missing cells (XXX) + * lowcaseTypeIdentifier - tolerate lowercase type identifiers in SEQUENCE OF Examples: