discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

code analysis tools

K
kitwallace
Wed, Oct 7, 2020 7:23 AM

I write a lot of OpenSCAD functions which I somewhat arbitarily organise into
multipe libraries.  When making the code available, for example this work on
generating polyhedra from Miller indices

https://kitwallace.tumblr.com/post/629139975142866944/miller-indices-to-polyhedra

I would like to be able to generate a script which extracts the functions
actually being used in the script to create a stand-alone version rather
than expect the user to download all the libraries.

Any pointers to existing analyis / parsing tools before I try to hack
sometihing myself?

--
Sent from: http://forum.openscad.org/

I write a lot of OpenSCAD functions which I somewhat arbitarily organise into multipe libraries. When making the code available, for example this work on generating polyhedra from Miller indices https://kitwallace.tumblr.com/post/629139975142866944/miller-indices-to-polyhedra I would like to be able to generate a script which extracts the functions actually being used in the script to create a stand-alone version rather than expect the user to download all the libraries. Any pointers to existing analyis / parsing tools before I try to hack sometihing myself? -- Sent from: http://forum.openscad.org/
WC
W. Craig Trader
Wed, Oct 7, 2020 8:20 PM

Kit ...

I had a similar problem; here's my solution:

https://github.com/wcraigtrader/game-parts/blob/master/bin/scad-expand.py

It's a Python 3 script that will create an all-in-one OpenSCAD model that
includes the model plus all of the libraries that the model depends upon
into a single file. It doesn't attempt to detect module or function
dependencies within a library; it just grabs the entire library file, but
ensures that any one library file will only be included once.

  • Craig -

On Wed, Oct 7, 2020 at 3:24 AM kitwallace kit.wallace@gmail.com wrote:

I write a lot of OpenSCAD functions which I somewhat arbitarily organise
into
multipe libraries.  When making the code available, for example this work
on
generating polyhedra from Miller indices

https://kitwallace.tumblr.com/post/629139975142866944/miller-indices-to-polyhedra

I would like to be able to generate a script which extracts the functions
actually being used in the script to create a stand-alone version rather
than expect the user to download all the libraries.

Any pointers to existing analyis / parsing tools before I try to hack
sometihing myself?

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Kit ... I had a similar problem; here's my solution: https://github.com/wcraigtrader/game-parts/blob/master/bin/scad-expand.py It's a Python 3 script that will create an all-in-one OpenSCAD model that includes the model plus all of the libraries that the model depends upon into a single file. It doesn't attempt to detect module or function dependencies within a library; it just grabs the entire library file, but ensures that any one library file will only be included once. - Craig - On Wed, Oct 7, 2020 at 3:24 AM kitwallace <kit.wallace@gmail.com> wrote: > I write a lot of OpenSCAD functions which I somewhat arbitarily organise > into > multipe libraries. When making the code available, for example this work > on > generating polyhedra from Miller indices > > > https://kitwallace.tumblr.com/post/629139975142866944/miller-indices-to-polyhedra > > I would like to be able to generate a script which extracts the functions > actually being used in the script to create a stand-alone version rather > than expect the user to download all the libraries. > > Any pointers to existing analyis / parsing tools before I try to hack > sometihing myself? > > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
K
kitwallace
Thu, Oct 8, 2020 8:31 AM

Thanks Craig for that python script - very useful.  I made a small change to
the include regexp because the syntax doesn't require a terminating ;

INCLUDE = re.compile( '^include <(.*)>;?$' )

I can see that expanding use statements does require more parsing.

Some of my libraries are quite big so I would like to include only the
functions and modules referenced but that needs a full parse.  I've just
found a new JS project
https://www.npmjs.com/package/openscad-parser which looks like it could be
adapted to do the job and to support visualisation of the call network.

--
Sent from: http://forum.openscad.org/

Thanks Craig for that python script - very useful. I made a small change to the include regexp because the syntax doesn't require a terminating ; INCLUDE = re.compile( '^include <(.*)>;?$' ) I can see that expanding use statements does require more parsing. Some of my libraries are quite big so I would like to include only the functions and modules referenced but that needs a full parse. I've just found a new JS project https://www.npmjs.com/package/openscad-parser which looks like it could be adapted to do the job and to support visualisation of the call network. -- Sent from: http://forum.openscad.org/