Replies: 1 comment 1 reply
-
@tcallred Thanks for this proposal! I think you were also considering the idea of allowing an abbreviaton when a
Did you maybe conclude that it's not a good idea? On the plus side, it seems like many uses of |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Rhombus and its syntactic primitives give us the opportunity to make defining a syntax class for macros especially nice. Here I'd like to share my ideas for how syntax classes might look.
General structure
Syntax classes are defined with a top-level binding form
stx_class
and take a name (Foo
) and a block. Inside the block, there would be a special binding formpatterns
that takes variants of different patterns to match on.Usage:
When defining a macro, we can declare parts of a pattern to be of a certain syntax class with the
$(name :: Class)
form. Then, inside the macro definition, we can use dot notation to extract the pattern variables and attributes from the matched pattern variable of the syntax class.Description and errors
To define an optional description and error to be thrown for the syntax class, we can use more special defining forms inside the body of the syntax class. These would take a block returning a string.
Pattern directives
Instead of pattern directives like the ones used in Racket syntax classes, we can allow pattern variants to take a block after the syntax pattern and the code in that block will be run when the pattern matches.
Definitions/attributes
Inside this block, you can define new variables within the scope like you would normally do with
def
,let
, etc. There could also be a special binding form calledattr
that will define an attribute of the matched syntax class that will be exposed and made available for the user of the syntax class.Guards
You could also declare guards within this block. These take a predicate expression and if the expression evaluates to false it will immediately reject that variant and move on to try and match on any of the remaining variants.
I would also propose a shorthand syntax in the form of a keyword
~when
following the patterns. (This shorthand would only have pattern variables matched in the pattern available to it).Pattern-specific errors
There could also be a form inside the body of the pattern variant for throwing specific errors. This could take a predicate and a block returning a string error message.
Beta Was this translation helpful? Give feedback.
All reactions