-
-
Save wavebeem/1577a0988dd40ea5aa9a1e9c1153febe to your computer and use it in GitHub Desktop.
Which syntax reigns supreme?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r => { | |
var ElseIf = ( | |
P.seqObj( | |
keyword("elseif"), | |
r.Expr.trim(_).as("condition"), | |
keyword("then"), | |
r.Block.trim(_).as("block"), | |
).node("ElseIf") | |
); | |
return ( | |
P.seqObj( | |
keyword("if"), | |
r.Expr.trim(_).as("ifCondition"), | |
keyword("then"), | |
r.Block.trim(_).as("ifBlock"), | |
ElseIf.many().as("elseIfBranches"), | |
keyword("else"), | |
r.Block.trim(_).as("elseBlock"), | |
keyword("end"), | |
).node("If") | |
); | |
}; | |
// or with more whitespace | |
r => { | |
var ElseIf = ( | |
P.seqObj( | |
keyword("elseif"), | |
r.Expr.trim(_) | |
.as("condition"), | |
keyword("then"), | |
r.Block.trim(_) | |
.as("block"), | |
).node("ElseIf") | |
); | |
return ( | |
P.seqObj( | |
keyword("if"), | |
r.Expr.trim(_) | |
.as("ifCondition"), | |
keyword("then"), | |
r.Block.trim(_) | |
.as("ifBlock"), | |
ElseIf.many() | |
.as("elseIfBranches"), | |
keyword("else"), | |
r.Block.trim(_) | |
.as("elseBlock"), | |
keyword("end"), | |
).node("If") | |
); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r => { | |
var ElseIf = ( | |
P.seqObj( | |
keyword("elseif"), | |
["condition", r.Expr.trim(_)], | |
keyword("then"), | |
["block", r.Block.trim(_)], | |
).node("ElseIf") | |
); | |
return ( | |
P.seqObj( | |
keyword("if"), | |
["ifCondition", r.Expr.trim(_)], | |
keyword("then"), | |
["ifBlock", r.Block.trim(_)], | |
["elseIfBranches", ElseIf.many()], | |
keyword("else"), | |
["elseBlock", r.Block.trim(_)], | |
keyword("end"), | |
).node("If") | |
); | |
}; | |
r => { | |
var ElseIf = ( | |
P.seqObj( | |
keyword("elseif"), | |
[ | |
"condition", | |
r.Expr.trim(_) | |
], | |
keyword("then"), | |
[ | |
"block", | |
r.Block.trim(_) | |
], | |
).node("ElseIf") | |
); | |
return ( | |
P.seqObj( | |
keyword("if"), | |
[ | |
"ifCondition", | |
r.Expr.trim(_) | |
], | |
keyword("then"), | |
[ | |
"ifBlock", | |
r.Block.trim(_) | |
], | |
[ | |
"elseIfBranches", | |
ElseIf.many() | |
], | |
keyword("else"), | |
[ | |
"elseBlock", | |
r.Block.trim(_) | |
], | |
keyword("end"), | |
).node("If") | |
); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r => { | |
var ElseIf = ( | |
P.seqObj( | |
keyword("elseif"), | |
{ condition: r.Expr.trim(_) }, | |
keyword("then"), | |
{ block: r.Block.trim(_) }, | |
).node("ElseIf") | |
); | |
return ( | |
P.seqObj( | |
keyword("if"), | |
{ ifCondition: r.Expr.trim(_) }, | |
keyword("then"), | |
{ ifBlock: r.Block.trim(_) }, | |
{ elseIfBranches: ElseIf.many() }, | |
keyword("else"), | |
{ elseBlock: r.Block.trim(_) }, | |
keyword("end"), | |
).node("If") | |
); | |
}; | |
r => { | |
var ElseIf = ( | |
P.seqObj( | |
keyword("elseif"), | |
{ | |
condition: r.Expr.trim(_) | |
}, | |
keyword("then"), | |
{ | |
block: r.Block.trim(_) | |
}, | |
).node("ElseIf") | |
); | |
return ( | |
P.seqObj( | |
keyword("if"), | |
{ | |
ifCondition: r.Expr.trim(_) | |
}, | |
keyword("then"), | |
{ | |
ifBlock: r.Block.trim(_) | |
}, | |
{ | |
elseIfBranches: ElseIf.many() | |
}, | |
keyword("else"), | |
{ | |
elseBlock: r.Block.trim(_) | |
}, | |
keyword("end"), | |
).node("If") | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment