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 DUNDER = Suppress(Literal("__"))
26 
27 # Default argument passed to functions/methods.
28 # Allow anything up to ',' or ';' except when they
29 # appear inside matched expressions such as
30 # (a, b) {c, b} "hello, world", templates, initializer lists, etc.
31 DEFAULT_ARG = originalTextFor(
32  OneOrMore(
33  QuotedString('"') ^ # parse double quoted strings
34  QuotedString("'") ^ # parse single quoted strings
35  Word(printables, excludeChars="(){}[]<>,;") ^ # parse arbitrary words
36  nestedExpr(opener='(', closer=')') ^ # parse expression in parentheses
37  nestedExpr(opener='[', closer=']') ^ # parse expression in brackets
38  nestedExpr(opener='{', closer='}') ^ # parse expression in braces
39  nestedExpr(opener='<', closer='>') # parse template expressions
40  ))
41 
42 CONST, VIRTUAL, CLASS, STATIC, PAIR, TEMPLATE, TYPEDEF, INCLUDE = map(
43  Keyword,
44  [
45  "const",
46  "virtual",
47  "class",
48  "static",
49  "pair",
50  "template",
51  "typedef",
52  "#include",
53  ],
54 )
55 ENUM = Keyword("enum") ^ Keyword("enum class") ^ Keyword("enum struct")
56 NAMESPACE = Keyword("namespace")
57 BASIC_TYPES = map(
58  Keyword,
59  [
60  "void",
61  "bool",
62  "unsigned char",
63  "char",
64  "int",
65  "size_t",
66  "double",
67  "float",
68  ],
69 )
70 
71 OPERATOR = Or(
72  map(
73  Literal,
74  [
75  '+', # __add__, __pos__
76  '-', # __sub__, __neg__
77  '*', # __mul__
78  '/', # __truediv__
79  '%', # __mod__
80  '^', # __xor__
81  '&', # __and__
82  '|', # __or__
83  # '~', # __invert__
84  '+=', # __iadd__
85  '-=', # __isub__
86  '*=', # __imul__
87  '/=', # __itruediv__
88  '%=', # __imod__
89  '^=', # __ixor__
90  '&=', # __iand__
91  '|=', # __ior__
92  '<<', # __lshift__
93  '<<=', # __ilshift__
94  '>>', # __rshift__
95  '>>=', # __irshift__
96  '==', # __eq__
97  '!=', # __ne__
98  '<', # __lt__
99  '>', # __gt__
100  '<=', # __le__
101  '>=', # __ge__
102  # '!', # Use `not` in python
103  # '&&', # Use `and` in python
104  # '||', # Use `or` in python
105  '()', # __call__
106  '[]', # __getitem__
107  ],
108  ))


gtsam
Author(s):
autogenerated on Tue Jun 25 2024 03:07:30