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
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)
def __init__(self, name, enumerators, parent='')
Definition: enum.py:51


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:02