Skip to content

source-academy/py-slang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9a3eceb · Jul 14, 2024

History

59 Commits
Apr 9, 2024
Jun 1, 2024
Jun 24, 2023
Jan 17, 2023
Jan 17, 2023
May 8, 2023
Feb 4, 2023
Feb 1, 2023
Jul 14, 2024
Feb 13, 2023
May 17, 2023
Feb 19, 2023

Repository files navigation

Python variant for SICP

What is py-slang?

py-slang is a language frontend for the js-slang repository. It parses a restricted subset of Python (enough to complete SICP), and outputs an estree-compatible AST. The grammar is a reduced version of Python 3.7's. This project does not aim to be a full Python to JS transpiler, but aims to transpile just a small enough subset of Python.

Usage

For local testing:

npm run start:dev # Add `-- <file.py>` to run a file

Consuming the API and generating an estree AST

import {parsePythonToEstreeAst} from 'py-slang';

// Sample Python code
const text = `
(lambda a: print(a))("Hello World!")
`;
// Arguments:
// Code to translate
// SICPy chapter number
// Whether to validate the code using a resolver.
console.dir(parsePythonToEstreeAst(text, 1, false));

Running the test suite

Ensure that all tests pass before committing.

npm run test

Regenerating the AST types

The AST types need to be regenerated after changing the AST type definitions in generate-ast.ts.

npm run regen

About

Python sublanguage for SICP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages