add node type
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="RegularExpression.Node.Char"
|
// file="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
|
||||||
@@ -34,74 +34,60 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.RegularAnalysis
|
namespace StgSharp.RegularAnalysis
|
||||||
{
|
{
|
||||||
internal class RegularExpressionCharNode : RegularStateNode
|
internal class RegularExpressionEpsilonNode : RegularStateNode
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal class RegularExpressionCharNode : RegularStateNode
|
||||||
|
{
|
||||||
|
|
||||||
|
private char _char;
|
||||||
|
|
||||||
|
public RegularExpressionCharNode(char c)
|
||||||
{
|
{
|
||||||
|
_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
internal class RegularExpressionCharsetNode : RegularStateNode
|
||||||
IEnumerable<char> charset,
|
{
|
||||||
bool isNegated = false
|
|
||||||
)
|
|
||||||
{
|
|
||||||
_charset = new(charset);
|
|
||||||
_isNegated = isNegated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegularExpressionCharsetNode(
|
private bool _isNegated;
|
||||||
ReadOnlySpan<char> charset,
|
private HashSet<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 RegularExpressionCharsetNode(IEnumerable<char> charset, bool isNegated = false)
|
||||||
|
{
|
||||||
|
_charset = new(charset);
|
||||||
|
_isNegated = isNegated;
|
||||||
|
}
|
||||||
|
|
||||||
public override bool IsValidateFrom(
|
public RegularExpressionCharsetNode(ReadOnlySpan<char> charset, bool isNegated = false)
|
||||||
RegularStateNode former,
|
{
|
||||||
RegularContext context
|
_charset = new(charset.Length);
|
||||||
)
|
_isNegated = isNegated;
|
||||||
{
|
}
|
||||||
int pos = context.Position;
|
|
||||||
char c = context.CurrentCharSpan[pos + 1];
|
|
||||||
bool contains = _charset.Contains(c);
|
|
||||||
return _isNegated ? !contains : contains;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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