Implement a top-down recursive descent parser for the Weld programming language in Rust, focusing on parsing expressions, types, and macros.
Specific Requirements:
Program Parsing:
Implement the parse_program function to parse an input string as a complete Weld program, which includes optional macros followed by a single body expression. Ensure that the function verifies there are no unexpected tokens after parsing.
Macro Parsing:
Implement the parse_macros function to parse a list of macros from the input string. Each macro should consist of a name, an optional list of parameters, an assignment, and a body expression followed by a semicolon. Ensure there are no unexpected tokens after parsing.
Expression Parsing:
Implement the parse_expr function to accommodate various Weld expression constructs, including:
Let expressions: let name = value; body
Lambda expressions: |params| body
Binary operations with respect to operator precedence (addition, subtraction, etc.).
Support for parsing expressions that include literals (e.g., integers, booleans, etc.), type casting, and built-in functions.
Type Parsing:
Implement the parse_type function to parse a type expression, including support for scalar types, vector types, and structures.
Error Handling:
Ensure to return appropriate errors for unexpected tokens or invalid input to make it clear where parsing issues occur.
Testing:
Verify that all provided test cases pass after the implementation is complete. The tests cover basic parsing, operator precedence, and range checks.