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 pyparsing import Optional, ParseResults
14 
15 from .tokens import DEFAULT_ARG, EQUAL, IDENT, SEMI_COLON, STATIC
16 from .type import TemplatedType, Type
17 
18 
19 class Variable:
20  """
21  Rule to parse variables.
22  Variables are a combination of Type/TemplatedType and the variable identifier.
23 
24  E.g.
25  ```
26  class Hello {
27  string name; // This is a property variable.
28  };
29 
30  Vector3 kGravity; // This is a global variable.
31  ````
32  """
33  rule = ((Type.rule ^ TemplatedType.rule)("ctype") #
34  + IDENT("name") #
35  #TODO(Varun) Add support for non-basic types
36  + Optional(EQUAL + (DEFAULT_ARG))("default") #
37  + SEMI_COLON #
38  ).setParseAction(lambda t: Variable(t.ctype, t.name, t.default))
39 
40  def __init__(self,
41  ctype: Type,
42  name: str,
43  default: ParseResults = None,
44  parent=''):
45  self.ctype = ctype[0] # ParseResult is a list
46  self.name = name
47  if default:
48  self.default = default[0]
49  else:
50  self.default = None
51 
52  self.parent = parent
53 
54  def __repr__(self) -> str:
55  return '{} {}'.format(self.ctype.__repr__(), self.name)


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