Fix array extent parsing logic for introspect.
Also fix the mjxmacro_test to correctly assert that all array extents defined in the X macros can be correctly parsed from field comments. PiperOrigin-RevId: 747808525 Change-Id: I0b08dc263f8a46118a07200ae044d6c491207245
This commit is contained in:
committed by
Copybara-Service
parent
ec186430ef
commit
71a7004057
@@ -47,7 +47,7 @@ _EXCLUDED = (
|
||||
'mjResource_',
|
||||
)
|
||||
|
||||
_ARRAY_COMMENT_PATTERN = re.compile(r'(.+?)\s\s+\((.+) x (.+)\)\Z')
|
||||
_ARRAY_COMMENT_PATTERN = re.compile(r'(.+?)\s+\(([^\(\)]+) x ([^\(\)]+)\)\Z')
|
||||
|
||||
|
||||
def traverse(node, visitor):
|
||||
@@ -93,16 +93,19 @@ class MjStructVisitor:
|
||||
# No valid normalization, just parse the declname.
|
||||
return type_parsing.parse_type(declname)
|
||||
|
||||
def _make_comment(self, node: ClangJsonNode) -> str:
|
||||
def _make_comment(self, node: ClangJsonNode, strip: bool = True) -> str:
|
||||
"""Makes a comment string from a Clang AST FullComment node."""
|
||||
kind = node.get('kind')
|
||||
if kind == 'TextComment':
|
||||
return node['text'].replace('\N{NO-BREAK SPACE}', ' ').strip()
|
||||
retval = node['text'].replace('\N{NO-BREAK SPACE}', ' ')
|
||||
else:
|
||||
strings = []
|
||||
for child in node['inner']:
|
||||
strings.append(self._make_comment(child))
|
||||
return ''.join(strings).strip()
|
||||
strings.append(self._make_comment(child, strip=False))
|
||||
retval = ''.join(strings)
|
||||
if strip:
|
||||
retval = retval.strip()
|
||||
return retval
|
||||
|
||||
def _make_field(
|
||||
self, node: ClangJsonNode
|
||||
|
||||
Reference in New Issue
Block a user