-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
msggen: adding example and fixes typo
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
- Loading branch information
1 parent
4e902fb
commit 2ab2061
Showing
3 changed files
with
43 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#! /usr/bin/python3 | ||
""" | ||
Example of usage msggen module. | ||
This example introduces a fake generator to understand how the | ||
package works, If you would like to see a real generator example | ||
try to see the Rust generator in the `msggen/gen/rust.py` | ||
author: https://github.com/vincenzopalazzo | ||
""" | ||
from msggen.gen.generator import GeneratorChain, IGenerator | ||
from msggen import Service | ||
from msggen.utils import load_jsonrpc_service | ||
|
||
|
||
class MonkylangGen(IGenerator): | ||
"""This is the custom generator that implements a monkylang generator | ||
that uses the interface handler IGenerator.""" | ||
|
||
def generate(self, service: Service): | ||
self.write('println("Monky")') | ||
|
||
|
||
def register_monkylang_gen(generator_chain: GeneratorChain): | ||
"""Helper function to register the custom generator, and | ||
load the correct path of the json schema.""" | ||
file = '<your_path_of_result>' | ||
dest = open(file, 'w') | ||
generator_chain.add_generator(MonkylangGen(dest)) | ||
|
||
|
||
if __name__ == '__main__': | ||
schema_dir = '<path_of_json_schema_dir>' | ||
service = load_jsonrpc_service(schema_dir=schema_dir) | ||
generator_chain = GeneratorChain() | ||
register_monkylang_gen(generator_chain) | ||
generator_chain.generate(service) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters