Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to PEG parser. Introduce boolean operators and constants. #2182

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1d2577d
Migrate to PEG parser. Introduce boolean operators and constants.
stephenquan Aug 19, 2024
bf34590
Update UnitTest. Added conditional sample.
stephenquan Sep 6, 2024
584eb1e
Merge branch 'main' of github.com:CommunityToolkit/Maui
stephenquan Sep 6, 2024
5a830f4
Improve null handling and added extra boolean/null unit tests
stephenquan Sep 10, 2024
7472ad0
Additional boolean tests
stephenquan Sep 10, 2024
d580a45
Allow nulls if operator is ? : && || == !=
stephenquan Sep 10, 2024
c60652f
__bool and MathToken record refactor
stephenquan Sep 18, 2024
ef3380a
First attempt to block null reference return
stephenquan Sep 18, 2024
cd8def9
Second attempt to block null reference return
stephenquan Sep 18, 2024
3c9b632
Addessed CS8603 possible null reference return issues
stephenquan Sep 18, 2024
5aaf5ef
Merge branch 'main' into main
pictos Sep 18, 2024
fde4fc1
Merge branch 'main' into main
pictos Sep 22, 2024
9bf1bef
Use correct C# property name pattern. Log invalid math expressions in…
stephenquan Sep 25, 2024
34d3883
Merge branch 'main' into main
pictos Sep 26, 2024
88b0103
Merge branch 'main' into main
stephenquan Oct 6, 2024
9b64f7b
Null Forgiving Operator removed. Adjust null checks in MultiMathExpre…
stephenquan Oct 6, 2024
c3ea28b
Merge branch 'main' into main
pictos Oct 21, 2024
9994c63
Merge branch 'main' into main
brminnick Nov 26, 2024
6808590
Add more logical and/or unit tests. Add XAML friendly comparator oper…
stephenquan Dec 5, 2024
31d712e
Improve unit test coverage on alternate operators.
stephenquan Dec 5, 2024
a983e7a
Improve null handling for logical operators && || and cover these cas…
stephenquan Dec 6, 2024
a4bcd8a
Merge branch 'main' into main
stephenquan Dec 8, 2024
ebf0d3a
Miscellaneous fixes for Copilot review
stephenquan Dec 12, 2024
91bd65b
Merge branch 'main' of github.com:stephenquan/Maui
stephenquan Dec 12, 2024
c59b197
Merge branch 'main' into pr/2182
brminnick Jan 2, 2025
241ed90
Update to .NET 9
brminnick Jan 2, 2025
11e9d72
Use Primary Constructor
brminnick Jan 2, 2025
53510d9
Merge branch 'main' into main
brminnick Jan 2, 2025
3e5b075
Remove redundant CodeAnalysis
brminnick Jan 2, 2025
5103c68
Update Regex naming
brminnick Jan 2, 2025
2967e7c
Use Index Operator
brminnick Jan 2, 2025
46e7b38
Merge branch 'main' of https://github.com/stephenquan/Maui into pr/2182
brminnick Jan 2, 2025
0bc4544
Update namings
brminnick Jan 3, 2025
3d6c9c8
Refactor
brminnick Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,86 @@
</ResourceDictionary>
</pages:BasePage.Resources>

<Grid Padding="20"
RowSpacing="20"
ColumnSpacing="12"
ColumnDefinitions="*,*,*,*,*,*,*"
RowDefinitions="100, *">
<Label Grid.ColumnSpan="7"
Grid.Row="0"
Text="This sample demonstrates the use of the MultiMathExpressionConverter. It utilizes the converter to perform various math operations of multiple variables."/>
<VerticalStackLayout Padding="20" Spacing="40">

<Entry Grid.Column="0"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="{Binding X0}"/>
<Grid RowSpacing="20"
ColumnSpacing="12"
ColumnDefinitions="*,*,*,*,*,*,*"
RowDefinitions="100, *">
<Label Grid.ColumnSpan="7"
Grid.Row="0"
Text="This sample demonstrates the use of the MultiMathExpressionConverter. It utilizes the converter to perform various math operations of multiple variables."/>

