UNPKG

blocklypy

Version:

BlocklyPy: SPIKE to Pybricks - word-block converter to Pybricks python code

205 lines (194 loc) 5.37 kB
/** * LEGO SPIKE and EV3 Mindstorms Code to Pybricks - block-code converter to Pybricks python code * * @remarks * This library will read, analyze and convert the LEGO standard graphical blockly files to Pybricks python files. * * SPIKE Prime ([45678](https://www.lego.com/en-us/product/lego-education-spike-prime-set-45678)) and SPIKE Essentials ([45345](https://www.lego.com/en-us/product/lego-education-spike-essential-set-45345)) kit and Robot Inventor ([51515](https://www.lego.com/en-us/product/robot-inventor-51515)) kit for **word-blocks** and **icon-blocks** transformation and LEGO python for analysis only. * * - SPIKE v2 (.llsp) and SPIKE v3 (.llsp3) files. * - Robot Inventor files (.lms). * * EV3 Mindstorms kit ([31313](https://www.lego.com/en-us/product/lego-mindstorms-ev3-31313)) LabView EV3-G code transformation: * * - EV3Classroom files (.lmsp). * - EV3 Lab (.ev3) files EV3 iPad (.ev3m) files. * - EV3 Lab Compiled Binary (.rbf) files. * * Analysis only: * * - Pybricks python (.py) files. * * @packageDocumentation */ /** * Analyzes and converts the project to Python code. * @param filedata - The project file data. * @param options - The conversion options. * @returns The result of the conversion. * @public */ export declare function convertProjectToPython(inputfiles: IPyConverterFile[], options: IPyConverterOptions): Promise<IPyProjectResult>; /** * Code block of the project. * @public */ export declare interface ICodeBlock { /** * The unique identifier of the block. */ id: string | undefined; /** * The opcode of the block. */ opcode: string; /** * Returns a description of the block. * @param isPythonMode - Whether the description should be in Python mode. */ getDescription(isPythonMode?: boolean): string; } /** * Input file to be converted. * @public */ export declare interface IPyConverterFile { /** * The name of the file. */ name: string; /** * The content of the file */ buffer: ArrayBuffer; /** * The size of the file. */ size?: number; /** * The last modified date of the file. */ date?: Date; } /** * Options for the conversion of the source code. * @public */ export declare interface IPyConverterOptions { debug?: { showOrphanCode?: boolean; skipHeader?: boolean; skipImports?: boolean; skipHelpers?: boolean; skipSetup?: boolean; skipVariableDeclarations?: boolean; showBlockIds?: boolean; showExplainingComments?: boolean; showThisStackOnly?: string; skipFiles?: string[]; skipPlainCode?: boolean; skipPyCode?: boolean; skipDependencyGraph?: boolean; skipRegionComments?: boolean; callback?: (...args: unknown[]) => void; }; output?: { 'blockly.svg'?: boolean; 'blockly.slot'?: boolean; 'sb3.source'?: boolean; 'ev3b.source'?: boolean | number; 'ev3g.source'?: boolean; 'wedo2.preview'?: boolean; }; log?: { level?: LOGLEVEL; callback?: (level: LOGLEVEL, ...args: unknown[]) => void; }; } /** * Conversion and analysis of the source code. * @public */ export declare interface IPyProjectResult { /** * Python representation of the blockly code in Pybricks flavour. */ pycode?: string | string[]; /** * The name of the file(s). */ name?: string | string[]; /** * Pseudo code text representation of the blockly code */ plaincode?: string; /** * The type of the device for which the code was generated. */ filetype?: string; /** * Dependency graph of the blocks. */ dependencygraph?: string; /** * Input format dependent extra information such as blockly slot and svg preview or rbf disassembly. */ extra?: { 'blockly.slot'?: string; 'blockly.svg'?: string; 'wedo2.preview'?: string; 'sb3.source'?: { [file: string]: string; }; 'ev3b.source'?: { [file: string]: string; }; 'ev3g.source'?: { [key: string]: string; }; }; /** * The top blocks of the project. */ topblocks?: ITopBlock[]; /** * Python representation per block of the blockly code in Pybricks flavour. */ pycodeByBlocks?: { [key: string]: { code: string[]; }; }; } /** * Top level block of the project. * @public */ export declare interface ITopBlock { /** * The name of the block. */ name: string; /** * The stack of blocks. */ stack: ICodeBlock | ICodeBlock[]; } declare enum LOGLEVEL { DEBUG = 0, INFO = 1, WARNING = 2, ERROR = 3, CRITICAL = 4 } /** * Supported file extensions. * @public */ export declare function supportedExtensions(): string[]; /** * Checks if the file extension is supported for conversion. * @public */ export declare function supportsExtension(file: string): boolean; export { }