Skip to content

Commit

Permalink
fix: parsing of non-decimal message opcodes (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov authored Jun 25, 2024
1 parent a98d4f4 commit d86aeab
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Name clashes with FunC keywords in struct constructor function parameters: PR [#467](https://github.com/tact-lang/tact/issues/467)
- Error messages for traversing non-path-expressions in `foreach`-loops : PR [#479](https://github.com/tact-lang/tact/pull/479)
- Shadowing of trait constants by contract storage variables: PR [#480](https://github.com/tact-lang/tact/pull/480)
- Parsing of non-decimal message opcodes: PR [#481](https://github.com/tact-lang/tact/pull/481)

## [1.4.0] - 2024-06-21

Expand Down
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"Korshakov",
"nocheck",
"noexcept",
"Nonterminal",
"nonterminal",
"Neovim",
"Offchain",
"Parens",
Expand Down
15 changes: 11 additions & 4 deletions src/grammar/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "./ast";
import { throwParseError, throwCompilationError } from "../errors";
import { checkVariableName } from "./checkVariableName";
import { Node, IterationNode } from "ohm-js";
import { Node, IterationNode, NonterminalNode } from "ohm-js";
import { TypeOrigin } from "../types/types";
import { checkFunctionAttributes } from "./checkFunctionAttributes";
import { checkConstAttributes } from "./checkConstAttributes";
Expand Down Expand Up @@ -112,7 +112,7 @@ semantics.addOperation<ASTNode>("astOfModuleItem", {
StructDecl_message(
_messageKwd,
_optLparen,
optId,
optIntMsgId,
_optRparen,
typeId,
_lbrace,
Expand All @@ -125,7 +125,9 @@ semantics.addOperation<ASTNode>("astOfModuleItem", {
origin: ctx!.origin,
name: typeId.sourceString,
fields: fields.astsOfList(),
prefix: unwrapOptNode(optId, (id) => parseInt(id.sourceString)),
prefix: unwrapOptNode(optIntMsgId, (number) =>
Number(bigintOfIntLiteral(number)),
),
message: true,
ref: createRef(this),
});
Expand Down Expand Up @@ -819,13 +821,18 @@ semantics.addOperation<ASTNode>("astOfType", {
},
});

// handles binary, octal, decimal and hexadecimal integer literals
function bigintOfIntLiteral(litString: NonterminalNode): bigint {
return BigInt(litString.sourceString.replaceAll("_", ""));
}

// Expressions
semantics.addOperation<ASTNode>("astOfExpression", {
// Literals
integerLiteral(number) {
return createNode({
kind: "number",
value: BigInt(number.sourceString.replaceAll("_", "")),
value: bigintOfIntLiteral(number),
ref: createRef(this),
}); // Parses dec, hex, and bin numbers
},
Expand Down
3 changes: 2 additions & 1 deletion src/test/codegen/all-contracts.tact
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "./empty-message.tact";
import "./large-contract.tact";
import "./struct-field-storage-annotation.tact";
import "./struct-field-func-keywords-name-clash";
import "./struct-field-func-keywords-name-clash";
import "./message-opcode-parsing.tact";
11 changes: 11 additions & 0 deletions src/test/codegen/message-opcode-parsing.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
message(0b101010) Binary {}
message(0o53) Octal {}
message(44) Decimal {}
message(0x2D) Hexadecimal {}

contract Example {
receive(msg: Binary) { }
receive(msg: Octal) { }
receive(msg: Decimal) { }
receive(msg: Hexadecimal) { }
}

0 comments on commit d86aeab

Please sign in to comment.