Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions effekt/shared/src/main/scala/effekt/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ class Parser(tokens: Seq[Token], source: Source) {
nonterminal:
var left = nonTerminal()
while (ops.contains(peek.kind)) {
checkBinaryOpWhitespace()
val op = next()
val right = nonTerminal()
left = binaryOp(left, op, right)
Expand Down Expand Up @@ -1053,6 +1054,34 @@ class Parser(tokens: Seq[Token], source: Source) {
def TypeTuple(tps: Many[Type]): Type =
TypeRef(IdRef(List("effekt"), s"Tuple${tps.size}", tps.span.synthesized), tps, tps.span.synthesized)

// Check that the current token is surrounded by whitespace.
// If not, soft fail.
//
// NOTE: Ideally, we'd reintroduce whitespace tokens and then just check here that
// the tokens at `position - 1` and `position + 1` are in fact, `isSpace`.
// But as of writing this, lexer doesn't even report whitespace tokens, so they never reach here.
private def checkBinaryOpWhitespace(): Unit = {
val opToken = peek
val opStart = opToken.start
val opEnd = opToken.end

// Check character immediately before operator
val wsBefore = opStart > 0 && {
val charBefore = source.content.charAt(opStart - 1)
charBefore.isWhitespace
}

// Check character immediately after operator
val wsAfter = opEnd + 1 < source.content.length && {
val charAfter = source.content.charAt(opEnd + 1)
charAfter.isWhitespace
}

if (!wsBefore || !wsAfter) {
softFail(s"Missing whitespace around binary operator", position, position)
}
}

/**
* This is a compound production for
* - member selection <EXPR>.<NAME>
Expand Down
6 changes: 3 additions & 3 deletions examples/benchmarks/are_we_fast_yet/nbody.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def run(n: Int) = {
def offsetMomentum(body: Body, px: Double, py: Double, pz: Double) =
Body(
body.x, body.y, body.z,
0.0 -(px / SOLAR_MASS),
0.0 -(py / SOLAR_MASS),
0.0 -(pz / SOLAR_MASS),
0.0 - (px / SOLAR_MASS),
0.0 - (py / SOLAR_MASS),
0.0 - (pz / SOLAR_MASS),
body.mass)

bodies.unsafeSet(0, sun.offsetMomentum(px, py, pz))
Expand Down
2 changes: 1 addition & 1 deletion examples/llvm/gids.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ def main() = region r {
println(g())
println(h())
} with GID {
def gid() = { n = n+1; resume(n) }
def gid() = { n = n + 1; resume(n) }
}
}
4 changes: 2 additions & 2 deletions examples/llvm/localfunctionasargument.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ def hof(x: Int){ f: Int => Int }: Int = {
}

def foo(a: Int) = {
def bar(b: Int): Int = b*a
def bar(b: Int): Int = b * a
hof(5){bar}
}

def main() = {
def main() = {
println(foo(2))
}
2 changes: 1 addition & 1 deletion examples/llvm/polymorphic_failtooption.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def safeDiv(x: Int, y: Int): Int / Fail = {
if (y == 0){
do Fail(); 0
} else {
x/y
x / y
}
}

Expand Down
26 changes: 13 additions & 13 deletions examples/llvm/polymorphism_data.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ def map[A,B](l: List[A]){ f: A => B }: List[B] = {

def show(i: Int): String = {
def impl_digit(i: Int): String = {
if(i==0){"0"} else
if(i==1){"1"} else
if(i==2){"2"} else
if(i==3){"3"} else
if(i==4){"4"} else
if(i==5){"5"} else
if(i==6){"6"} else
if(i==7){"7"} else
if(i==8){"8"} else
if(i==9){"9"} else
if(i == 0){"0"} else
if(i == 1){"1"} else
if(i == 2){"2"} else
if(i == 3){"3"} else
if(i == 4){"4"} else
if(i == 5){"5"} else
if(i == 6){"6"} else
if(i == 7){"7"} else
if(i == 8){"8"} else
if(i == 9){"9"} else
"?"
}
def impl(i: Int): String = {
if(i<10){impl_digit(i)}else{
impl(i/10) ++ impl_digit(mod(i,10))
if(i < 10){impl_digit(i)}else{
impl(i / 10) ++ impl_digit(mod(i, 10))
}
}
if(i==0) {
if(i == 0) {
"0"
} else {
impl(i)
Expand Down
2 changes: 1 addition & 1 deletion examples/pos/doubles.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def main() = {
println(1.2 + 2.0 * 3.0 / 4.0 + 1.4);
println(toInt(1.5));
println(round(1.5));
println(toDouble(2)+ 0.1);
println(toDouble(2) + 0.1);
println(floor(1.7));
println(ceil(2.1));
}
2 changes: 1 addition & 1 deletion examples/pos/issue661.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def my_map[T, U] {action: () => Unit / {Iter[T]}} {f: T => U}: Unit / {Iter[U]}
}

def main() =
try my_map { iter([1, 2, 3]) } { x => x+1 }
try my_map { iter([1, 2, 3]) } { x => x + 1 }
with Iter[Int] {
def yield(x) = { println(x); resume(()) }
}
2 changes: 1 addition & 1 deletion libraries/common/random.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def main() = {
val b = randomInt(0, 9)
val c = randomInt(0, 9)
println(a.show ++ " " ++ b.show ++ " " ++ c.show)
println(a*100 + b*10 + c)
println(a * 100 + b * 10 + c)
}
}

Expand Down