matthewpratt13 / feo-new

A novel blockchain programming language written in Rust (WIP)
GNU General Public License v3.0
1 stars 0 forks source link

Parser: function call vs. tuple struct syntax similar #26

Closed matthewpratt13 closed 1 month ago

matthewpratt13 commented 4 months ago

It is presently impossible for the parser to syntactically distinguish between a functional call expression (i.e., foo(bar, baz)) and a tuple struct expression (i.e., Foo(bar, baz)). This can likely be solved later on, using a symbol table, so it's not a massive problem at present.

According to the Rust reference book:

"A struct expression with fields enclosed in parentheses constructs a tuple struct. Though it is listed here as a specific expression for completeness, it is equivalent to a call expression to the tuple struct's constructor."

For example:

struct Position(i32, i32, i32);
Position(0, 0, 0);  // Typical way of creating a tuple struct.
let c = Position;  // `c` is a function that takes 3 arguments.
let pos = c(8, 6, 7);  // Creates a `Position` value.

It would just be a matter of looking up the type of the symbol c and treating its subsequent assignment as a struct constructor function call, where pos is the constructed struct.

matthewpratt13 commented 3 months ago

An idea: