-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite the MarkupLexer as a state machine
- Loading branch information
Showing
5 changed files
with
166 additions
and
69 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,13 @@ | ||
|
||
namespace GuildWars2.Markup; | ||
|
||
internal enum MarkupLexerState | ||
{ | ||
Text, | ||
|
||
TagOpen, | ||
|
||
TagValue, | ||
|
||
TagClose | ||
} |
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 |
---|---|---|
@@ -1,35 +1,19 @@ | ||
| ||
using System.Diagnostics; | ||
|
||
namespace GuildWars2.Markup; | ||
|
||
internal class Scanner(string input) | ||
{ | ||
private int position; | ||
|
||
public char Current => position >= input.Length ? '\0' : input[position]; | ||
|
||
public bool CanAdvance => position < input.Length; | ||
|
||
public void Advance() => position++; | ||
public int Position { get; private set; } | ||
|
||
public string ReadUntil(char c) | ||
{ | ||
var start = position; | ||
while (Current != c && CanAdvance) | ||
{ | ||
Advance(); | ||
} | ||
public char Current => Position >= input.Length ? '\0' : input[Position]; | ||
|
||
return input[start..position]; | ||
} | ||
public bool CanAdvance => Position < input.Length; | ||
|
||
public string ReadUntilAny(params char[] chars) | ||
{ | ||
var start = position; | ||
while (!chars.Contains(Current) && CanAdvance) | ||
{ | ||
Advance(); | ||
} | ||
[DebuggerStepThrough] | ||
public char Peek() => Position + 1 >= input.Length ? '\0' : input[Position + 1]; | ||
|
||
return input[start..position]; | ||
} | ||
[DebuggerStepThrough] | ||
public void Advance() => Position++; | ||
} |