old data
This commit is contained in:
@@ -44,16 +44,14 @@ using System.Xml.Schema;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Model.Step
|
||||
namespace StgSharp.Modeling.Step
|
||||
{
|
||||
internal partial class StepExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
private static Regex _entityTypeCheckPattern = GetEntityTypeCheckPattern();
|
||||
|
||||
private StepDependencyDetector _dependencyDetector = new StepDependencyDetector();
|
||||
|
||||
[GeneratedRegex( @"^[A-Z0-9_]+$", RegexOptions.Singleline )]
|
||||
[GeneratedRegex( @"^[A-Z_]+$", RegexOptions.Singleline )]
|
||||
private static partial Regex GetEntityTypeCheckPattern();
|
||||
|
||||
private bool IsSeparatorMatch( Token leftSeparator, Token rightSeparator )
|
||||
@@ -149,16 +147,10 @@ namespace StgSharp.Model.Step
|
||||
goto case 1;
|
||||
case 1:
|
||||
_cache.PopOperand( out _, out ExpSyntaxNode? statement );
|
||||
if( t.Value == ";" )
|
||||
{
|
||||
StepEntityDefineSequence sequence = new StepEntityDefineSequence(
|
||||
statement, _dependencyDetector.ExportAllDependencies() );
|
||||
StepEntityInitStatements.Enqueue( sequence );
|
||||
} else
|
||||
{
|
||||
_cache.StatementsInDepth.Push( statement );
|
||||
_cache.StatementsInDepth.Push( statement );
|
||||
if( t.Value == ";" ) {
|
||||
StepEntityInitStatements.Enqueue( statement );
|
||||
}
|
||||
|
||||
return true;
|
||||
default:
|
||||
ExpInvalidSyntaxException.ThrowNoOperator( t );
|
||||
@@ -221,12 +213,6 @@ namespace StgSharp.Model.Step
|
||||
{
|
||||
switch( t.Value )
|
||||
{
|
||||
case "$":
|
||||
_cache.PushOperand( StepEntityInstanceNode.RegisterNull( t ) );
|
||||
return true;
|
||||
case "*":
|
||||
_cache.PushOperand( StepEntityInstanceNode.RegisterRuntimeInference( t ) );
|
||||
return true;
|
||||
case ExpKeyword.E:
|
||||
_cache.PushOperand( new ExpRealNumberNode( t, MathF.E, true ) );
|
||||
return true;
|
||||
@@ -260,15 +246,8 @@ namespace StgSharp.Model.Step
|
||||
|
||||
private bool TryParseFunction( Token t )
|
||||
{
|
||||
if( _entityTypeCheckPattern.IsMatch( t.Value ) )
|
||||
{
|
||||
if( _cache.PeekOperator().Flag == TokenFlag.Member )
|
||||
{
|
||||
Token op = _cache.PopOperator();
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
if( _entityTypeCheckPattern.IsMatch( t.Value ) ) {
|
||||
_cache.PushOperator( t );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -277,11 +256,7 @@ namespace StgSharp.Model.Step
|
||||
{
|
||||
if( t.Value[ 0 ] == '#' )
|
||||
{
|
||||
StepEntityInstanceNode node = StepEntityInstanceNode.Register( t );
|
||||
if( t.Column != 0 ) {
|
||||
_dependencyDetector.AddDependency( node );
|
||||
}
|
||||
_cache.PushOperand( node );
|
||||
_cache.PushOperand( StepEntityInstanceNode.Register( t ) );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -34,7 +34,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Model.Step
|
||||
namespace StgSharp.Modeling.Step
|
||||
{
|
||||
internal partial class StepExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Model.Step.SyntaxNode;
|
||||
using StgSharp.Script;
|
||||
using StgSharp.Script.Express;
|
||||
|
||||
@@ -39,7 +40,7 @@ using System.Threading.Tasks;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Model.Step
|
||||
namespace StgSharp.Modeling.Step
|
||||
{
|
||||
internal partial class StepExpSyntaxAnalyzer
|
||||
{
|
||||
@@ -91,7 +92,7 @@ namespace StgSharp.Model.Step
|
||||
_cache.PopOperand( out _, out ExpSyntaxNode? p );
|
||||
StepEntityInitCaller caller = StepEntityInitCaller.CreateCaller( op.Value );
|
||||
node = ExpFunctionCallingNode.CallFunction( op, caller, p );
|
||||
_cache.StatementsInDepth.Push( node );
|
||||
_cache.PushOperand( node );
|
||||
return node;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
@@ -100,27 +101,43 @@ namespace StgSharp.Model.Step
|
||||
|
||||
private bool TryGenerateBinaryNode( Token t, out ExpSyntaxNode node )
|
||||
{
|
||||
/*
|
||||
ExpSyntaxNode right = GetNextOperandCache();
|
||||
ExpSyntaxNode left = GetNextOperandCache();
|
||||
/**/
|
||||
switch( t.Value )
|
||||
{
|
||||
case "=":
|
||||
ExpSyntaxNode right = GetNextOperandCache();
|
||||
ExpSyntaxNode left;
|
||||
if( right is ExpTupleNode tuple )
|
||||
{
|
||||
right = StepComplexEntityNode.FromTuple( tuple );
|
||||
left = GetNextOperandCache();
|
||||
} else
|
||||
{
|
||||
left = right;
|
||||
right = _cache.StatementsInDepth.Pop();
|
||||
}
|
||||
|
||||
case ExpKeyword.Add:
|
||||
node = ExpBinaryOperatorNode.Add( t, left, right );
|
||||
return true;
|
||||
case ExpKeyword.Sub:
|
||||
node = ExpBinaryOperatorNode.Sub( t, left, right );
|
||||
return true;
|
||||
case ExpKeyword.Mul:
|
||||
node = ExpBinaryOperatorNode.Mul( t, left, right );
|
||||
return true;
|
||||
case ExpKeyword.Div:
|
||||
node = ExpBinaryOperatorNode.Div( t, left, right );
|
||||
return true;
|
||||
case ExpKeyword.Equal:
|
||||
node = ExpBinaryOperatorNode.EqualTo( t, left, right );
|
||||
return true;
|
||||
case ExpKeyword.NotEqual:
|
||||
node = ExpBinaryOperatorNode.NotEqualTo( t, left, right );
|
||||
return true;
|
||||
case ExpKeyword.GreaterThan:
|
||||
node = ExpBinaryOperatorNode.GreaterThan( t, left, right );
|
||||
return true;
|
||||
case ExpKeyword.LessThan:
|
||||
node = ExpBinaryOperatorNode.LessThan( t, left, right );
|
||||
return true;
|
||||
case ExpKeyword.Assignment:
|
||||
node = ExpBinaryOperatorNode.Assign( t, left, right );
|
||||
return true;
|
||||
case ExpKeyword.InstanceEqual:
|
||||
node = ExpBinaryOperatorNode.CompareInstanceEqual( t, left, right );
|
||||
return true;
|
||||
case ExpKeyword.InstanceNotEqual:
|
||||
node = ExpBinaryOperatorNode.CompareInstanceNotEqual( t, left, right );
|
||||
return true;
|
||||
default:
|
||||
node = ExpSyntaxNode.Empty;
|
||||
return false;
|
||||
|
||||
@@ -40,7 +40,7 @@ using System.Threading.Tasks;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Model.Step
|
||||
namespace StgSharp.Modeling.Step
|
||||
{
|
||||
internal partial class StepExpSyntaxAnalyzer
|
||||
{
|
||||
@@ -57,19 +57,15 @@ namespace StgSharp.Model.Step
|
||||
_cache.StatementsInDepth.Push( statement );
|
||||
} else
|
||||
{
|
||||
_cache.StatementsInDepth.Push( ExpSyntaxNode.Empty );
|
||||
ExpInvalidSyntaxException.ThrowNoOperator( rightSeparator );
|
||||
}
|
||||
} else
|
||||
{
|
||||
while( _cache.TryPopOperator( out op ) )
|
||||
{
|
||||
ExpSyntaxNode node = ConvertAndPushOneOperator( op );
|
||||
}
|
||||
if( _cache.OperandAheadOfDepth == 1 )
|
||||
{
|
||||
_cache.PopOperand( out _, out root );
|
||||
_cache.StatementsInDepth.Push( root );
|
||||
while( _cache.TryPopOperator( out op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
_cache.PopOperand( out _, out root );
|
||||
_cache.StatementsInDepth.Push( root );
|
||||
}
|
||||
|
||||
root = _cache.PackAllStatements();
|
||||
@@ -77,7 +73,6 @@ namespace StgSharp.Model.Step
|
||||
if( IsSeparatorMatch( _cache.PeekOperator(), rightSeparator ) )
|
||||
{
|
||||
_cache.PopOperator();
|
||||
root = ExpTupleNode.Pack( root );
|
||||
_cache.PushOperand( root );
|
||||
} else
|
||||
{
|
||||
|
||||
@@ -45,7 +45,7 @@ using System.Threading.Tasks;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Model.Step
|
||||
namespace StgSharp.Modeling.Step
|
||||
{
|
||||
internal partial class StepExpSyntaxAnalyzer : ISyntaxAnalyzer
|
||||
{
|
||||
@@ -62,10 +62,24 @@ namespace StgSharp.Model.Step
|
||||
public StepExpSyntaxAnalyzer()
|
||||
{
|
||||
_cache = new CompileStack<ExpSyntaxNode, IExpElementSource>();
|
||||
_context = new ExpressStepUtil();
|
||||
}
|
||||
|
||||
public ConcurrentQueue<StepEntityDefineSequence> StepEntityInitStatements { get; } = new();
|
||||
public StepExpSyntaxAnalyzer( ExpSchema context, IExpElementSource local )
|
||||
{
|
||||
_cache = new CompileStack<ExpSyntaxNode, IExpElementSource>();
|
||||
ArgumentNullException.ThrowIfNull( context );
|
||||
if( context is not ExpSchema_Builtin )
|
||||
{
|
||||
_context = context;
|
||||
} else
|
||||
{
|
||||
throw new InvalidCastException( "Not a valid Schema type" );
|
||||
}
|
||||
_local = local;
|
||||
}
|
||||
|
||||
public ConcurrentQueue<ExpSyntaxNode> StepEntityInitStatements { get; } = new ConcurrentQueue<ExpSyntaxNode>(
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Append a token to top of cache. This method will automatically convert token to node
|
||||
@@ -100,9 +114,6 @@ namespace StgSharp.Model.Step
|
||||
case TokenFlag.Member:
|
||||
TryAppendMember( expToken );
|
||||
break;
|
||||
case TokenFlag.Enum:
|
||||
TryAppendEnum( expToken );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -38,44 +38,44 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Model.Step
|
||||
namespace StgSharp.Modeling.Step
|
||||
{
|
||||
public class StepDataSectionTransmitter : IScriptSourceProvider
|
||||
{
|
||||
|
||||
private const string EndDataText = "ENDSEC;";
|
||||
|
||||
//private bool _isEmpty;
|
||||
private bool _isEmpty;
|
||||
private ConcurrentQueue<string> _cache = new ConcurrentQueue<string>();
|
||||
private int _line = 0;
|
||||
|
||||
public StepDataSectionTransmitter() { }
|
||||
|
||||
public StepDataSectionTransmitter( int begins )
|
||||
{
|
||||
Begin = begins;
|
||||
_line = Begin;
|
||||
}
|
||||
|
||||
public bool IsEmpty => _cache.IsEmpty && !IsWriting;
|
||||
public bool IsEmpty => _isEmpty;
|
||||
|
||||
public bool IsWriting { get; private set; } = true;
|
||||
|
||||
public int Begin { get; internal set; }
|
||||
|
||||
public int Location => _line;
|
||||
|
||||
public void EndWriting()
|
||||
{
|
||||
_cache.Enqueue( EndDataText );
|
||||
IsWriting = false;
|
||||
}
|
||||
|
||||
public string ReadLine()
|
||||
{
|
||||
if( _cache.TryDequeue( out string? line ) )
|
||||
_cache.TryDequeue( out string? line );
|
||||
while( !IsEmpty )
|
||||
{
|
||||
_line++;
|
||||
return line;
|
||||
if( _cache.TryDequeue( out line ) )
|
||||
{
|
||||
if( line == EndDataText )
|
||||
{
|
||||
_isEmpty = true;
|
||||
return string.Empty;
|
||||
}
|
||||
_line++;
|
||||
return line;
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
@@ -89,17 +89,10 @@ namespace StgSharp.Model.Step
|
||||
|
||||
public void WriteLine( string line )
|
||||
{
|
||||
if( line == "DATA;" ) {
|
||||
return;
|
||||
}
|
||||
if( line == EndDataText )
|
||||
{
|
||||
if( line == EndDataText ) {
|
||||
EndWriting();
|
||||
return;
|
||||
}
|
||||
if( IsWriting ) {
|
||||
_cache.Enqueue( line );
|
||||
}
|
||||
_cache.Enqueue( line );
|
||||
}
|
||||
|
||||
IScriptSourceProvider IScriptSourceProvider.Slice( int location, int count )
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Model.Step;
|
||||
using StgSharp.Modeling.Step;
|
||||
using StgSharp.Script;
|
||||
using StgSharp.Script.Express;
|
||||
|
||||
@@ -41,14 +41,14 @@ using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Model.Step
|
||||
namespace StgSharp.Modeling.Step
|
||||
{
|
||||
public partial class StepDataTokenReader : IScriptTokenReader
|
||||
public class StepDataTokenReader : IScriptTokenReader
|
||||
{
|
||||
|
||||
private ExpTokenReader _reader;
|
||||
|
||||
private HashSet<string> tokenHash = [
|
||||
private HashSet<string> token1Hash = [
|
||||
"T","F","UNSPECIFIED"
|
||||
];
|
||||
private Queue<Token> _cache = new Queue<Token>();
|
||||
@@ -63,13 +63,7 @@ namespace StgSharp.Model.Step
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get
|
||||
{
|
||||
if( _reader.IsEmpty ) {
|
||||
return !_transmitter.IsWriting;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
get => _reader.IsEmpty && _transmitter.IsWriting;
|
||||
}
|
||||
|
||||
public Token ReadToken()
|
||||
@@ -82,93 +76,40 @@ namespace StgSharp.Model.Step
|
||||
return _reader.TryReadToken( out t );
|
||||
}
|
||||
|
||||
private partial class TokenPreReader : ExpTokenReaderPreProcessor
|
||||
private class TokenPreReader : ExpTokenReaderPreProcessor
|
||||
{
|
||||
|
||||
private static Regex
|
||||
_nextHashtagSymbolPattern = GetEntityTagSymbolPattern(),
|
||||
_nextEnumPattern = GetNextEnumPattern(),
|
||||
_stringPattern = GetStringPattern();
|
||||
private static Regex NextEnumPattern = GetNextEnumPattern();
|
||||
|
||||
public override bool Process( string codeLine, int line, ref int current, out Token t )
|
||||
{
|
||||
ReadOnlySpan<char> chars = codeLine.AsSpan( current );
|
||||
char c = chars[ 0 ];
|
||||
Match match;
|
||||
switch( c )
|
||||
if( c != '.' )
|
||||
{
|
||||
case '#':
|
||||
match = _nextHashtagSymbolPattern.Match( codeLine, current );
|
||||
if( match.Success )
|
||||
{
|
||||
int begin = match.Groups[ "token" ].Index;
|
||||
int end = match.Groups[ "end" ].Index;
|
||||
int rest = match.Groups[ "rest" ].Index;
|
||||
current = rest;
|
||||
t = new(
|
||||
ExpressCompile.PoolString( chars[ 0..( end - begin ) ] ), line,
|
||||
begin, TokenFlag.Member );
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case '.':
|
||||
match = _nextEnumPattern.Match( codeLine, current );
|
||||
if( match.Success )
|
||||
{
|
||||
int begin = match.Groups[ "token" ].Index;
|
||||
int end = match.Groups[ "end" ].Index;
|
||||
int rest = match.Groups[ "rest" ].Index;
|
||||
current = rest;
|
||||
t = new Token(
|
||||
match.Groups[ "token" ].Value, line, begin, TokenFlag.Enum );
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case '$':
|
||||
t = new Token( "$", line, current, TokenFlag.Member );
|
||||
current++;
|
||||
return true;
|
||||
case '*':
|
||||
t = new Token( "*", line, current, TokenFlag.Member );
|
||||
current++;
|
||||
return true;
|
||||
case '\'':
|
||||
match = _stringPattern.Match( codeLine, current );
|
||||
if( match.Success )
|
||||
{
|
||||
int begin = match.Groups[ "token" ].Index;
|
||||
int end = match.Groups[ "end" ].Index;
|
||||
int rest = match.Groups[ "rest" ].Index;
|
||||
current = rest;
|
||||
string value = chars.Slice( 1, ( end - begin - 1 ) ).ToString();
|
||||
if( string.IsNullOrWhiteSpace( value ) ) {
|
||||
value = string.Empty;
|
||||
}
|
||||
t = new Token( value, line, begin, TokenFlag.String );
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
t = Token.Empty;
|
||||
return false;
|
||||
}
|
||||
Match match = NextEnumPattern.Match( codeLine, current );
|
||||
if( match.Success )
|
||||
{
|
||||
int begin = match.Groups[ "begin" ].Index;
|
||||
int end = match.Groups[ "end" ].Length;
|
||||
int rest = match.Groups[ "rets" ].Length;
|
||||
current = rest;
|
||||
t = new Token( match.Groups[ "begin" ].Value, line, begin, TokenFlag.Enum );
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
t = Token.Empty;
|
||||
return false;
|
||||
}
|
||||
t = Token.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>#[0-9A-Za-z]+)(?<end>\s*?)(?<rest>\S|$)",
|
||||
@"(?<begin>\.[A-Za-z_]+\.)(?<end>\s*)(?<rest>\S*)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetEntityTagSymbolPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>\.[A-Za-z_]+\.)(?<end>\s*)(?<rest>\S*)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetNextEnumPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>')(?>\\\\|''|(?!')[^'])*(?<end>')\s*?(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetStringPattern();
|
||||
private static extern Regex GetNextEnumPattern();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user