Skip to content

Commit

Permalink
Merge pull request #228 from nvergez/fix-type-expression-parser
Browse files Browse the repository at this point in the history
Fix type expression parser
  • Loading branch information
ccorcoveanu authored Aug 1, 2022
2 parents 2d0a737 + 4170c97 commit fcd30aa
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 33 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 50 additions & 27 deletions src/smartcontracts/typesystem/typeExpressionParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,33 +102,31 @@ describe("test parser", () => {
],
});

// TODO: In a future PR, replace the JSON-based parsing logic with a better one and enable this test,
// which currently fails.

// type = parser.parse("MultiArg<Option<u8>, List<u16>>");
// assert.deepEqual(type.toJSON(), {
// "name": "MultiArg",
// "typeParameters": [
// {
// "name": "Option",
// "typeParameters": [
// {
// "name": "u8",
// "typeParameters": []
// }
// ]
// },
// {
// "name": "List",
// "typeParameters": [
// {
// "name": "u16",
// "typeParameters": []
// }
// ]
// }
// ]
// });

type = parser.parse("MultiArg<Option<u8>, List<u16>>");
assert.deepEqual(type.toJSON(), {
"name": "MultiArg",
"typeParameters": [
{
"name": "Option",
"typeParameters": [
{
"name": "u8",
"typeParameters": []
}
]
},
{
"name": "List",
"typeParameters": [
{
"name": "u16",
"typeParameters": []
}
]
}
]
});
});

it("should parse expression: tuples", () => {
Expand Down Expand Up @@ -189,6 +187,31 @@ describe("test parser", () => {
},
],
});

type = parser.parse("tuple<List<u64>,List<u64>>");
assert.deepEqual(type.toJSON(), {
name: "tuple",
typeParameters: [
{
name: "List",
typeParameters: [
{
name: "u64",
typeParameters: [],
}
],
},
{
name: "List",
typeParameters: [
{
name: "u64",
typeParameters: [],
}
],
},
],
});
});

it("should handle utf-8 string types which contain spaces", () => {
Expand Down
2 changes: 2 additions & 0 deletions src/smartcontracts/typesystem/typeExpressionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export class TypeExpressionParser {
} else if (char == ",") {
if (nextChar == ">") {
// Skip superfluous comma
} else if (previousChar == ">") {
jsoned += ",";
} else {
jsoned += ": {},";
}
Expand Down

0 comments on commit fcd30aa

Please sign in to comment.