vapourlang / vapour

Typed superset of R
http://vapour.run
Apache License 2.0
194 stars 3 forks source link

Spacing and newline edits #66

Open jonocarroll opened 2 months ago

jonocarroll commented 2 months ago

Feel free to ignore this - I just wanted to play around with it and see if I could fix a very minor annoyance.

With this toy vapour code

func foo(a: int = 1, b: char = "", c:char = ""): int {
    return paste(b, c, a)
}

let bar: int = foo(0, "Hello, ", "World!")

I get this result

vapour@0.0.5

foo = function(a = 1,b = "",c = "") {
return(paste(b, c, a)
)
}
bar = foo(0, "Hello, ", "World!")

With the minor changes in this PR, I get

vapour@0.0.6

foo = function(a = 1, b = "", c = "") {
return(paste(b, c, a))
}
bar = foo(0, "Hello, ", "World!")

I have not tested what else this changes or if this is even the right place to make these changes. Actually, I'm fairly sure it's not for the extra newline; it happens for other functions containing expressions, too.

One option would be to style the generated R file with e.g. {styler} which would take care of any inconsistencies from transpilation, e.g. dealing with indentation which sounds like a whole world of trouble. Running styler::style_file("R/vapour.R") over the file generated by vapour@0.0.5 produces

foo <- function(a = 1, b = "", c = "") {
  return(paste(b, c, a))
}
bar <- foo(0, "Hello, ", "World!")

which appears to have fixed both issues.

JohnCoene commented 2 months ago

Sorry for commenting on this so late!

The reason for the (too) numerous line breaks is partially an issue I have in parser #29 which I will look into soon.

I did some thinking about the transpiler and realise we would just need to add indentation \t when we enclose an environment. I think we can already get much cleaner code.