Skip to content

Commit

Permalink
Add support bell char and decode null char (#94)
Browse files Browse the repository at this point in the history
* support bell char and decode null char

* add tests for new chars

---------

Co-authored-by: Luke Murray <luke@xysense.com>
  • Loading branch information
lukemurray and Luke Murray authored Apr 24, 2024
1 parent e945eb0 commit f1586c8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Parlot/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public static TextSpan DecodeString(TextSpan span)
case '\'': c = '\''; break;
case '"': c = '\"'; break;
case '\\': c = '\\'; break;
case '0': c = '\0'; break;
case 'a': c = '\a'; break;
case 'b': c = '\b'; break;
case 'f': c = '\f'; break;
case 'n': c = '\n'; break;
Expand Down
1 change: 1 addition & 0 deletions src/Parlot/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ private bool ReadQuotedString(char quoteChar, out TokenResult result)
{
case '0':
case '\\':
case 'a':
case 'b':
case 'f':
case 'n':
Expand Down
2 changes: 2 additions & 0 deletions test/Parlot.Tests/CharacterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class CharacterTests
[InlineData(" \\xa0 ", " \xa0 ")]
[InlineData(" \\xfh ", " \xfh ")]
[InlineData(" \u03B2 ", " β ")]
[InlineData(" \\a ", " \a ")]
[InlineData(" \\0hello ", " \0hello ")]

public void ShouldDescodeString(string text, string expected)
{
Expand Down
1 change: 1 addition & 0 deletions test/Parlot.Tests/ScannerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void ShouldReadEscapedStringWithMatchingQuotes(string text, string expect
[InlineData("\"Lo\\trem \\n ipsum\"", "\"Lo\\trem \\n ipsum\"")]
[InlineData("'Lorem \\u1234 ipsum'", "'Lorem \\u1234 ipsum'")]
[InlineData("'Lorem \\xabcd ipsum'", "'Lorem \\xabcd ipsum'")]
[InlineData("'\\a ding'", "'\\a ding'")]
public void ShouldReadStringWithEscapes(string text, string expected)
{
Scanner s = new(text);
Expand Down

0 comments on commit f1586c8

Please sign in to comment.