Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in syntax templates don't greedily tokenize dollar before curly brace #732

Open
disnet opened this issue Jul 13, 2017 · 4 comments
Open

Comments

@disnet
Copy link
Member

disnet commented Jul 13, 2017

eg:

#`foo${...}`
@gabejohnson
Copy link
Member

So you're saying this should be tokenized as foo$ and {...}?

If so, I would find this behavior surprising as it is at odds w/ template literal syntax.

@disnet
Copy link
Member Author

disnet commented Jul 16, 2017

I also would find that behavior surprising...it's the current behavior :)

syntax m = function (ctx) {
  return #`foo${x}`;
}
m

expands to:

foo$;
{
  x;
}

Sorry for the unclear issue description. Was in a rush the other day.

@gabejohnson
Copy link
Member

Haha! The title is a directive, not a description.

I know what's going on and think I have a solution. I'll check it out tonight.

@gabejohnson
Copy link
Member

It's never as easy as I think. The source of the problem is simple. Syntax templates are being lexed as regular source strings, bookended by LSYNTAX and RSYNTAX tokens. They are then parsed and the identifier $ coming before {...} is consumed. This doesn't work for foo${...} as foo$ is a valid identifier.

My first thought was to make $ a terminating character. But that fails unless it's followed by {.

Another strategy is to tokenize syntax templates just as we do string templates. Then do a second pass and run the template elements through the reader. This might work as a hack, but source information (line & column number) is gonna be all messed up.

The "correct" answer is probably to add multi-character dispatch. It looks like more and more weight is building up to a rewrite of the reader.

As soon as things die down a bit at work I plan to prototype something in PureScript using parser combinators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants