Skip to content

Instantly share code, notes, and snippets.

@wavebeem
Created Jun 23, 2017
Embed
What would you like to do?
Which syntax reigns supreme?
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")
);
};
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")
);
};
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