<Label Grid.Column="1"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="+" />
<Entry Grid.Column="0"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="{Binding X0}"/>

<Entry Grid.Column="2"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="{Binding X1}"/>
<Label Grid.Column="1"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="+" />

<Label Grid.Column="3"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="+" />
<Entry Grid.Column="2"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="{Binding X1}"/>

<Entry Grid.Column="4"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="{Binding X2}"/>
<Label Grid.Column="3"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="+" />

<Label Grid.Column="5"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="=" />
<Entry Grid.Column="4"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="{Binding X2}"/>

<Label Grid.Column="6"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center">
<Label.Text>
<MultiBinding Converter="{StaticResource MultiMathExpressionConverter}"
ConverterParameter="x0 + x1 + x2">
<Binding Path="X0" Mode="OneWay"/>
<Binding Path="X1" Mode="OneWay"/>
<Binding Path="X2" Mode="OneWay"/>
</MultiBinding>
</Label.Text>
<Label Grid.Column="5"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center"
Text="=" />

<Label Grid.Column="6"
Grid.Row="1"
VerticalTextAlignment="Center"
VerticalOptions="Center">
<Label.Text>
<MultiBinding Converter="{StaticResource MultiMathExpressionConverter}"
ConverterParameter="x0 + x1 + x2">
<Binding Path="X0" Mode="OneWay"/>
<Binding Path="X1" Mode="OneWay"/>
<Binding Path="X2" Mode="OneWay"/>
</MultiBinding>
</Label.Text>
</Label>
</Grid>

<Label HorizontalOptions="Center"
Text="Valid: Value greater than or equal to 60"
TextColor="Green">
<Label.Triggers>
<DataTrigger TargetType="Label" Value="False">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource MultiMathExpressionConverter}"
ConverterParameter="x0 + x1 + x2 &gt;= 60">
<Binding Path="X0" Mode="OneWay"/>
<Binding Path="X1" Mode="OneWay"/>
<Binding Path="X2" Mode="OneWay"/>
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Text" Value="Error: Value not greater than or equal to 60"/>
<Setter Property="TextColor" Value="Red"/>
</DataTrigger>
</Label.Triggers>
</Label>
</Grid>

</VerticalStackLayout>

</pages:BasePage>
38 changes: 16 additions & 22 deletions src/CommunityToolkit.Maui.Core/Primitives/MathOperator.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum MathOperatorPrecedence
/// <summary>High</summary>
High,
/// <summary>Constant</summary>
Constant,
Constant
}

/// <summary>
Expand All @@ -25,31 +25,25 @@ public enum MathOperatorPrecedence
/// </remarks>
/// <param name="name">Name</param>
/// <param name="numericCount">Number of Numerals</param>
/// <param name="precedence">Math Operator Preference</param>
/// <param name="calculateFunc">Calculation Function</param>
public sealed class MathOperator(
string name,
int numericCount,
MathOperatorPrecedence precedence,
Func<double[], double> calculateFunc)
string name,
int numericCount,
Func<object?[], object?> calculateFunc)
{
/// <summary>
/// Name
/// </summary>
public string Name { get; } = name;

/// <summary>
/// Number of Numerals
/// </summary>
public int NumericCount { get; } = numericCount;
/// <summary>
/// Name
/// </summary>
public string Name { get; } = name;

/// <summary>
/// Math Operator Precedence
/// </summary>
public MathOperatorPrecedence Precedence { get; } = precedence;
/// <summary>
/// Number of Numerals
/// </summary>
public int NumericCount { get; } = numericCount;

/// <summary>
/// Calculation Function
/// </summary>
public Func<double[], double> CalculateFunc { get; } = calculateFunc;
/// <summary>
/// Calculation Function
/// </summary>
public Func<object?[], object?> CalculateFunc { get; } = calculateFunc;
}
Loading