| 
									
										
										
										
											2021-03-25 04:14:55 +08:00
										 |  |  | """
 | 
					
						
							|  |  |  | GTSAM Copyright 2010-2020, Georgia Tech Research Corporation, | 
					
						
							|  |  |  | Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  | All Rights Reserved | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Rules and classes for parsing a module. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # pylint: disable=unnecessary-lambda, unused-import, expression-not-assigned, no-else-return, protected-access, too-few-public-methods, too-many-arguments | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-11 23:10:35 +08:00
										 |  |  | from pyparsing import (ParseResults, ZeroOrMore,  # type: ignore | 
					
						
							|  |  |  |                        cppStyleComment, stringEnd) | 
					
						
							| 
									
										
										
										
											2021-03-25 04:14:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | from .classes import Class | 
					
						
							|  |  |  | from .declaration import ForwardDeclaration, Include | 
					
						
							| 
									
										
										
										
											2021-04-21 05:05:32 +08:00
										 |  |  | from .enum import Enum | 
					
						
							| 
									
										
										
										
											2021-03-25 04:14:55 +08:00
										 |  |  | from .function import GlobalFunction | 
					
						
							|  |  |  | from .namespace import Namespace | 
					
						
							|  |  |  | from .template import TypedefTemplateInstantiation | 
					
						
							| 
									
										
										
										
											2021-04-20 04:09:06 +08:00
										 |  |  | from .variable import Variable | 
					
						
							| 
									
										
										
										
											2021-03-25 04:14:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Module: | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Module is just a global namespace. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     E.g. | 
					
						
							|  |  |  |     ``` | 
					
						
							|  |  |  |     namespace gtsam { | 
					
						
							|  |  |  |         ... | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ``` | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rule = ( | 
					
						
							|  |  |  |         ZeroOrMore(ForwardDeclaration.rule  # | 
					
						
							|  |  |  |                    ^ Include.rule  # | 
					
						
							|  |  |  |                    ^ Class.rule  # | 
					
						
							|  |  |  |                    ^ TypedefTemplateInstantiation.rule  # | 
					
						
							|  |  |  |                    ^ GlobalFunction.rule  # | 
					
						
							| 
									
										
										
										
											2021-04-21 05:05:32 +08:00
										 |  |  |                    ^ Enum.rule  # | 
					
						
							|  |  |  |                    ^ Variable.rule  # | 
					
						
							| 
									
										
										
										
											2021-03-25 04:14:55 +08:00
										 |  |  |                    ^ Namespace.rule  # | 
					
						
							|  |  |  |                    ).setParseAction(lambda t: Namespace('', t.asList())) + | 
					
						
							|  |  |  |         stringEnd) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rule.ignore(cppStyleComment) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @staticmethod | 
					
						
							|  |  |  |     def parseString(s: str) -> ParseResults: | 
					
						
							|  |  |  |         """Parse the source string and apply the rules.""" | 
					
						
							|  |  |  |         return Module.rule.parseString(s)[0] |