This repository has been archived by the owner on May 30, 2022. It is now read-only.
forked from CosmosOS/XSharp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c69175
commit 937ceea
Showing
5 changed files
with
88 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
|
||
namespace Spruce.Tokens | ||
{ | ||
public class CharacterLiteral : Token | ||
{ | ||
// We are overriding the parse method to set rStart itself | ||
public override object Parse(string aText, ref int rStart) | ||
{ | ||
int i; | ||
|
||
var isEscaped = false; | ||
var foundEndQuote = false; | ||
|
||
for (i = 1; i < aText.Length - rStart; i++) | ||
{ | ||
if (aText[rStart + i] == '\\') | ||
{ | ||
isEscaped = true; | ||
continue; | ||
} | ||
|
||
if (aText[rStart + i] == '\'' && !isEscaped) | ||
{ | ||
foundEndQuote = true; | ||
i += 1; // Increment i so that the end quote is also included | ||
break; | ||
} | ||
|
||
isEscaped = false; | ||
} | ||
|
||
// Cannot find end quote. We cannot parse the object as string. | ||
if (!foundEndQuote) | ||
return null; | ||
|
||
// Replace all \' with ' and then remove the opening quotes | ||
var xResult = aText.Substring(rStart + 1, i - 2).Replace(@"\'", @"'"); | ||
if (xResult.Length != 1) | ||
{ | ||
throw new ArgumentOutOfRangeException("CharacterLiteral should only be a single character."); | ||
} | ||
rStart += i; | ||
return xResult; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters