Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do block syntax: tuple arguments #19

Merged
merged 3 commits into from
Jan 17, 2025
Merged
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
2 changes: 1 addition & 1 deletion src/julia.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ array {
}


DoClause[group=CompoundStatement]{ kw<'do'> Parameters { sep1<',', Identifier | operation<expr>>? } _t block? end }
DoClause[group=CompoundStatement]{ kw<'do'> Parameters { sep1<',', Identifier | TupleExpression | operation<expr>>? } _t block? end }

CallExpression {
(primary-expr (immediateDot '.')? | Operator)
Expand Down
23 changes: 23 additions & 0 deletions test/definitions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,29 @@ Program(
)


# Function definitions - exploded parameters

function f((x,(y1,y2)), (u,v)=2)
x, y
end

==>
Program(
FunctionDefinition(
function,
Signature(
CallExpression(Identifier, Arguments(
TupleExpression(Identifier,TupleExpression(Identifier,Identifier)),
KwArg(TupleExpression(Identifier,Identifier), AssignmentOp, IntegerLiteral),
))
),
OpenTuple(Identifier, Identifier),
end
)
)



# Function definitions - keyword parameters

function a(; x, y) end
Expand Down
22 changes: 19 additions & 3 deletions test/macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ Program(

# Closed macro call expressions - Do blocks

@test() do x, y

@test() do x
xs
end

@test() do x, (y,z)
body
end

Expand All @@ -181,11 +186,22 @@ Program(
Arguments,
DoClause(
do,
Parameters(Identifier, Identifier),
Parameters(Identifier),
Identifier,
end
)
)
),

MacrocallExpression(
MacroIdentifier(Identifier),
Arguments,
DoClause(
do,
Parameters(Identifier, TupleExpression(Identifier,Identifier)),
Identifier,
end
)
),
)


Expand Down
29 changes: 27 additions & 2 deletions test/primary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Program(

# Function call expressions with do blocks

reduce(xs) do x, y
reduce(xs) do x, (y,(z,w))
f(x, y)
end

Expand All @@ -255,7 +255,9 @@ Program(
Arguments(Identifier),
DoClause(
do,
Parameters(Identifier, Identifier),
Parameters(Identifier,
TupleExpression(Identifier, TupleExpression(Identifier, Identifier)),
),
CallExpression(
Identifier,
Arguments(Identifier, Identifier),
Expand Down Expand Up @@ -302,6 +304,29 @@ Program(
)


# Function call expressions with do blocks - typed and exploded parameter

f(xs) do (x,y)::Int; end

==>
Program(
CallExpression(
Identifier,
Arguments(Identifier),
DoClause(
do,
Parameters(
BinaryExpression(
TupleExpression(Identifier, Identifier),
Type(Identifier),
)
),
end
)
)
)


# Quote expressions and symbols

:foo
Expand Down
Loading