Ideas and Issues for syntax/parse in Rhombus #194
tail-reversion
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My first observation is that the interfaces can be simplified a bit because deprecated options can be omitted, literals needn’t be declared in Rhombus syntax templates, and the
#:track-literals
option ofsyntax-parse
can always be implicitly active.Questions Raised by Shrubbery
The
syntax/parse
pattern grammar has its S-, H-, EH-, and A-patterns. What should the pattern grammar for the Rhombus version look like? This will depend partly on the particular underlying language grammar that is finally selected.As a first step towards porting
syntax/parse
to Rhombus, I suggest adding an operator,%
(or some other name) that serves as an escape to the various pattern forms ofsyntax/parse
. As an example:Of course, some patterns could be simplified with syntax-level operators, such as
pat1 <&> pat2
being used for%and(pat1, pat2)
. In particular, for the times where the#:role
part of a variable annotation is omitted, a binary annotation syntax like$var $: syntax_class
could be used.Significant Changes
These are some changes that I think could improve the clarity and utility of
syntax/parse
:List(Syntax)
, a depth of 2 asList(List(Syntax))
, &c.Syntax Classes as First-Class Types
My idea is to make syntax classes more like structs (classes, in Rhombus). This would both simplify writing macros and (perhaps) provide a small performance boost.
Say that I define the following syntax class:
being analogous to the Racket syntax class:
given some term
op_expr $: Binop
, I could write'($op_expr.operator)
to retrieve the operator attribute and write'($op_expr)
to retrieve the original raw syntax.Thus, syntax that is parsed according to a syntax class are, effectively, converted into a struct of the form
This has the immediate benefit of eliminating the frustrating pattern of having to use
define/syntax-parse
to reparse syntax stored in some data so that the attributes are again accessible. The aforementioned performance boost would come from eliminating these reparsings.Finally, since parsed syntax would now be first-class, the
attribute
form for accessing attributes outside of a syntax template would be unnecessary. One could simply writevar.attr
.Beta Was this translation helpful? Give feedback.
All reactions