diff --git a/StgSharp.Model/STEP/ExpressStepUntil.cs b/StgSharp.Model/STEP/ExpressStepUntil.cs new file mode 100644 index 00000000..38550067 --- /dev/null +++ b/StgSharp.Model/STEP/ExpressStepUntil.cs @@ -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 entitiesDefine; + + public ExpressStepUntil() + { + Span> source = [ + new KeyValuePair( StepItemTypeExtensions.AdvancedFaceText, + ), + ]; + Dictionary tIndex = new Dictionary(); + } + + 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(); + } + + } +} \ No newline at end of file diff --git a/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.Common.cs b/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.Common.cs new file mode 100644 index 00000000..39b9e54f --- /dev/null +++ b/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.Common.cs @@ -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; + } + } + + } +} diff --git a/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.ErrorProcess.cs b/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.ErrorProcess.cs new file mode 100644 index 00000000..fdc40b02 --- /dev/null +++ b/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.ErrorProcess.cs @@ -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; + } + } + + } +} diff --git a/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.OperatorParser.cs b/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.OperatorParser.cs new file mode 100644 index 00000000..3b4e16e3 --- /dev/null +++ b/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.OperatorParser.cs @@ -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; + } + } + + /// + /// WARNING: This method cannot process INDEXOF, FUNCTION CALLING, LOOP and any ENDING + /// SYMBOLS. + /// + 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; + } + } + + } +} diff --git a/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.PrefixReverseAnalysing.cs b/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.PrefixReverseAnalysing.cs new file mode 100644 index 00000000..51f43bbd --- /dev/null +++ b/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.PrefixReverseAnalysing.cs @@ -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" ); + } + } + + } +} diff --git a/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.cs b/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.cs new file mode 100644 index 00000000..ebb46007 --- /dev/null +++ b/StgSharp.Model/STEP/Reader/ExpSyntaxAnalyzer.cs @@ -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 _cache; + private ExpNode _lastStatement; + private ExpSchema _context; + private IExpElementSource _local; + + public StepExpSyntaxAnalyzer() + { + _cache = new CompileStack(); + } + + public StepExpSyntaxAnalyzer( ExpSchema context, IExpElementSource local ) + { + _cache = new CompileStack(); + ArgumentNullException.ThrowIfNull( context ); + if( context is not ExpSchema_Builtin ) + { + _context = context; + } else + { + throw new InvalidCastException( "Not a valid Schema type" ); + } + _local = local; + } + + /// + /// Append a token to top of cache. This method will automatically convert token to node + /// if meets separators or operators. + /// + 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, + + } + + } +} diff --git a/StgSharp.Model/STEP/Reader/StepDataSectionTokenReader.cs b/StgSharp.Model/STEP/Reader/StepDataSectionTokenReader.cs new file mode 100644 index 00000000..9a2ffcc4 --- /dev/null +++ b/StgSharp.Model/STEP/Reader/StepDataSectionTokenReader.cs @@ -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 _cache = new Queue(); + 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 ); + } + + } +} diff --git a/StgSharp.Model/STEP/Reader/StepDataSectionsTranmitter.cs b/StgSharp.Model/STEP/Reader/StepDataSectionsTranmitter.cs new file mode 100644 index 00000000..93d8ca32 --- /dev/null +++ b/StgSharp.Model/STEP/Reader/StepDataSectionsTranmitter.cs @@ -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 _cache = new ConcurrentQueue(); + 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(); + } + + } +} diff --git a/StgSharp.Model/STEP/Reader/StepExpressParser.cs b/StgSharp.Model/STEP/Reader/StepExpressParser.cs new file mode 100644 index 00000000..f7df989c --- /dev/null +++ b/StgSharp.Model/STEP/Reader/StepExpressParser.cs @@ -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 ) + { + } + + } +} diff --git a/StgSharp.Model/STEP/StepHeader.cs b/StgSharp.Model/STEP/StepHeader.cs new file mode 100644 index 00000000..6dc00213 --- /dev/null +++ b/StgSharp.Model/STEP/StepHeader.cs @@ -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 +{ + /// + /// C# implementation of HEADER part in STEP file. + /// + 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; + } + + } + + /// + /// C# implementation of FILE_NAME part in header of STEP file. + /// + 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 _schema; + + public string Data + { + get; + internal set; + } + + } + + /// + /// C# implementation of FILE_NAME part in header of STEP file. + /// + public struct STEPFileDescriptor + { + + public (int mainLevel,int? subLevel) Level + { + get; + internal set; + } + + public string Description + { + get; + internal set; + } + + } +} diff --git a/StgSharp.Model/STEP/StepModel.cs b/StgSharp.Model/STEP/StepModel.cs new file mode 100644 index 00000000..54524c1c --- /dev/null +++ b/StgSharp.Model/STEP/StepModel.cs @@ -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 _nodes + = new Dictionary(); + 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 node in _nodes ) { } + } + + } +} diff --git a/StgSharp.Model/STEP/StepObjectConstructor.cs b/StgSharp.Model/STEP/StepObjectConstructor.cs new file mode 100644 index 00000000..7a478bb7 --- /dev/null +++ b/StgSharp.Model/STEP/StepObjectConstructor.cs @@ -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( + @"(?.+?(\)|'\s?\)|'))\s?(?,)\s?(?(.|\(|\(\s?').+)", + RegexOptions.Compiled ); + + private readonly int _id; + private readonly List _paramList; + private string _caller; + + public StepObjectConstructor( int id, string caller, string parameters ) + { + _caller = caller; + _paramList = new List(); + SplitParameter( parameters ); + } + + public string this[ int paramIndex ] + { + get => _paramList[ paramIndex ]; + } + + public ReadOnlyCollection 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 ); + } + + } +} diff --git a/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.AssemblyInfo.cs b/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.AssemblyInfo.cs index b616e550..a7df0221 100644 --- a/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.AssemblyInfo.cs +++ b/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")] [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.Model")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/StgSharp.Script/Common/IScriptTokenReader.cs b/StgSharp.Script/Common/IScriptTokenReader.cs new file mode 100644 index 00000000..43186003 --- /dev/null +++ b/StgSharp.Script/Common/IScriptTokenReader.cs @@ -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 ); + + } +} \ No newline at end of file diff --git a/StgSharp.Script/Common/ISyntaxAnalyzer.cs b/StgSharp.Script/Common/ISyntaxAnalyzer.cs new file mode 100644 index 00000000..67f85156 --- /dev/null +++ b/StgSharp.Script/Common/ISyntaxAnalyzer.cs @@ -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 ); + + } +} \ No newline at end of file diff --git a/StgSharp.Script/Express/CompileEnv/DefaultSchema.cs b/StgSharp.Script/Express/CompileEnv/DefaultSchema.cs index d0b96b72..d4c06811 100644 --- a/StgSharp.Script/Express/CompileEnv/DefaultSchema.cs +++ b/StgSharp.Script/Express/CompileEnv/DefaultSchema.cs @@ -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(); diff --git a/StgSharp.Script/Express/ExpAstNode/ExpFunctionCallingNode.cs b/StgSharp.Script/Express/ExpAstNode/ExpFunctionCallingNode.cs index 16f44df2..eb4a2b1b 100644 --- a/StgSharp.Script/Express/ExpAstNode/ExpFunctionCallingNode.cs +++ b/StgSharp.Script/Express/ExpAstNode/ExpFunctionCallingNode.cs @@ -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 ); } diff --git a/StgSharp.Script/Express/ExpAstNode/_ExpNode.cs b/StgSharp.Script/Express/ExpAstNode/_ExpNode.cs index a40e8090..d97eaf19 100644 --- a/StgSharp.Script/Express/ExpAstNode/_ExpNode.cs +++ b/StgSharp.Script/Express/ExpAstNode/_ExpNode.cs @@ -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; diff --git a/StgSharp.Script/Express/ExpElmentSource.cs b/StgSharp.Script/Express/ExpElmentSource.cs index 8b517fa0..7e6edbcc 100644 --- a/StgSharp.Script/Express/ExpElmentSource.cs +++ b/StgSharp.Script/Express/ExpElmentSource.cs @@ -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 ) diff --git a/StgSharp.Script/Express/ExpNodeNextEnumerator.cs b/StgSharp.Script/Express/ExpNodeNextEnumerator.cs index 63dc3bc7..9bb4bdb9 100644 --- a/StgSharp.Script/Express/ExpNodeNextEnumerator.cs +++ b/StgSharp.Script/Express/ExpNodeNextEnumerator.cs @@ -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 { diff --git a/StgSharp.Script/Express/ExpSourceReader.cs b/StgSharp.Script/Express/ExpSourceReader.cs index 37fd9256..7b0d158b 100644 --- a/StgSharp.Script/Express/ExpSourceReader.cs +++ b/StgSharp.Script/Express/ExpSourceReader.cs @@ -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 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.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 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 line ) + public bool TryReadLine(out ReadOnlySpan line) { line = ReadLine(); return line != ReadOnlySpan.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( @"(?[a-zA-Z][a-zA-Z0-9_]*)(?\s*?)(?\S|$)", - RegexOptions.Singleline )] + RegexOptions.Singleline)] private static partial Regex GetNextWordTokenPattern(); [GeneratedRegex( @"(?-?\s*?[0-9]+(?:\.[0-9]*)?E?(?:[+-]?[0-9]+)?)(?\s*?)(?\S|$)", - RegexOptions.Singleline )] + RegexOptions.Singleline)] private static partial Regex GetNumberLiteralPattern(); - [GeneratedRegex( @"(?:\s+?)(?\S|$)", RegexOptions.Singleline )] + [GeneratedRegex(@"(?:\s+?)(?\S|$)", RegexOptions.Singleline)] private static partial Regex GetSkipBlankPattern(); [GeneratedRegex( @"(?"")(?>\\\\|\\""|(?!')[^""])*(?""|$)\s*?(?\S|$)", - RegexOptions.Singleline )] + RegexOptions.Singleline)] private static partial Regex GetStringLiteralPattern(); [GeneratedRegex( @"(?')(?>\\\\|\\'|''|(?!')[^'])*(?')\s*?(?\S|$)", - RegexOptions.Singleline )] + RegexOptions.Singleline)] private static partial Regex GetStringLiteralPatternWithSingle(); [GeneratedRegex( @"(?[:<>=+\-*\/]+)(?\s?)\s*?(?\S|$)", - RegexOptions.Singleline )] + RegexOptions.Singleline)] private static partial Regex GetSymbolPattern(); } diff --git a/StgSharp.Script/Express/ExpSyntaxAnalyzer.cs b/StgSharp.Script/Express/ExpSyntaxAnalyzer.cs index 29d9b7a3..b09b52ba 100644 --- a/StgSharp.Script/Express/ExpSyntaxAnalyzer.cs +++ b/StgSharp.Script/Express/ExpSyntaxAnalyzer.cs @@ -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(); + } + /// /// Append a token to top of cache. This method will automatically convert token to node /// if meets separators or operators. /// - 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 ); diff --git a/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs b/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs index dc76c632..35150b6f 100644 --- a/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs +++ b/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs @@ -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")]