Skip to content

Commit 082fc12

Browse files
committed
Started work on unnamed function
1 parent ab9c140 commit 082fc12

File tree

4 files changed

+104
-50
lines changed

4 files changed

+104
-50
lines changed

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

Lines changed: 91 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ pub use solidity::SolidityDefinition;
2323
// - a bunch of fixed/ufixed cases: similar to fallback and receive, they should be disabled when unreserved (since they
2424
// were identifiers). This is a bit trickier since they are single definitions within a keyword that has other
2525
// definitions that should be enabled throughout. We should discuss this a bit more.
26+
// - unnamedfunction:
27+
// - 'function() foo;' this can be either an unnamed function with modifier foo, or a state variable.
28+
// in solc theres a validation where a non implemented function can't have a modifier.
29+
// I'd like to double check this in the reference.
2630

2731
language_v2_macros::compile!(Language(
2832
name = Solidity,
@@ -2354,6 +2358,7 @@ ConstantDefinition: ConstantDefinition = {
23542358
// error definition or a state variable definition.
23552359
//
23562360
// To solve this we match against state variables where the type is exactly `error` as a special case.
2361+
#[inline]
23572362
StateVariableDefinition: StateVariableDefinition = {
23582363
// When allowing any type except function types without return, we can parse normally.
23592364
// Note the `IdentifierPathNoError`, it avoids matching against `error` as an identifier.
@@ -2597,55 +2602,89 @@ SpecialStateVariableAttribute: StateVariableAttribute = {
25972602
]
25982603
),
25992604
// TODO(v2) removing conflict - UnnamedFunctionDefinition conflicts with FunctionDefinition
2600-
// Struct(
2601-
// name = UnnamedFunctionDefinition,
2602-
// enabled = Till("0.6.0"),
2603-
// fields = (
2604-
// function_keyword = Required(FunctionKeyword),
2605-
// parameters = Required(ParametersDeclaration),
2606-
// attributes = Required(UnnamedFunctionAttributes),
2607-
// body = Required(FunctionBody)
2608-
// )
2609-
// ),
2610-
// Repeated(
2611-
// name = UnnamedFunctionAttributes,
2612-
// reference = UnnamedFunctionAttribute,
2613-
// enabled = Till("0.6.0"),
2614-
// allow_empty = true
2615-
// ),
2616-
// Enum(
2617-
// name = UnnamedFunctionAttribute,
2618-
// enabled = Till("0.6.0"),
2619-
// variants = [
2620-
// EnumVariant(reference = ModifierInvocation),
2621-
// EnumVariant(
2622-
// reference = ConstantKeyword,
2623-
// enabled = Till("0.5.0")
2624-
// ),
2625-
// EnumVariant(reference = ExternalKeyword),
2626-
// EnumVariant(
2627-
// reference = InternalKeyword,
2628-
// enabled = Till("0.5.0")
2629-
// ),
2630-
// EnumVariant(reference = PayableKeyword),
2631-
// EnumVariant(
2632-
// reference = PrivateKeyword,
2633-
// enabled = Till("0.5.0")
2634-
// ),
2635-
// EnumVariant(
2636-
// reference = PublicKeyword,
2637-
// enabled = Till("0.5.0")
2638-
// ),
2639-
// EnumVariant(
2640-
// reference = PureKeyword,
2641-
// enabled = Range(from = "0.4.16", till = "0.6.0")
2642-
// ),
2643-
// EnumVariant(
2644-
// reference = ViewKeyword,
2645-
// enabled = Range(from = "0.4.16", till = "0.6.0")
2646-
// )
2647-
// ]
2648-
// ),
2605+
// Struct(
2606+
// name = UnnamedFunctionDefinition,
2607+
// enabled = Till("0.6.0"),
2608+
// fields = (
2609+
// function_keyword = Required(FunctionKeyword),
2610+
// parameters = Required(ParametersDeclaration),
2611+
// attributes = Required(UnnamedFunctionAttributes),
2612+
// body = Required(FunctionBody)
2613+
// ),
2614+
// parser_options = ParserOptions(inline = false, pubb = false, verbatim = r#"
2615+
// #[inline]
2616+
// UnnamedFunctionDefinition: UnnamedFunctionDefinition = {
2617+
// <_function_keyword: FunctionKeyword> <_parameters: ParametersDeclaration> <_attributes: UnnamedFunctionAttributes<ModifierInvocation>> <_body: Block> => {
2618+
// new_unnamed_function_definition(_function_keyword, _parameters, _attributes, new_function_body_block(_body))
2619+
// },
2620+
2621+
// <_function_keyword: FunctionKeyword> <_parameters: ParametersDeclaration> <_attributes: UnnamedFunctionAttributes<NoModifier>> <_body: Semicolon> => {
2622+
// new_unnamed_function_definition(_function_keyword, _parameters, _attributes, new_function_body_semicolon(_body))
2623+
// },
2624+
// };
2625+
2626+
// NoModifier: ModifierInvocation = {};
2627+
// "#)
2628+
// ),
2629+
// Repeated(
2630+
// name = UnnamedFunctionAttributes,
2631+
// reference = UnnamedFunctionAttribute,
2632+
// enabled = Till("0.6.0"),
2633+
// allow_empty = true,
2634+
// parser_options = ParserOptions(inline = false, pubb = false, verbatim = r#"
2635+
// UnnamedFunctionAttributes<ModifierRule>: UnnamedFunctionAttributes = {
2636+
// <_UnnamedFunctionAttribute: Rep<<UnnamedFunctionAttribute<ModifierRule>>>> => new_unnamed_function_attributes(<>),
2637+
// };
2638+
// "#)
2639+
2640+
// ),
2641+
// Enum(
2642+
// name = UnnamedFunctionAttribute,
2643+
// enabled = Till("0.6.0"),
2644+
// variants = [
2645+
// EnumVariant(reference = ModifierInvocation),
2646+
// EnumVariant(
2647+
// reference = ConstantKeyword,
2648+
// enabled = Till("0.5.0")
2649+
// ),
2650+
// EnumVariant(reference = ExternalKeyword),
2651+
// EnumVariant(
2652+
// reference = InternalKeyword,
2653+
// enabled = Till("0.5.0")
2654+
// ),
2655+
// EnumVariant(reference = PayableKeyword),
2656+
// EnumVariant(
2657+
// reference = PrivateKeyword,
2658+
// enabled = Till("0.5.0")
2659+
// ),
2660+
// EnumVariant(
2661+
// reference = PublicKeyword,
2662+
// enabled = Till("0.5.0")
2663+
// ),
2664+
// EnumVariant(
2665+
// reference = PureKeyword,
2666+
// enabled = Range(from = "0.4.16", till = "0.6.0")
2667+
// ),
2668+
// EnumVariant(
2669+
// reference = ViewKeyword,
2670+
// enabled = Range(from = "0.4.16", till = "0.6.0")
2671+
// )
2672+
// ],
2673+
// parser_options = ParserOptions(inline = false, pubb = false, verbatim = r#"
2674+
// UnnamedFunctionAttribute<ModifierRule>: UnnamedFunctionAttribute = {
2675+
// <_ModifierInvocation: ModifierRule> => new_unnamed_function_attribute_modifier_invocation(<>),
2676+
// <_ConstantKeyword: ConstantKeyword> => new_unnamed_function_attribute_constant_keyword(<>),
2677+
// <_ExternalKeyword: ExternalKeyword> => new_unnamed_function_attribute_external_keyword(<>),
2678+
// <_InternalKeyword: InternalKeyword> => new_unnamed_function_attribute_internal_keyword(<>),
2679+
// <_PayableKeyword: PayableKeyword> => new_unnamed_function_attribute_payable_keyword(<>),
2680+
// <_PrivateKeyword: PrivateKeyword> => new_unnamed_function_attribute_private_keyword(<>),
2681+
// <_PublicKeyword: PublicKeyword> => new_unnamed_function_attribute_public_keyword(<>),
2682+
// <_PureKeyword: PureKeyword> => new_unnamed_function_attribute_pure_keyword(<>),
2683+
// <_ViewKeyword: ViewKeyword> => new_unnamed_function_attribute_view_keyword(<>),
2684+
2685+
// };
2686+
// "#)
2687+
// ),
26492688
Struct(
26502689
name = FallbackFunctionDefinition,
26512690
enabled = From("0.6.0"),
@@ -2933,6 +2972,7 @@ FunctionType: FunctionType = {
29332972
FunctionTypeInternalReturn => <>,
29342973
};
29352974
2975+
#[inline]
29362976
FunctionTypeInternalNoReturn: FunctionType = {
29372977
<_function_keyword: FunctionKeyword> <_parameters: ParametersDeclaration> <_attributes: FunctionTypeAttributes> => new_function_type(_function_keyword, _parameters, _attributes, None),
29382978
};
@@ -2945,7 +2985,8 @@ FunctionTypeInternalReturn: FunctionType = {
29452985
Repeated(
29462986
name = FunctionTypeAttributes,
29472987
reference = FunctionTypeAttribute,
2948-
allow_empty = true
2988+
allow_empty = true,
2989+
parser_options = ParserOptions(inline = true, pubb = false)
29492990
),
29502991
Enum(
29512992
name = FunctionTypeAttribute,

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

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

crates/solidity/outputs/cargo/tests/src/cst/cst_output/generated/source_unit.rs

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This should be parsed as a state variable
2+
// Non implemented functions are not allowed to have modifiers
3+
contract Foo {
4+
function() external foo;
5+
}

0 commit comments

Comments
 (0)