mirror of
https://github.com/ton-blockchain/ton
synced 2025-02-12 11:12:16 +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:
parent
7a1602f591
commit
5b44e01455
9 changed files with 47 additions and 69 deletions
|
@ -14,6 +14,18 @@ fun autoInferIntNull(x: int) {
|
|||
return x;
|
||||
}
|
||||
|
||||
fun typesAsIdentifiers(builder: builder) {
|
||||
var int = 1;
|
||||
var cell = builder.endCell();
|
||||
var slice = cell.beginParse();
|
||||
{
|
||||
var cell: cell = cell;
|
||||
var tuple: tuple = createEmptyTuple();
|
||||
var bool: bool = tuple.tupleAt<int>(0) > 0;
|
||||
}
|
||||
return int;
|
||||
}
|
||||
|
||||
fun main(value: int) {
|
||||
var (x: int, y) = (autoInferIntNull(value), autoInferIntNull(value * 2));
|
||||
if (x == null && y == null) { return null; }
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
fun main() {
|
||||
try {
|
||||
|
||||
} catch(int, arg) {}
|
||||
} catch(if, arg) {}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@compilation_should_fail
|
||||
@stderr expected identifier, got `int`
|
||||
@stderr catch(int
|
||||
@stderr expected identifier, got `if`
|
||||
@stderr catch(if
|
||||
*/
|
||||
|
|
|
@ -4,5 +4,5 @@ fun main(int): int {
|
|||
|
||||
/**
|
||||
@compilation_should_fail
|
||||
@stderr expected parameter name, got `int`
|
||||
@stderr expected `: <parameter_type>`, got `)`
|
||||
*/
|
||||
|
|
|
@ -4,5 +4,5 @@ fun main() {
|
|||
|
||||
/**
|
||||
@compilation_should_fail
|
||||
@stderr probably, you use FunC-like declarations; valid syntax is `var x: int = ...`
|
||||
@stderr expected `;`, got `x`
|
||||
*/
|
||||
|
|
|
@ -4,6 +4,8 @@ fun foo1(): int { return 111; }
|
|||
fun foo2(): int { return 222; }
|
||||
@method_id(10)
|
||||
fun foo3(): int { return 333; }
|
||||
@method_id(11)
|
||||
fun slice(slice: slice): slice { return slice; }
|
||||
fun main(): int { return 999; }
|
||||
|
||||
/**
|
||||
|
|
|
@ -111,16 +111,6 @@ static void diagnose_addition_in_bitshift(SrcLocation loc, std::string_view bits
|
|||
}
|
||||
}
|
||||
|
||||
// fire an error for FunC-style variable declaration, like "int i"
|
||||
GNU_ATTRIBUTE_NORETURN GNU_ATTRIBUTE_COLD
|
||||
static void fire_error_FunC_style_var_declaration(Lexer& lex) {
|
||||
SrcLocation loc = lex.cur_location();
|
||||
std::string type_str = static_cast<std::string>(lex.cur_str()); // int / slice / etc.
|
||||
lex.next();
|
||||
std::string var_name = lex.tok() == tok_identifier ? static_cast<std::string>(lex.cur_str()) : "name";
|
||||
throw ParseError(loc, "can't parse; probably, you use FunC-like declarations; valid syntax is `var " + var_name + ": " + type_str + " = ...`");
|
||||
}
|
||||
|
||||
// replace (a == null) and similar to isNull(a) (call of a built-in function)
|
||||
static AnyExprV maybe_replace_eq_null_with_isNull_call(V<ast_binary_operator> v) {
|
||||
bool has_null = v->get_lhs()->type == ast_null_keyword || v->get_rhs()->type == ast_null_keyword;
|
||||
|
@ -377,14 +367,8 @@ static AnyExprV parse_expr100(Lexer& lex) {
|
|||
}
|
||||
return createV<ast_reference>(loc, v_ident, v_instantiationTs);
|
||||
}
|
||||
default: {
|
||||
// show a proper error for `int i` (FunC-style declarations)
|
||||
TokenType t = lex.tok();
|
||||
if (t == tok_int || t == tok_cell || t == tok_slice || t == tok_builder || t == tok_tuple) {
|
||||
fire_error_FunC_style_var_declaration(lex);
|
||||
}
|
||||
default:
|
||||
lex.unexpected("<expression>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -331,7 +331,6 @@ struct ChunkIdentifierOrKeyword final : ChunkLexerBase {
|
|||
if (str == "as") return tok_as;
|
||||
break;
|
||||
case 3:
|
||||
if (str == "int") return tok_int;
|
||||
if (str == "var") return tok_var;
|
||||
if (str == "fun") return tok_fun;
|
||||
if (str == "asm") return tok_asm;
|
||||
|
@ -342,18 +341,13 @@ struct ChunkIdentifierOrKeyword final : ChunkLexerBase {
|
|||
case 4:
|
||||
if (str == "else") return tok_else;
|
||||
if (str == "true") return tok_true;
|
||||
if (str == "cell") return tok_cell;
|
||||
if (str == "null") return tok_null;
|
||||
if (str == "void") return tok_void;
|
||||
if (str == "bool") return tok_bool;
|
||||
if (str == "self") return tok_self;
|
||||
if (str == "tolk") return tok_tolk;
|
||||
if (str == "type") return tok_type;
|
||||
if (str == "enum") return tok_enum;
|
||||
break;
|
||||
case 5:
|
||||
if (str == "slice") return tok_slice;
|
||||
if (str == "tuple") return tok_tuple;
|
||||
if (str == "const") return tok_const;
|
||||
if (str == "false") return tok_false;
|
||||
if (str == "redef") return tok_redef;
|
||||
|
@ -374,16 +368,12 @@ struct ChunkIdentifierOrKeyword final : ChunkLexerBase {
|
|||
if (str == "export") return tok_export;
|
||||
break;
|
||||
case 7:
|
||||
if (str == "builder") return tok_builder;
|
||||
if (str == "builtin") return tok_builtin;
|
||||
break;
|
||||
case 8:
|
||||
if (str == "continue") return tok_continue;
|
||||
if (str == "operator") return tok_operator;
|
||||
break;
|
||||
case 12:
|
||||
if (str == "continuation") return tok_continuation;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -118,14 +118,6 @@ enum TokenType {
|
|||
tok_if,
|
||||
tok_else,
|
||||
|
||||
tok_int,
|
||||
tok_cell,
|
||||
tok_bool,
|
||||
tok_slice,
|
||||
tok_builder,
|
||||
tok_continuation,
|
||||
tok_tuple,
|
||||
tok_void,
|
||||
tok_arrow,
|
||||
tok_as,
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue