unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* how to implement mutual recursive parsers in syntax-parse
@ 2012-05-14 19:13 Stefan Israelsson Tampe
  2012-05-15 18:38 ` Andy Wingo
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Israelsson Tampe @ 2012-05-14 19:13 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 682 bytes --]

I do have a cludgy fix for this but are in search for a better solution.

consider the problem:

(define-syntax-class a (pattern (1 x:b)) (pattern ()))
(define-syntax-class b (pattern (2 x:a)) (pattern ()))

the syntax class definitions above would expand to something like

(begin
   (define parser-a code-a ...)
   (define-syntax a spec-a))

(begin
   (define parser-b code-b ...)
   (define-syntax b spec-b))

In racket they manage to evaluate the define-syntax forms before the
define-forms cause in the expansion
of code-a amd code-b they need the spec's spec-a and spec-b.

Do you have any ideas how solve this. I do have a fix for problem but it is
not easy to use.

/Stefan

[-- Attachment #2: Type: text/html, Size: 769 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to implement mutual recursive parsers in syntax-parse
  2012-05-14 19:13 how to implement mutual recursive parsers in syntax-parse Stefan Israelsson Tampe
@ 2012-05-15 18:38 ` Andy Wingo
  2012-05-18 21:58   ` Stefan Israelsson Tampe
  2012-05-18 22:05   ` Stefan Israelsson Tampe
  0 siblings, 2 replies; 7+ messages in thread
From: Andy Wingo @ 2012-05-15 18:38 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: guile-devel

On Mon 14 May 2012 21:13, Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:

> (begin
>    (define parser-a code-a ...)
>    (define-syntax a spec-a))
>
> (begin
>    (define parser-b code-b ...)
>    (define-syntax b spec-b))
>
> In racket they manage to evaluate the define-syntax forms before the define-forms cause in the expansion
> of code-a amd code-b they need the spec's spec-a and spec-b.
>
> Do you have any ideas how solve this. I do have a fix for problem but it is not easy to use.

Have you tried master?  If I understand you correctly I think it should
work there.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to implement mutual recursive parsers in syntax-parse
  2012-05-15 18:38 ` Andy Wingo
@ 2012-05-18 21:58   ` Stefan Israelsson Tampe
  2012-05-21  8:25     ` Andy Wingo
  2012-05-18 22:05   ` Stefan Israelsson Tampe
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Israelsson Tampe @ 2012-05-18 21:58 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1339 bytes --]

I manage to make it work under master as well as guile-2.0
But the mutual code does not work. On the other hand what you said
some months ago was correct and I believe that we do not need special
constructs
for local syntax-classes anymore which if correct is a plus.

Please read the mail again is master supposed to expand and evaluate all
the syntax
defines before expanding the defines? And if a plain macro is encountered
at the toplevel
it is expanded as well in the first run. I don't understand exactly how the
expansion progresses so can you describe or link to a description?

Regards
Stefan

On Tue, May 15, 2012 at 8:38 PM, Andy Wingo <wingo@pobox.com> wrote:

> On Mon 14 May 2012 21:13, Stefan Israelsson Tampe <stefan.itampe@gmail.com>
> writes:
>
> > (begin
> >    (define parser-a code-a ...)
> >    (define-syntax a spec-a))
> >
> > (begin
> >    (define parser-b code-b ...)
> >    (define-syntax b spec-b))
> >
> > In racket they manage to evaluate the define-syntax forms before the
> define-forms cause in the expansion
> > of code-a amd code-b they need the spec's spec-a and spec-b.
> >
> > Do you have any ideas how solve this. I do have a fix for problem but it
> is not easy to use.
>
> Have you tried master?  If I understand you correctly I think it should
> work there.
>
> Andy
> --
> http://wingolog.org/
>

[-- Attachment #2: Type: text/html, Size: 1902 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to implement mutual recursive parsers in syntax-parse
  2012-05-15 18:38 ` Andy Wingo
  2012-05-18 21:58   ` Stefan Israelsson Tampe
@ 2012-05-18 22:05   ` Stefan Israelsson Tampe
  2012-05-21  8:59     ` Andy Wingo
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Israelsson Tampe @ 2012-05-18 22:05 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1255 bytes --]

Another clue,

