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