Skip to content

Commit

Permalink
Handle Strings of style "name"_group and add Unit Test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Haidon committed Jul 22, 2014
1 parent 3caa1a1 commit 7f7841c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Pdoxcl2Sharp.Test/Parse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ public void SimpleName()
Assert.AreEqual("Nick", actual);
}

[Test]
public void PartialQuotedName()
{
string toParse = "name=\"Nick\"_name";
var data = toParse.ToStream();

string actual = String.Empty;
Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
{
{ "name", x => actual = x.ReadString() }
};
ParadoxParser.Parse(data, dictionary.ParserAdapter());

Assert.AreEqual( "Nick_name", actual );
}

[Test]
public void SimpleComment()
{
Expand Down
19 changes: 19 additions & 0 deletions Pdoxcl2Sharp/ParadoxParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ public string ReadString()
{
while ((currentChar = ReadNext()) != '"' && !eof)
stringBuffer[stringBufferCount++] = currentChar;

// Check for partially quoted string of the style "name"_group.
// If it is, then read string as if untyped.
char nextChar = ReadNext();
if ( nextChar == '_' )
{
stringBuffer[stringBufferCount++] = nextChar;
currentToken = GetNextToken();
do
{
stringBuffer[stringBufferCount++] = currentChar;
} while(!IsSpace(currentChar = ReadNext()) &&
SetCurrentToken(currentChar) == LexerToken.Untyped && !eof);
} else
{
// Enqueue because it could be important (Equals, quote, etc.)
nextChars.Enqueue( nextChar );
nextCharsEmpty = false;
}
}
else if (currentToken == LexerToken.LeftCurly &&
PeekToken() == LexerToken.RightCurly)
Expand Down

0 comments on commit 7f7841c

Please sign in to comment.