LBStanza C-Wrapper Tools
========================
This project contains some python tools for making wrappers around C
libraries in stanza. The idea is to convert the C syntax into something
that stanza can read and process.
These tools are based on
`pycparser <https://github.com/eliben/pycparser>`__.
Setup
-----
::
pip install lbstanza-wrappers
Examples
--------
Extract an Enumerated Type in C:
Example Header:
`libtidy <https://github.com/htacg/tidy-html5/blob/a873a190e10227c47c675b8c89e6619659784db9/include/tidyenum.h#L692>`__
.. code:: c
/** A Tidy configuration option can have one of these data types. */
typedef enum
{
TidyString, /**< String */
TidyInteger, /**< Integer or enumeration */
TidyBoolean /**< Boolean */
} TidyOptionType;
First pass this though the C PREPROCESSOR so that we get rid of symbols
and things that the ``pycparser`` can’t handle:
::
gcc -E -std=c99 ./tidy-html5/include/tidyenum.h > header.h
Then we can run the tool:
::
convert2stanza.py --input header.h enums --out-dir ./temp --pkg-prefix "tidy/Enums"
This will create a file ``./temp/TidyOptionType.stanza`` (among others)
containing:
::
defpackage tidy/Enums/TidyOptionType :
import core
public deftype TidyOptionType
public deftype TidyString <: TidyOptionType
public deftype TidyInteger <: TidyOptionType
public deftype TidyBoolean <: TidyOptionType
public defn to-int (v:TidyOptionType) -> Int:
match(v) :
(x:TidyString) : 0
(x:TidyInteger) : 1
(x:TidyBoolean) : 2
public defn TidyOptionType (v:Int) -> TidyOptionType :
switch {v == _}:
0 : new TidyString
1 : new TidyInteger
2 : new TidyBoolean
else: throw(Exception("Invalid Exception Value"))
public lostanza defn TidyOptionType (v:int) -> ref<TidyOptionType> :
return TidyOptionType(new Int{v})
defmethod print (o:OutputStream, v:TidyOptionType) :
match(v) :
(x:TidyString) : print(o, "TidyString")
(x:TidyInteger) : print(o, "TidyInteger")
(x:TidyBoolean) : print(o, "TidyBoolean")
See `lbstanza-tidy <https://github.com/callendorph/lbstanza-tidy>`__
Raw data
{
"_id": null,
"home_page": "https://github.com/callendorph/lbstanza-wrappers",
"name": "lbstanza-wrappers",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "lbstanza wrappers utility",
"author": "Carl Allendorph",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/2b/2f/ac7d64da14c9f7c761b23a78e77b284c5be7184dd11b2861d3a7da49a41d/lbstanza-wrappers-0.3.0.tar.gz",
"platform": null,
"description": "LBStanza C-Wrapper Tools\n========================\n\nThis project contains some python tools for making wrappers around C\nlibraries in stanza. The idea is to convert the C syntax into something\nthat stanza can read and process.\n\nThese tools are based on\n`pycparser <https://github.com/eliben/pycparser>`__.\n\nSetup\n-----\n\n::\n pip install lbstanza-wrappers\n\nExamples\n--------\n\nExtract an Enumerated Type in C:\n\nExample Header:\n`libtidy <https://github.com/htacg/tidy-html5/blob/a873a190e10227c47c675b8c89e6619659784db9/include/tidyenum.h#L692>`__\n\n.. code:: c\n\n /** A Tidy configuration option can have one of these data types. */\n typedef enum\n {\n TidyString, /**< String */\n TidyInteger, /**< Integer or enumeration */\n TidyBoolean /**< Boolean */\n } TidyOptionType;\n\nFirst pass this though the C PREPROCESSOR so that we get rid of symbols\nand things that the ``pycparser`` can\u2019t handle:\n\n::\n\n gcc -E -std=c99 ./tidy-html5/include/tidyenum.h > header.h\n\nThen we can run the tool:\n\n::\n\n convert2stanza.py --input header.h enums --out-dir ./temp --pkg-prefix \"tidy/Enums\"\n\nThis will create a file ``./temp/TidyOptionType.stanza`` (among others)\ncontaining:\n\n::\n\n defpackage tidy/Enums/TidyOptionType :\n import core\n\n public deftype TidyOptionType\n public deftype TidyString <: TidyOptionType\n public deftype TidyInteger <: TidyOptionType\n public deftype TidyBoolean <: TidyOptionType\n\n public defn to-int (v:TidyOptionType) -> Int:\n match(v) :\n (x:TidyString) : 0\n (x:TidyInteger) : 1\n (x:TidyBoolean) : 2\n\n public defn TidyOptionType (v:Int) -> TidyOptionType :\n switch {v == _}:\n 0 : new TidyString\n 1 : new TidyInteger\n 2 : new TidyBoolean\n else: throw(Exception(\"Invalid Exception Value\"))\n\n public lostanza defn TidyOptionType (v:int) -> ref<TidyOptionType> :\n return TidyOptionType(new Int{v})\n\n defmethod print (o:OutputStream, v:TidyOptionType) :\n match(v) :\n (x:TidyString) : print(o, \"TidyString\")\n (x:TidyInteger) : print(o, \"TidyInteger\")\n (x:TidyBoolean) : print(o, \"TidyBoolean\")\n\nSee `lbstanza-tidy <https://github.com/callendorph/lbstanza-tidy>`__\n\n\n",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "Utility to create lbstanza wrappers from C headers",
"version": "0.3.0",
"project_urls": {
"Homepage": "https://github.com/callendorph/lbstanza-wrappers"
},
"split_keywords": [
"lbstanza",
"wrappers",
"utility"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "61142006ae6c3cd3163dc7822682d65e3752de748d315c0ca21c539f9b89ad16",
"md5": "80a821b4dff491ca174f27384b2f8de5",
"sha256": "f69711aaa140fd391ba54212a4ca84c9d8defb8e8e7bfec2614743218bde4201"
},
"downloads": -1,
"filename": "lbstanza_wrappers-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "80a821b4dff491ca174f27384b2f8de5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 23106,
"upload_time": "2023-12-19T06:01:07",
"upload_time_iso_8601": "2023-12-19T06:01:07.091521Z",
"url": "https://files.pythonhosted.org/packages/61/14/2006ae6c3cd3163dc7822682d65e3752de748d315c0ca21c539f9b89ad16/lbstanza_wrappers-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2b2fac7d64da14c9f7c761b23a78e77b284c5be7184dd11b2861d3a7da49a41d",
"md5": "9f9dbb6a069c08975f2aeda982b60580",
"sha256": "d5a2dc174b26cc87ed555df634a2708c7958c4b9fab35557b46f3740e005074e"
},
"downloads": -1,
"filename": "lbstanza-wrappers-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "9f9dbb6a069c08975f2aeda982b60580",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 23510,
"upload_time": "2023-12-19T06:01:27",
"upload_time_iso_8601": "2023-12-19T06:01:27.266382Z",
"url": "https://files.pythonhosted.org/packages/2b/2f/ac7d64da14c9f7c761b23a78e77b284c5be7184dd11b2861d3a7da49a41d/lbstanza-wrappers-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-19 06:01:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "callendorph",
"github_project": "lbstanza-wrappers",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "lbstanza-wrappers"
}