npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dcharatan/shape-assembly-parser

v6.8.1

Published

A parser for ShapeAssembly.

Downloads

147

Readme

shape-assembly-parser

This parses ShapeAssembly (with syntactic sugar, similar to what was presented in the original ShapeAssembly paper) into a simple abstract syntax tree (AST). This AST can be used for validation and syntax highlighting or be transpiled into ShapeAssembly that the original Python executor understands.

ShapeAssembly Specification

ShapeAssembly uses a Python-like syntax. The core ShapeAssembly functions are Cuboid, which creates a cuboid, and attach, which is used to position and resize cuboids. Their signatures are expressed below in TypeScript syntax.

// Create a cuboid with the given dimensions.
Cuboid: (length: PositiveFloat, width: PositiveFloat, height: PositiveFloat, aligned: boolean) => CuboidType

// Attach the child cuboid to the base cuboid. The child cuboid moves.
attach: (child: CuboidType, base: CuboidType, childX: UnitFloat, childY: UnitFloat, childZ: UnitFloat, baseX: UnitFloat, baseY: UnitFloat, baseZ: UnitFloat) => void

Root Assemblies

To create an object using ShapeAssembly, you must define a root assembly using the @root_assembly decorator. Root assembly functions cannot take arguments and must define a cuboid named bbox. Note that bbox is invisible when a ShapeAssembly program is executed.

@root_assembly
def my_root_assembly():
  bbox = Cuboid(1, 1, 1, True)
  ...

Beyond using Cuboid and attach in the root assembly, you can define abstractions and child assemblies.

Abstractions

These are groups of statements. Think of them like functions in a programming language—an abstraction can have an arbitrary number of parameters, and parameter types are inferred based on usage.

def my_abstraction(some_positive_float, some_boolean):
  Cuboid(5 * some_positive_float, 1, 1, some_boolean)

Child Assemblies

A child assembly (subassembly) completely replaces a cuboid with more fine-grained geometry. The decorator @child_assembly denotes that a function is a child assembly. A child assembly function's single argument is its bounding box (of type cuboid).

@child_assembly
def my_child_assembly(bbox):
  ...

@root_assembly
def my_root_assembly():
  bbox = Cuboid(2, 2, 2, True)
  ...
  child_bbox = Cuboid(1, 1, 1, True)
  my_child_assembly(child_bbox)
  ...

Notes

Inside function arguments, ShapeAssembly supports the use of mathematical expressions that contain parentheses and the operators *, /, + and - (e.g. Cuboid(-3 * (some_float - 1), ...)). However, it does not support nested function calls (e.g. attach(Cuboid(...), ...) or the assignment of arbitrary expressions to variables (e.g. x = 3). These features would be relatively easy to add by modifying the expression parser to support functions and parsing the right-hand side of assignment statements using the expression parser, but would make transpilation more complicated. Beyond a certain point, it would be easier to hack Python to create ShapeAssembly ASTs.