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

fix: forbid strings in ASM functions until we have proper grammar for it #1757

Closed
wants to merge 9 commits into from
Closed
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
1 change: 1 addition & 0 deletions dev-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Forbid traits inherit implicitly from BaseTrait: PR [#1591](https://github.com/tact-lang/tact/pull/1591)
- Forbid the `override` modifier for constants without the corresponding super-constant: PR [#1591](https://github.com/tact-lang/tact/pull/1591)
- Remove "remainder" from error messages: PR [#1699](https://github.com/tact-lang/tact/pull/1699)
- Forbid strings in ASM functions until we have proper grammar for it: PR [#1757](https://github.com/tact-lang/tact/pull/1757)

### Docs

Expand Down
86 changes: 25 additions & 61 deletions src/grammar/next/__snapshots__/grammar.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ exports[`grammar should fail abstract-const-without-modifier 1`] = `
"
`;

exports[`grammar should fail asm-instruction-string 1`] = `
"<unknown>:1:32: Expected "/*", "//", "{", or "}"
> 1 | asm fun Bar(): Address { b{00} "PUSHSLICE" }
^
2 |
"
`;

exports[`grammar should fail const-abstract-abstract 1`] = `
"<unknown>:4:10: Duplicate constant attribute "abstract"
3 |
Expand Down Expand Up @@ -4110,7 +4118,7 @@ exports[`grammar should parse expr-with-var 1`] = `

exports[`grammar should parse items-asm-funs 1`] = `
{
"id": 67,
"id": 63,
"imports": [],
"items": [
{
Expand Down Expand Up @@ -4476,50 +4484,6 @@ exports[`grammar should parse items-asm-funs 1`] = `
{
"attributes": [],
"id": 47,
"instructions": [
""Works!" DEBUGSTR",
],
"kind": "asm_function_def",
"loc": asm fun debugStr1() {
"Works!" DEBUGSTR
},
"name": {
"id": 46,
"kind": "id",
"loc": debugStr1,
"text": "debugStr1",
},
"params": [],
"return": null,
"shuffle": {
"args": [],
"ret": [],
},
},
{
"attributes": [],
"id": 49,
"instructions": [
""Works!"",
],
"kind": "asm_function_def",
"loc": asm fun debugStr2() { "Works!" },
"name": {
"id": 48,
"kind": "id",
"loc": debugStr2,
"text": "debugStr2",
},
"params": [],
"return": null,
"shuffle": {
"args": [],
"ret": [],
},
},
{
"attributes": [],
"id": 51,
"instructions": [
"{ INC }",
],
Expand All @@ -4528,7 +4492,7 @@ exports[`grammar should parse items-asm-funs 1`] = `
{ INC }
},
"name": {
"id": 50,
"id": 46,
"kind": "id",
"loc": createWord,
"text": "createWord",
Expand All @@ -4542,7 +4506,7 @@ exports[`grammar should parse items-asm-funs 1`] = `
},
{
"attributes": [],
"id": 54,
"id": 50,
"instructions": [
"{ INC } : incinc
41 incinc",
Expand All @@ -4553,14 +4517,14 @@ exports[`grammar should parse items-asm-funs 1`] = `
41 incinc
},
"name": {
"id": 52,
"id": 48,
"kind": "id",
"loc": createAndUseWord1,
"text": "createAndUseWord1",
},
"params": [],
"return": {
"id": 53,
"id": 49,
"kind": "type_id",
"loc": Int,
"text": "Int",
Expand All @@ -4572,7 +4536,7 @@ exports[`grammar should parse items-asm-funs 1`] = `
},
{
"attributes": [],
"id": 57,
"id": 53,
"instructions": [
"{ INC
}
Expand All @@ -4584,14 +4548,14 @@ exports[`grammar should parse items-asm-funs 1`] = `
: incinc 41 incinc
},
"name": {
"id": 55,
"id": 51,
"kind": "id",
"loc": createAndUseWord2,
"text": "createAndUseWord2",
},
"params": [],
"return": {
"id": 56,
"id": 52,
"kind": "type_id",
"loc": Int,
"text": "Int",
Expand All @@ -4603,7 +4567,7 @@ exports[`grammar should parse items-asm-funs 1`] = `
},
{
"attributes": [],
"id": 60,
"id": 56,
"instructions": [
"{
INC
Expand All @@ -4624,14 +4588,14 @@ incinc
incinc
},
"name": {
"id": 58,
"id": 54,
"kind": "id",
"loc": createAndUseWord3,
"text": "createAndUseWord3",
},
"params": [],
"return": {
"id": 59,
"id": 55,
"kind": "type_id",
"loc": Int,
"text": "Int",
Expand All @@ -4643,7 +4607,7 @@ incinc
},
{
"attributes": [],
"id": 66,
"id": 62,
"instructions": [
"<{
TRY:<{
Expand All @@ -4664,32 +4628,32 @@ incinc
}>CONT 1 1 CALLXARGS
},
"name": {
"id": 61,
"id": 57,
"kind": "id",
"loc": isIntAnInt,
"text": "isIntAnInt",
},
"params": [
{
"id": 65,
"id": 61,
"kind": "typed_parameter",
"loc": x: Int,
"name": {
"id": 63,
"id": 59,
"kind": "id",
"loc": x,
"text": "x",
},
"type": {
"id": 64,
"id": 60,
"kind": "type_id",
"loc": Int,
"text": "Int",
},
},
],
"return": {
"id": 62,
"id": 58,
"kind": "type_id",
"loc": Int,
"text": "Int",
Expand Down
3 changes: 1 addition & 2 deletions src/grammar/next/grammar.gg
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ assemblySequence = assemblyItem*;
assemblyItem
= "{" assemblySequence "}"
/ comment
/ "\"" [^"]* "\""
/ (!(["{}] / "//" / "/*") .)+;

ascription = ":" @type;
Expand Down Expand Up @@ -334,4 +333,4 @@ singleLineComment = "//" @$[^\r\n]*;
// it is useful for imports resolution
JustImports = imports:Import* .*;

inter<A, B> = head:A tail:(op:B right:A)*;
inter<A, B> = head:A tail:(op:B right:A)*;
4 changes: 2 additions & 2 deletions src/grammar/next/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export namespace $ast {
export type multiLineComment = string;
export type singleLineComment = string;
export type comment = multiLineComment | singleLineComment;
export type assemblyItem = {} | comment | {} | readonly {}[];
export type assemblyItem = {} | comment | readonly {}[];
export type assemblySequence = readonly assemblyItem[];
export type TypeAs = $.Located<{
readonly $: "TypeAs";
Expand Down Expand Up @@ -448,7 +448,7 @@ export const assembly: $.Parser<$ast.assembly> = $.lex($.stry($.lazy(() => assem
export const multiLineComment: $.Parser<$ast.multiLineComment> = $.right($.str("/*"), $.left($.stry($.star($.right($.lookNeg($.str("*/")), $.right($.any, $.eps)))), $.str("*/")));
export const singleLineComment: $.Parser<$ast.singleLineComment> = $.right($.str("//"), $.stry($.star($.regex<"\r" | "\n">("^\\r\\n", $.negateExps([$.ExpString("\r"), $.ExpString("\n")])))));
export const comment: $.Parser<$ast.comment> = $.alt(multiLineComment, singleLineComment);
export const assemblyItem: $.Parser<$ast.assemblyItem> = $.alt($.right($.str("{"), $.right($.lazy(() => assemblySequence), $.right($.str("}"), $.eps))), $.alt(comment, $.alt($.right($.str("\""), $.right($.star($.regex<"\"">("^\"", $.negateExps([$.ExpString("\"")]))), $.right($.str("\""), $.eps))), $.plus($.right($.lookNeg($.alt($.regex<"\"" | "{" | "}">("\"{}", [$.ExpString("\""), $.ExpString("{"), $.ExpString("}")]), $.alt($.str("//"), $.str("/*")))), $.right($.any, $.eps))))));
export const assemblyItem: $.Parser<$ast.assemblyItem> = $.alt($.right($.str("{"), $.right($.lazy(() => assemblySequence), $.right($.str("}"), $.eps))), $.alt(comment, $.plus($.right($.lookNeg($.alt($.regex<"\"" | "{" | "}">("\"{}", [$.ExpString("\""), $.ExpString("{"), $.ExpString("}")]), $.alt($.str("//"), $.str("/*")))), $.right($.any, $.eps)))));
export const assemblySequence: $.Parser<$ast.assemblySequence> = $.star(assemblyItem);
export const TypeAs: $.Parser<$ast.TypeAs> = $.loc($.field($.pure("TypeAs"), "$", $.field($.lazy(() => TypeOptional), "type", $.field($.star($.right(keyword($.str("as")), Id)), "as", $.eps))));
export const $type: $.Parser<$ast.$type> = TypeAs;
Expand Down
Loading