add node type

This commit is contained in:
Nitload
2026-02-02 00:38:15 +08:00
parent c056938e7c
commit 73b222bbc6
@@ -1,9 +1,9 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="RegularExpression.Node.Char"
// file="Node.Char"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -35,24 +35,24 @@ using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis
{
internal class RegularExpressionEpsilonNode : RegularStateNode
{
}
internal class RegularExpressionCharNode : RegularStateNode
{
private char _char;
public RegularExpressionCharNode(
char c
)
public RegularExpressionCharNode(char c)
{
_char = c;
}
public override NodeType Type => NodeType.CHAR;
public override bool IsValidateFrom(
RegularStateNode former,
RegularContext context
)
public override bool IsValidateFrom(RegularStateNode former, RegularContext context)
{
int pos = context.Position;
char c = context.CurrentCharSpan[pos + 1];
@@ -67,33 +67,21 @@ namespace StgSharp.RegularAnalysis
private bool _isNegated;
private HashSet<char> _charset;
public RegularExpressionCharsetNode(
IEnumerable<char> charset,
bool isNegated = false
)
public RegularExpressionCharsetNode(IEnumerable<char> charset, bool isNegated = false)
{
_charset = new(charset);
_isNegated = isNegated;
}
public RegularExpressionCharsetNode(
ReadOnlySpan<char> charset,
bool isNegated = false
)
public RegularExpressionCharsetNode(ReadOnlySpan<char> charset, bool isNegated = false)
{
_charset = new(charset.Length);
foreach (char item in _charset) {
_charset.Add(item);
}
_isNegated = isNegated;
}
public override NodeType Type => NodeType.CHARSET;
public override bool IsValidateFrom(
RegularStateNode former,
RegularContext context
)
public override bool IsValidateFrom(RegularStateNode former, RegularContext context)
{
int pos = context.Position;
char c = context.CurrentCharSpan[pos + 1];
@@ -101,7 +89,5 @@ namespace StgSharp.RegularAnalysis
return _isNegated ? !contains : contains;
}
}
}