This is a rather large refactor of the stylus proc macros with the main goal of improving maintainability, testability, and documentation of these macros. The following changes have been made:
Operate on AST nodes instead of raw tokens. This allows testing of smaller parts of the macros as unit tests. This also allows some composibility within the implementations.
Use the visitor pattern in several places to avoid confusing nesting of for-loops.
Separation of export-abi code using "extention" traits so that it is easy to reason about export-abi when needed, and otherwise ignore it.
Improved error reporting. The main change here is the ability to report multiple errors when compilation fails, allowing the user to see all errors at once. There is also some small changes with regards to consistency between the macros.
Unit tests for utilities and macro generation at the AST level. This includes a assert_ast_eq() function which can be used to compare two ASTs of the same type. If an error occurs, the ASTs are pretty printed and a diff is output so that the issue can be easily addressed.
Integration tests in the stylus-proc/tests directory. These allow compiled macros to be tested as working correctly. Additionally the stylus-proc/tests/fail directory will contain failing integration tests. These all fail to compile and include expected stderr outputs.
Modify code snippets within docstrings so that they are not ignored, and pass as part of the cargo test process.
A README.md which will contain information about developing and maintaining these proc macros.
Support for solidity.path.separator to rust::path::separator for custom structs within sol_interface! definitions.
Change the folder structure to have all macro implementations in a macros module. Easier to find the macro implementation you are looking for.
Docstrings within the macro implementations for developer reference.
Utilities for handing inner attributes including those which contain tokens which need to be parsed.
A little more work is going to be done before this is ready for merge, but it will be good to get this out for review since it is such a large set of changes.
Checklist
[ ] I have documented these changes where necessary.
[ ] I have read the DCO and ensured that these changes comply.
Description
This is a rather large refactor of the stylus proc macros with the main goal of improving maintainability, testability, and documentation of these macros. The following changes have been made:
assert_ast_eq()
function which can be used to compare two ASTs of the same type. If an error occurs, the ASTs are pretty printed and a diff is output so that the issue can be easily addressed.stylus-proc/tests
directory. These allow compiled macros to be tested as working correctly. Additionally thestylus-proc/tests/fail
directory will contain failing integration tests. These all fail to compile and include expected stderr outputs.cargo test
process.README.md
which will contain information about developing and maintaining these proc macros.solidity.path.separator
torust::path::separator
for custom structs withinsol_interface!
definitions.macros
module. Easier to find the macro implementation you are looking for.A little more work is going to be done before this is ready for merge, but it will be good to get this out for review since it is such a large set of changes.
Checklist