Open brywhitak opened 3 months ago
Some further clarification:
=>
is usually reserved for lambda functions, however, there is another use where it can be used to make named functions. An example:
public override string ToString() => $"{fname} {lname}".Trim();
These are called expression body definitions in C#. This will require further investigation into whether or not it should be marked up as a function or as a lambda. This does confirm that it is an expression, though, so that would change some of the markup:
<switch_expr> <condition/> switch <block/> </switch_expr>
Since a <guard>
tag is already being used as a statement in other proposals, another change in suggested markup would be to change the <guard>
tag to a <condition>
tag, in order to keep srcML consistent across languages:
<case> <expr/> when <condition/> => <expr/> , </case>
Cases without conditions remain the same:
<case> <expr/> => <expr/> , </case>
Additionally, there should be no <default>
case specifically marked up. Instead, since _
is just a <name>
, it should just be another case. As a side note, C# formally calls the entire block of x => y
as an "arm," but I believe it is best to leave it as case as to keep it consistent with switch statements.
Below is an example of a C# switch expression, which is not currently marked up properly in srcML:
Here is suggested markup for the given code:
Below are examples of multiple different cases, also not properly marked up in srcML:
The first case uses a code block to hold a pattern to match to; this is done if the object passed to the switch expression has multiple different member variables that can be checked.
Marked up as:
The second case uses a code block and a guard clause to limit when the case can be matched; this case only executes when x is greater than y, and then returns a point with a transform.
Marked up as:
In the third case, _ is used as a catch-all to make sure there is something for all execution paths. Therefore, it is the default case.
Marked up as: