daily update on 20250210 by nitload youmu

This commit is contained in:
Nitload
2025-02-10 12:48:02 +08:00
parent ae94c265ae
commit c23b640cae
70 changed files with 2135 additions and 805 deletions
@@ -63,50 +63,50 @@ namespace StgSharp.Script.Express
_isReadingMultiLineComment = false;
}
public int LineNumber
{
get => _provider.Location;
}
public bool IsEmpty
{
get => (( string.IsNullOrEmpty( _lineCache ) ||
_current >= _lineCache.Length )) && _provider.IsEmpty;
get => ( ( string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length ) ) && _provider.IsEmpty;
}
/// <summary>
/// <para>Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// <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>
/// 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>
public unsafe ReadOnlySpan<char> ReadLine()
{
bool lineOver = string.IsNullOrEmpty(_lineCache) || _current >=
_lineCache.Length;
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length;
while( lineOver || _isReadingMultiLineComment ) {
if (lineOver)
{
do
{
if( lineOver ) {
do {
_lineCache = _provider.ReadLine();
} while (string.IsNullOrEmpty(_lineCache));
} while (string.IsNullOrEmpty( _lineCache ));
_current = 0;
}
if( _isReadingMultiLineComment ) {
int index;
fixed( char* cPtr = _lineCache.AsSpan(_current) ) {
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 );
}
@@ -118,99 +118,96 @@ namespace StgSharp.Script.Express
ReadOnlySpan<char> source = ReadLine();
char c = source[ 0 ];
if (char.IsLetter(c)) {
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;
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return source.Slice(0, end - begin);
return source.Slice( 0, end - begin );
} else {
throw new ExpInvalidTokenException(_current);
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 '"':
Match match = _nextStringLiteralPattern.Match(
_lineCache, _current);
if (match.Success) {
begin = match.Groups["token"].Index;
end = match.Groups["end"].Index;
rest = match.Groups["rest"].Index;
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ "token" ].Index;
end = match.Groups[ "end" ].Index;
rest = match.Groups[ "rest" ].Index;
_current = rest;
return source[..(end - begin)];
return source[ ..( end - begin ) ];
} else {
throw new ExpInvalidCharException('\"');
throw new ExpInvalidCharException( '\"' );
}
case '(':
char cNext = source[1];
if (cNext == '*') {
char cNext = source[ 1 ];
if( cNext == '*' ) {
_isReadingMultiLineComment = true;
_current += 2;
goto readLine;
} else {
return source[..1];
return source[ ..1 ];
}
case '-':
// 1. -number
// 2. -- comment
// 3. - number type param
cNext = source[1];
if (char.IsNumber(cNext)) {
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;
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return source[..(end - begin)];
return source[ ..( end - begin ) ];
} else {
throw new ExpInvalidTokenException(_current);
throw new ExpInvalidTokenException( _current );
}
} else if (cNext == '-') {
} else if( cNext == '-' ) {
_lineCache = string.Empty;
_current = 0;
goto readLine;
} else {
_current++;
return source[..1];
return source[ ..1 ];
}
case ')' or '[' or ']' or '{' or '}' or
case ')' or '[' or ']' or '{' or '}' or ':' or ';' or
'+' or '/' or '\\' or '*' or '.' or ',':
_current++;
return source[..1];
return source[ ..1 ];
default:
throw new ExpInvalidCharException(c);
throw new ExpInvalidCharException( c );
}
} else if (char.IsNumber(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;
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return source[..(end - begin)];
return source[ ..( end - begin ) ];
} else {
throw new ExpInvalidTokenException(_current);
throw new ExpInvalidTokenException( _current );
}
} else if (char.IsWhiteSpace(c)) {
Match match = _skipBlankPattern.Match(_lineCache, _current);
if (match.Success)
{
rest = match.Groups[Rest].Index;
} else if( char.IsWhiteSpace( c ) ) {
Match match = _skipBlankPattern.Match( _lineCache, _current );
if( match.Success ) {
rest = match.Groups[ Rest ].Index;
_current = rest;
goto readLine;
} else {
throw new ExpInvalidTokenException( _current );
}
else
{
throw new ExpInvalidTokenException(_current);
}
}else {
} else {
throw new ExpInvalidCharException( c );
}
}