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:
Nitload
2025-04-15 03:15:23 +08:00
parent 9457309c5a
commit c29993fd84
23 changed files with 1838 additions and 159 deletions
+101
View File
@@ -0,0 +1,101 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpressStepUntil.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Modeling.Step;
using StgSharp.Modeling.Step;
using StgSharp.Script;
using StgSharp.Script.Express;
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace StgSharp.Modeling.Step
{
public class ExpressStepUntil : ExpSchema
{
private FrozenDictionary<string, ExpTypeSource> entitiesDefine;
public ExpressStepUntil()
{
Span<KeyValuePair<string, ExpTypeSource>> source = [
new KeyValuePair<string, ExpTypeSource>( StepItemTypeExtensions.AdvancedFaceText,
),
];
Dictionary<string, ExpTypeSource> tIndex = new Dictionary<string, ExpTypeSource>();
}
internal StepModel Current { get; set; }
public override void LoadFromSource( ExpSchemaSource source )
{
return;
}
public override bool TryGetConst( string name, out ExpElementInstance c )
{
c = null!;
return false;
}
public override bool TryGetEntity( string name, out ExpEntitySource e )
{
throw new NotImplementedException();
}
public override bool TryGetFunction( string name, out ExpFunctionSource f )
{
throw new NotImplementedException();
}
public override bool TryGetProcedure( string name, out ExpProcedureSource p )
{
throw new NotImplementedException();
}
public override bool TryGetRule( string name, out ExpRuleSource r )
{
throw new NotImplementedException();
}
public override bool TryGetSchemaInclude( string name, out ExpSchema include )
{
throw new NotImplementedException();
}
public override bool TryGetType( string name, out ExpTypeSource t )
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,290 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StepExpSyntaxAnalyzer.Common.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using Microsoft.CodeAnalysis.CSharp.Syntax;
using StgSharp.Script;
using StgSharp.Script.Express;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Schema;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Modeling.Step
{
public partial class StepExpSyntaxAnalyzer
{
private bool IsSeparatorMatch( Token leftSperator, Token rightSeparator )
{
return leftSperator.Value switch
{
ExpKeyword.LeftBrace => rightSeparator.Value == ExpKeyword.RightBrace,
ExpKeyword.LeftParen => rightSeparator.Value == ExpKeyword.RightParen,
ExpKeyword.Comma => rightSeparator.Value == ExpKeyword.Comma,
ExpKeyword.Semicolon => rightSeparator.Value == ExpKeyword.Semicolon,
_ => false
};
}
private bool TryAppendIndexLeft( Token t )
{
if( t.Flag != TokenFlag.Index_Left ) {
return false;
}
if( _cache.TryPeekOperand( out bool isNode, out _, out ExpNode? node ) )
{
if( node.EqualityTypeConvert is not ExpCollectionBase ) {
ExpInvalidSyntaxException.ThrowNonCollectionIndex( t );
}
}
_cache.PushOperator( t );
_cache.IncreaseDepth( ( int )ExpCompileStateCode.CollectionIndex );
return true;
}
private bool TryAppendIndexRight( Token t )
{
if( t.Flag != TokenFlag.Index_Right ) {
return false;
}
//reverse building
ClosePrefixReverse( t );
//make index node
_cache.PopOperand( out _, out ExpNode? expNode );
if( !_cache.PopOperand( out Token colleToken, out ExpNode? colleNode ) ) { }
_cache.PushOperand(
ExpCollectionIndexNode.Create(
t, ( colleNode as ExpCollectionInstanceBase )!, expNode ) );
return true;
}
private bool TryAppendMember( Token t )
{
if( t.Flag != TokenFlag.Member ) {
return false;
}
if( TryParseConstant( t ) ) {
return true;
}
if( TryParseFunction( t ) ) {
return true;
}
if( TryParseInstance( t ) ) {
return true;
}
if( TryParseKeyword( t ) ) {
return true;
}
if( TryParseElementName( t ) ) {
return true;
}
//Many thing miss here
_cache.PushOperand( ExpElementMemberNameNode.Create( t ) );
return true;
}
private bool TryAppendMiddleSeparator( Token t )
{
if( t.Flag != TokenFlag.Separator_Middle ) {
return false;
}
while( _cache.OperatorAheadOfDepth > 0 )
{
_cache.TryPopOperator( out Token op );
ExpNode node = ConvertAndPushOneOperator( op );
}
switch( _cache.OperandAheadOfDepth )
{
case 0:
if( t.Value == ";" ) {
return true;
}
_cache.StatementsInDepth.Push( ExpNode.Empty );
goto case 1;
case 1:
_cache.PopOperand( out _, out ExpNode? statement );
_cache.StatementsInDepth.Push( statement );
return true;
default:
ExpInvalidSyntaxException.ThrowNoOperator( t );
break;
}
return true;
}
private bool TryAppendNumAndStrLiteral( Token t )
{
if( ( t.Flag & ( TokenFlag.String | TokenFlag.Number ) ) == 0 ) {
return false;
}
_cache.PushOperand( ExpElementInstance.CreateLiteral( t ) );
return true;
}
private bool TryAppendPrefixSeparator( Token t )
{
if( t.Flag != TokenFlag.Separator_Left ) {
return false;
}
_cache.PushOperator( t );
_cache.IncreaseDepth( ( int )ExpCompileStateCode.Common );
return true;
}
private bool TryAppendPrefixSeparatorEnd( Token t )
{
if( t.Flag != TokenFlag.Separator_Right ) {
return false;
}
ClosePrefixReverse( t );
return true;
}
private bool TryAppendSymbol( Token t )
{
if( ( t.Flag & ( TokenFlag.Symbol_Unary | TokenFlag.Symbol_Binary ) ) == 0 ) {
return false;
}
int cmp = -1;
processPrecedence:
if( _cache.TryPeekOperator( out Token tmp ) )
{
cmp = CompareOperatorPrecedence( t, tmp );
if( cmp >= 0 )
{
_cache.PopOperator();
ExpNode node = ConvertAndPushOneOperator( tmp );
goto processPrecedence;
}
}
_cache.PushOperator( t );
return true;
}
private bool TryParseConstant( Token t )
{
switch( t.Value )
{
case ExpKeyword.E:
_cache.PushOperand( new ExpRealNumberNode( t, MathF.E, true ) );
return true;
case ExpKeyword.Pi:
_cache.PushOperand( new ExpRealNumberNode( t, MathF.PI, true ) );
return true;
default:
if( ExpElementInstance.TryCreateLiteral( t, out ExpElementInstance? node ) )
{
_cache.PushOperand( node );
return true;
}
return false;
}
}
private bool TryParseElementName( Token t )
{
if( _context.TryGetType( t.Value, out ExpTypeSource? type ) )
{
_cache.PushOperand( ExpMetaRefNode.RefType( t, type ) );
return true;
}
if( _context.TryGetEntity( t.Value, out ExpEntitySource? entity ) )
{
_cache.PushOperand( ExpMetaRefNode.RefEntity( t, entity ) );
return true;
}
return false;
}
private bool TryParseFunction( Token t )
{
if( ExpKeyword.BuiltinFunctions.Contains( t.Value ) )
{
_cache.PushOperator( t );
return true;
} else if( _context.TryGetFunction( t.Value, out ExpFunctionSource? f ) )
{
_cache.PushOperand( t );
return true;
}
return false;
}
private bool TryParseInstance( Token t )
{
if( _local.TryGetMember( t.Value,
out ExpNode? node ) && node is ExpElementInstance instance )
{
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
return true;
} else if( _cache.IsLastAddedOperator )
{
if( _cache.PeekOperand( out _,
out ExpNode? typenode ) && typenode is ExpMetaRefNode typeRef )
{
_cache.PopOperand( out _, out _ );
_local.AddMember( t.Value, typeRef.SourceRef.CreateInstanceNode( t ) );
} else
{
return false;
}
}
return false;
}
private bool TryParseKeyword( Token t )
{
switch( t.Value )
{
case ExpKeyword.Return:
_cache.PushOperator( t );
return true;
case ExpKeyword.Skip:
_cache.PushOperand( ExpProcedureControlNode.Skip( t ) );
return true;
default:
return false;
}
}
}
}
@@ -0,0 +1,56 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.ErrorProcess.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Modeling.Step
{
public partial class StepExpSyntaxAnalyzer
{
public void ThrowCompileException( int errorCode )
{
switch( errorCode )
{
case 0 or 1:
return;
case TokenTypeNotMatch:
throw new Exception();
default:
break;
}
}
}
}
@@ -0,0 +1,184 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.OperatorParser.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Script;
using StgSharp.Script.Express;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Modeling.Step
{
public partial class StepExpSyntaxAnalyzer
{
public int CompareOperatorPrecedence( Token left, Token right )
{
ExpressCompile.TryGetOperatorPrecedence( left.Value, out int leftPrecedence );
ExpressCompile.TryGetOperatorPrecedence( right.Value, out int rightPrecedence );
return leftPrecedence - rightPrecedence;
}
public bool TryGenerateUnaryNode( Token t, out ExpNode node )
{
ExpNode operand = GetNextOperandCache();
switch( t.Value )
{
case ExpKeyword.UnaryPlus:
node = ExpUnaryOperatorNode.UnaryPlus( t, operand );
return true;
case ExpKeyword.UnaryMinus:
node = ExpUnaryOperatorNode.UnaryMinus( t, operand );
return true;
case ExpKeyword.Not:
node = ExpUnaryOperatorNode.UnaryNot( t, operand );
return true;
default:
node = ExpNode.Empty;
return false;
}
}
/// <summary>
/// WARNING: This method cannot process INDEXOF, FUNCTION CALLING, LOOP and any ENDING
/// SYMBOLS.
/// </summary>
private ExpNode ConvertAndPushOneOperator( Token op )
{
switch( op.Flag )
{
case TokenFlag.Symbol_Unary:
TryGenerateUnaryNode( op, out ExpNode? node );
_cache.PushOperand( node );
return node;
case TokenFlag.Symbol_Binary:
TryGenerateBinaryNode( op, out node );
_cache.PushOperand( node );
return node;
case TokenFlag.Member:
if( _context.TryGetFunction( op.Value, out ExpFunctionSource? f ) )
{
if( !_cache.PopOperand( out Token t, out ExpNode? p ) )
{
node = ExpFunctionCallingNode.CallFunction( op, f, p );
return node;
} else
{
throw new ExpCompileException(
t,
"An ExpNode for function calling is needed, but a token was popped" );
}
} else if( _context.TryGetProcedure( op.Value, out ExpProcedureSource? p ) )
{
if( !_cache.PopOperand( out Token t, out ExpNode? param ) )
{
node = ExpProcedureCallingNode.CallProcedure( op, p, param );
return node;
} else
{
throw new ExpCompileException(
t,
"An ExpNode for function calling is needed, but a token was popped" );
}
} else if( ExpSchema.BuiltinSchema.TryGetFunction( op.Value, out f ) )
{
if( !_cache.PopOperand( out Token t, out ExpNode? param ) )
{
node = ExpFunctionCallingNode.CallFunction( op, f, param );
return node;
} else
{
throw new ExpCompileException(
t,
"An ExpNode for function calling is needed, but a token was popped" );
}
} else
{
throw new NotImplementedException();
//uncertain case here
}
default:
throw new NotImplementedException();
}
}
private bool TryGenerateBinaryNode( Token t, out ExpNode node )
{
ExpNode right = GetNextOperandCache();
ExpNode left = GetNextOperandCache();
switch( t.Value )
{
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 = ExpNode.Empty;
return false;
}
}
}
}
@@ -0,0 +1,85 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StepExpSyntaxAnalyzer.PrefixReverseAnalysing.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Script;
using StgSharp.Script.Express;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Modeling.Step
{
public partial class StepExpSyntaxAnalyzer
{
private void ClosePrefixReverse( Token rightSeparator )
{
Token op;
ExpNode root;
if( _cache.OperatorAheadOfDepth == 0 )
{
if( _cache.OperandAheadOfDepth == 1 )
{
_cache.PopOperand( out _, out ExpNode? statement );
_cache.StatementsInDepth.Push( statement );
} else
{
ExpInvalidSyntaxException.ThrowNoOperator( rightSeparator );
}
} else
{
while( _cache.TryPopOperator( out op ) ) {
ConvertAndPushOneOperator( op );
}
_cache.PopOperand( out _, out root );
_cache.StatementsInDepth.Push( root );
}
root = _cache.PackAllStatements();
_cache.DecreaseDepth();
if( IsSeparatorMatch( _cache.PeekOperator(), rightSeparator ) )
{
_cache.PopOperator();
_cache.PushOperand( root );
} else
{
throw new ExpCompileException(
rightSeparator, "Ending of block does not match its begging" );
}
}
}
}
@@ -0,0 +1,145 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StepExpSyntaxAnalyzer.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using Microsoft.CodeAnalysis.CSharp.Syntax;
using StgSharp.Script;
using StgSharp.Script.Express;
using StgSharp.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Pipes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Modeling.Step
{
public partial class StepExpSyntaxAnalyzer : ISyntaxAnalyzer
{
private const int EndLine = 1;
private const int TokenGenerated = 0;
private const int TokenTypeNotMatch = -1;
private CompileStack<ExpNode, IExpElementSource> _cache;
private ExpNode _lastStatement;
private ExpSchema _context;
private IExpElementSource _local;
public StepExpSyntaxAnalyzer()
{
_cache = new CompileStack<ExpNode, IExpElementSource>();
}
public StepExpSyntaxAnalyzer( ExpSchema context, IExpElementSource local )
{
_cache = new CompileStack<ExpNode, IExpElementSource>();
ArgumentNullException.ThrowIfNull( context );
if( context is not ExpSchema_Builtin )
{
_context = context;
} else
{
throw new InvalidCastException( "Not a valid Schema type" );
}
_local = local;
}
/// <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( Token expToken )
{
switch( expToken.Flag )
{
case TokenFlag.Symbol_Unary or TokenFlag.Symbol_Binary:
TryAppendSymbol( expToken );
break;
case TokenFlag.Number or TokenFlag.String:
ExpElementInstance node = ExpElementInstance.CreateLiteral( expToken );
_cache.PushOperand( node );
break;
case TokenFlag.Separator_Left:
TryAppendPrefixSeparator( expToken );
break;
case TokenFlag.Separator_Right:
TryAppendPrefixSeparatorEnd( expToken );
break;
case TokenFlag.Separator_Middle:
TryAppendMiddleSeparator( expToken );
break;
case TokenFlag.Index_Left:
TryAppendIndexLeft( expToken );
break;
case TokenFlag.Index_Right:
TryAppendIndexRight( expToken );
break;
case TokenFlag.Member:
TryAppendMember( expToken );
break;
default:
break;
}
}
public ExpNode GetNextOperandCache()
{
if( _cache.PopOperand( out Token t, out ExpNode? n ) )
{
return n;
} else
{
// process some rare case here
}
throw new NotImplementedException();
}
public enum ExpCompileStateCode
{
Common,
ForLoop,
RepeatLoop,
UntilLoop,
IfBranch,
CaseBranch,
CollectionIndex,
}
}
}
@@ -0,0 +1,143 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StepDataSectionTokenReader.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Modeling.Step;
using StgSharp.Script;
using StgSharp.Script.Express;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Modeling.Step
{
public class StepDataSectionTokenReader : IScriptTokenReader
{
private ExpSourceReader _reader;
private Queue<Token> _cache = new Queue<Token>();
private StepDataSectionTransmitter _transmitter;
public StepDataSectionTokenReader( StepDataSectionTransmitter transmitter )
{
_reader = new ExpSourceReader( transmitter );
_transmitter = transmitter;
}
public Token ReadToken()
{
if( _cache.Count == 0 )
{
if( _reader.TryReadToken( out Token token0 ) && ( token0.Value != "." ) ) {
return token0;
}
if( _reader.TryReadToken( out Token token1 ) && ( token1.Value != "T" || token1.Value !=
"F" ) )
{
_cache.Enqueue( token1 );
return token0;
}
if( _reader.TryReadToken( out Token token2 ) && ( token2.Value != "." ) )
{
_cache.Enqueue( token1 );
_cache.Enqueue( token2 );
return token0;
}
switch( token1.Value )
{
case "T":
return new Token( ".T.", token0.Line, token1.Column, TokenFlag.Member );
case "F":
return new Token( ".F.", token0.Line, token1.Column, TokenFlag.Member );
default:
break;
}
}
return _cache.Dequeue();
}
public bool TryReadToken( out Token t )
{
if( _cache.Count == 0 )
{
if( _reader.TryReadToken( out Token token0 ) )
{
if( token0.Value != "." )
{
t = token0;
return true;
}
} else
{
t = Token.Empty;
return false;
}
if( _reader.TryReadToken( out Token token1 ) )
{
if( token1.Value != "T" || token1.Value != "F" )
{
_cache.Enqueue( token1 );
t = token0;
return true;
}
} else
{
t = Token.Empty;
return false;
}
if( _reader.TryReadToken( out Token token2 ) )
{
if( token2.Value != "." )
{
_cache.Enqueue( token1 );
_cache.Enqueue( token2 );
t = token0;
return true;
}
} else
{
t = Token.Empty;
return false;
}
t = token1.Value switch
{
"T" => new Token( ".T.", token0.Line, token1.Column, TokenFlag.Member ),
"F" => new Token( ".F.", token0.Line, token1.Column, TokenFlag.Member ),
_ => Token.Empty
};
}
return _reader.TryReadToken( out t );
}
}
}
@@ -0,0 +1,95 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StepDataSectionsTranmitter.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Script;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Modeling.Step
{
public class StepDataSectionTransmitter : IScriptSourceProvider
{
private bool _isEmpty;
private ConcurrentQueue<string> _cache = new ConcurrentQueue<string>();
private int _line = 0;
public bool IsEmpty => _isEmpty;
public int Location => _line;
public void EndWriting()
{
_cache.Enqueue( "END_DATA" );
}
public string ReadLine()
{
_cache.TryDequeue( out string? line );
while( !IsEmpty )
{
if( _cache.TryDequeue( out line ) )
{
if( line == "END_DATA" )
{
_isEmpty = true;
return string.Empty;
}
_line++;
return line;
}
}
return string.Empty;
}
public string ReadLine( out int position )
{
string ret = ReadLine();
position = _line;
return ret;
}
public void WriteLine( string line )
{
_cache.Enqueue( line );
}
IScriptSourceProvider IScriptSourceProvider.Slice( int location, int count )
{
throw new NotSupportedException();
}
}
}
@@ -0,0 +1,57 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StepExpressParser.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Modeling.Step;
using StgSharp.Script;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Modeling.Step
{
public class StepExpressSyntaxParser : ISyntaxAnalyzer
{
private StepExpSyntaxAnalyzer _analyzer;
public StepExpressSyntaxParser()
{
_analyzer = new StepExpSyntaxAnalyzer();
}
public void AppendToken( Token t )
{
}
}
}
+227
View File
@@ -0,0 +1,227 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="STEPHeader.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Modeling.Step
{
/// <summary>
/// C# implementation of HEADER part in STEP file.
/// </summary>
public struct StepInfo
{
private STEPFileDescriptor _header;
private STEPFileName _name;
private STEPSchema _schema;
public (int mainLevel, int? subLevel) Level
{
get => _header.Level;
internal set => _header.Level = value;
}
public DateTime TimeStamp
{
get => _name.TimeStamp;
internal set => _name.TimeStamp = value;
}
public STEPFileDescriptor Descriptor
{
get => _header;
internal set => _header = value;
}
public STEPFileName FileName
{
get => _name;
internal set => _name = value;
}
public STEPSchema Schema
{
get => _schema;
internal set => _schema = value;
}
public string Description
{
get => _header.Description;
internal set => _header.Description = value;
}
public string Name
{
get => _name.Name;
internal set => _name.Name = value;
}
public string Author
{
get => _name.Author;
internal set => _name.Author = value;
}
public string Organization
{
get => _name.Organization;
internal set => _name.Organization = value;
}
public string OriginatingSystem
{
get => _name.OriginatingSystem;
internal set => _name.OriginatingSystem = value;
}
public string Authorization
{
get => _name.Authorization;
internal set => _name.Authorization = value;
}
public string PreprocessorVersion
{
get => _name.PreprocessorVersion;
internal set => _name.PreprocessorVersion = value;
}
public string Version
{
get => _name.Version;
internal set => _name.Version = value;
}
public string SchemaString
{
get => _schema.Data;
internal set => _schema.Data = value;
}
}
/// <summary>
/// C# implementation of FILE_NAME part in header of STEP file.
/// </summary>
public struct STEPFileName
{
public DateTime TimeStamp
{
get;
internal set;
}
public string Name
{
get;
internal set;
}
public string Author
{
get;
internal set;
}
public string Description
{
get;
internal set;
}
public string PreprocessorVersion
{
get;
internal set;
}
public string Version
{
get;
internal set;
}
public string Organization
{
get;
internal set;
}
public string OriginatingSystem
{
get;
internal set;
}
public string Authorization
{
get;
internal set;
}
}
public struct STEPSchema
{
private List<string> _schema;
public string Data
{
get;
internal set;
}
}
/// <summary>
/// C# implementation of FILE_NAME part in header of STEP file.
/// </summary>
public struct STEPFileDescriptor
{
public (int mainLevel,int? subLevel) Level
{
get;
internal set;
}
public string Description
{
get;
internal set;
}
}
}
+80
View File
@@ -0,0 +1,80 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StepModel.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.PipeLine;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Modeling.Step
{
public class StepModel
{
private BlueprintScheduler _builder;
private Dictionary<int, StepUncertainEntity> _nodes
= new Dictionary<int, StepUncertainEntity>();
private StepInfo _header;
internal StepModel( StepInfo header )
{
_header = header;
_builder = new BlueprintScheduler();
}
public StepUncertainEntity this[ int id ]
{
get
{
if( _nodes.TryGetValue( id, out StepUncertainEntity? node ) ) {
return node;
}
node = StepUncertainEntity.Create( id );
return node;
}
}
public void AddUncertainEntity( int id, StepUncertainEntity entity )
{
if( _nodes.ContainsKey( id ) ) {
throw new InvalidOperationException(
"Attempt to add entity with same id more than once" );
}
_nodes.Add( id, entity );
}
public void OrganizeNode()
{
foreach( KeyValuePair<int, StepUncertainEntity> node in _nodes ) { }
}
}
}
@@ -0,0 +1,101 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StepObjectConstructor.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StgSharp.Modeling.Step
{
public class StepObjectConstructor
{
private static Regex regex = new Regex(
@"(?<param1>.+?(\)|'\s?\)|'))\s?(?<sepcomma>,)\s?(?<other>(.|\(|\(\s?').+)",
RegexOptions.Compiled );
private readonly int _id;
private readonly List<string> _paramList;
private string _caller;
public StepObjectConstructor( int id, string caller, string parameters )
{
_caller = caller;
_paramList = new List<string>();
SplitParameter( parameters );
}
public string this[ int paramIndex ]
{
get => _paramList[ paramIndex ];
}
public ReadOnlyCollection<string> ParamList
{
get => _paramList.AsReadOnly();
}
public static string TempCallerName
{
get => "TEMPCALLER";
}
public string Caller
{
get => _caller;
internal set => _caller = value;
}
public static StepObjectConstructor CreateTempExpression( int id )
{
return new StepObjectConstructor( id, "TEMPCALLER", string.Empty );
}
private void SplitParameter( string parameters )
{
if( string.IsNullOrEmpty( parameters ) || string.IsNullOrWhiteSpace( parameters ) ) {
return;
}
Match match = regex.Match( parameters );
while( match.Success )
{
_paramList.Add( match.Groups[ "param1" ].Value );
parameters = match.Groups[ "other" ].Value;
match = regex.Match( parameters );
}
_paramList.Add( parameters );
}
}
}
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")] [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [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.Model")] [assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -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 );
}
}
+39
View File
@@ -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 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(); private static readonly ExpSchema_Builtin _onlyInstance = new ExpSchema_Builtin();
@@ -36,7 +36,7 @@ using System.Threading.Tasks;
namespace StgSharp.Script.Express namespace StgSharp.Script.Express
{ {
internal class ExpFunctionCallingNode : ExpNode public class ExpFunctionCallingNode : ExpNode
{ {
private ExpFunctionSource _function; private ExpFunctionSource _function;
@@ -44,9 +44,9 @@ namespace StgSharp.Script.Express
private ExpNode _parameter; private ExpNode _parameter;
private ExpFunctionCallingNode( private ExpFunctionCallingNode(
Token source, Token source,
ExpFunctionSource function, ExpFunctionSource function,
ExpNode firstParameter ) ExpNode firstParameter )
: base( source ) : base( source )
{ {
_function = function; _function = function;
@@ -66,9 +66,9 @@ namespace StgSharp.Script.Express
} }
public static ExpFunctionCallingNode CallFunction( public static ExpFunctionCallingNode CallFunction(
Token source, Token source,
ExpFunctionSource function, ExpFunctionSource function,
ExpNode param ) ExpNode param )
{ {
return new ExpFunctionCallingNode( source, function, param ); return new ExpFunctionCallingNode( source, function, param );
} }
@@ -93,11 +93,6 @@ namespace StgSharp.Script.Express
Next.Previous = this; Next.Previous = this;
} }
public ExpNodeNextEnumerator GetEnumerator()
{
return new ExpNodeNextEnumerator( this );
}
public static bool IsNullOrEmpty( [AllowNull]ExpNode node ) public static bool IsNullOrEmpty( [AllowNull]ExpNode node )
{ {
return node == ExpEmptyNode._only || node == null; return node == ExpEmptyNode._only || node == null;
@@ -70,6 +70,11 @@ namespace StgSharp.Script.Express
public abstract string Name { get; } public abstract string Name { get; }
public void AddMember( string name, ExpNode memberNode )
{
throw new NotImplementedException();
}
public abstract void Analyse(); public abstract void Analyse();
public abstract ExpNode CreateInstanceNode( Token t ); public abstract ExpNode CreateInstanceNode( Token t );
@@ -131,6 +136,11 @@ namespace StgSharp.Script.Express
public abstract string Name { get; } public abstract string Name { get; }
public void AddMember( string name, ExpNode memberNode )
{
throw new NotImplementedException();
}
public abstract void Analyse(); public abstract void Analyse();
public bool IsConvertable( IExpElementSource targetType ) public bool IsConvertable( IExpElementSource targetType )
@@ -34,11 +34,23 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Script.Express 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> public class ExpNodeNextEnumerator : IEnumerator<ExpNode>
{ {
+146 -128
View File
@@ -38,10 +38,10 @@ using System.Text.RegularExpressions;
namespace StgSharp.Script.Express namespace StgSharp.Script.Express
{ {
public partial class ExpSourceReader public partial class ExpSourceReader : IScriptTokenReader
{ {
private const int private const int
MultiLineEnd = 0x0029002A; // *) MultiLineEnd = 0x0029002A; // *)
private const string TokenMark = "token", EndMark = "end", RestMark = "rest"; private const string TokenMark = "token", EndMark = "end", RestMark = "rest";
@@ -59,7 +59,7 @@ namespace StgSharp.Script.Express
private string _lineCache; private string _lineCache;
private Token _last; private Token _last;
public ExpSourceReader( IScriptSourceProvider provider ) public ExpSourceReader(IScriptSourceProvider provider)
{ {
_provider = provider; _provider = provider;
_current = 0; _current = 0;
@@ -69,7 +69,7 @@ namespace StgSharp.Script.Express
public bool IsEmpty public bool IsEmpty
{ {
get => ( ( string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length ) ) && _provider.IsEmpty; get => ((string.IsNullOrEmpty(_lineCache) || _current >= _lineCache.Length)) && _provider.IsEmpty;
} }
public int LineNumber public int LineNumber
@@ -79,163 +79,175 @@ namespace StgSharp.Script.Express
public unsafe ReadOnlySpan<char> ReadLine() public unsafe ReadOnlySpan<char> ReadLine()
{ {
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length; bool lineOver = string.IsNullOrEmpty(_lineCache) || _current >= _lineCache.Length;
while( lineOver || _isReadingMultiLineComment ) while (lineOver || _isReadingMultiLineComment)
{ {
if( IsEmpty ) { if (IsEmpty)
{
return ReadOnlySpan<char>.Empty; return ReadOnlySpan<char>.Empty;
} }
if( lineOver ) if (lineOver)
{ {
do do
{ {
_lineCache = _provider.ReadLine( out _lineNum ); _lineCache = _provider.ReadLine(out _lineNum);
} while (string.IsNullOrEmpty( _lineCache )); } while (string.IsNullOrEmpty(_lineCache));
_current = 0; _current = 0;
} }
if( _isReadingMultiLineComment ) if (_isReadingMultiLineComment)
{ {
int index; int index;
fixed( char* cPtr = _lineCache.AsSpan( _current ) ) { fixed (char* cPtr = _lineCache.AsSpan(_current))
{
index = UnsafeCompute.IndexOfCharPair( index = UnsafeCompute.IndexOfCharPair(
cPtr, MultiLineEnd, _lineCache.Length ); cPtr, MultiLineEnd, _lineCache.Length);
} }
if( index == -1 ) if (index == -1)
{ {
_lineCache = string.Empty; _lineCache = string.Empty;
} else }
else
{ {
_isReadingMultiLineComment = false; _isReadingMultiLineComment = false;
_current += index + 2; _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() public unsafe Token ReadToken()
{ {
int begin, end, rest; int begin, end, rest;
readLine: readLine:
ReadOnlySpan<char> source; ReadOnlySpan<char> source;
if( !TryReadLine( out source ) ) { if (!TryReadLine(out source))
{
return Token.Empty; 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 ); Match match = _nextWordTokenPattern.Match(_lineCache, _current);
if( match.Success ) if (match.Success)
{ {
begin = match.Groups[ TokenMark ].Index; begin = match.Groups[TokenMark].Index;
end = match.Groups[ EndMark ].Index; end = match.Groups[EndMark].Index;
rest = match.Groups[ RestMark ].Index; rest = match.Groups[RestMark].Index;
_current = rest; _current = rest;
_last = new( _last = new(
ExpressCompile.PoolString( source[ .. ( end - begin ) ] ), _lineNum, begin, ExpressCompile.PoolString(source[..(end - begin)]), _lineNum, begin,
TokenFlag.Member ); TokenFlag.Member);
return _last; 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 '\'':
case '"': case '"':
char cNext = source[ 1 ]; char cNext = source[1];
if( cNext == '\"' ) //empty string if (cNext == '\"') //empty string
{ {
begin = _current; begin = _current;
_current += 2; _current += 2;
return new( string.Empty, _lineNum, begin, TokenFlag.String ); return new(string.Empty, _lineNum, begin, TokenFlag.String);
} }
Match match = _nextStringLiteralPattern.Match( _lineCache, _current ); Match match = _nextStringLiteralPattern.Match(_lineCache, _current);
if( match.Success ) if (match.Success)
{ {
begin = match.Groups[ "token" ].Index; begin = match.Groups["token"].Index;
end = match.Groups[ "end" ].Index; end = match.Groups["end"].Index;
rest = match.Groups[ "rest" ].Index; rest = match.Groups["rest"].Index;
_current = rest; _current = rest;
_last = new( _last = new(
ExpressCompile.PoolString( source[ 1..( end - begin ) ] ), _lineNum, ExpressCompile.PoolString(source[1..(end - begin)]), _lineNum,
begin, TokenFlag.String ); begin, TokenFlag.String);
return _last; return _last;
} else }
else
{ {
throw new ExpInvalidCharException( '\"' ); throw new ExpInvalidCharException('\"');
} }
case '(': case '(':
cNext = source[ 1 ]; cNext = source[1];
if( cNext == '*' ) if (cNext == '*')
{ {
_isReadingMultiLineComment = true; _isReadingMultiLineComment = true;
_current += 2; _current += 2;
goto readLine; goto readLine;
} else }
else
{ {
begin = _current; begin = _current;
_current++; _current++;
_last = new( _last = new(
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin, ExpressCompile.PoolString(source[..1]), _lineNum, begin,
TokenFlag.Separator_Left ); TokenFlag.Separator_Left);
return _last; return _last;
} }
case ')' or '}': case ')' or '}':
begin = _current; begin = _current;
_current++; _current++;
_last = new Token( _last = new Token(
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin, ExpressCompile.PoolString(source[..1]), _lineNum, begin,
TokenFlag.Separator_Right ); TokenFlag.Separator_Right);
return _last; return _last;
case '-': case '-':
// 1. - number // 1. - number
// 2. -- comment // 2. -- comment
// 3. - number type param(UNARY) // 3. - number type param(UNARY)
// 4. param - param(BINARY) // 4. param - param(BINARY)
cNext = source[ 1 ]; cNext = source[1];
if( char.IsNumber( cNext ) ) if (char.IsNumber(cNext))
{ {
match = _nextNumberLiteralPattern.Match( _lineCache, _current ); match = _nextNumberLiteralPattern.Match(_lineCache, _current);
if( match.Success ) if (match.Success)
{ {
begin = match.Groups[ TokenMark ].Index; begin = match.Groups[TokenMark].Index;
end = match.Groups[ EndMark ].Index; end = match.Groups[EndMark].Index;
rest = match.Groups[ RestMark ].Index; rest = match.Groups[RestMark].Index;
_current = rest; _current = rest;
return new( return new(
ExpressCompile.PoolString( source[ ..( end - begin ) ] ), ExpressCompile.PoolString(source[..(end - begin)]),
_lineNum, begin, TokenFlag.Number ); _lineNum, begin, TokenFlag.Number);
} else
{
throw new ExpInvalidCharException( _current );
} }
} else if( cNext == '-' ) else
{
throw new ExpInvalidCharException(_current);
}
}
else if (cNext == '-')
{ {
_lineCache = string.Empty; _lineCache = string.Empty;
_current = 0; _current = 0;
goto readLine; goto readLine;
} else }
else
{ {
begin = _current; begin = _current;
_current++; _current++;
if( _last.Flag == TokenFlag.Member || _last.Flag == if (_last.Flag == TokenFlag.Member || _last.Flag ==
TokenFlag.Index_Right || _last.Flag == TokenFlag.Separator_Right ) TokenFlag.Index_Right || _last.Flag == TokenFlag.Separator_Right)
{ {
_last = new( _last = new(
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin, ExpressCompile.PoolString(source[..1]), _lineNum, begin,
TokenFlag.Symbol_Binary ); TokenFlag.Symbol_Binary);
} else }
else
{ {
_last = new( _last = new(
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin, ExpressCompile.PoolString(source[..1]), _lineNum, begin,
TokenFlag.Symbol_Unary ); TokenFlag.Symbol_Unary);
} }
return _last; return _last;
} }
@@ -243,108 +255,114 @@ namespace StgSharp.Script.Express
begin = _current; begin = _current;
_current++; _current++;
_last = new Token( _last = new Token(
ExpressCompile.PoolString( "{" ), _lineNum, begin, ExpressCompile.PoolString("{"), _lineNum, begin,
TokenFlag.Separator_Left ); TokenFlag.Separator_Left);
return _last; return _last;
case '[': case '[':
begin = _current; begin = _current;
_current++; _current++;
_last = new Token( _last = new Token(
ExpressCompile.PoolString( "[" ), _lineNum, begin, ExpressCompile.PoolString("["), _lineNum, begin,
TokenFlag.Index_Left ); TokenFlag.Index_Left);
return _last; return _last;
case ']': case ']':
begin = _current; begin = _current;
_current++; _current++;
_last = new Token( _last = new Token(
ExpressCompile.PoolString( "]" ), _lineNum, begin, ExpressCompile.PoolString("]"), _lineNum, begin,
TokenFlag.Index_Right ); TokenFlag.Index_Right);
return _last; return _last;
case ';' or ',': case ';' or ',':
begin = _current; begin = _current;
_current++; _current++;
_last = new Token( _last = new Token(
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin, ExpressCompile.PoolString(source[..1]), _lineNum, begin,
TokenFlag.Separator_Middle ); TokenFlag.Separator_Middle);
return _last; return _last;
case ':': case ':':
match = _nextSymbolPattern.Match( _lineCache, _current ); match = _nextSymbolPattern.Match(_lineCache, _current);
begin = match.Groups[ TokenMark ].Index; begin = match.Groups[TokenMark].Index;
end = match.Groups[ EndMark ].Index; end = match.Groups[EndMark].Index;
rest = match.Groups[ RestMark ].Index; rest = match.Groups[RestMark].Index;
_current = rest; _current = rest;
if( end - begin == 1 ) if (end - begin == 1)
{ {
_last = new Token( _last = new Token(
ExpressCompile.Keyword.Colon, _lineNum, begin, ExpressCompile.Keyword.Colon, _lineNum, begin,
TokenFlag.Separator_Middle ); TokenFlag.Separator_Middle);
} else }
else
{ {
_last = new Token( _last = new Token(
ExpressCompile.PoolString( source[ ..( end - begin ) ] ), _lineNum, ExpressCompile.PoolString(source[..(end - begin)]), _lineNum,
begin, TokenFlag.Symbol_Binary ); begin, TokenFlag.Symbol_Binary);
} }
return _last; return _last;
case '+' or '/' or '\\' or '*' or '.': case '+' or '/' or '\\' or '*' or '.':
match = _nextSymbolPattern.Match( _lineCache, _current ); match = _nextSymbolPattern.Match(_lineCache, _current);
begin = match.Groups[ TokenMark ].Index; begin = match.Groups[TokenMark].Index;
end = match.Groups[ EndMark ].Index; end = match.Groups[EndMark].Index;
rest = match.Groups[ RestMark ].Index; rest = match.Groups[RestMark].Index;
_current = rest; _current = rest;
_last = new Token( _last = new Token(
ExpressCompile.PoolString( source[ ..( end - begin ) ] ), _lineNum, ExpressCompile.PoolString(source[..(end - begin)]), _lineNum,
begin, TokenFlag.Symbol_Binary ); begin, TokenFlag.Symbol_Binary);
return _last; return _last;
case '=': case '=':
begin = _current; begin = _current;
_current++; _current++;
_last = new Token( _last = new Token(
ExpressCompile.Keyword.Equal, _lineNum, begin, ExpressCompile.Keyword.Equal, _lineNum, begin,
TokenFlag.Symbol_Binary ); TokenFlag.Symbol_Binary);
return _last; return _last;
default: 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 ); Match match = _nextNumberLiteralPattern.Match(_lineCache, _current);
if( match.Success ) if (match.Success)
{ {
begin = match.Groups[ TokenMark ].Index; begin = match.Groups[TokenMark].Index;
end = match.Groups[ EndMark ].Index; end = match.Groups[EndMark].Index;
rest = match.Groups[ RestMark ].Index; rest = match.Groups[RestMark].Index;
_current = rest; _current = rest;
string str = ExpressCompile.PoolString( source[ ..( end - begin ) ] ); string str = ExpressCompile.PoolString(source[..(end - begin)]);
return new( str, _lineNum, begin, TokenFlag.Number ); return new(str, _lineNum, begin, TokenFlag.Number);
} else
{
throw new ExpInvalidCharException( _current );
} }
} else if( char.IsWhiteSpace( c ) ) else
{
Match match = _skipBlankPattern.Match( _lineCache, _current );
if( match.Success )
{ {
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; _current = rest;
goto readLine; 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(); line = ReadLine();
return line != ReadOnlySpan<char>.Empty; return line != ReadOnlySpan<char>.Empty;
} }
public bool TryReadToken( out Token t ) public bool TryReadToken(out Token t)
{ {
t = ReadToken(); t = ReadToken();
return !IsEmpty; return !IsEmpty;
@@ -352,30 +370,30 @@ namespace StgSharp.Script.Express
[GeneratedRegex( [GeneratedRegex(
@"(?<token>[a-zA-Z][a-zA-Z0-9_]*)(?<end>\s*?)(?<rest>\S|$)", @"(?<token>[a-zA-Z][a-zA-Z0-9_]*)(?<end>\s*?)(?<rest>\S|$)",
RegexOptions.Singleline )] RegexOptions.Singleline)]
private static partial Regex GetNextWordTokenPattern(); private static partial Regex GetNextWordTokenPattern();
[GeneratedRegex( [GeneratedRegex(
@"(?<token>-?\s*?[0-9]+(?:\.[0-9]*)?E?(?:[+-]?[0-9]+)?)(?<end>\s*?)(?<rest>\S|$)", @"(?<token>-?\s*?[0-9]+(?:\.[0-9]*)?E?(?:[+-]?[0-9]+)?)(?<end>\s*?)(?<rest>\S|$)",
RegexOptions.Singleline )] RegexOptions.Singleline)]
private static partial Regex GetNumberLiteralPattern(); private static partial Regex GetNumberLiteralPattern();
[GeneratedRegex( @"(?:\s+?)(?<rest>\S|$)", RegexOptions.Singleline )] [GeneratedRegex(@"(?:\s+?)(?<rest>\S|$)", RegexOptions.Singleline)]
private static partial Regex GetSkipBlankPattern(); private static partial Regex GetSkipBlankPattern();
[GeneratedRegex( [GeneratedRegex(
@"(?<token>"")(?>\\\\|\\""|(?!')[^""])*(?<end>""|$)\s*?(?<rest>\S|$)", @"(?<token>"")(?>\\\\|\\""|(?!')[^""])*(?<end>""|$)\s*?(?<rest>\S|$)",
RegexOptions.Singleline )] RegexOptions.Singleline)]
private static partial Regex GetStringLiteralPattern(); private static partial Regex GetStringLiteralPattern();
[GeneratedRegex( [GeneratedRegex(
@"(?<token>')(?>\\\\|\\'|''|(?!')[^'])*(?<end>')\s*?(?<rest>\S|$)", @"(?<token>')(?>\\\\|\\'|''|(?!')[^'])*(?<end>')\s*?(?<rest>\S|$)",
RegexOptions.Singleline )] RegexOptions.Singleline)]
private static partial Regex GetStringLiteralPatternWithSingle(); private static partial Regex GetStringLiteralPatternWithSingle();
[GeneratedRegex( [GeneratedRegex(
@"(?<token>[:<>=+\-*\/]+)(?<end>\s?)\s*?(?<rest>\S|$)", @"(?<token>[:<>=+\-*\/]+)(?<end>\s?)\s*?(?<rest>\S|$)",
RegexOptions.Singleline )] RegexOptions.Singleline)]
private static partial Regex GetSymbolPattern(); private static partial Regex GetSymbolPattern();
} }
+16 -16
View File
@@ -44,7 +44,7 @@ using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Script.Express namespace StgSharp.Script.Express
{ {
public partial class ExpSyntaxAnalyzer public partial class ExpSyntaxAnalyzer : ISyntaxAnalyzer
{ {
private const int EndLine = 1; 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> /// <summary>
/// Append a token to top of cache. This method will automatically convert token to node /// Append a token to top of cache. This method will automatically convert token to node
/// if meets separators or operators. /// if meets separators or operators.
/// </summary> /// </summary>
public void AppendToken_common( Token expToken ) private void AppendToken_common( Token expToken )
{ {
switch( expToken.Flag ) 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 ) private CompileDepthMark TryEnterBranch( Token t )
{ {
if( t.Flag == TokenFlag.String ) { if( t.Flag == TokenFlag.String ) {
@@ -153,7 +153,7 @@ namespace StgSharp.Script.Express
} }
switch( t.Value ) switch( t.Value )
{ {
case ExpKeyword.Case: case ExpKeyword.Case:
return _cache.IncreaseDepth( ( int )ExpCompileStateCode.CaseBranch ); return _cache.IncreaseDepth( ( int )ExpCompileStateCode.CaseBranch );
case ExpKeyword.If: case ExpKeyword.If:
return _cache.IncreaseDepth( ( int )ExpCompileStateCode.IfBranch ); return _cache.IncreaseDepth( ( int )ExpCompileStateCode.IfBranch );
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")] [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [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.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]