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

Support for trailing comma #179

Merged
merged 25 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1c3d633
Restore the closed commit
vitorpy Mar 20, 2024
4797e78
Add support for trailing commas in argument lists
vitorpy Mar 20, 2024
f566f7e
Revert changes to serialization-2.tact
vitorpy Mar 20, 2024
4547492
Expand coverage to Function, convert to using ? syntax instead of dup…
vitorpy Mar 20, 2024
99e689d
Adding test case for empty argument list
vitorpy Mar 20, 2024
8b61dad
Add changes to CHANGELOG
vitorpy Mar 20, 2024
b439d71
Better wording on CHANGELOG.md
vitorpy Mar 20, 2024
9943023
Add additional test case for more than two arguments
vitorpy Mar 20, 2024
42b1d55
Fixing test case
vitorpy Mar 21, 2024
ae10d4e
Expand coverage to include ExpressionCall, ExpressionInitOf and Expre…
vitorpy Mar 21, 2024
9703fec
Expand test cases
vitorpy Mar 21, 2024
baf26c5
Update src/grammar/test/case-17.tact
vitorpy Mar 22, 2024
9bde284
Fix tests
vitorpy Mar 22, 2024
d9d392f
Expand tests and checks for dangling commas
vitorpy Mar 24, 2024
24998a6
Fix and expand tests
vitorpy Mar 25, 2024
3c85b22
Merge branch 'main' into trailing-comma
vitorpy Mar 25, 2024
58b7d22
Fix parsing and tests for abstract functions.
vitorpy Mar 25, 2024
f161773
Fix support for native functions
vitorpy Mar 25, 2024
11b736e
:Merge branch 'main' into trailing-comma
vitorpy Mar 31, 2024
572dedd
Split test cases into different files
vitorpy Mar 31, 2024
4f4de39
revert accidental deletion in grammar.ts
anton-trunov Apr 2, 2024
e362df6
Merge branch 'main' into trailing-comma
anton-trunov Apr 2, 2024
6984209
Update src/grammar/test-failed/case-26.tact
anton-trunov Apr 2, 2024
9f8f808
Update src/grammar/test-failed/case-25.tact
anton-trunov Apr 2, 2024
46e45f7
update snapshot
anton-trunov Apr 2, 2024
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
5 changes: 4 additions & 1 deletion src/grammar/grammar.ohm
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Tact {
// Static function
StaticFunction = Function
NativeFunction = nameAttribute "(" funcId ")" FunctionAttribute* native id "(" ListOf<FunctionArg,","> ")" ";" --withVoid
| nameAttribute "(" funcId ")" FunctionAttribute* native id "(" ListOf<FunctionArg,","> "," ")" ";" --withVoidAndTrailingComma
| nameAttribute "(" funcId ")" FunctionAttribute* native id "(" ListOf<FunctionArg,","> ")" ":" Type ";" --withType
| nameAttribute "(" funcId ")" FunctionAttribute* native id "(" ListOf<FunctionArg,","> "," ")" ":" Type ";" --withTypeAndTrailingComma

// Field declarations
Type = typeLiteral "?" --optional
Expand Down Expand Up @@ -174,7 +176,8 @@ Tact {
ExpressionString = stringLiteral
ExpressionField = ExpressionValue "." id ~"("
ExpressionCall = ExpressionValue "." id "(" ListOf<Expression, ","> ")"
ExpressionNew = id "{" ListOf<NewParameter, ","> "}"
ExpressionNew = id "{" ListOf<NewParameter, ","> "}" --noTrailing
| id "{" ListOf<NewParameter, ","> "," "}" --withTrailing
NewParameter = id ":" Expression
ExpressionStaticCall = id "(" ListOf<Expression, ","> ")"
ExpressionInitOf = initOf id "(" ListOf<Expression, ","> ")"
Expand Down
6 changes: 5 additions & 1 deletion src/grammar/grammar.ohm-bundle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export interface TactActionDict<T> extends ActionDict<T> {
Primitive?: (this: NonterminalNode, arg0: TerminalNode, arg1: NonterminalNode, arg2: TerminalNode) => T;
StaticFunction?: (this: NonterminalNode, arg0: NonterminalNode) => T;
NativeFunction_withVoid?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode, arg3: TerminalNode, arg4: IterationNode, arg5: NonterminalNode, arg6: NonterminalNode, arg7: TerminalNode, arg8: NonterminalNode, arg9: TerminalNode, arg10: TerminalNode) => T;
NativeFunction_withVoidAndTrailingComma?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode, arg3: TerminalNode, arg4: IterationNode, arg5: NonterminalNode, arg6: NonterminalNode, arg7: TerminalNode, arg8: NonterminalNode, arg9: TerminalNode, arg10: TerminalNode, arg11: TerminalNode) => T;
NativeFunction_withType?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode, arg3: TerminalNode, arg4: IterationNode, arg5: NonterminalNode, arg6: NonterminalNode, arg7: TerminalNode, arg8: NonterminalNode, arg9: TerminalNode, arg10: TerminalNode, arg11: NonterminalNode, arg12: TerminalNode) => T;
NativeFunction_withTypeAndTrailingComma?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode, arg3: TerminalNode, arg4: IterationNode, arg5: NonterminalNode, arg6: NonterminalNode, arg7: TerminalNode, arg8: NonterminalNode, arg9: TerminalNode, arg10: TerminalNode, arg11: TerminalNode, arg12: NonterminalNode, arg13: TerminalNode) => T;
NativeFunction?: (this: NonterminalNode, arg0: NonterminalNode) => T;
Type_optional?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode) => T;
Type_required?: (this: NonterminalNode, arg0: NonterminalNode) => T;
Expand Down Expand Up @@ -136,7 +138,9 @@ export interface TactActionDict<T> extends ActionDict<T> {
ExpressionString?: (this: NonterminalNode, arg0: NonterminalNode) => T;
ExpressionField?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode) => T;
ExpressionCall?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode, arg3: TerminalNode, arg4: NonterminalNode, arg5: TerminalNode) => T;
ExpressionNew?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode, arg3: TerminalNode) => T;
ExpressionNew_noTrailing?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode, arg3: TerminalNode) => T;
ExpressionNew_withTrailing?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode, arg3: TerminalNode, arg4: TerminalNode) => T;
ExpressionNew?: (this: NonterminalNode, arg0: NonterminalNode) => T;
NewParameter?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode) => T;
ExpressionStaticCall?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode, arg3: TerminalNode) => T;
ExpressionInitOf?: (this: NonterminalNode, arg0: NonterminalNode, arg1: NonterminalNode, arg2: TerminalNode, arg3: NonterminalNode, arg4: TerminalNode) => T;
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/grammar.ohm-bundle.js

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion src/grammar/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,19 @@ semantics.addOperation<ASTNode>('resolve_declaration', {
ref: createRef(this)
})
},
NativeFunction_withTypeAndTrailingComma(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, _arg9, _arg10, arg11, _arg12, _arg13) {
checkVariableName(arg5.sourceString, createRef(arg5));
return createNode({
kind: 'def_native_function',
origin: ctx!.origin,
attributes: arg4.children.map((v) => v.resolve_attributes()),
name: arg6.sourceString,
nativeName: arg2.sourceString,
return: arg11.resolve_expression(),
args: arg8.asIteration().children.map((v) => v.resolve_declaration()),
ref: createRef(this)
})
},
NativeFunction_withVoid(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, _arg9, _arg10) {
checkVariableName(arg5.sourceString, createRef(arg5));
return createNode({
Expand All @@ -368,6 +381,19 @@ semantics.addOperation<ASTNode>('resolve_declaration', {
ref: createRef(this)
})
},
NativeFunction_withVoidAndTrailingComma(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, _arg9, _arg10, _arg11) {
checkVariableName(arg5.sourceString, createRef(arg5));
return createNode({
kind: 'def_native_function',
origin: ctx!.origin,
attributes: arg4.children.map((v) => v.resolve_attributes()),
name: arg6.sourceString,
nativeName: arg2.sourceString,
return: null,
args: arg8.asIteration().children.map((v) => v.resolve_declaration()),
ref: createRef(this)
})
},
ContractInit(_arg0, _arg1, arg2, _arg3, _arg4, arg5, _arg6) {
return createNode({
kind: 'def_init_function',
Expand Down Expand Up @@ -712,7 +738,10 @@ semantics.addOperation<ASTNode>('resolve_expression', {
ExpressionStaticCall(arg0, _arg1, arg2, _arg3) {
return createNode({ kind: 'op_static_call', name: arg0.sourceString, args: arg2.asIteration().children.map((v) => v.resolve_expression()), ref: createRef(this) });
},
ExpressionNew(arg0, _arg1, arg2, _arg3) {
ExpressionNew_withTrailing(arg0, _arg1, arg2, _arg3, _arg4) {
return createNode({ kind: 'op_new', type: arg0.sourceString, args: arg2.asIteration().children.map((v) => v.resolve_expression()), ref: createRef(this) });
},
ExpressionNew_noTrailing(arg0, _arg1, arg2, _arg3) {
return createNode({ kind: 'op_new', type: arg0.sourceString, args: arg2.asIteration().children.map((v) => v.resolve_expression()), ref: createRef(this) });
},
NewParameter(arg0, _arg1, arg2) {
Expand Down
22 changes: 21 additions & 1 deletion src/grammar/test/case-17.tact
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
struct A {
x: Int;
y: Int;
}

const a: A = new { x: 1 };

fun getA(): A {
return A {
x: 1,
y: 2,
};
}

message B {
x: Int;
}
y: Int;
}

const b: B = new {
x: 2,
y: 3,
};

fun getB(): B {
return B { x = 1, y = 5, };
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
}
7 changes: 7 additions & 0 deletions src/grammar/test/case-25.tact
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
fun function(a: Int, b: Int): Int {
return (a >> b) || (a << (32 - b));
}

fun anotherFunction(
a: Int,
b: Int,
): Int {
return (a >> b) || (a << (32 - b));
}
10 changes: 8 additions & 2 deletions src/test/features/serialization-2.tact
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ contract SerializationTester2 {
}

get fun getBoth():Both {
return Both{a: self.a, b: self.b};
return Both{
a: self.a,
b: self.b,
};
}

get fun getBothOpt():Both? {
return Both{a: self.a, b: self.b};
return Both{
a: self.a,
b: self.b,
};
}

get fun process(src: Vars, both: Both, both2: Both?): Vars {
Expand Down