Closed kkirby closed 10 years ago
macro \\
syntax b as Body
ASTE $b
if thisreallylongexpression and \\
thisOtherReallyLongExpression
Do something
works for this simple two-line expression. Not an elegant solution, though. For multiline one it becomes
if one and \\
two and \\
three and \\
four \\
Do something
with successive indentings.
I’m not a pro in writing macros and processing AST nodes; it may be better solution.
Ha, that's pretty brilliant. Thanks!
A bit better:
macro multiline!
syntax op as Logic, b as Body
let mutable vals = null
if b.func.inspect() == 'Symbol.block'
vals := b.args[0].args[0]
for line, ind in b.args
if ind
vals := @call op, vals, line.args[0]
else
vals := b.args[0]
vals
if multiline! (and)
_ thisreallylongexpression
_ thisOtherReallyLongExpression
_ that.Other + Really (complex Expression or not very) and multiline! (or)
// An ignored underscore may be replaced by any identifier
// but not a macro, hence ‘OR’, not ‘or’:
OR true
OR false
Do something
It’s somewhat tricky but seems to work.
It can be used not only with logical expressions:
let sum = multiline! (+)
_ first.summand
_ second summand
_ this.is the-third
I had to use function-call syntax with ignored callee (‘_ something’ is syntactically nothing more than function call) due to GorillaScript’s annihilation of evidently-non-side-effect expressions. So,
bad-multiline! (and)
one two
three.four
five()
would immediately reduce to
bad-multiline! (and)
one two
five()
Coming back to this after awhile, but @McSaks you can also do:
if (and)(
a == b,
c == d
)
console.log true
@kkirby, Well, it was facepalmly obvious… in retrospective. Heh, Haven’t heard of gorilla for years, nearly forgot. It didn’t run now without a patch.
@McSaks Yeah, check out my fork at https://github.com/kkirby/gorillascript it has a few patches keeping GorillaScript working with the newer javascript engines.
The only issue with that (and)(...)
style is that is breaks shortcircuiting :/.
Is it possible to have multiline if statements?
Thanks