Put this into a file and load it

 (define (f x) (c))
 (define-syntax c (lambda (x) (pk 'c) #t))

,x f shows

   0    (assert-nargs-ee/locals 1)      ;; 1 arg, 0 locals
   2    (toplevel-ref 1)                ;; #<syntax-transformer c>
   4    (tail-call 0)                                         at
examples/mutual.scm:9:14

and (f 1) yields

scheme@(guile-user) [4]> (f 1)
ERROR: In procedure #<syntax-transformer c>:
ERROR: Wrong type to apply: #<syntax-transformer c>

This is confusing!!

/Stefan

On Tue, May 15, 2012 at 8:38 PM, Andy Wingo <wingo@pobox.com> wrote:

> On Mon 14 May 2012 21:13, Stefan Israelsson Tampe <stefan.itampe@gmail.com>
> writes:
>
> > (begin
> >    (define parser-a code-a ...)
> >    (define-syntax a spec-a))
> >
> > (begin
> >    (define parser-b code-b ...)
> >    (define-syntax b spec-b))
> >
> > In racket they manage to evaluate the define-syntax forms before the
> define-forms cause in the expansion
> > of code-a amd code-b they need the spec's spec-a and spec-b.
> >
> > Do you have any ideas how solve this. I do have a fix for problem but it
> is not easy to use.
>
> Have you tried master?  If I understand you correctly I think it should
> work there.
>
> Andy
> --
> http://wingolog.org/
>

[-- Attachment #2: Type: text/html, Size: 1873 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to implement mutual recursive parsers in syntax-parse
  2012-05-18 21:58   ` Stefan Israelsson Tampe
@ 2012-05-21  8:25     ` Andy Wingo
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Wingo @ 2012-05-21  8:25 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: guile-devel

On Fri 18 May 2012 23:58, Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:

> is master supposed to expand and evaluate all the syntax defines
> before expanding the defines?

Yes, provided they are within one expansion unit -- i.e. a "begin"
statement.  Separate toplevel forms are expanded separately.

> And if a plain macro is encountered at the toplevel it is expanded as
> well in the first run. I don't understand exactly how the expansion
> progresses so can you describe or link to a description?

From psyntax.scm:

    ;; At top-level, we allow mixed definitions and expressions.  Like
    ;; expand-body we expand in two passes.
    ;;
    ;; First, from left to right, we expand just enough to know what
    ;; expressions are definitions, syntax definitions, and splicing
    ;; statements (`begin').  If we anything needs evaluating at
    ;; expansion-time, it is expanded directly.
    ;;
    ;; Otherwise we collect expressions to expand, in thunks, and then
    ;; expand them all at the end.  This allows all syntax expanders
    ;; visible in a toplevel sequence to be visible during the
    ;; expansions of all normal definitions and expressions in the
    ;; sequence.
    ;;

Cheers,

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to implement mutual recursive parsers in syntax-parse
  2012-05-18 22:05   ` Stefan Israelsson Tampe
@ 2012-05-21  8:59     ` Andy Wingo
  2012-05-21  9:33       ` Stefan Israelsson Tampe
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Wingo @ 2012-05-21  8:59 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: guile-devel

On Sat 19 May 2012 00:05, Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:

>  (define (f x) (c))
>  (define-syntax c (lambda (x) (pk 'c) #t))

These expressions are expanded in order, not together.  To expand them
together they need to be wrapped in a "begin".

We can consider changing our toplevel expansion process to do something
else, if there is a right thing.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to implement mutual recursive parsers in syntax-parse
  2012-05-21  8:59     ` Andy Wingo
@ 2012-05-21  9:33       ` Stefan Israelsson Tampe
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Israelsson Tampe @ 2012-05-21  9:33 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 525 bytes --]

Jolly nice, this is perfect!
Den 21 maj 2012 10:59 skrev "Andy Wingo" <wingo@pobox.com>:

> On Sat 19 May 2012 00:05, Stefan Israelsson Tampe <stefan.itampe@gmail.com>
> writes:
>
> >  (define (f x) (c))
> >  (define-syntax c (lambda (x) (pk 'c) #t))
>
> These expressions are expanded in order, not together.  To expand them
> together they need to be wrapped in a "begin".
>
> We can consider changing our toplevel expansion process to do something
> else, if there is a right thing.
>
> Andy
> --
> http://wingolog.org/
>

[-- Attachment #2: Type: text/html, Size: 921 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-05-21  9:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-14 19:13 how to implement mutual recursive parsers in syntax-parse Stefan Israelsson Tampe
2012-05-15 18:38 ` Andy Wingo
2012-05-18 21:58   ` Stefan Israelsson Tampe
2012-05-21  8:25     ` Andy Wingo
2012-05-18 22:05   ` Stefan Israelsson Tampe
2012-05-21  8:59     ` Andy Wingo
2012-05-21  9:33       ` Stefan Israelsson Tampe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).