erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.69k stars 55 forks source link

Add stream operator #233

Closed ytoml closed 1 year ago

ytoml commented 1 year ago

Fixes #170 .

Hi, I implemented stream operator.

Changes proposed in this PR:

print! 1 |> Point.new(10) |> .norm() # prints 101



@mtshiba
mtshiba commented 1 year ago

Thank you. But I found a mistake in the parsing.

print!(1 + 1 |> f())
print!(1 + 1 |> .abs())

should be

print!(f(1+1))
print!((1+1).abs())

but we got

image

ytoml commented 1 year ago

Thanks, I fixed it by collecting binop(Expr Op Expr) into single Expr before parsing a pipe op, in order to confirm that all BinOps precede pipes.

ytoml commented 1 year ago

stream.er:

スクリーンショット 2022-11-16 13 08 27
mtshiba commented 1 year ago

Thank you!