1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

[Tolk] Allow cell and slice be valid identifiers

They are not keywords anymore.
> var cell = ...;
> var cell: cell = ...;
Motivation: in the future, when structures are implemented, this obviously should be valid:
> struct a { ... }
> var a = ...;
Struct fields will also be allowed to have names int/slice/cell.
This commit is contained in:
tolk-vm 2025-01-27 10:33:24 +03:00
parent 7a1602f591
commit 5b44e01455
No known key found for this signature in database
GPG key ID: 7905DD7FE0324B12
9 changed files with 47 additions and 69 deletions

View file

@ -581,40 +581,38 @@ std::vector<TypePtr> parse_nested_type_list_in_parenthesis(Lexer& lex) {
static TypePtr parse_simple_type(Lexer& lex) {
switch (lex.tok()) {
case tok_int:
lex.next();
return TypeDataInt::create();
case tok_bool:
lex.next();
return TypeDataBool::create();
case tok_cell:
lex.next();
return TypeDataCell::create();
case tok_builder:
lex.next();
return TypeDataBuilder::create();
case tok_slice:
lex.next();
return TypeDataSlice::create();
case tok_tuple:
lex.next();
return TypeDataTuple::create();
case tok_continuation:
lex.next();
return TypeDataContinuation::create();
case tok_null:
lex.next();
return TypeDataNullLiteral::create();
case tok_void:
lex.next();
return TypeDataVoid::create();
case tok_self:
case tok_identifier: {
SrcLocation loc = lex.cur_location();
std::string text = static_cast<std::string>(lex.cur_str());
std::string_view str = lex.cur_str();
lex.next();
return TypeDataUnresolved::create(std::move(text), loc);
switch (str.size()) {
case 3:
if (str == "int") return TypeDataInt::create();
break;
case 4:
if (str == "cell") return TypeDataCell::create();
if (str == "void") return TypeDataVoid::create();
if (str == "bool") return TypeDataBool::create();
break;
case 5:
if (str == "slice") return TypeDataSlice::create();
if (str == "tuple") return TypeDataTuple::create();
break;
case 7:
if (str == "builder") return TypeDataBuilder::create();
break;
case 12:
if (str == "continuation") return TypeDataContinuation::create();
break;
default:
break;
}
return TypeDataUnresolved::create(std::string(str), loc);
}
case tok_null:
lex.next();
return TypeDataNullLiteral::create();
case tok_oppar: {
std::vector<TypePtr> items = parse_nested_type_list_in_parenthesis(lex);
if (items.size() == 1) {