py-slang is a Python implementation developed specifically for the Source Academy online learning environment. Unlike previous versions where Python was treated as a subset within js-slang, py-slang now stands as an independent language implementation. It features its own parser, csemachine, and runtime, designed to process a tailored subset of Python for educational purposes.
For local testing:
npm run start:dev # Add `-- <file.py>` to run a fileimport {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));Ensure that all tests pass before committing.
npm run testThe AST types need to be regenerated after changing
the AST type definitions in generate-ast.ts.
npm run regenThis project adapts the Conductor Interface from source-academy/conductor, which is part of the Source Academy ecosystem.
Specifically, all files under the following folders are derived from the conductor repository:
src/conductor/src/common/src/conduit/
All credits go to the original authors of the Source Academy Conductor Interface.