daily update on 20250220 by nitload youmu, building AST generator, correct type naming

This commit is contained in:
Nitload
2025-02-21 08:11:26 +08:00
parent ccef0de6f6
commit 83bde12d22
98 changed files with 4182 additions and 1855 deletions
@@ -53,7 +53,13 @@ namespace StgSharp.Script.Express
private bool _isReadingMultiLineComment;
private int _current, _lineNum;
private IScriptSourceProvider _provider;
private Regex _nextWordTokenPattern = GetNextWordTokenPattern(),
_nextStringLiteralPattern = GetStringLiteralPattern(),
_nextNumberLiteralPattern = GetNumberLiteralPattern(),
_skipBlankPattern = GetSkipBlankPattern();
private string _lineCache;
private Token _last;
public ExpSourceReader( IScriptSourceProvider provider )
{
@@ -75,10 +81,10 @@ namespace StgSharp.Script.Express
}
/// <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()
@@ -111,7 +117,7 @@ namespace StgSharp.Script.Express
return _lineCache.AsSpan().Slice( _current );
}
public unsafe TokenSource ReadToken()
public unsafe Token ReadToken()
{
int begin, end, rest;
readLine:
@@ -126,9 +132,10 @@ namespace StgSharp.Script.Express
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return new(
source[ .. ( end - begin ) ], _lineNum, begin,
PreprocessingMask.Names );
_last = new(
ExpCompile.PoolString( source[ .. ( end - begin ) ] ),
_lineNum, begin, TokenFlag.Member );
return _last;
} else {
throw new ExpInvalidTokenException( _current );
}
@@ -141,8 +148,8 @@ namespace StgSharp.Script.Express
begin = _current;
_current += 2;
return new(
ReadOnlySpan<char>.Empty, _lineNum, begin,
PreprocessingMask.String );
string.Empty, _lineNum, begin,
TokenFlag.String );
}
Match match = _nextStringLiteralPattern.Match(
_lineCache, _current );
@@ -151,9 +158,11 @@ namespace StgSharp.Script.Express
end = match.Groups[ "end" ].Index;
rest = match.Groups[ "rest" ].Index;
_current = rest;
return new(
source[ 1..( end - begin ) ], _lineNum, begin,
PreprocessingMask.String );
_last = new(
ExpCompile.PoolString(
source[ 1..( end - begin ) ] ),
_lineNum, begin, TokenFlag.String );
return _last;
} else {
throw new ExpInvalidCharException( '\"' );
}
@@ -166,15 +175,24 @@ namespace StgSharp.Script.Express
} else {
begin = _current;
_current++;
return new(
source[ ..1 ], _lineNum, begin,
PreprocessingMask.Symbol );
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Separator_Left );
return _last;
}
case ')' or '}':
begin = _current;
_current++;
_last = new Token(
ExpCompile.PoolString( ")" ), _lineNum, begin,
TokenFlag.Separator_Right );
return _last;
case '-':
// 1. -number
// 2. -- comment
// 3. - number type param
// 3. - number type param(UNARY)
// 4. param - param(BINARY)
cNext = source[ 1 ];
if( char.IsNumber( cNext ) ) {
match = _nextNumberLiteralPattern.Match(
@@ -185,8 +203,9 @@ namespace StgSharp.Script.Express
rest = match.Groups[ Rest ].Index;
_current = rest;
return new(
source[ ..( end - begin ) ], _lineNum,
begin, PreprocessingMask.Number );
ExpCompile.PoolString(
source[ ..( end - begin ) ] ),
_lineNum, begin, TokenFlag.Number );
} else {
throw new ExpInvalidTokenException( _current );
}
@@ -197,17 +216,47 @@ namespace StgSharp.Script.Express
} else {
begin = _current;
_current++;
return new(
source[ ..1 ], _lineNum, begin,
PreprocessingMask.Symbol );
if( _last.Flag != TokenFlag.Member ) {
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Symbol_Unary );
} else {
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Symbol_Binary );
}
return _last;
}
case ')' or '[' or ']' or '{' or '}' or ':' or ';' or
'+' or '/' or '\\' or '*' or '.' or ',':
case '{':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "{" ), _lineNum, begin,
TokenFlag.Separator_Left );
case '[':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "[" ), _lineNum, begin,
TokenFlag.Index_Left );
case ']':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "]" ), _lineNum, begin,
TokenFlag.Index_Right );
case ';' or ',':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
begin, TokenFlag.Separator_Single );
case ':' or '+' or '/' or '\\' or '*' or '.':
begin = _current;
_current++;
return new(
source[ ..1 ], _lineNum, begin,
PreprocessingMask.Symbol );
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
begin, TokenFlag.Symbol_Binary );
default:
throw new ExpInvalidCharException( c );
}
@@ -219,9 +268,16 @@ namespace StgSharp.Script.Express
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return new(
source[ ..( end - begin ) ], _lineNum, begin,
PreprocessingMask.Number );
string str = ExpCompile.PoolString(
source[ ..( end - begin ) ] );
TokenFlag flag;
if( ReferenceEquals( str, ExpCompile.KeyWord.NOT ) ) {
flag = TokenFlag.Symbol_Unary;
} else {
flag = ExpCompile.LetterIsOperator( str ) ?
TokenFlag.Symbol_Binary : TokenFlag.Member;
}
return new( str, _lineNum, begin, flag );
} else {
throw new ExpInvalidTokenException( _current );
}
@@ -257,10 +313,5 @@ namespace StgSharp.Script.Express
RegexOptions.Singleline )]
private static partial Regex GetStringLiteralPattern();
private Regex _nextWordTokenPattern = GetNextWordTokenPattern(),
_nextStringLiteralPattern = GetStringLiteralPattern(),
_nextNumberLiteralPattern = GetNumberLiteralPattern(),
_skipBlankPattern = GetSkipBlankPattern();
}
}