enum.py
Go to the documentation of this file.
1 """
2 GTSAM Copyright 2010-2020, Georgia Tech Research Corporation,
3 Atlanta, Georgia 30332-0415
4 All Rights Reserved
5 
6 See LICENSE for the license information
7 
8 Parser class and rules for parsing C++ enums.
9 
10 Author: Varun Agrawal
11 """
12 
13 from pyparsing import delimitedList # type: ignore
14 
15 from .tokens import ENUM, IDENT, LBRACE, RBRACE, SEMI_COLON
16 from .type import Typename
17 from .utils import collect_namespaces
18 
19 
20 class Enumerator:
21  """
22  Rule to parse an enumerator inside an enum.
23  """
24  rule = (
25  IDENT("enumerator")).setParseAction(lambda t: Enumerator(t.enumerator))
26 
27  def __init__(self, name):
28  self.name = name
29 
30  def __repr__(self):
31  return "Enumerator: ({0})".format(self.name)
32 
33 
34 class Enum:
35  """
36  Rule to parse enums defined in the interface file.
37 
38  E.g.
39  ```
40  enum Kind {
41  Dog,
42  Cat
43  };
44  ```
45  """
46 
47  rule = (ENUM + IDENT("name") + LBRACE +
48  delimitedList(Enumerator.rule)("enumerators") + RBRACE +
49  SEMI_COLON).setParseAction(lambda t: Enum(t.name, t.enumerators))
50 
51  def __init__(self, name, enumerators, parent=''):
52  self.name = name
53  self.enumerators = enumerators
54  self.parent = parent
55 
56  def namespaces(self) -> list:
57  """Get the namespaces which this class is nested under as a list."""
58  return collect_namespaces(self)
59 
60  def cpp_typename(self):
61  """
62  Return a Typename with the namespaces and cpp name of this
63  class.
64  """
65  namespaces_name = self.namespaces()
66  namespaces_name.append(self.name)
67  return Typename(namespaces_name)
68 
69  def __repr__(self):
70  return "Enum: {0}".format(self.name)
gtwrap.interface_parser.enum.Enum.namespaces
list namespaces(self)
Definition: enum.py:56
format
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
Definition: openglsupport.cpp:226
gtwrap.interface_parser.enum.Enumerator.__init__
def __init__(self, name)
Definition: enum.py:27
gtwrap.interface_parser.type.Typename
Definition: type.py:24
gtwrap.interface_parser.tokens.IDENT
IDENT
Definition: tokens.py:19
gtwrap.interface_parser.utils.collect_namespaces
def collect_namespaces(obj)
Definition: utils.py:14
gtwrap.interface_parser.enum.Enumerator.__repr__
def __repr__(self)
Definition: enum.py:30
gtwrap.interface_parser.enum.Enum.parent
parent
Definition: enum.py:54
gtwrap.interface_parser.enum.Enum.__init__
def __init__(self, name, enumerators, parent='')
Definition: enum.py:51
gtwrap.interface_parser.enum.Enum
Definition: enum.py:34
gtwrap.interface_parser.enum.Enumerator
Definition: enum.py:20
gtwrap.interface_parser.enum.Enum.name
name
Definition: enum.py:52
gtwrap.interface_parser.enum.Enum.enumerators
enumerators
Definition: enum.py:53
gtwrap.interface_parser.enum.Enum.__repr__
def __repr__(self)
Definition: enum.py:69
gtwrap.interface_parser.enum.Enumerator.name
name
Definition: enum.py:28
gtwrap.interface_parser.enum.Enum.cpp_typename
def cpp_typename(self)
Definition: enum.py:60


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:29