2 GTSAM Copyright 2010-2020, Georgia Tech Research Corporation, 3 Atlanta, Georgia 30332-0415 6 See LICENSE for the license information 8 Classes and rules to parse a namespace. 10 Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert 15 from typing
import List, Union
17 from pyparsing
import Forward, ParseResults, ZeroOrMore
19 from .classes
import Class, collect_namespaces
20 from .declaration
import ForwardDeclaration, Include
21 from .enum
import Enum
22 from .function
import GlobalFunction
23 from .template
import TypedefTemplateInstantiation
24 from .tokens
import IDENT, LBRACE, NAMESPACE, RBRACE
25 from .type
import Typename
26 from .variable
import Variable
30 str_namespaces: List[
"Namespace"]) -> list:
32 Get the namespaces nested under `namespace`, filtered by a list of namespace strings. 35 namespace: The top-level namespace under which to find sub-namespaces. 36 str_namespaces: The list of namespace strings to filter against. 38 if not str_namespaces:
41 sub_namespaces = (ns
for ns
in namespace.content
45 ns
for ns
in sub_namespaces
if ns.name == str_namespaces[0]
47 if not found_namespaces:
51 for found_namespace
in found_namespaces:
59 """Rule for parsing a namespace in the interface file.""" 67 ForwardDeclaration.rule
70 ^ TypedefTemplateInstantiation.rule
77 ).setParseAction(
lambda t: Namespace.from_parse_result(t))
79 def __init__(self, name: str, content: ZeroOrMore, parent=
''):
88 """Return the result of parsing.""" 90 content = t.content.asList()
96 self, typename: Typename) -> Union[Class, GlobalFunction, ForwardDeclaration]:
98 Find the Class or GlobalFunction object given its typename. 99 We have to traverse the tree of namespaces. 103 for namespace
in found_namespaces:
104 classes_and_funcs = (c
for c
in namespace.content
105 if isinstance(c, (Class, GlobalFunction, ForwardDeclaration)))
106 res += [c
for c
in classes_and_funcs
if c.name == typename.name]
108 raise ValueError(
"Cannot find class {} in module!".
format(
112 "Found more than one classes {} in module!".
format(
118 """Return the top level namespace.""" 128 """Get the full namespace list.""" 131 ancestors.append(self.
name)
bool isinstance(handle obj)
def find_class_or_function
def collect_namespaces(obj)
def full_namespaces(self)
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
size_t len(handle h)
Get the length of a Python object.