akeep / nanopass-framework-racket

Racket port of the nanopass-framework
MIT License
34 stars 9 forks source link

nanopass-case #15

Open soegaard opened 9 years ago

soegaard commented 9 years ago

This may or may not be a bug in nanopass-case. If there were a nanopass-mailing list I would tried there before filing an issue.

This works:

 (let ([M (parse '((λ (x) x) 4))])
    (nanopass-case (LCS Term) M
       [(call ,M ,M1 ...) (list 'call M M1)]
      [else  'huh]))

But this

(let ([M (parse '(let (y 5) 6))])
    (nanopass-case (LCS Term) M
      [(let (,x ,M) ,M1 ...) (list M M1)]
      [else  'huh]))

gives the error:

define-pass: quoted terminals currently unsupported in match patterns in: (quote let)

The problem is that let is defined as a non-terminal of Term in the language LCS. I.e. it is not a quoted terminal.

Am I using nanopass-case in the wrong way, or is there a bug?

The entire program is here:

https://gist.github.com/soegaard/b52cb97f65c608251d60

akeep commented 9 years ago

What is you're language definition?  If you don't have a (let (x M) M* ...) in LCS Term, it having trouble finding a match, and hence trying to interpret it as a different production.

-andy:)

As far as a mailing list, up until now, it has only been a handful of people using this (and I work with most of them).  I'm happy to have the need to setup a list, and I'll try to do so this weekend.

On July 2, 2015 at 4:04:24 PM, Jens Axel Søgaard (notifications@github.com) wrote:

This may or may not be a bug in nanopass-case. If there were a nanopass-mailing list I would tried there before filing an issue.

This works:

(let ([M (parse '((λ (x) x) 4))]) (nanopass-case (LCS Term) M [(call ,M ,M1 ...) (list 'call M M1)] [else 'huh]))

But this

(let ([M (parse '(let (y 5) 6))]) (nanopass-case (LCS Term) M [(let (,x ,M) ,M1 ...) (list M M1)] [else 'huh]))

gives the error:

define-pass: quoted terminals currently unsupported in match patterns in: (quote let)

The problem is that let is defined as a non-terminal of Term in the language LCS. I.e. it is not a quoted terminal.

Am I using nanopass-case in the wrong way, or is there a bug?

The entire program is here:

https://gist.github.com/soegaard/b52cb97f65c608251d60

— Reply to this email directly or view it on GitHub.

soegaard commented 9 years ago

The language definition is here:

https://gist.github.com/soegaard/b52cb97f65c608251d60

2015-07-02 22:26 GMT+02:00 Andy Keep notifications@github.com:

What is you're language definition? If you don't have a (let (x M) M* ...) in LCS Term, it having trouble finding a match, and hence trying to interpret it as a different production.

-andy:)

As far as a mailing list, up until now, it has only been a handful of people using this (and I work with most of them). I'm happy to have the need to setup a list, and I'll try to do so this weekend.

On July 2, 2015 at 4:04:24 PM, Jens Axel Søgaard (notifications@github.com) wrote:

This may or may not be a bug in nanopass-case. If there were a nanopass-mailing list I would tried there before filing an issue.

This works:

(let ([M (parse '((λ (x) x) 4))]) (nanopass-case (LCS Term) M [(call ,M ,M1 ...) (list 'call M M1)] [else 'huh]))

But this

(let ([M (parse '(let (y 5) 6))]) (nanopass-case (LCS Term) M [(let (,x ,M) ,M1 ...) (list M M1)] [else 'huh]))

gives the error:

define-pass: quoted terminals currently unsupported in match patterns in: (quote let)

The problem is that let is defined as a non-terminal of Term in the language LCS. I.e. it is not a quoted terminal.

Am I using nanopass-case in the wrong way, or is there a bug?

The entire program is here:

https://gist.github.com/soegaard/b52cb97f65c608251d60

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/akeep/nanopass-framework-racket/issues/15#issuecomment-118156705 .

Jens Axel Søgaard

akeep commented 9 years ago

Yes, so your language definition does not match your pass, so the nanopass-framework is trying to figure out the best thing to do.

You have the productions:

(let (x M1) M2) and (M M1 …)

and you are trying to use the pattern:

(let (,x ,M1) ,M …)

This doesn’t match the (let (x M1) M2), because in the production you are expecting only one Term in the body, and in the pattern you are telling it you have a list of Term in the body. Since that doesn’t work, it tries to look for other productions that might work, and it finds (M M1 …) and starts trying to see if this will match, but when it tries to parse the (let (,x ,M1) ,M …) it realizes it needs to process the let as a quoted constant in a pattern, and this is what results in the error you are seeing (because this is not allowed).

Probably this is another thing that could use a better error message—possibly by special casing the error where the first field in the pattern might (or might not) be a keyword, and looking to see if there is already a production with this keyword.

-andy:)

On Jul 2, 2015, at 4:27 PM, Jens Axel Søgaard notifications@github.com wrote:

The language definition is here:

https://gist.github.com/soegaard/b52cb97f65c608251d60 https://gist.github.com/soegaard/b52cb97f65c608251d60

2015-07-02 22:26 GMT+02:00 Andy Keep <notifications@github.com mailto:notifications@github.com>:

What is you're language definition? If you don't have a (let (x M) M* ...) in LCS Term, it having trouble finding a match, and hence trying to interpret it as a different production.

-andy:)

As far as a mailing list, up until now, it has only been a handful of people using this (and I work with most of them). I'm happy to have the need to setup a list, and I'll try to do so this weekend.

On July 2, 2015 at 4:04:24 PM, Jens Axel Søgaard (notifications@github.com mailto:notifications@github.com) wrote:

This may or may not be a bug in nanopass-case. If there were a nanopass-mailing list I would tried there before filing an issue.

This works:

(let ([M (parse '((λ (x) x) 4))]) (nanopass-case (LCS Term) M [(call ,M ,M1 ...) (list 'call M M1)] [else 'huh]))

But this

(let ([M (parse '(let (y 5) 6))]) (nanopass-case (LCS Term) M [(let (,x ,M) ,M1 ...) (list M M1)] [else 'huh]))

gives the error:

define-pass: quoted terminals currently unsupported in match patterns in: (quote let)

The problem is that let is defined as a non-terminal of Term in the language LCS. I.e. it is not a quoted terminal.

Am I using nanopass-case in the wrong way, or is there a bug?

The entire program is here:

https://gist.github.com/soegaard/b52cb97f65c608251d60

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub <https://github.com/akeep/nanopass-framework-racket/issues/15#issuecomment-118156705 https://github.com/akeep/nanopass-framework-racket/issues/15#issuecomment-118156705> .

Jens Axel Søgaard — Reply to this email directly or view it on GitHub https://github.com/akeep/nanopass-framework-racket/issues/15#issuecomment-118157368.

soegaard commented 9 years ago

The example was:

(let ([M (parse '(let (y 5) 6))])
   (nanopass-case (LCS Term) M
       [(let (,x ,M) ,M1 ...) (list M M1)]
       [else 'huh]))

For some reason I fixated on the pattern ,M1 ... should the 6 and therefore (let (x, M) ,M1 ...) ought to be allowed.

I forgot that parse turns the expression into nanopass-structures and thus it now makes sense that ,M1 ... doesn't work.

The error message I got

define-pass: quoted terminals currently unsupported in match patterns

in: (quote let)

was not that helpful though. If it were worded to suggest that there was a problem with the full (let (,x ,M) ,M1 ...) form I might have spotted the problem.

I see now that the let error comes from trying to interpret the pattern as an s-expression-production, but that isn't obvious for a nanopass beginner.

Thanks for the explanation, Jens Axel

akeep commented 9 years ago

Yeah, I definitely agree the error message should be better.  When Kent (my advisor) and I were first recoding Chez Scheme with the nanopass framework we tried to be careful about fixing error messages when we encountered bad ones, but clearly more of that needs to happen, which is why I appreciate the bug reports!

I'll try to get some more fixes in for bad error messages today, if I get some time to work on it.

-andy:) On July 3, 2015 at 1:16:29 PM, Jens Axel Søgaard (notifications@github.com) wrote:

The example was:

(let ([M (parse '(let (y 5) 6))]) (nanopass-case (LCS Term) M [(let (,x ,M) ,M1 ...) (list M M1)] [else 'huh]))

For some reason I fixated on the pattern ,M1 ... should the 6 and therefore (let (x, M) ,M1 ...) ought to be allowed.

I forgot that parse turns the expression into nanopass-structures and thus it now makes sense that ,M1 ... doesn't work.

The error message I got

define-pass: quoted terminals currently unsupported in match patterns in: (quote let)

was not that helpful though. If it were worded to suggest that there was a problem with the full (let (,x ,M) ,M1 ...) form I might have spotted the problem.

I see now that the let error comes from trying to interpret the pattern as an s-expression-production, but that isn't obvious for a nanopass beginner.

Thanks for the explanation, Jens Axel — Reply to this email directly or view it on GitHub.

akeep commented 9 years ago

Initial issue is fixed by fix to #9, however, the issue with the define language is not yet fixed, so this is really a new error.

soegaard commented 2 years ago

Should this be closed?