openscad

package module
v0.0.0-...-04f0d06 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 10 Imported by: 1

README

openscad

This is a PoC for a shim over the OpenSCAD language.

Currently it has a half-baked OpenSCAD parser and printer, as well as building blocks to generate OpenSCAD code programmatically.

Parser

Currently the parser does not report errors well (especially in the lexer), because I was being lazy during initial development. PRs are very much welcome.

stmt, err := ast.Parse([]byte(...OpenSCAD source code...))

Parsed code does not contain comments.

You can output this code back by using one of the Emit functions:

ast.Emit(stmt, os.Stdout) // emits to stdout

Amalgamation

One of the goals of this library is to make (re)distribution of OpenSCAD code. Because OpenSCAD does not by itself have a way to handle file dependencies, it becomes increasingly harder to control these dependencies both for development and distribution.

This library can make this slightly easier by allowing you to create amalgamated files, where all of the related source code is provided as a single file.

For example, suppose you have an OpenSCAD code like the following:

// main.scad
include <foo.scad>

Then you could register this main.scad file and the foo.scad file in this library:

openscad.RegisterFile(`main.scad`)
opnescad.RegisterFile(`foo.scad`)

And then you could generate the amalgamated version using the following code

stmt, _ := openscad.Lookup(`main.scad`)
ast.Emit(stmt, os.Stdout, ast.WithAmalgamation())

Documentation

Index

Constants

View Source
const (
	EOF = iota
	Keyword
	Literal
	Numeric
	Ident
	Comma
	Equal
	Semicolon
	Colon
	Question
	DoubleQuote
	Asterisk
	Plus
	Minus
	Slash
	LessThan
	LessThanEqual
	GreaterThan
	GreaterThanEqual
	Equality     // ==
	OpenParen    // (
	CloseParen   // )
	OpenBracket  // [
	CloseBracket // ]
	OpenBrace    // {
	CloseBrace   // }
	Percent
	Sharp
	And
	BitwiseAnd
	Exclamation
)

Variables

This section is empty.

Functions

func Lex

func Lex(ch chan *Token, src []byte)

func Lookup

func Lookup(name string) (ast.Stmt, bool)

func Parse

func Parse(src []byte) (ast.Stmts, error)

Parse parses an OpenSCAD source code, and turns it into an internal representation that can be used to output the same source code afterwrads, programmatically.

Currently comments are out of scope of this implementation.

func ParseFile

func ParseFile(filename string, options ...ParseFileOption) (ast.Stmt, error)

func Register

func Register(name string, stmt ast.Stmt) error

func RegisterFile

func RegisterFile(filename string, options ...RegisterFileOption) error

Types

type ParseFileOption

type ParseFileOption interface {
	RegisterFileOption
	option.Interface
	// contains filtered or unexported methods
}

func WithFS

func WithFS(src fs.FS) ParseFileOption

type RegisterFileOption

type RegisterFileOption interface {
	option.Interface
	// contains filtered or unexported methods
}

func WithLookupName

func WithLookupName(name string) RegisterFileOption

type Token

type Token struct {
	Type  int
	Value string
}

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL