Blog
PPSCAD is now open source
The language every PrintParams model is written in now has a public specification, a conformance test suite and its interpreter on GitHub, under open licences.
PPSCAD is the small language behind every model you write on PrintParams. A program declares its parameters and builds a solid from primitives, booleans and transforms; the site turns every parameter into a control.
// A spacer: a ring of the height you give
param outer_d: float = 12 [6:40:0.5] "Outer diameter (mm)"
param hole_d: float = 4.2 [2:20:0.1] "Hole diameter (mm)"
param height: float = 8 [2:40:0.5] "Height (mm)"
difference {
cylinder(h: height, d: outer_d, segments: 64)
translate(0, 0, -1)
cylinder(h: height + 2, d: hole_d, segments: 32)
}Until today the language was described only by the reference in the docs, and it ran only inside this site. Both are now public. The language is PPSCAD 1.0, and everything that defines it is in one repository: github.com/jaapenstaart/ppscad.
What is in the repository
- The specification of PPSCAD 1.0: from the characters of a source file to what every statement, primitive and operator means, with a formal grammar beside it.
- Documentation: getting started, a tour of the language, a cookbook, guides on parameters and on parts that fit, a page for people who come from OpenSCAD, a cheat sheet, and guides for embedding the interpreter and for language models.
- Examples as
.ppscadfiles with a rendered picture each: the basics, techniques, the twenty everyday parts of the PrintParams catalog and the six starter templates of the editor. - A conformance test suite: programs with the result they must give, written as JSON, and programs that must fail.
- The reference interpreter in TypeScript: the lexer, the parser and the interpreter over the Manifold kernel. It is the code that runs on printparams.com, with a command-line tool that turns a
.ppscadfile into an STL. - A TextMate grammar, so an editor can color the code.
Why
A design on PrintParams is saved as code, and code is only worth keeping when it can be run. With the specification and the interpreter public, a program you write here keeps its meaning without this site.
It also lets other tools join in. A script, another editor or a language model can read and write PPSCAD from the specification instead of guessing from examples. And anyone can check what a program means: when the site and the specification disagree, that is a bug with an address.
The licences
The interpreter, the tests and the examples are under the MIT licence. The specification and the documentation are under Creative Commons Attribution 4.0: copy them, translate them and build on them, with credit.
What changed in the interpreter
Writing a language down shows where its interpreter does something nobody would put in a specification. The ones you could run into are fixed with 1.0, and the fixes are live on this site:
&&and||stop at the operand that decides, sox != 0 && 1 / x > 2no longer divides by zero.- A reserved word can name an argument:
extrude(h: 20, scale: 0.5)andcylinder(h: 10, r: 5, fn: 6)now run. - A solid of no size, such as a cube of 0 or a negative extrusion, is the empty solid. It used to empty the whole model.
text("")is an empty shape instead of a fault..offset()rounds corners unless you ask otherwise, as the reference always said. Every offset used to come out with square joins;joinType:takes"round","square"or"miter".- A
returnoutside a function or module is reported with its line.
Take part
- Does the site read a program differently from the specification? Open an issue.
- A change to the language starts as a proposal: a short text on what should change and why, discussed before anyone builds it.
- Writing another implementation? The conformance suite is made for it: every test is a program and the result it must give.