takikawa / sweet-racket

A port of sweet expressions to Racket
http://pkg-build.racket-lang.org/doc/sweet/index.html
Other
47 stars 10 forks source link

Added \\ processing, fixed parsing bug #44

Open Kalimehtar opened 4 years ago

Kalimehtar commented 4 years ago

There was a bug.

list 1 2 3
  list 4 5

raised a error, because it was parsed as (list 1 2 3 (list 4 . 5)) Now it's fixed.

And now \ can be not only an empty head, but also can be used to split a list.

let
  \\
    a 1 \\ b 2 \\ c 3
  {a + b + c}

or

map $ lambda (x) {1 / x} \\ '(1 2 3)
AlexKnauth commented 2 years ago

In what situation did that nested list expression parse as (list 1 2 3 (list 4 . 5))?

I'm having trouble reproducing that bug:

#lang sweet-exp racket
list 1 2 3
  list 4 5

produces (list 1 2 3 (list 4 5)) as expected.

Kalimehtar commented 2 years ago

Delete last newline. If "5" is the last character of the file, then branch [(eof-object? rest) (cons new-level first)] returns item, while a list is expected.

AlexKnauth commented 2 years ago

The precedence between $ sublist and \\ split is off. I thought something like

map $ lambda (x) {1 / x} \\ '(1 2 3)

was supposed to parse as

(map (lambda (x) (/ 1 x)))
'(1 2 3)

and not as

(map (lambda (x) (/ 1 x))
     '(1 2 3))
Kalimehtar commented 2 years ago

Then raise block [(e1 ... (~and $ (~datum $)) e2 ...) ...] before [(before ... (e1 (~literal \\) e2) after ...). It will switch the precedence.

Kalimehtar commented 2 years ago

I'm wrong. \\ processed (in my commit) first, so map $ lambda (x) {1 / x} \\ '(1 2 3) is really

map $ lambda (x) {1 / x}
'(1 2 3)
AlexKnauth commented 2 years ago

Okay. This definitely needs some tests then.