variable.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 classes and rules for parsing C++ variables.
9 
10 Author: Varun Agrawal, Gerry Chen
11 """
12 
13 from typing import List
14 
15 from pyparsing import Optional, ParseResults # type: ignore
16 
17 from .tokens import DEFAULT_ARG, EQUAL, IDENT, SEMI_COLON
18 from .type import TemplatedType, Type
19 
20 
21 class Variable:
22  """
23  Rule to parse variables.
24  Variables are a combination of Type/TemplatedType and the variable identifier.
25 
26  E.g.
27  ```
28  class Hello {
29  string name; // This is a property variable.
30  };
31 
32  Vector3 kGravity; // This is a global variable.
33  ````
34  """
35  rule = ((Type.rule ^ TemplatedType.rule)("ctype") #
36  + IDENT("name") #
37  + Optional(EQUAL + DEFAULT_ARG)("default") #
38  + SEMI_COLON #
39  ).setParseAction(lambda t: Variable(
40  t.ctype, #
41  t.name, #
42  t.default[0] if isinstance(t.default, ParseResults) else None))
43 
44  def __init__(self,
45  ctype: List[Type],
46  name: str,
47  default: ParseResults = None,
48  parent=''):
49  self.ctype = ctype[0] # ParseResult is a list
50  self.name = name
51  self.default = default
52  self.parent = parent
53 
54  def __repr__(self) -> str:
55  return '{} {}'.format(self.ctype.__repr__(), self.name)
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.variable.Variable.parent
parent
Definition: variable.py:48
gtwrap.interface_parser.variable.Variable.__repr__
str __repr__(self)
Definition: variable.py:54
gtwrap.interface_parser.variable.Variable
Definition: variable.py:21
gtwrap.interface_parser.variable.Variable.default
default
Definition: variable.py:47
gtwrap.interface_parser.tokens.IDENT
IDENT
Definition: tokens.py:19
isinstance
bool isinstance(handle obj)
Definition: pytypes.h:842
gtwrap.interface_parser.variable.Variable.ctype
ctype
Definition: variable.py:45
gtwrap.interface_parser.variable.Variable.name
name
Definition: variable.py:46
gtwrap.interface_parser.variable.Variable.__init__
def __init__(self, List[Type] ctype, str name, ParseResults default=None, parent='')
Definition: variable.py:44


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:18:23