nanopass / nanopass-framework-scheme

The new nanopass framework; an embedded DSL for writing compilers in Scheme
nanopass.org
MIT License
487 stars 55 forks source link

Framework cannot handle languages with simple list of terminals #10

Open akeep opened 7 years ago

akeep commented 7 years ago

@LeifAndersen reported that a nanopass language with a simple list of expressions does not handle creating a list with no elements in it, even though this should be handled without a problem.

@LeifAndersen has a solution in the nanopass/nanopass-framework-racket, however, things have drifted enough that I'll need to adapt the solution a bit.

Here is the example:

(define-language Lsrc 
  (terminals
    (symbol (s))) 
  (Expr (e) 
    s
    (e* ...)))
(with-output-language (Lsrc Expr) `()) => '()

But should produce an Expr with an empty list in it.

amirouche commented 5 years ago

How to workaround that problem?

akeep commented 5 years ago

If you wan this syntax, there really isn't a work around for this. You can always add a keyword in the language:

(define-language Lsrc
  (terminals
    (symbol (s)))
  (Expr (e)
    s
    (list e* ...)))

For instance, will produce the expected language form in all cases:

> (with-output-language (Lsrc Expr) `(list a b c))
#[#{Lsrc:list:Expr.6 dykr8jd2wmthrm6w7m6embc8t-26} 2 (a b c)]
> (with-output-language (Lsrc Expr) `(list))
#[#{Lsrc:list:Expr.6 dykr8jd2wmthrm6w7m6embc8t-26} 2 ()]