Re: [racket-users] help with splicing syntax class error report
On Tuesday, March 14, 2017 at 11:05:08 AM UTC-7, Stephen Chang wrote: > > 1) Use a commit pattern, which tells syntax-parse not to backtrack > past the commit point. You have to change the order of patterns for > this to work. > [...] > 2) Use the ~post pattern, which essentially tells syntax-parse to give > priority to a particular pattern. > Both these suggestions have been helpful, in addition to these from Philip McGrath: > > This works: > #lang racket/base > > (require > (for-syntax > racket/base > syntax/parse > )) > > (define-syntax (test stx) > > (define-splicing-syntax-class maybe > #:datum-literals (:thing) > (pattern (~seq :thing n:id)) > (pattern (~seq ) #:attr n #'0)) > > (syntax-parse stx > #:datum-literals (:thing) > ((_ a:maybe > (~describe "parenthesized sequence of identifiers" >(b:id ...))) > #''(a.n b ... > > (test (x y z)) > (test :thing v (x y z)) > (test :thung v (x y z)) > > You could also do this using ~optional instead of a syntax class if you want: > (define-syntax (test stx) > (syntax-parse stx > #:datum-literals (:thing) > ((_ (~optional (~seq :thing n:id) >#:defaults ([n #'0])) > (~describe "parenthesized sequence of identifiers" >(b:id ...))) > #''(n b ... -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] help with splicing syntax class error report
You get the dreaded "bad syntax" because syntax-parse doesnt know which pattern failed. There a couple of things you can do: 1) Use a commit pattern, which tells syntax-parse not to backtrack past the commit point. You have to change the order of patterns for this to work. (define-splicing-syntax-class maybe #:datum-literals (:thing) (pattern (~seq) #:attr n #'0) (pattern (~seq ~! :thing n:id))) 2) Use the ~post pattern, which essentially tells syntax-parse to give priority to a particular pattern. (define-splicing-syntax-class maybe #:datum-literals (:thing) (pattern (~post (~seq :thing n:id))) (pattern (~seq) #:attr n #'0)) On Tue, Mar 14, 2017 at 1:13 PM, Dan Liebgold wrote: > Hi - > > I have some legacy code syntax I'm retrofitting with syntax-parse. Is there a > simple way to have this type of syntax error report a better error message: > > http://pasterack.org/pastes/59739 > > I'd like it to point directly to ":thung" and say it expected ":thing" or > nothing there if possible. > > Thanks, > Dan > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] help with splicing syntax class error report
Hi - I have some legacy code syntax I'm retrofitting with syntax-parse. Is there a simple way to have this type of syntax error report a better error message: http://pasterack.org/pastes/59739 I'd like it to point directly to ":thung" and say it expected ":thing" or nothing there if possible. Thanks, Dan -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.