Parse TVMScript source code str to doc AST. Its interface is consistent with python built-in ast.parse. And it will parse by python 3.8 first if possible, or it will parse with python version in current environment. Parameters ---------- source : str The TVMScript s
(
source: str,
filename: str = "<unknown>",
mode: str = "exec",
)
| 183 | |
| 184 | |
| 185 | def parse( |
| 186 | source: str, |
| 187 | filename: str = "<unknown>", |
| 188 | mode: str = "exec", |
| 189 | ) -> doc.AST: |
| 190 | """Parse TVMScript source code str to doc AST. |
| 191 | |
| 192 | Its interface is consistent with python built-in ast.parse. |
| 193 | And it will parse by python 3.8 first if possible, |
| 194 | or it will parse with python version in current environment. |
| 195 | |
| 196 | Parameters |
| 197 | ---------- |
| 198 | source : str |
| 199 | The TVMScript source code. |
| 200 | |
| 201 | filename : str |
| 202 | The optional filename of the file where source code locates. |
| 203 | |
| 204 | mode : str |
| 205 | The parsing mode for ast.parse. |
| 206 | |
| 207 | Returns |
| 208 | ------- |
| 209 | res : doc.AST |
| 210 | The parsed doc AST. |
| 211 | """ |
| 212 | try: |
| 213 | program = ast.parse( # pylint: disable=unexpected-keyword-arg |
| 214 | source=source, |
| 215 | filename=filename, |
| 216 | mode=mode, |
| 217 | feature_version=(3, 8), |
| 218 | ) |
| 219 | except: # pylint: disable=bare-except |
| 220 | program = ast.parse( |
| 221 | source=source, |
| 222 | filename=filename, |
| 223 | mode=mode, |
| 224 | ) |
| 225 | return to_doc(program) |
| 226 | |
| 227 | |
| 228 | class NodeVisitor: |
no test coverage detected
searching dependent graphs…