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 for parsing C++ templates and typedefs for template instantiations. 10 Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert 13 from typing
import List
15 from pyparsing
import Optional, ParseResults, delimitedList
17 from .tokens
import (EQUAL, IDENT, LBRACE, LOPBRACK, RBRACE, ROPBRACK,
18 SEMI_COLON, TEMPLATE, TYPEDEF)
19 from .type
import Typename, TemplatedType
24 Rule to parse templated values in the interface file. 27 template<POSE> // this is the Template. 32 Rule to parse the template parameters. 34 template<typename POSE> // POSE is the Instantiation. 41 + ((delimitedList(TemplatedType.rule ^ Typename.rule)
45 t.typename, t.instantiations))
47 def __init__(self, typename: str, instantiations: ParseResults):
52 for inst
in instantiations:
54 TemplatedType)
else inst
55 self.instantiations.append(x)
60 + delimitedList(TypenameAndInstantiations.rule)(
61 "typename_and_instantiations_list")
64 lambda t:
Template(t.typename_and_instantiations_list.asList()))
68 typename_and_instantiations_list: List[TypenameAndInstantiations]):
69 ti_list = typename_and_instantiations_list
74 return "<{0}>".format(
", ".join(self.
typenames))
79 Rule for parsing typedefs (with templates) within the interface file. 83 typedef SuperComplexName<Arg1, Arg2, Arg3> EasierName; 86 rule = (TYPEDEF + TemplatedType.rule(
"templated_type") +
89 t.templated_type[0], t.new_name))
92 templated_type: TemplatedType,
100 return "Typedef: {new_name} = {typename}".format(
bool isinstance(handle obj)