Skip to content

Commit 99bcd05

Browse files
committed
Fixing New Expression
1 parent 86530f8 commit 99bcd05

File tree

23 files changed

+522
-844
lines changed

23 files changed

+522
-844
lines changed

crates/solidity-v2/inputs/language/src/definition.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,10 +3903,10 @@ ExpressionTrailingBlock: (Expression<'arena>, Block<'arena>) = {
39033903
// option calls)
39043904
//
39053905
// Note: To simplify my life right now, this is a bit different from what's generated, but we'll get there
3906-
Expression0<IndexAccessPathRule>: Expression<'arena> = {
3906+
Expression0<IndexAccessPathRule, NewExpressionRule>: Expression<'arena> = {
39073907
<_IndexAccessPath: IndexAccessPathRule> => new_expression_index_access_path(arena, <>),
39083908
3909-
<_NewExpression: NewExpression> => new_expression_new_expression(arena, <>),
3909+
<_NewExpression: NewExpressionRule> => new_expression_new_expression(arena, <>),
39103910
39113911
<_TupleExpression: ProtoTuple<"True">> => new_expression_tuple_expression(arena, new_tuple_expression_from_proto_tuple(arena, <>)),
39123912
@@ -3935,20 +3935,24 @@ NoIndexAccessPath_Expr: IndexAccessPath<'arena> = {};
39353935
39363936
// We simplifiy all these levels of expressions into a single one, there's no need
39373937
// for precedence here
3938-
Expression1<IndexAccessPathRule>: Expression<'arena> = {
3938+
Expression1<IndexAccessPathRule, NewExpressionRule>: Expression<'arena> = {
39393939
3940-
<_Expression: Expression1<NoIndexAccessPath_Expr>> <_open_bracket: OpenBracket> <_start: (Expression)?> <_end: (IndexAccessEnd)?> <_close_bracket: CloseBracket> => new_expression_index_access_expression(arena, new_index_access_expression(arena, <>)),
3940+
<_Expression: Expression1<NoIndexAccessPath_Expr, NoNewExpression>> <_open_bracket: OpenBracket> <_start: (Expression)?> <_end: (IndexAccessEnd)?> <_close_bracket: CloseBracket> => new_expression_index_access_expression(arena, new_index_access_expression(arena, <>)),
39413941
3942-
<_Expression: Expression1<IndexAccessPath<NoIdentPath>>> <_period: Period> <_member: MemberAccessIdentifier> => new_expression_member_access_expression(arena, new_member_access_expression(arena, <>)),
3942+
<_Expression: Expression1<IndexAccessPath<NoIdentPath>, NoNewExpression>> <_period: Period> <_member: MemberAccessIdentifier> => new_expression_member_access_expression(arena, new_member_access_expression(arena, <>)),
39433943
3944-
<_Expression: Expression1<IndexAccessPath<IdentifierPath>>> <_open_brace: OpenBrace> <_options: CallOptions> <_close_brace: CloseBrace> => new_expression_call_options_expression(arena, new_call_options_expression(arena, <>)),
3944+
<_Expression: Expression1<IndexAccessPath<IdentifierPath>, NewExpression>> <_open_brace: OpenBrace> <_options: CallOptions> <_close_brace: CloseBrace> => new_expression_call_options_expression(arena, new_call_options_expression(arena, <>)),
39453945
3946-
<_Expression: Expression1<IndexAccessPath<IdentifierPath>>> <_arguments: ArgumentsDeclaration> => new_expression_function_call_expression(arena, new_function_call_expression(arena, <>)),
3946+
<_Expression: Expression1<IndexAccessPath<IdentifierPath>, NewExpression>> <_arguments: ArgumentsDeclaration> => new_expression_function_call_expression(arena, new_function_call_expression(arena, <>)),
39473947
3948-
<Expression: Expression0<IndexAccessPathRule>> => <>,
3948+
<Expression: Expression0<IndexAccessPathRule, NewExpressionRule>> => <>,
39493949
39503950
};
39513951
3952+
NoNewExpression: NewExpression<'arena> = {};
3953+
3954+
3955+
39523956
// Tail is a rule identifying what comes after the expression, whatever is captured is added to the tuple result
39533957
Expression5<Tail>: (Expression<'arena>, Tail) = {
39543958
@@ -3958,7 +3962,7 @@ Expression5<Tail>: (Expression<'arena>, Tail) = {
39583962
},
39593963
39603964
// A tail can appear just after a postfix or primary expression
3961-
<Expression: Expression1<IndexAccessPath<IdentifierPath>>> <tail: Tail> => {
3965+
<Expression: Expression1<IndexAccessPath<IdentifierPath>, NewExpression>> <tail: Tail> => {
39623966
(Expression, tail)
39633967
},
39643968
@@ -4326,26 +4330,24 @@ IndexAccessPath1<IdentPathRule>: IndexAccessPath<'arena> = {
43264330
name = NewExpression,
43274331
fields = (
43284332
new_keyword = Required(NewKeyword),
4329-
type_name = Required(TypeName),
4330-
// TODO(v2): This disallows some grammar ambiguities, we should double check it's ok
4331-
options =
4332-
Optional(reference = MultipleCallOptionsNew, enabled = From("0.6.2")),
4333-
arguments = Required(ArgumentsDeclaration)
4334-
)
4335-
),
4336-
Repeated(
4337-
name = MultipleCallOptionsNew,
4338-
reference = CallOptionsNew,
4339-
enabled = From("0.6.2")
4340-
),
4341-
Struct(
4342-
name = CallOptionsNew,
4343-
enabled = From("0.6.2"),
4344-
fields = (
4345-
open_brace = Required(OpenBrace),
4346-
options = Required(CallOptions),
4347-
close_brace = Required(CloseBrace)
4348-
)
4333+
type_name = Required(TypeName)
4334+
),
4335+
parser_options = ParserOptions(
4336+
inline = false,
4337+
pubb = true,
4338+
verbatim = r#"
4339+
// TODO(v2): Right now we're avoiding function types entirely in new expressions, this is ok since they're not allowed
4340+
// in Solidity, but the error will be syntactic rather than semantic, which may be confusing.
4341+
// We do this to avoid the amibiguity of `try new function () returns (uint) ...`, where the returns clause may be
4342+
// parsed either as part of the function type or as part of a try statement.
4343+
NewExpression: NewExpression<'arena> = {
4344+
<_new_keyword: NewKeyword> <_type_name: TypeName1<NoFunctionType, IndexAccessPath<IdentifierPath>>> => new_new_expression(arena, <>),
4345+
4346+
};
4347+
4348+
NoFunctionType: FunctionType<'arena> = {};
4349+
4350+
"#)
43494351
),
43504352
Struct(
43514353
name = TupleExpression,

crates/solidity-v2/outputs/cargo/cst/src/structured_cst/nodes.generated.rs

Lines changed: 0 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/solidity-v2/outputs/cargo/parser/src/parser/grammar.generated.lalrpop

Lines changed: 24 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)