feat: support generics with define_language
macro
#318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Before this PR, it was not possible to define generic
Language
usingdefine_macro
because the macro itself was not parsing the generic part. So the following code piece was failing:Where
SaturationNumber
is a super trait of required set of traits such asFromStr
,Debug
,Display
etc. This PR adds the required parsing patterns to the macro so that it is possible to define such language enums, using the macro easily. I added a test to showcase both that:T
that the language is generic over (Display
).Docs are updated to showcase new generic language usage.
Motivation
I wanted to make my language generic over the number type. So that I can easily switch between different custom number representations to experiment with the effect on saturation performance given that some implementations are going to be faster to work with, saturation might be able to cover a larger space and I wanted to observe the effect experimentally without needing to re-implement same language. But in more general it should be useful to anyone who requires to define a language generic over a type.