Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chip-repl tests: xml parsing to report location of where unrecognized handlers reside #24674

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions scripts/py_matter_idl/matter_idl/zapxml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
import logging
import typing
import xml.sax.handler

from dataclasses import dataclass
from typing import Optional, Union, List
from typing import List, Optional, Union

from matter_idl.zapxml.handlers import Context, ZapXmlHandler
from matter_idl.matter_idl_types import Idl
from matter_idl.zapxml.handlers import Context, ZapXmlHandler


class ParseHandler(xml.sax.handler.ContentHandler):
Expand Down Expand Up @@ -50,6 +49,8 @@ def PrepareParsing(self, filename):
if self._include_meta_data:
self._idl.parse_file_name = filename

self._context.file_name = filename

def Finish(self) -> Idl:
self._context.PostProcess(self._idl)
return self._idl
Expand Down
18 changes: 17 additions & 1 deletion scripts/py_matter_idl/matter_idl/zapxml/handlers/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Context:
def __init__(self, locator: Optional[xml.sax.xmlreader.Locator] = None):
self.path = ProcessingPath()
self.locator = locator
self.file_name = None
self._not_handled = set()
self._idl_post_processors = []

Expand All @@ -93,6 +94,15 @@ def GetCurrentLocationMeta(self) -> ParseMetaData:

return ParseMetaData(line=self.locator.getLineNumber(), column=self.locator.getColumnNumber())

def ParseLogLocation(self) -> Optional[str]:
if not self.file_name:
return None
meta = self.GetCurrentLocationMeta()
if not meta:
return None

return f"{self.file_name}:{meta.line}:{meta.column}"

def GetGlobalAttribute(self, code):
if code in self._global_attributes:
return self._global_attributes[code]
Expand All @@ -112,7 +122,13 @@ def AddGlobalAttribute(self, attribute: Attribute):
def MarkTagNotHandled(self):
path = str(self.path)
if path not in self._not_handled:
logging.warning("TAG %s was not handled/recognized" % path)
msg = "TAG %s was not handled/recognized" % path

where = self.ParseLogLocation()
if where:
msg = msg + " at " + where

logging.warning(msg)
self._not_handled.add(path)

def AddIdlPostProcessor(self, processor: IdlPostProcessor):
Expand Down