Daily update on 20250323-151439 by Nitload Youmu. Additional Message : none

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-03-23 15:14:39 +08:00
parent 528d0c5462
commit 148b0fed4a
29 changed files with 313 additions and 178 deletions
+134 -89
View File
@@ -44,7 +44,7 @@ namespace StgSharp.Script.Express
private const int
MultiLineEnd = 0x0029002A; // *)
private const string Token = "token", End = "end", Rest = "rest";
private const string TokenMark = "token", EndMark = "end", RestMark = "rest";
private bool _isReadingMultiLineComment;
private int _current, _lineNum;
@@ -67,8 +67,7 @@ namespace StgSharp.Script.Express
public bool IsEmpty
{
get => ( ( string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length ) ) && _provider.IsEmpty;
get => ( ( string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length ) ) && _provider.IsEmpty;
}
public int LineNumber
@@ -77,38 +76,44 @@ namespace StgSharp.Script.Express
}
/// <summary>
/// <para> Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// begins with part of multi-line comment will automatically remove the comment part, but
/// beginning with a full multi-line comment will not causing removing. </para> <para>(*Just
/// Like The Comment Here*) Will Not Be Removed</para>
/// <para> Read code until end of a line. Lines in multi-line comment will be ignored.
/// Line begins with part of multi-line comment will automatically remove the comment
/// part, but beginning with a full multi-line comment will not causing removing. </para>
/// <para> (*Just Like The Comment Here*) Will Not Be Removed</para>
/// </summary>
/// <returns></returns>
/// <returns>
///
/// </returns>
public unsafe ReadOnlySpan<char> ReadLine()
{
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length;
while( lineOver || _isReadingMultiLineComment ) {
if( lineOver ) {
do {
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length;
while( lineOver || _isReadingMultiLineComment )
{
if( lineOver )
{
do
{
_lineCache = _provider.ReadLine( out _lineNum );
} while (string.IsNullOrEmpty( _lineCache ));
_current = 0;
}
if( _isReadingMultiLineComment ) {
if( _isReadingMultiLineComment )
{
int index;
fixed( char* cPtr = _lineCache.AsSpan( _current ) ) {
index = UnsafeCompute.IndexOfCharPair(
cPtr, MultiLineEnd, _lineCache.Length );
}
if( index == -1 ) {
if( index == -1 )
{
_lineCache = string.Empty;
} else {
} else
{
_isReadingMultiLineComment = false;
_current += index + 2;
}
}
lineOver = string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length;
lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length;
}
return _lineCache.AsSpan().Slice( _current );
}
@@ -120,67 +125,71 @@ namespace StgSharp.Script.Express
ReadOnlySpan<char> source = ReadLine();
char c = source[ 0 ];
if( char.IsLetter( c ) ) {
Match match = _nextWordTokenPattern.Match(
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
if( char.IsLetter( c ) )
{
Match match = _nextWordTokenPattern.Match( _lineCache, _current );
if( match.Success )
{
begin = match.Groups[ TokenMark ].Index;
end = match.Groups[ EndMark ].Index;
rest = match.Groups[ RestMark ].Index;
_current = rest;
_last = new(
ExpCompile.PoolString( source[ .. ( end - begin ) ] ),
_lineNum, begin, TokenFlag.Member );
ExpressCompile.PoolString( source[ .. ( end - begin ) ] ), _lineNum, begin,
TokenFlag.Member );
return _last;
} else {
} else
{
throw new ExpInvalidTokenException( _current );
}
} else if( char.IsPunctuation( c ) || char.IsSymbol( c ) ) {
switch( c ) {
} else if( char.IsPunctuation( c ) || char.IsSymbol( c ) )
{
switch( c )
{
case '"':
char cNext = source[ 1 ];
if( cNext == '\"' ) //empty string
{
begin = _current;
_current += 2;
return new(
string.Empty, _lineNum, begin,
TokenFlag.String );
return new( string.Empty, _lineNum, begin, TokenFlag.String );
}
Match match = _nextStringLiteralPattern.Match(
_lineCache, _current );
if( match.Success ) {
Match match = _nextStringLiteralPattern.Match( _lineCache, _current );
if( match.Success )
{
begin = match.Groups[ "token" ].Index;
end = match.Groups[ "end" ].Index;
rest = match.Groups[ "rest" ].Index;
_current = rest;
_last = new(
ExpCompile.PoolString(
source[ 1..( end - begin ) ] ),
_lineNum, begin, TokenFlag.String );
ExpressCompile.PoolString( source[ 1..( end - begin ) ] ), _lineNum,
begin, TokenFlag.String );
return _last;
} else {
} else
{
throw new ExpInvalidCharException( '\"' );
}
case '(':
cNext = source[ 1 ];
if( cNext == '*' ) {
if( cNext == '*' )
{
_isReadingMultiLineComment = true;
_current += 2;
goto readLine;
} else {
} else
{
begin = _current;
_current++;
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Separator_Left );
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Separator_Left );
return _last;
}
case ')' or '}':
begin = _current;
_current++;
_last = new Token(
ExpCompile.PoolString( ")" ), _lineNum, begin,
ExpressCompile.PoolString( ")" ), _lineNum, begin,
TokenFlag.Separator_Right );
return _last;
case '-':
@@ -190,36 +199,41 @@ namespace StgSharp.Script.Express
// 3. - number type param(UNARY)
// 4. param - param(BINARY)
cNext = source[ 1 ];
if( char.IsNumber( cNext ) ) {
match = _nextNumberLiteralPattern.Match(
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
if( char.IsNumber( cNext ) )
{
match = _nextNumberLiteralPattern.Match( _lineCache, _current );
if( match.Success )
{
begin = match.Groups[ TokenMark ].Index;
end = match.Groups[ EndMark ].Index;
rest = match.Groups[ RestMark ].Index;
_current = rest;
return new(
ExpCompile.PoolString(
source[ ..( end - begin ) ] ),
ExpressCompile.PoolString( source[ ..( end - begin ) ] ),
_lineNum, begin, TokenFlag.Number );
} else {
} else
{
throw new ExpInvalidTokenException( _current );
}
} else if( cNext == '-' ) {
} else if( cNext == '-' )
{
_lineCache = string.Empty;
_current = 0;
goto readLine;
} else {
} else
{
begin = _current;
_current++;
if( _last.Flag != TokenFlag.Member ) {
if( _last.Flag != TokenFlag.Member )
{
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Symbol_Unary );
} else {
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Symbol_Unary );
} else
{
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Symbol_Binary );
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Symbol_Binary );
}
return _last;
}
@@ -227,70 +241,101 @@ namespace StgSharp.Script.Express
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "{" ), _lineNum, begin,
ExpressCompile.PoolString( "{" ), _lineNum, begin,
TokenFlag.Separator_Left );
case '[':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "[" ), _lineNum, begin,
ExpressCompile.PoolString( "[" ), _lineNum, begin,
TokenFlag.Index_Left );
case ']':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "]" ), _lineNum, begin,
ExpressCompile.PoolString( "]" ), _lineNum, begin,
TokenFlag.Index_Right );
case ';' or ',':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
begin, TokenFlag.Separator_Middle );
case ':' or '+' or '/' or '\\' or '*' or '.':
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Separator_Middle );
case ':':
if( source[ 1 ] == '=' )
{
begin = _current;
_current += 2;
return new Token(
ExpressCompile.KeyWord.Assignment, _lineNum, begin,
TokenFlag.Index_Right );
}
begin = _current;
_current++;
return new Token(
ExpressCompile.KeyWord.Colon, _lineNum, begin, TokenFlag.Index_Right );
case '+' or '/' or '\\' or '*' or '.':
begin = _current;
_current++;
return new(
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
begin, TokenFlag.Symbol_Binary );
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Symbol_Binary );
default:
throw new ExpInvalidCharException( c );
}
} else if( char.IsNumber( c ) ) {
Match match = _nextNumberLiteralPattern.Match(
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
} else if( char.IsNumber( c ) )
{
Match match = _nextNumberLiteralPattern.Match( _lineCache, _current );
if( match.Success )
{
begin = match.Groups[ TokenMark ].Index;
end = match.Groups[ EndMark ].Index;
rest = match.Groups[ RestMark ].Index;
_current = rest;
string str = ExpCompile.PoolString(
source[ ..( end - begin ) ] );
string str = ExpressCompile.PoolString( source[ ..( end - begin ) ] );
TokenFlag flag;
if( ReferenceEquals( str, ExpCompile.KeyWord.Not ) ) {
if( ReferenceEquals( str, ExpressCompile.KeyWord.Not ) )
{
flag = TokenFlag.Symbol_Unary;
} else {
flag = ExpCompile.LetterIsOperator( str ) ?
} else
{
flag = ExpressCompile.LetterIsOperator( str ) ?
TokenFlag.Symbol_Binary : TokenFlag.Member;
}
return new( str, _lineNum, begin, flag );
} else {
} else
{
throw new ExpInvalidTokenException( _current );
}
} else if( char.IsWhiteSpace( c ) ) {
} else if( char.IsWhiteSpace( c ) )
{
Match match = _skipBlankPattern.Match( _lineCache, _current );
if( match.Success ) {
rest = match.Groups[ Rest ].Index;
if( match.Success )
{
rest = match.Groups[ RestMark ].Index;
_current = rest;
goto readLine;
} else {
} else
{
throw new ExpInvalidTokenException( _current );
}
} else {
} else
{
throw new ExpInvalidCharException( c );
}
}
public bool TryReadToken( out Token t )
{
if( IsEmpty )
{
t = Token.Empty;
return false;
}
t = ReadToken();
return true;
}
[GeneratedRegex(
@"(?<token>[a-zA-Z][a-zA-Z0-9_]*)(?<end>\s*?)(?<rest>\S|$)",
RegexOptions.Singleline )]