https://github.com/ziman/macro-pp
Universal macro preprocessor
https://github.com/ziman/macro-pp
Last synced: 10 months ago
JSON representation
Universal macro preprocessor
- Host: GitHub
- URL: https://github.com/ziman/macro-pp
- Owner: ziman
- Created: 2018-04-04T07:27:46.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-17T08:14:37.000Z (about 8 years ago)
- Last Synced: 2025-03-27T02:44:06.550Z (about 1 year ago)
- Language: Haskell
- Size: 30.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# macro-pp
Universal preprocessor
1. Write your macro matcher/parser with Parsec
2. Implement conversion of parsed macros to whatever you want
3. Non-matching portions of the input are copied verbatim
## Example
`ExamplePython.hs` defines a *mypy*-supported enum for Python.
This takes the following code...
```python
@enum(deriving=Codec)
class Model:
PreorderMaximization(p = PreorderParams, q = bool)
UndominatedChoice(strict = bool)
TopTwo
ChooseSome(models = List[Model])
#end#
```
...and generates the following Python source.
```python
class PreorderMaximization(NamedTuple):
p : PreorderParams
q : bool
tag : int = 0
class UndominatedChoice(NamedTuple):
strict : bool
tag : int = 1
class TopTwo(NamedTuple):
tag : int = 2
class ChooseSome(NamedTuple):
models : List[Model]
tag : int = 3
Model = Union[
PreorderMaximization,
UndominatedChoice,
TopTwo,
ChooseSome,
]
ModelC = enumC('Model', {
PreorderMaximization: (PreorderParamsC, boolC,),
UndominatedChoice: (boolC,),
TopTwo: (),
ChooseSome: (listC(ModelC),),
})
```