Skip to content

Commit

Permalink
chip-repl tests: xml parsing to report location of where unrecognized…
Browse files Browse the repository at this point in the history
… handlers reside (#24674)

* Report location of where unrecognized handlers reside

* Restyle
  • Loading branch information
andy31415 authored and pull[bot] committed Nov 15, 2023
1 parent 2f5dafd commit 055bbb4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
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

0 comments on commit 055bbb4

Please sign in to comment.