Skip to content

Commit

Permalink
Use generated regex
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Nov 14, 2023
1 parent 0a0559f commit ea0706a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Resources/SteamLanguageParser/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,27 @@ readonly struct TokenSourceInfo(string fileName, int startLineNumber, int startC
public int EndColumnNumber { get; } = endColumnNumber;
}

class LanguageParser
partial class LanguageParser
{
public static string pattern =
@"(?<whitespace>\s+)|" +
@"(?<terminator>[;])|" +
[GeneratedRegex(
@"(?<whitespace>\s+)|" +
@"(?<terminator>[;])|" +

"[\"](?<string>.+?)[\"]|" +
"[\"](?<string>.+?)[\"]|" +

@"\/\/(?<comment>.*)$|" +
@"\/\/(?<comment>.*)$|" +

@"(?<identifier>-?[a-zA-Z_0-9][a-zA-Z0-9_:.]*)|" +
@"[#](?<preprocess>[a-zA-Z]*)|" +
@"(?<identifier>-?[a-zA-Z_0-9][a-zA-Z0-9_:.]*)|" +
@"[#](?<preprocess>[a-zA-Z]*)|" +

@"(?<operator>[{}<>\]=|])|" +
@"(?<invalid>[^\s]+)";

private static readonly Regex regexPattern = new(pattern, RegexOptions.Multiline | RegexOptions.Compiled);
@"(?<operator>[{}<>\]=|])|" +
@"(?<invalid>[^\s]+)",
RegexOptions.Multiline)]
private static partial Regex RegexPattern();

public static Queue<Token> TokenizeString(string buffer, string fileName = "")
{
var regexPattern = RegexPattern();
var bufferLines = buffer.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

MatchCollection matches = regexPattern.Matches(buffer);
Expand Down

0 comments on commit ea0706a

Please sign in to comment.