Skip to content

Commit

Permalink
Markers now allow properties beginning with digits
Browse files Browse the repository at this point in the history
Previously, we required property names to begin with a letter or an
underscore,but this requirement wasn't really necessary, because there's
no ambiguity avoided here (additionally, it prevented [select] from
working with numbers)
  • Loading branch information
desplesda committed Apr 13, 2022
1 parent 9944960 commit 29cd408
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions YarnSpinner.Tests/MarkupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions YarnSpinner/YarnSpinner.Markup/LineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit 29cd408

Please sign in to comment.