tokens.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 All the token definitions.
9 
10 Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert
11 """
12 
13 from pyparsing import Or # type: ignore
14 from pyparsing import (Keyword, Literal, OneOrMore, QuotedString, Suppress,
15  Word, alphanums, alphas, nestedExpr, nums,
16  originalTextFor, printables)
17 
18 # rule for identifiers (e.g. variable names)
19 IDENT = Word(alphas + '_', alphanums + '_') ^ Word(nums)
20 
21 RAW_POINTER, SHARED_POINTER, REF = map(Literal, "@*&")
22 
23 LPAREN, RPAREN, LBRACE, RBRACE, COLON, SEMI_COLON = map(Suppress, "(){}:;")
24 LOPBRACK, ROPBRACK, COMMA, EQUAL = map(Suppress, "<>,=")
25 
26 # Default argument passed to functions/methods.
27 # Allow anything up to ',' or ';' except when they
28 # appear inside matched expressions such as
29 # (a, b) {c, b} "hello, world", templates, initializer lists, etc.
30 DEFAULT_ARG = originalTextFor(
31  OneOrMore(
32  QuotedString('"') ^ # parse double quoted strings
33  QuotedString("'") ^ # parse single quoted strings
34  Word(printables, excludeChars="(){}[]<>,;") ^ # parse arbitrary words
35  nestedExpr(opener='(', closer=')') ^ # parse expression in parentheses
36  nestedExpr(opener='[', closer=']') ^ # parse expression in brackets
37  nestedExpr(opener='{', closer='}') ^ # parse expression in braces
38  nestedExpr(opener='<', closer='>') # parse template expressions
39  ))
40 
41 CONST, VIRTUAL, CLASS, STATIC, PAIR, TEMPLATE, TYPEDEF, INCLUDE = map(
42  Keyword,
43  [
44  "const",
45  "virtual",
46  "class",
47  "static",
48  "pair",
49  "template",
50  "typedef",
51  "#include",
52  ],
53 )
54 ENUM = Keyword("enum") ^ Keyword("enum class") ^ Keyword("enum struct")
55 NAMESPACE = Keyword("namespace")
56 BASIC_TYPES = map(
57  Keyword,
58  [
59  "void",
60  "bool",
61  "unsigned char",
62  "char",
63  "int",
64  "size_t",
65  "double",
66  "float",
67  ],
68 )
69 
70 OPERATOR = Or(
71  map(
72  Literal,
73  [
74  '+', # __add__, __pos__
75  '-', # __sub__, __neg__
76  '*', # __mul__
77  '/', # __truediv__
78  '%', # __mod__
79  '^', # __xor__
80  '&', # __and__
81  '|', # __or__
82  # '~', # __invert__
83  '+=', # __iadd__
84  '-=', # __isub__
85  '*=', # __imul__
86  '/=', # __itruediv__
87  '%=', # __imod__
88  '^=', # __ixor__
89  '&=', # __iand__
90  '|=', # __ior__
91  '<<', # __lshift__
92  '<<=', # __ilshift__
93  '>>', # __rshift__
94  '>>=', # __irshift__
95  '==', # __eq__
96  '!=', # __ne__
97  '<', # __lt__
98  '>', # __gt__
99  '<=', # __le__
100  '>=', # __ge__
101  # '!', # Use `not` in python
102  # '&&', # Use `and` in python
103  # '||', # Use `or` in python
104  '()', # __call__
105  '[]', # __getitem__
106  ],
107  ))


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