import type { NodeName } from '@hey-api/codegen-core'; import type { py } from '../ts-python'; import { ClassPyDsl } from './decl/class'; // import { DecoratorPyDsl } from './decl/decorator'; // import { EnumPyDsl } from './decl/enum'; // import { FieldPyDsl } from './decl/field'; import { FuncPyDsl } from './decl/func'; // import { GetterPyDsl } from './decl/getter'; // import { InitPyDsl } from './decl/init'; // import { EnumMemberPyDsl } from './decl/member'; // import { MethodPyDsl } from './decl/method'; // import { ParamPyDsl } from './decl/param'; // import { PatternPyDsl } from './decl/pattern'; // import { SetterPyDsl } from './decl/setter'; // import { ArrayPyDsl } from './expr/array'; // import { AsPyDsl } from './expr/as'; // import { AwaitPyDsl } from './expr/await'; import { BinaryPyDsl } from './expr/binary'; import { CallPyDsl } from './expr/call'; import { DictPyDsl } from './expr/dict'; import { ExprPyDsl } from './expr/expr'; // import { fromValue as exprValue } from './expr/fromValue'; import { IdPyDsl } from './expr/identifier'; import { ListPyDsl } from './expr/list'; import { LiteralPyDsl } from './expr/literal'; import { AttrPyDsl } from './expr/member'; // import { NewPyDsl } from './expr/new'; // import { ObjectPyDsl } from './expr/object'; // import { PrefixPyDsl } from './expr/prefix'; // import { ObjectPropPyDsl } from './expr/prop'; // import { RegExpPyDsl } from './expr/regexp'; import { SetPyDsl } from './expr/set'; // import { TemplatePyDsl } from './expr/template'; // import { TernaryPyDsl } from './expr/ternary'; import { TuplePyDsl } from './expr/tuple'; // import { TypeOfExprPyDsl } from './expr/typeof'; import { DocPyDsl } from './layout/doc'; import { HintPyDsl } from './layout/hint'; import { NewlinePyDsl } from './layout/newline'; import { BlockPyDsl } from './stmt/block'; import { BreakPyDsl } from './stmt/break'; import { ContinuePyDsl } from './stmt/continue'; import { ForPyDsl } from './stmt/for'; import { IfPyDsl } from './stmt/if'; import { ImportPyDsl } from './stmt/import'; import { RaisePyDsl } from './stmt/raise'; import { ReturnPyDsl } from './stmt/return'; import { StmtPyDsl } from './stmt/stmt'; import { TryPyDsl } from './stmt/try'; import { VarPyDsl } from './stmt/var'; import { WhilePyDsl } from './stmt/while'; import { WithPyDsl } from './stmt/with'; // import { TokenPyDsl } from './token'; // import { TypeAliasPyDsl } from './type/alias'; // import { TypeAndPyDsl } from './type/and'; // import { TypeAttrPyDsl } from './type/attr'; // import { TypeExprPyDsl } from './type/expr'; // import { fromValue as typeValue } from './type/fromValue'; // import { TypeFuncPyDsl } from './type/func'; // import { TypeIdxPyDsl } from './type/idx'; // import { TypeLiteralPyDsl } from './type/literal'; // import { TypeMappedPyDsl } from './type/mapped'; // import { TypeObjectPyDsl } from './type/object'; // import { TypeOperatorPyDsl } from './type/operator'; // import { TypeOrPyDsl } from './type/or'; // import { TypeParamPyDsl } from './type/param'; // import { TypeQueryPyDsl } from './type/query'; // import { TypeTemplatePyDsl } from './type/template'; // import { TypeTuplePyDsl } from './type/tuple'; import { LazyPyDsl } from './utils/lazy'; const pyDsl = { /** Creates an array literal expression (e.g. `[1, 2, 3]`). */ // array: (...args: ConstructorParameters) => new ArrayTsDsl(...args), /** Creates an `as` type assertion expression (e.g. `value as Type`). */ // as: (...args: ConstructorParameters) => new AsTsDsl(...args), /** Creates a property access expression (e.g. `obj.foo`). */ attr: (...args: ConstructorParameters) => new AttrPyDsl(...args), /** Creates an await expression (e.g. `await promise`). */ // await: (...args: ConstructorParameters) => new AwaitTsDsl(...args), /** Creates a binary expression (e.g. `a + b`). */ binary: (...args: ConstructorParameters) => new BinaryPyDsl(...args), /** Creates a statement block. */ block: (...args: ConstructorParameters) => new BlockPyDsl(...args), /** Creates a break statement. */ break: (...args: ConstructorParameters) => new BreakPyDsl(...args), /** Creates a function or method call expression (e.g. `fn(arg)`). */ call: (...args: ConstructorParameters) => new CallPyDsl(...args), /** Creates a class declaration or expression. */ class: (...args: ConstructorParameters) => new ClassPyDsl(...args), /** Creates a continue statement. */ continue: (...args: ConstructorParameters) => new ContinuePyDsl(...args), /** Creates a decorator expression (e.g. `@decorator`). */ // decorator: (...args: ConstructorParameters) => new DecoratorTsDsl(...args), /** Creates a dictionary expression (e.g. `{ 'a': 1 }`). */ dict: (...args: ConstructorParameters) => new DictPyDsl(...args), /** Creates a Python docstring (`"""..."""`). */ doc: (...args: ConstructorParameters) => new DocPyDsl(...args), /** Creates an enum declaration. */ // enum: (...args: ConstructorParameters) => new EnumTsDsl(...args), /** Creates a general expression node. */ expr: (...args: ConstructorParameters) => new ExprPyDsl(...args), /** Creates a field declaration in a class or object. */ // field: (...args: ConstructorParameters) => new FieldTsDsl(...args), /** Creates a for statement (e.g. `for x in items:`). */ for: (...args: ConstructorParameters) => new ForPyDsl(...args), /** Converts a runtime value into a corresponding expression node. */ // fromValue: (...args: Parameters) => exprValue(...args), /** Creates a function declaration. */ func: ((name: NodeName, fn?: (f: FuncPyDsl) => void) => new FuncPyDsl(name, fn)) as { (name: NodeName): FuncPyDsl; (name: NodeName, fn: (f: FuncPyDsl) => void): FuncPyDsl; }, /** Creates a getter method declaration. */ // getter: (...args: ConstructorParameters) => new GetterTsDsl(...args), /** Creates a Python comment (`# ...`). */ hint: (...args: ConstructorParameters) => new HintPyDsl(...args), /** Creates an identifier (e.g. `foo`). */ id: (...args: ConstructorParameters) => new IdPyDsl(...args), /** Creates an if statement. */ if: (...args: ConstructorParameters) => new IfPyDsl(...args), /** Creates an import statement. */ import: (...args: ConstructorParameters) => new ImportPyDsl(...args), /** Creates an initialization block or statement. */ // init: (...args: ConstructorParameters) => new InitTsDsl(...args), /** Creates a lazy, context-aware node with deferred evaluation. */ lazy: (...args: ConstructorParameters>) => new LazyPyDsl(...args), /** Creates a list expression (e.g. `[1, 2, 3]`). */ list: (...args: ConstructorParameters) => new ListPyDsl(...args), /** Creates a literal value (e.g. string, number, boolean). */ literal: (...args: ConstructorParameters) => new LiteralPyDsl(...args), /** Creates an enum member declaration. */ // member: (...args: ConstructorParameters) => new EnumMemberTsDsl(...args), /** Creates a method declaration inside a class or object. */ // method: (...args: ConstructorParameters) => new MethodTsDsl(...args), /** Creates a negation expression (`-x`). */ // neg: (...args: ConstructorParameters) => new PrefixTsDsl(...args).neg(), /** Creates a new expression (e.g. `new ClassName()`). */ // new: (...args: ConstructorParameters) => new NewTsDsl(...args), /** Creates a newline (for formatting purposes). */ newline: (...args: ConstructorParameters) => new NewlinePyDsl(...args), /** Creates a logical NOT expression (`!x`). */ // not: (...args: ConstructorParameters) => new PrefixTsDsl(...args).not(), /** Creates an object literal expression. */ // object: (...args: ConstructorParameters) => new ObjectTsDsl(...args), /** Creates a parameter declaration for functions or methods. */ // param: (...args: ConstructorParameters) => new ParamTsDsl(...args), /** Creates a pattern for destructuring or matching. */ // pattern: (...args: ConstructorParameters) => new PatternTsDsl(...args), /** Creates a prefix unary expression (e.g. `-x`, `!x`, `~x`). */ // prefix: (...args: ConstructorParameters) => new PrefixTsDsl(...args), /** Creates an object literal property (e.g. `{ foo: bar }`). */ // prop: (...args: ConstructorParameters) => new ObjectPropTsDsl(...args), /** Creates a raise statement. */ raise: (...args: ConstructorParameters) => new RaisePyDsl(...args), /** Creates a regular expression literal (e.g. `/foo/gi`). */ // regexp: (...args: ConstructorParameters) => new RegExpTsDsl(...args), /** Creates a return statement. */ return: (...args: ConstructorParameters) => new ReturnPyDsl(...args), /** Creates a set expression (e.g. `{1, 2, 3}`). */ set: (...args: ConstructorParameters) => new SetPyDsl(...args), /** Creates a setter method declaration. */ // setter: (...args: ConstructorParameters) => new SetterTsDsl(...args), /** Wraps an expression or statement-like value into a `StmtPyDsl`. */ stmt: (...args: ConstructorParameters) => new StmtPyDsl(...args), /** Creates a template literal expression. */ // template: (...args: ConstructorParameters) => new TemplateTsDsl(...args), /** Creates a ternary conditional expression (if ? then : else). */ // ternary: (...args: ConstructorParameters) => new TernaryTsDsl(...args), // /** Creates a throw statement. */ // throw: (...args: ConstructorParameters) => new ThrowTsDsl(...args), /** Creates a syntax token (e.g. `?`, `readonly`, `+`, `-`). */ // token: (...args: ConstructorParameters) => new TokenTsDsl(...args), /** Creates a try/except/finally statement. */ try: (...args: ConstructorParameters) => new TryPyDsl(...args), /** Creates a tuple expression (e.g. `(1, 2, 3)`). */ tuple: (...args: ConstructorParameters) => new TuplePyDsl(...args), /** Creates a basic type reference or type expression (e.g. Foo or Foo). */ // type: Object.assign( // (...args: ConstructorParameters) => new TypeExprTsDsl(...args), // { /** Creates a type alias declaration (e.g. `type Foo = Bar`). */ // alias: (...args: ConstructorParameters) => new TypeAliasTsDsl(...args), /** Creates an intersection type (e.g. `A & B`). */ // and: (...args: ConstructorParameters) => new TypeAndTsDsl(...args), /** Creates a qualified type reference (e.g. Foo.Bar). */ // attr: (...args: ConstructorParameters) => new TypeAttrTsDsl(...args), /** Creates a basic type reference or type expression (e.g. Foo or Foo). */ // expr: (...args: ConstructorParameters) => new TypeExprTsDsl(...args), /** Converts a runtime value into a corresponding type expression node. */ // fromValue: (...args: Parameters) => typeValue(...args), /** Creates a function type node (e.g. `(a: string) => number`). */ // func: (...args: ConstructorParameters) => new TypeFuncTsDsl(...args), /** Creates an indexed-access type (e.g. `Foo[K]`). */ // idx: (...args: ConstructorParameters) => new TypeIdxTsDsl(...args), /** Creates a literal type node (e.g. 'foo', 42, or true). */ // literal: (...args: ConstructorParameters) => // new TypeLiteralTsDsl(...args), /** Creates a mapped type (e.g. `{ [K in keyof T]: U }`). */ // mapped: (...args: ConstructorParameters) => // new TypeMappedTsDsl(...args), /** Creates a type literal node (e.g. { foo: string }). */ // object: (...args: ConstructorParameters) => // new TypeObjectTsDsl(...args), /** Creates a type operator node (e.g. `readonly T`, `keyof T`, `unique T`). */ // operator: (...args: ConstructorParameters) => // new TypeOperatorTsDsl(...args), /** Represents a union type (e.g. `A | B | C`). */ // or: (...args: ConstructorParameters) => new TypeOrTsDsl(...args), /** Creates a type parameter (e.g. ``). */ // param: (...args: ConstructorParameters) => new TypeParamTsDsl(...args), /** Creates a type query node (e.g. `typeof Foo`). */ // query: (...args: ConstructorParameters) => new TypeQueryTsDsl(...args), /** Builds a TypeScript template literal *type* (e.g. `${Foo}-${Bar}` as a type). */ // template: (...args: ConstructorParameters) => // new TypeTemplateTsDsl(...args), /** Creates a tuple type (e.g. [A, B, C]). */ // tuple: (...args: ConstructorParameters) => new TypeTupleTsDsl(...args), // }, // ), /** Creates a `typeof` expression (e.g. `typeof value`). */ // typeofExpr: (...args: ConstructorParameters) => // new TypeOfExprTsDsl(...args), /** Creates a variable assignment. */ var: (...args: ConstructorParameters) => new VarPyDsl(...args), /** Creates a while statement (e.g. `while x:`). */ while: (...args: ConstructorParameters) => new WhilePyDsl(...args), /** Creates a with statement (e.g. `with open(f) as file:`). */ with: (...args: ConstructorParameters) => new WithPyDsl(...args), }; export const $ = Object.assign( (...args: ConstructorParameters) => new ExprPyDsl(...args), pyDsl, ); export type DollarPyDsl = { /** * Entry point to the Python DSL. * * `$` creates a general expression node by default, but also exposes * builders for all other constructs. * * Example: * ```ts * const node = $('console').attr('log').call($.literal('Hello')); * ``` * * Returns: * - A new `ExprPyDsl` instance when called directly. * - The `pyDsl` object for constructing more specific nodes. */ $: typeof $; }; export type { MaybePyDsl } from './base'; // export type { MaybePyDsl, TypePyDsl } from './base'; export { PyDsl } from './base'; export type { CallArgs } from './expr/call'; export type { ExampleOptions } from './utils/context'; export { ctx, PyDslContext } from './utils/context'; export { keywords } from './utils/keywords'; export { regexp } from './utils/regexp'; export { PythonRenderer } from './utils/render'; export { reserved } from './utils/reserved';