add node type
This commit is contained in:
@@ -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
|
||||
@@ -34,74 +34,60 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.RegularAnalysis
|
||||
{
|
||||
internal class RegularExpressionCharNode : RegularStateNode
|
||||
{
|
||||
internal class RegularExpressionEpsilonNode : RegularStateNode
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
internal class RegularExpressionCharNode : RegularStateNode
|
||||
{
|
||||
|
||||
private char _char;
|
||||
|
||||
public RegularExpressionCharNode(char c)
|
||||
{
|
||||
|
||||
private char _char;
|
||||
|
||||
public RegularExpressionCharNode(
|
||||
char c
|
||||
)
|
||||
{
|
||||
_char = c;
|
||||
}
|
||||
|
||||
public override NodeType Type => NodeType.CHAR;
|
||||
|
||||
public override bool IsValidateFrom(
|
||||
RegularStateNode former,
|
||||
RegularContext context
|
||||
)
|
||||
{
|
||||
int pos = context.Position;
|
||||
char c = context.CurrentCharSpan[pos + 1];
|
||||
return c == _char;
|
||||
}
|
||||
|
||||
_char = c;
|
||||
}
|
||||
|
||||
internal class RegularExpressionCharsetNode : RegularStateNode
|
||||
public override NodeType Type => NodeType.CHAR;
|
||||
|
||||
public override bool IsValidateFrom(RegularStateNode former, RegularContext context)
|
||||
{
|
||||
int pos = context.Position;
|
||||
char c = context.CurrentCharSpan[pos + 1];
|
||||
return c == _char;
|
||||
}
|
||||
|
||||
private bool _isNegated;
|
||||
private HashSet<char> _charset;
|
||||
}
|
||||
|
||||
public RegularExpressionCharsetNode(
|
||||
IEnumerable<char> charset,
|
||||
bool isNegated = false
|
||||
)
|
||||
{
|
||||
_charset = new(charset);
|
||||
_isNegated = isNegated;
|
||||
}
|
||||
internal class RegularExpressionCharsetNode : RegularStateNode
|
||||
{
|
||||
|
||||
public RegularExpressionCharsetNode(
|
||||
ReadOnlySpan<char> charset,
|
||||
bool isNegated = false
|
||||
)
|
||||
{
|
||||
_charset = new(charset.Length);
|
||||
foreach (char item in _charset) {
|
||||
_charset.Add(item);
|
||||
}
|
||||
_isNegated = isNegated;
|
||||
}
|
||||
private bool _isNegated;
|
||||
private HashSet<char> _charset;
|
||||
|
||||
public override NodeType Type => NodeType.CHARSET;
|
||||
public RegularExpressionCharsetNode(IEnumerable<char> charset, bool isNegated = false)
|
||||
{
|
||||
_charset = new(charset);
|
||||
_isNegated = isNegated;
|
||||
}
|
||||
|
||||
public override bool IsValidateFrom(
|
||||
RegularStateNode former,
|
||||
RegularContext context
|
||||
)
|
||||
{
|
||||
int pos = context.Position;
|
||||
char c = context.CurrentCharSpan[pos + 1];
|
||||
bool contains = _charset.Contains(c);
|
||||
return _isNegated ? !contains : contains;
|
||||
}
|
||||
public RegularExpressionCharsetNode(ReadOnlySpan<char> charset, bool isNegated = false)
|
||||
{
|
||||
_charset = new(charset.Length);
|
||||
_isNegated = isNegated;
|
||||
}
|
||||
|
||||
|
||||
public override NodeType Type => NodeType.CHARSET;
|
||||
|
||||
public override bool IsValidateFrom(RegularStateNode former, RegularContext context)
|
||||
{
|
||||
int pos = context.Position;
|
||||
char c = context.CurrentCharSpan[pos + 1];
|
||||
bool contains = _charset.Contains(c);
|
||||
return _isNegated ? !contains : contains;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user