Daily update on 20250415-031523 by Nitload Youmu. Additional Message : Add: merge a step specified EXPRESS syntax analyzer and token reader
Change: remove nearly all ixmilia interface, abstact class and supporting classes from step entity calsses, the next is to remove Base classes, and use ones defined in StgSharp instead Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IScriptTokenReader.cs"
|
||||
// Project: StgSharp
|
||||
// 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 in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
namespace StgSharp.Script
|
||||
{
|
||||
public interface IScriptTokenReader
|
||||
{
|
||||
|
||||
Token ReadToken();
|
||||
|
||||
bool TryReadToken( out Token t );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ISyntaxAnalyzer.cs"
|
||||
// Project: StgSharp
|
||||
// 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 in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
namespace StgSharp.Script
|
||||
{
|
||||
public interface ISyntaxAnalyzer
|
||||
{
|
||||
|
||||
void AppendToken( Token t );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ using static StgSharp.Script.Express.ExpressCompile;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
internal partial class ExpSchema_Builtin : ExpSchema
|
||||
public sealed partial class ExpSchema_Builtin : ExpSchema
|
||||
{
|
||||
|
||||
private static readonly ExpSchema_Builtin _onlyInstance = new ExpSchema_Builtin();
|
||||
|
||||
@@ -36,7 +36,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
internal class ExpFunctionCallingNode : ExpNode
|
||||
public class ExpFunctionCallingNode : ExpNode
|
||||
{
|
||||
|
||||
private ExpFunctionSource _function;
|
||||
@@ -44,9 +44,9 @@ namespace StgSharp.Script.Express
|
||||
private ExpNode _parameter;
|
||||
|
||||
private ExpFunctionCallingNode(
|
||||
Token source,
|
||||
ExpFunctionSource function,
|
||||
ExpNode firstParameter )
|
||||
Token source,
|
||||
ExpFunctionSource function,
|
||||
ExpNode firstParameter )
|
||||
: base( source )
|
||||
{
|
||||
_function = function;
|
||||
@@ -66,9 +66,9 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
|
||||
public static ExpFunctionCallingNode CallFunction(
|
||||
Token source,
|
||||
ExpFunctionSource function,
|
||||
ExpNode param )
|
||||
Token source,
|
||||
ExpFunctionSource function,
|
||||
ExpNode param )
|
||||
{
|
||||
return new ExpFunctionCallingNode( source, function, param );
|
||||
}
|
||||
|
||||
@@ -93,11 +93,6 @@ namespace StgSharp.Script.Express
|
||||
Next.Previous = this;
|
||||
}
|
||||
|
||||
public ExpNodeNextEnumerator GetEnumerator()
|
||||
{
|
||||
return new ExpNodeNextEnumerator( this );
|
||||
}
|
||||
|
||||
public static bool IsNullOrEmpty( [AllowNull]ExpNode node )
|
||||
{
|
||||
return node == ExpEmptyNode._only || node == null;
|
||||
|
||||
@@ -70,6 +70,11 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public abstract string Name { get; }
|
||||
|
||||
public void AddMember( string name, ExpNode memberNode )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public abstract void Analyse();
|
||||
|
||||
public abstract ExpNode CreateInstanceNode( Token t );
|
||||
@@ -131,6 +136,11 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public abstract string Name { get; }
|
||||
|
||||
public void AddMember( string name, ExpNode memberNode )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public abstract void Analyse();
|
||||
|
||||
public bool IsConvertable( IExpElementSource targetType )
|
||||
|
||||
@@ -34,11 +34,23 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public static class ExpNodeNextEnumeratorExtensions
|
||||
{
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static ExpNodeNextEnumerator AsEnumerator( this ExpNode token )
|
||||
{
|
||||
return new ExpNodeNextEnumerator( token );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpNodeNextEnumerator : IEnumerator<ExpNode>
|
||||
{
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpSourceReader
|
||||
public partial class ExpSourceReader : IScriptTokenReader
|
||||
{
|
||||
|
||||
private const int
|
||||
private const int
|
||||
MultiLineEnd = 0x0029002A; // *)
|
||||
|
||||
private const string TokenMark = "token", EndMark = "end", RestMark = "rest";
|
||||
@@ -59,7 +59,7 @@ namespace StgSharp.Script.Express
|
||||
private string _lineCache;
|
||||
private Token _last;
|
||||
|
||||
public ExpSourceReader( IScriptSourceProvider provider )
|
||||
public ExpSourceReader(IScriptSourceProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
_current = 0;
|
||||
@@ -69,7 +69,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
|
||||
@@ -79,163 +79,175 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public unsafe ReadOnlySpan<char> ReadLine()
|
||||
{
|
||||
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length;
|
||||
while( lineOver || _isReadingMultiLineComment )
|
||||
bool lineOver = string.IsNullOrEmpty(_lineCache) || _current >= _lineCache.Length;
|
||||
while (lineOver || _isReadingMultiLineComment)
|
||||
{
|
||||
if( IsEmpty ) {
|
||||
if (IsEmpty)
|
||||
{
|
||||
return ReadOnlySpan<char>.Empty;
|
||||
}
|
||||
if( lineOver )
|
||||
if (lineOver)
|
||||
{
|
||||
do
|
||||
{
|
||||
_lineCache = _provider.ReadLine( out _lineNum );
|
||||
} while (string.IsNullOrEmpty( _lineCache ));
|
||||
_lineCache = _provider.ReadLine(out _lineNum);
|
||||
} while (string.IsNullOrEmpty(_lineCache));
|
||||
_current = 0;
|
||||
}
|
||||
if( _isReadingMultiLineComment )
|
||||
if (_isReadingMultiLineComment)
|
||||
{
|
||||
int index;
|
||||
fixed( char* cPtr = _lineCache.AsSpan( _current ) ) {
|
||||
fixed (char* cPtr = _lineCache.AsSpan(_current))
|
||||
{
|
||||
index = UnsafeCompute.IndexOfCharPair(
|
||||
cPtr, MultiLineEnd, _lineCache.Length );
|
||||
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 );
|
||||
return _lineCache.AsSpan().Slice(_current);
|
||||
}
|
||||
|
||||
public unsafe Token ReadToken()
|
||||
{
|
||||
int begin, end, rest;
|
||||
readLine:
|
||||
readLine:
|
||||
ReadOnlySpan<char> source;
|
||||
if( !TryReadLine( out source ) ) {
|
||||
if (!TryReadLine(out source))
|
||||
{
|
||||
return Token.Empty;
|
||||
}
|
||||
char c = source[ 0 ];
|
||||
char c = source[0];
|
||||
|
||||
if( char.IsLetter( c ) )
|
||||
if (char.IsLetter(c))
|
||||
{
|
||||
Match match = _nextWordTokenPattern.Match( _lineCache, _current );
|
||||
if( match.Success )
|
||||
Match match = _nextWordTokenPattern.Match(_lineCache, _current);
|
||||
if (match.Success)
|
||||
{
|
||||
begin = match.Groups[ TokenMark ].Index;
|
||||
end = match.Groups[ EndMark ].Index;
|
||||
rest = match.Groups[ RestMark ].Index;
|
||||
begin = match.Groups[TokenMark].Index;
|
||||
end = match.Groups[EndMark].Index;
|
||||
rest = match.Groups[RestMark].Index;
|
||||
_current = rest;
|
||||
_last = new(
|
||||
ExpressCompile.PoolString( source[ .. ( end - begin ) ] ), _lineNum, begin,
|
||||
TokenFlag.Member );
|
||||
ExpressCompile.PoolString(source[..(end - begin)]), _lineNum, begin,
|
||||
TokenFlag.Member);
|
||||
return _last;
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidCharException( _current );
|
||||
}
|
||||
} else if( char.IsPunctuation( c ) || char.IsSymbol( c ) )
|
||||
else
|
||||
{
|
||||
throw new ExpInvalidCharException(_current);
|
||||
}
|
||||
}
|
||||
else if (char.IsPunctuation(c) || char.IsSymbol(c))
|
||||
{
|
||||
switch( c )
|
||||
switch (c)
|
||||
{
|
||||
case '\'':
|
||||
|
||||
case '"':
|
||||
char cNext = source[ 1 ];
|
||||
if( cNext == '\"' ) //empty string
|
||||
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;
|
||||
begin = match.Groups["token"].Index;
|
||||
end = match.Groups["end"].Index;
|
||||
rest = match.Groups["rest"].Index;
|
||||
_current = rest;
|
||||
_last = new(
|
||||
ExpressCompile.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( '\"' );
|
||||
throw new ExpInvalidCharException('\"');
|
||||
}
|
||||
case '(':
|
||||
cNext = source[ 1 ];
|
||||
if( cNext == '*' )
|
||||
cNext = source[1];
|
||||
if (cNext == '*')
|
||||
{
|
||||
_isReadingMultiLineComment = true;
|
||||
_current += 2;
|
||||
goto readLine;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
begin = _current;
|
||||
_current++;
|
||||
_last = new(
|
||||
ExpressCompile.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(
|
||||
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
|
||||
TokenFlag.Separator_Right );
|
||||
return _last;
|
||||
ExpressCompile.PoolString(source[..1]), _lineNum, begin,
|
||||
TokenFlag.Separator_Right);
|
||||
return _last;
|
||||
case '-':
|
||||
|
||||
// 1. - number
|
||||
// 2. -- comment
|
||||
// 3. - number type param(UNARY)
|
||||
// 4. param - param(BINARY)
|
||||
cNext = source[ 1 ];
|
||||
if( char.IsNumber( cNext ) )
|
||||
cNext = source[1];
|
||||
if (char.IsNumber(cNext))
|
||||
{
|
||||
match = _nextNumberLiteralPattern.Match( _lineCache, _current );
|
||||
if( match.Success )
|
||||
match = _nextNumberLiteralPattern.Match(_lineCache, _current);
|
||||
if (match.Success)
|
||||
{
|
||||
begin = match.Groups[ TokenMark ].Index;
|
||||
end = match.Groups[ EndMark ].Index;
|
||||
rest = match.Groups[ RestMark ].Index;
|
||||
begin = match.Groups[TokenMark].Index;
|
||||
end = match.Groups[EndMark].Index;
|
||||
rest = match.Groups[RestMark].Index;
|
||||
_current = rest;
|
||||
return new(
|
||||
ExpressCompile.PoolString( source[ ..( end - begin ) ] ),
|
||||
_lineNum, begin, TokenFlag.Number );
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidCharException( _current );
|
||||
ExpressCompile.PoolString(source[..(end - begin)]),
|
||||
_lineNum, begin, TokenFlag.Number);
|
||||
}
|
||||
} else if( cNext == '-' )
|
||||
else
|
||||
{
|
||||
throw new ExpInvalidCharException(_current);
|
||||
}
|
||||
}
|
||||
else if (cNext == '-')
|
||||
{
|
||||
_lineCache = string.Empty;
|
||||
_current = 0;
|
||||
goto readLine;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
begin = _current;
|
||||
_current++;
|
||||
if( _last.Flag == TokenFlag.Member || _last.Flag ==
|
||||
TokenFlag.Index_Right || _last.Flag == TokenFlag.Separator_Right )
|
||||
if (_last.Flag == TokenFlag.Member || _last.Flag ==
|
||||
TokenFlag.Index_Right || _last.Flag == TokenFlag.Separator_Right)
|
||||
{
|
||||
_last = new(
|
||||
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
|
||||
TokenFlag.Symbol_Binary );
|
||||
} else
|
||||
ExpressCompile.PoolString(source[..1]), _lineNum, begin,
|
||||
TokenFlag.Symbol_Binary);
|
||||
}
|
||||
else
|
||||
{
|
||||
_last = new(
|
||||
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
|
||||
TokenFlag.Symbol_Unary );
|
||||
ExpressCompile.PoolString(source[..1]), _lineNum, begin,
|
||||
TokenFlag.Symbol_Unary);
|
||||
}
|
||||
return _last;
|
||||
}
|
||||
@@ -243,108 +255,114 @@ namespace StgSharp.Script.Express
|
||||
begin = _current;
|
||||
_current++;
|
||||
_last = new Token(
|
||||
ExpressCompile.PoolString( "{" ), _lineNum, begin,
|
||||
TokenFlag.Separator_Left );
|
||||
ExpressCompile.PoolString("{"), _lineNum, begin,
|
||||
TokenFlag.Separator_Left);
|
||||
return _last;
|
||||
case '[':
|
||||
begin = _current;
|
||||
_current++;
|
||||
_last = new Token(
|
||||
ExpressCompile.PoolString( "[" ), _lineNum, begin,
|
||||
TokenFlag.Index_Left );
|
||||
ExpressCompile.PoolString("["), _lineNum, begin,
|
||||
TokenFlag.Index_Left);
|
||||
return _last;
|
||||
case ']':
|
||||
begin = _current;
|
||||
_current++;
|
||||
_last = new Token(
|
||||
ExpressCompile.PoolString( "]" ), _lineNum, begin,
|
||||
TokenFlag.Index_Right );
|
||||
ExpressCompile.PoolString("]"), _lineNum, begin,
|
||||
TokenFlag.Index_Right);
|
||||
return _last;
|
||||
case ';' or ',':
|
||||
begin = _current;
|
||||
_current++;
|
||||
_last = new Token(
|
||||
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
|
||||
TokenFlag.Separator_Middle );
|
||||
ExpressCompile.PoolString(source[..1]), _lineNum, begin,
|
||||
TokenFlag.Separator_Middle);
|
||||
return _last;
|
||||
case ':':
|
||||
match = _nextSymbolPattern.Match( _lineCache, _current );
|
||||
begin = match.Groups[ TokenMark ].Index;
|
||||
end = match.Groups[ EndMark ].Index;
|
||||
rest = match.Groups[ RestMark ].Index;
|
||||
match = _nextSymbolPattern.Match(_lineCache, _current);
|
||||
begin = match.Groups[TokenMark].Index;
|
||||
end = match.Groups[EndMark].Index;
|
||||
rest = match.Groups[RestMark].Index;
|
||||
_current = rest;
|
||||
if( end - begin == 1 )
|
||||
if (end - begin == 1)
|
||||
{
|
||||
_last = new Token(
|
||||
ExpressCompile.Keyword.Colon, _lineNum, begin,
|
||||
TokenFlag.Separator_Middle );
|
||||
} else
|
||||
TokenFlag.Separator_Middle);
|
||||
}
|
||||
else
|
||||
{
|
||||
_last = new Token(
|
||||
ExpressCompile.PoolString( source[ ..( end - begin ) ] ), _lineNum,
|
||||
begin, TokenFlag.Symbol_Binary );
|
||||
ExpressCompile.PoolString(source[..(end - begin)]), _lineNum,
|
||||
begin, TokenFlag.Symbol_Binary);
|
||||
}
|
||||
return _last;
|
||||
case '+' or '/' or '\\' or '*' or '.':
|
||||
match = _nextSymbolPattern.Match( _lineCache, _current );
|
||||
begin = match.Groups[ TokenMark ].Index;
|
||||
end = match.Groups[ EndMark ].Index;
|
||||
rest = match.Groups[ RestMark ].Index;
|
||||
match = _nextSymbolPattern.Match(_lineCache, _current);
|
||||
begin = match.Groups[TokenMark].Index;
|
||||
end = match.Groups[EndMark].Index;
|
||||
rest = match.Groups[RestMark].Index;
|
||||
_current = rest;
|
||||
_last = new Token(
|
||||
ExpressCompile.PoolString( source[ ..( end - begin ) ] ), _lineNum,
|
||||
begin, TokenFlag.Symbol_Binary );
|
||||
ExpressCompile.PoolString(source[..(end - begin)]), _lineNum,
|
||||
begin, TokenFlag.Symbol_Binary);
|
||||
return _last;
|
||||
case '=':
|
||||
begin = _current;
|
||||
_current++;
|
||||
_last = new Token(
|
||||
ExpressCompile.Keyword.Equal, _lineNum, begin,
|
||||
TokenFlag.Symbol_Binary );
|
||||
TokenFlag.Symbol_Binary);
|
||||
return _last;
|
||||
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 )
|
||||
Match match = _nextNumberLiteralPattern.Match(_lineCache, _current);
|
||||
if (match.Success)
|
||||
{
|
||||
begin = match.Groups[ TokenMark ].Index;
|
||||
end = match.Groups[ EndMark ].Index;
|
||||
rest = match.Groups[ RestMark ].Index;
|
||||
begin = match.Groups[TokenMark].Index;
|
||||
end = match.Groups[EndMark].Index;
|
||||
rest = match.Groups[RestMark].Index;
|
||||
_current = rest;
|
||||
string str = ExpressCompile.PoolString( source[ ..( end - begin ) ] );
|
||||
return new( str, _lineNum, begin, TokenFlag.Number );
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidCharException( _current );
|
||||
string str = ExpressCompile.PoolString(source[..(end - begin)]);
|
||||
return new(str, _lineNum, begin, TokenFlag.Number);
|
||||
}
|
||||
} else if( char.IsWhiteSpace( c ) )
|
||||
{
|
||||
Match match = _skipBlankPattern.Match( _lineCache, _current );
|
||||
if( match.Success )
|
||||
else
|
||||
{
|
||||
rest = match.Groups[ RestMark ].Index;
|
||||
throw new ExpInvalidCharException(_current);
|
||||
}
|
||||
}
|
||||
else if (char.IsWhiteSpace(c))
|
||||
{
|
||||
Match match = _skipBlankPattern.Match(_lineCache, _current);
|
||||
if (match.Success)
|
||||
{
|
||||
rest = match.Groups[RestMark].Index;
|
||||
_current = rest;
|
||||
goto readLine;
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidCharException( _current );
|
||||
}
|
||||
} else
|
||||
else
|
||||
{
|
||||
throw new ExpInvalidCharException(_current);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ExpInvalidCharException( c );
|
||||
throw new ExpInvalidCharException(c);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryReadLine( out ReadOnlySpan<char> line )
|
||||
public bool TryReadLine(out ReadOnlySpan<char> line)
|
||||
{
|
||||
line = ReadLine();
|
||||
return line != ReadOnlySpan<char>.Empty;
|
||||
}
|
||||
|
||||
public bool TryReadToken( out Token t )
|
||||
public bool TryReadToken(out Token t)
|
||||
{
|
||||
t = ReadToken();
|
||||
return !IsEmpty;
|
||||
@@ -352,30 +370,30 @@ namespace StgSharp.Script.Express
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>[a-zA-Z][a-zA-Z0-9_]*)(?<end>\s*?)(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
RegexOptions.Singleline)]
|
||||
private static partial Regex GetNextWordTokenPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>-?\s*?[0-9]+(?:\.[0-9]*)?E?(?:[+-]?[0-9]+)?)(?<end>\s*?)(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
RegexOptions.Singleline)]
|
||||
private static partial Regex GetNumberLiteralPattern();
|
||||
|
||||
[GeneratedRegex( @"(?:\s+?)(?<rest>\S|$)", RegexOptions.Singleline )]
|
||||
[GeneratedRegex(@"(?:\s+?)(?<rest>\S|$)", RegexOptions.Singleline)]
|
||||
private static partial Regex GetSkipBlankPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>"")(?>\\\\|\\""|(?!')[^""])*(?<end>""|$)\s*?(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
RegexOptions.Singleline)]
|
||||
private static partial Regex GetStringLiteralPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>')(?>\\\\|\\'|''|(?!')[^'])*(?<end>')\s*?(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
RegexOptions.Singleline)]
|
||||
private static partial Regex GetStringLiteralPatternWithSingle();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>[:<>=+\-*\/]+)(?<end>\s?)\s*?(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
RegexOptions.Singleline)]
|
||||
private static partial Regex GetSymbolPattern();
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
public partial class ExpSyntaxAnalyzer : ISyntaxAnalyzer
|
||||
{
|
||||
|
||||
private const int EndLine = 1;
|
||||
@@ -95,11 +95,24 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
}
|
||||
|
||||
public ExpNode GetNextOperandCache()
|
||||
{
|
||||
if( _cache.PopOperand( out Token t, out ExpNode? n ) )
|
||||
{
|
||||
return n;
|
||||
} else
|
||||
{
|
||||
// process some rare case here
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append a token to top of cache. This method will automatically convert token to node
|
||||
/// if meets separators or operators.
|
||||
/// </summary>
|
||||
public void AppendToken_common( Token expToken )
|
||||
private void AppendToken_common( Token expToken )
|
||||
{
|
||||
switch( expToken.Flag )
|
||||
{
|
||||
@@ -133,19 +146,6 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
}
|
||||
|
||||
public ExpNode GetNextOperandCache()
|
||||
{
|
||||
if( _cache.PopOperand( out Token t, out ExpNode? n ) )
|
||||
{
|
||||
return n;
|
||||
} else
|
||||
{
|
||||
// process some rare case here
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private CompileDepthMark TryEnterBranch( Token t )
|
||||
{
|
||||
if( t.Flag == TokenFlag.String ) {
|
||||
@@ -153,7 +153,7 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.Case:
|
||||
case ExpKeyword.Case:
|
||||
return _cache.IncreaseDepth( ( int )ExpCompileStateCode.CaseBranch );
|
||||
case ExpKeyword.If:
|
||||
return _cache.IncreaseDepth( ( int )ExpCompileStateCode.IfBranch );
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2692495dc8460e1f60a2d073f162c5f526e1ba1b")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9457309c5ab188ce824a10ab60e572553986b6eb")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
Reference in New Issue
Block a user