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)
bool isinstance(handle obj)
Definition: pytypes.h:700
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:40:43