diff --git a/CHANGELOG.md b/CHANGELOG.md index b91cd7c95..9bfe3654d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added + +- Markup attributes may now begin with a digit, letter or underscore. Previously, they were required to begin with a letter or an underscore. This allows the `select` marker to work with numbers: `[select value=1 1=one 2=two 3=three /]` + ## [2.2.0] 2022-04-08 ### Added diff --git a/YarnSpinner.Tests/MarkupTests.cs b/YarnSpinner.Tests/MarkupTests.cs index 61ee3e908..685cafa09 100644 --- a/YarnSpinner.Tests/MarkupTests.cs +++ b/YarnSpinner.Tests/MarkupTests.cs @@ -295,5 +295,21 @@ public void TestMarkupEscaping() { Assert.Equal(0, markup.Attributes[0].Position); Assert.Equal(18, markup.Attributes[0].Length); } + + [Fact] + public void TestNumericProperties() { + var line = @"[select value=1 1=one 2=two 3=three /]"; + var markup = dialogue.ParseMarkup(line); + + Assert.Single(markup.Attributes); + Assert.Equal("select", markup.Attributes[0].Name); + Assert.Equal(4, markup.Attributes[0].Properties.Count); + Assert.Equal(1, markup.Attributes[0].Properties["value"].IntegerValue); + Assert.Equal("one", markup.Attributes[0].Properties["1"].StringValue); + Assert.Equal("two", markup.Attributes[0].Properties["2"].StringValue); + Assert.Equal("three", markup.Attributes[0].Properties["3"].StringValue); + + Assert.Equal("one", markup.Text); + } } } diff --git a/YarnSpinner/YarnSpinner.Markup/LineParser.cs b/YarnSpinner/YarnSpinner.Markup/LineParser.cs index 7339cc967..c7f07fc6d 100644 --- a/YarnSpinner/YarnSpinner.Markup/LineParser.cs +++ b/YarnSpinner/YarnSpinner.Markup/LineParser.cs @@ -787,7 +787,7 @@ private string ParseID() this.ConsumeWhitespace(); var idStringBuilder = new StringBuilder(); - // Read the first character, which must be a letter + // Read the first character, which must be a letter, number, or underscore int tempNext = this.stringReader.Read(); this.sourcePosition += 1; this.AssertNotEndOfInput(tempNext); @@ -805,7 +805,7 @@ private string ParseID() idStringBuilder.Append(nextChar); idStringBuilder.Append(nextNextChar); } - else if (char.IsLetter(nextChar) || nextChar == '_') + else if (char.IsLetterOrDigit(nextChar) || nextChar == '_') { idStringBuilder.Append((char)tempNext); }