@@ -16,34 +16,25 @@ npm run start:dev # Add `-- <file.py>` to run a file
16
16
17
17
### Consuming the API and generating an estree AST
18
18
``` javascript
19
- import {Tokenizer , Parser , Resolver , Translator } from ' py-slang' ;
19
+ import {parsePythonToEstreeAst } from ' py-slang' ;
20
20
21
21
// Sample Python code
22
22
const text = `
23
- (lambda a:display (a))("Hello World!")
23
+ (lambda a: print (a))("Hello World!")
24
24
` ;
25
- // Add a new line because Python scripts need to end with a blank newline.
26
- text += ' \n ' ;
27
- // Scan the text.
28
- const tokenizer = new Tokenizer (text);
29
- const tokens = tokenizer .scanEverything ();
30
- // If you want to view the tokens, you can.
31
- // tokenizer.printTokens();
32
-
33
- // Parse the tokens.
34
- const parser = new Parser (text, tokens);
35
- const ast = parser .parse ();
36
-
37
- // Validate and resolve symbols in namespaces.
38
- // This step may throw false errors.
39
- // This is when we detect variable declarations
40
- // and hoist them out of blocks.
41
- const resolver = new Resolver (text, ast);
42
- resolver .resolve (ast);
43
-
44
- // Finally, translate the AST to estree AST.
45
- const translator = new Translator (text);
46
- const estreeAst = translator .resolve (ast);
25
+ // Arguments:
26
+ // Code to translate
27
+ // SICPy chapter number
28
+ // Whether to validate the code using a resolver.
29
+ console .dir (parsePythonToEstreeAst (text, 1 , false ));
30
+ ```
31
+
32
+ ### Running the test suite
33
+
34
+ Ensure that all tests pass before committing.
35
+
36
+ ``` shell
37
+ npm run test
47
38
```
48
39
49
40
### Regenerating the AST types
0 commit comments