Skip to content

Commit

Permalink
markup parser now correctly handles negative values.
Browse files Browse the repository at this point in the history
Previously it was seeing the negation symbol as the start of a string value.
This meant when you asked for the float/int form of the property you got back nothing.
  • Loading branch information
McJones committed Jan 13, 2025
1 parent eb20171 commit b829f15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions YarnSpinner.Tests/MarkupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ private LineParser.MarkupTreeNode Descendant(LineParser.MarkupTreeNode root, par
[InlineData("this is a line with [markup markup = 1]a single markup[/markup] inside of it", new LineParser.LexerTokenTypes[] { LineParser.LexerTokenTypes.Text, LineParser.LexerTokenTypes.OpenMarker, LineParser.LexerTokenTypes.Identifier, LineParser.LexerTokenTypes.Identifier, LineParser.LexerTokenTypes.Equals, LineParser.LexerTokenTypes.NumberValue, LineParser.LexerTokenTypes.CloseMarker, LineParser.LexerTokenTypes.Text, LineParser.LexerTokenTypes.OpenMarker, LineParser.LexerTokenTypes.CloseSlash, LineParser.LexerTokenTypes.Identifier, LineParser.LexerTokenTypes.CloseMarker, LineParser.LexerTokenTypes.Text }, new string[] { "this is a line with ", "[", "markup", "markup", "=", "1", "]", "a single markup", "[", "/", "markup", "]", " inside of it" })]
[InlineData("this is a line with [interpolated markup = {$property} /] inside", new LineParser.LexerTokenTypes[] { LineParser.LexerTokenTypes.Text, LineParser.LexerTokenTypes.OpenMarker, LineParser.LexerTokenTypes.Identifier, LineParser.LexerTokenTypes.Identifier, LineParser.LexerTokenTypes.Equals, LineParser.LexerTokenTypes.InterpolatedValue, LineParser.LexerTokenTypes.CloseSlash, LineParser.LexerTokenTypes.CloseMarker, LineParser.LexerTokenTypes.Text, }, new string[] { "this is a line with ", "[", "interpolated", "markup", "=", "{$property}", "/", "]", " inside" })]
[InlineData("á [a]S[/a]", new LineParser.LexerTokenTypes[] { LineParser.LexerTokenTypes.Text, LineParser.LexerTokenTypes.OpenMarker, LineParser.LexerTokenTypes.Identifier, LineParser.LexerTokenTypes.CloseMarker, LineParser.LexerTokenTypes.Text, LineParser.LexerTokenTypes.OpenMarker, LineParser.LexerTokenTypes.CloseSlash, LineParser.LexerTokenTypes.Identifier, LineParser.LexerTokenTypes.CloseMarker, }, new string[] { "á ", "[", "a", "]", "S", "[", "/", "a", "]" })]
[InlineData("start [markup=-1 /] end", new LineParser.LexerTokenTypes[] {LineParser.LexerTokenTypes.Text, LineParser.LexerTokenTypes.OpenMarker, LineParser.LexerTokenTypes.Identifier, LineParser.LexerTokenTypes.Equals, LineParser.LexerTokenTypes.NumberValue, LineParser.LexerTokenTypes.CloseSlash, LineParser.LexerTokenTypes.CloseMarker, LineParser.LexerTokenTypes.Text}, new string[] {"start ", "[", "markup", "=", "-1", "/", "]", " end"})]
[InlineData("start [markup=-1.0 /] end", new LineParser.LexerTokenTypes[] {LineParser.LexerTokenTypes.Text, LineParser.LexerTokenTypes.OpenMarker, LineParser.LexerTokenTypes.Identifier, LineParser.LexerTokenTypes.Equals, LineParser.LexerTokenTypes.NumberValue, LineParser.LexerTokenTypes.CloseSlash, LineParser.LexerTokenTypes.CloseMarker, LineParser.LexerTokenTypes.Text}, new string[] {"start ", "[", "markup", "=", "-1.0", "/", "]", " end"})]
void TestLexerGeneratesCorrectTokens(string line, LineParser.LexerTokenTypes[] types, string[] texts)
{
var lineParser = new LineParser();
Expand Down Expand Up @@ -1079,6 +1081,8 @@ public void TestMarkupMultiplePropertyParsing()
[InlineData("[a p=true]s[/a]", MarkupValueType.Bool, "True")]
[InlineData("[a p=false]s[/a]", MarkupValueType.Bool, "False")]
[InlineData("[a p={$someValue}]s[/a]", MarkupValueType.String, "$someValue")]
[InlineData("[p=-1 /]", MarkupValueType.Integer, "-1")]
[InlineData("[p=-1.1 /]", MarkupValueType.Float, "-1.1")]
public void TestMarkupPropertyParsing(string input, MarkupValueType expectedType, string expectedValueAsString)
{
var lineParser = new LineParser();
Expand Down
3 changes: 2 additions & 1 deletion YarnSpinner/YarnSpinner.Markup/LineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ internal List<LexerToken> LexMarkup(string input)
if (!char.IsWhiteSpace(c))
{
// we are a number
if (char.IsDigit(c))
// this happens if we are either a digit or the negation symbol
if (char.IsDigit(c) || c == '-')
{
var token = new LexerToken()
{
Expand Down

0 comments on commit b829f15

Please sign in to comment.