add from giga-device, new branch added
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpBuiltinType.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.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
internal sealed class ExpBuiltinType : ExpTypeSource
|
||||
{
|
||||
|
||||
private Type _marshalType;
|
||||
|
||||
internal ExpBuiltinType( string name, Type origin )
|
||||
: base( name, ScriptSourceTransmitter.Empty )
|
||||
{
|
||||
_marshalType = origin;
|
||||
}
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//A method convert value to CLR type
|
||||
//Used for direct running rather than compiling to C# code.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpCollection.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;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public abstract class ExpCollectionBase : ExpInstantiableElement, IEnumerable<ExpElementInstance>
|
||||
{
|
||||
|
||||
protected internal string _accurateType;
|
||||
|
||||
protected ExpCollectionBase( string accurateType )
|
||||
{
|
||||
_accurateType = accurateType;
|
||||
}
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Collection;
|
||||
|
||||
public abstract int Count { get; }
|
||||
|
||||
public override sealed IScriptSourceProvider SourceProvider => ScriptSourceTransmitter.Empty;
|
||||
|
||||
public string MemberType
|
||||
{
|
||||
get => _accurateType;
|
||||
}
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public abstract IEnumerator<ExpElementInstance> GetEnumerator();
|
||||
|
||||
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
|
||||
{
|
||||
memberNode = ExpSyntaxNode.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpArray : ExpCollectionBase
|
||||
{
|
||||
|
||||
private ExpElementInstance[] _collection;
|
||||
|
||||
public ExpArray( string accurateType ) : base( accurateType ) { }
|
||||
|
||||
public ExpElementInstance this[ int index ]
|
||||
{
|
||||
get { return _collection[ index ]; }
|
||||
set
|
||||
{
|
||||
if( value.TypeName != MemberType ) {
|
||||
throw new ExpInvalidCollectionMemberTypeException( value, this );
|
||||
}
|
||||
_collection[ index ] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override int Count => _collection.Length;
|
||||
|
||||
public override string Name => ExpressCompile.PoolString( "ARRAY" );
|
||||
|
||||
public override ExpSyntaxNode CreateInstanceNode( Token t )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerator<ExpElementInstance> GetEnumerator()
|
||||
{
|
||||
return ( ( IEnumerable<ExpElementInstance> )_collection )
|
||||
.GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpBag : ExpCollectionBase
|
||||
{
|
||||
|
||||
private ConcurrentBag<ExpElementInstance> _collection = new ConcurrentBag<ExpElementInstance>(
|
||||
);
|
||||
|
||||
public ExpBag( string accurateType ) : base( accurateType ) { }
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override string Name => ExpressCompile.PoolString( "BAG" );
|
||||
|
||||
public override ExpSyntaxNode CreateInstanceNode( Token t )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerator<ExpElementInstance> GetEnumerator()
|
||||
{
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpList : ExpCollectionBase
|
||||
{
|
||||
|
||||
private List<ExpElementInstance> _collection = new List<ExpElementInstance>();
|
||||
|
||||
public ExpList( string accurateType ) : base( accurateType ) { }
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override string Name => ExpressCompile.PoolString( "LIST" );
|
||||
|
||||
public override ExpSyntaxNode CreateInstanceNode( Token t )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerator<ExpElementInstance> GetEnumerator()
|
||||
{
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpSet : ExpCollectionBase
|
||||
{
|
||||
|
||||
private HashSet<ExpElementInstance> _collection = new();
|
||||
|
||||
public ExpSet( string accurateType ) : base( accurateType ) { }
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override string Name => ExpressCompile.PoolString( "SET" );
|
||||
|
||||
public void Add( ExpElementInstance token )
|
||||
{
|
||||
if( token.TypeName != MemberType ) {
|
||||
throw new ExpInvalidCollectionMemberTypeException( token, this );
|
||||
}
|
||||
_collection.Add( token );
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode CreateInstanceNode( Token t )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override sealed IEnumerator<ExpElementInstance> GetEnumerator()
|
||||
{
|
||||
return ( ( IEnumerable<ExpElementInstance> )_collection )
|
||||
.GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpCollectionInstance.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.Script.Express
|
||||
{
|
||||
public abstract class ExpCollectionInstanceBase : ExpSyntaxNode
|
||||
{
|
||||
|
||||
protected internal (int min, int max) _range;
|
||||
protected internal ExpElementType _memberType;
|
||||
|
||||
protected ExpCollectionInstanceBase( Token source ) : base( source ) { }
|
||||
|
||||
public abstract ExpCollectionBase CollectionValue { get; }
|
||||
|
||||
public ExpElementType MemberType
|
||||
{
|
||||
get => _memberType;
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => null!;
|
||||
|
||||
public override ExpSyntaxNode Right => null!;
|
||||
|
||||
public int MinCapacity => _range.min;
|
||||
|
||||
public int MaxCapacity => _range.max;
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpSetInstance : ExpCollectionInstanceBase
|
||||
{
|
||||
|
||||
private ExpSet _collection;
|
||||
|
||||
public ExpSetInstance( Token source, ExpSet set )
|
||||
: base( source )
|
||||
{
|
||||
_collection = set;
|
||||
}
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpBagInstance : ExpCollectionInstanceBase
|
||||
{
|
||||
|
||||
private ExpBag _collection;
|
||||
|
||||
public ExpBagInstance( Token source, ExpBag bag )
|
||||
: base( source )
|
||||
{
|
||||
_collection = bag;
|
||||
}
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpListInstance : ExpCollectionInstanceBase
|
||||
{
|
||||
|
||||
private ExpList _collection;
|
||||
|
||||
public ExpListInstance( Token source, ExpList list )
|
||||
: base( source )
|
||||
{
|
||||
_collection = list;
|
||||
}
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpArrayInstance : ExpCollectionInstanceBase
|
||||
{
|
||||
|
||||
private ExpArray _collection;
|
||||
|
||||
public ExpArrayInstance( Token source, ExpArray array )
|
||||
: base( source )
|
||||
{
|
||||
_collection = array;
|
||||
}
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpInstantiableElement EqualityTypeConvert => _collection;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpLogic.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.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public enum ExpLogicValue
|
||||
{
|
||||
|
||||
True,
|
||||
False,
|
||||
Unknown
|
||||
|
||||
}
|
||||
|
||||
public struct ExpLogic
|
||||
{
|
||||
|
||||
public static readonly ExpLogic False = new ExpLogic( ExpLogicValue.False );
|
||||
|
||||
public static readonly ExpLogic True = new ExpLogic( ExpLogicValue.True );
|
||||
public static readonly ExpLogic Unknown = new ExpLogic( ExpLogicValue.Unknown );
|
||||
|
||||
private readonly ExpLogicValue _value;
|
||||
|
||||
public ExpLogic( ExpLogicValue value )
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public bool IsTrue => _value == ExpLogicValue.True;
|
||||
|
||||
public bool IsFalse => _value == ExpLogicValue.False;
|
||||
|
||||
public bool IsUnknown => _value == ExpLogicValue.Unknown;
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public bool ToBoolean()
|
||||
{
|
||||
return _value == ExpLogicValue.True;
|
||||
}
|
||||
|
||||
public override string ToString() => _value.ToString();
|
||||
|
||||
public static bool TryParse( ReadOnlySpan<char> value, out ExpLogic result )
|
||||
{
|
||||
if( Enum.TryParse<ExpLogicValue>( value, out ExpLogicValue e ) )
|
||||
{
|
||||
result = new ExpLogic( e );
|
||||
return true;
|
||||
}
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
// NOT !
|
||||
public static ExpLogic operator !( ExpLogic a )
|
||||
{
|
||||
return a.IsTrue ? False : a.IsFalse ? True : Unknown;
|
||||
}
|
||||
|
||||
// AND &
|
||||
public static ExpLogic operator &( ExpLogic a, ExpLogic b )
|
||||
{
|
||||
if( a.IsFalse || b.IsFalse ) {
|
||||
return False;
|
||||
}
|
||||
|
||||
if( a.IsUnknown || b.IsUnknown ) {
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
// XOR ^
|
||||
public static ExpLogic operator ^( ExpLogic a, ExpLogic b )
|
||||
{
|
||||
if( a.IsUnknown || b.IsUnknown ) {
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
return ( a.IsTrue ^ b.IsTrue ) ? True : False;
|
||||
}
|
||||
|
||||
// OR |
|
||||
public static ExpLogic operator |( ExpLogic a, ExpLogic b )
|
||||
{
|
||||
if( a.IsTrue || b.IsTrue ) {
|
||||
return True;
|
||||
}
|
||||
|
||||
if( a.IsUnknown || b.IsUnknown ) {
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="BuiltinType.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.Script.Express
|
||||
{
|
||||
public static partial class ExpressCompile
|
||||
{
|
||||
|
||||
public static ExpTypeSource ExpInt { get; private set; }
|
||||
|
||||
public static ExpTypeSource ExpReal { get; private set; }
|
||||
|
||||
public static ExpTypeSource ExpBool { get; private set; }
|
||||
|
||||
public static ExpTypeSource ExpString { get; private set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="DefaultSchema.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;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using static StgSharp.Script.Express.ExpressCompile;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public sealed partial class ExpSchema_Builtin : ExpSchema
|
||||
{
|
||||
|
||||
private static readonly ExpSchema_Builtin _onlyInstance = new ExpSchema_Builtin();
|
||||
|
||||
private ExpSchema_Builtin()
|
||||
: base()
|
||||
{
|
||||
Name = "Nitload";
|
||||
}
|
||||
|
||||
internal static ExpSchema_Builtin Only
|
||||
{
|
||||
get => _onlyInstance;
|
||||
}
|
||||
|
||||
public override void LoadFromSource( ExpSchemaSource source )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public override bool TryGetConst( string name, out ExpElementInstance c )
|
||||
{
|
||||
return ConstDict.TryGetValue( name, out c );
|
||||
}
|
||||
|
||||
public override bool TryGetEntity( string name, out ExpEntitySource e )
|
||||
{
|
||||
e = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetFunction( string name, out ExpFunctionSource f )
|
||||
{
|
||||
return FunctionDict.TryGetValue( name, out f! );
|
||||
}
|
||||
|
||||
public override bool TryGetProcedure( string name, out ExpProcedureSource p )
|
||||
{
|
||||
return ProcedureDict.TryGetValue( name, out p! );
|
||||
}
|
||||
|
||||
public override bool TryGetRule( string name, out ExpRuleSource r )
|
||||
{
|
||||
r = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetSchemaInclude( string name, out ExpSchema include )
|
||||
{
|
||||
include = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetType( string name, out ExpTypeSource t )
|
||||
{
|
||||
return TypeDict.TryGetValue( name, out t );
|
||||
}
|
||||
|
||||
internal void Init()
|
||||
{
|
||||
IEnumerable<KeyValuePair<string, ExpTypeSource>> builtinTypeSource = [
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( Keyword.Integer ),
|
||||
new ExpBuiltinType( Keyword.Integer, typeof( int ) ) ),
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( Keyword.Real ), new ExpBuiltinType( Keyword.Real, typeof( float ) ) ),
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( Keyword.Boolean ),
|
||||
new ExpBuiltinType( Keyword.Boolean, typeof( bool ) ) ),
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( Keyword.Logical ),
|
||||
new ExpBuiltinType( Keyword.Logical, typeof( ExpLogic ) ) ),
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( Keyword.String ),
|
||||
new ExpBuiltinType( Keyword.String, typeof( string ) ) ),
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( Keyword.Binary ),
|
||||
new ExpBuiltinType( Keyword.Binary, typeof( BitArray ) ) ),
|
||||
|
||||
];
|
||||
TypeDict = new Dictionary<string, ExpTypeSource>( builtinTypeSource,
|
||||
Multiplexer ).ToFrozenDictionary();
|
||||
|
||||
|
||||
ConstDict = new Dictionary<string, ExpElementInstance>( Multiplexer ) {
|
||||
{ PoolString( "PI" ), new ExpRealNumberNode(
|
||||
new Token( PoolString( "PI" ), -1, -1, TokenFlag.Number ), MathF.PI, true ) },
|
||||
{ PoolString( "E" ), new ExpRealNumberNode(
|
||||
new Token( PoolString( "E" ), -1, -1, TokenFlag.Number ), MathF.E, true ) },
|
||||
}.ToFrozenDictionary();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpCompile.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 CommunityToolkit.HighPerformance.Buffers;
|
||||
|
||||
using StgSharp.Collections;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public static partial class ExpressCompile
|
||||
{
|
||||
|
||||
private static string[] _operatorsWithLetter;
|
||||
private static ConcurrentStringHashMultiplexer _multiplexer;
|
||||
private static FrozenDictionary<string, ExpElementInstance> _builtinConst;
|
||||
private static FrozenDictionary<string, ExpTypeSource> _builtinType;
|
||||
private static FrozenDictionary<string, ExpBinaryOperatorNode> _operators;
|
||||
private static StringPool _compileStringCache,_emptyCache;
|
||||
|
||||
internal static ConcurrentStringHashMultiplexer Multiplexer
|
||||
{
|
||||
get
|
||||
{
|
||||
if( _multiplexer == null ) {
|
||||
throw new ExpCompileNotInitializedException();
|
||||
}
|
||||
return _multiplexer;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearStringCache()
|
||||
{
|
||||
_compileStringCache.Reset();
|
||||
}
|
||||
|
||||
public static void DeinitCompile()
|
||||
{
|
||||
_compileStringCache.Reset();
|
||||
_compileStringCache = null!;
|
||||
|
||||
_multiplexer.Dispose();
|
||||
_multiplexer = null!;
|
||||
}
|
||||
|
||||
public static void InitCompile()
|
||||
{
|
||||
_compileStringCache = new StringPool();
|
||||
_multiplexer = new ConcurrentStringHashMultiplexer();
|
||||
|
||||
ExpSchema_Builtin.Only.Init();
|
||||
|
||||
PoolKeywords();
|
||||
InitPrecedence();
|
||||
|
||||
_operatorsWithLetter = [
|
||||
Keyword.Add,
|
||||
Keyword.Sub,
|
||||
Keyword.Mul,
|
||||
Keyword.Div,
|
||||
Keyword.And,
|
||||
Keyword.Or,
|
||||
Keyword.Xor,
|
||||
Keyword.AndOr,
|
||||
Keyword.Not,
|
||||
];
|
||||
|
||||
ExpSchema_Builtin.Only
|
||||
.TryGetType(
|
||||
PoolString( Keyword.Integer ), out ExpTypeSource? _expInt );
|
||||
ExpInt = _expInt;
|
||||
|
||||
ExpSchema_Builtin.Only
|
||||
.TryGetType( PoolString( Keyword.Real ), out ExpTypeSource? _expReal );
|
||||
ExpReal = _expReal;
|
||||
ExpSchema_Builtin.Only
|
||||
.TryGetType(
|
||||
PoolString( Keyword.Boolean ), out ExpTypeSource? _expBool );
|
||||
ExpBool = _expBool;
|
||||
|
||||
ExpSchema_Builtin.Only
|
||||
.TryGetType(
|
||||
PoolString( Keyword.Boolean ), out ExpTypeSource? _expString );
|
||||
ExpString = _expString;
|
||||
|
||||
|
||||
_emptyCache = new StringPool();
|
||||
/*
|
||||
foreach( string str in _compileStringCache ) {
|
||||
_emptyCache.Add( str );
|
||||
}
|
||||
/**/
|
||||
}
|
||||
|
||||
public static bool LetterIsKeyword( string str )
|
||||
{
|
||||
if( char.IsLetter( str[ 0 ] ) ) {
|
||||
return _keywordSet.Contains( str );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool LetterIsOperator( string str )
|
||||
{
|
||||
if( char.IsLetter( str[ 0 ] ) ) {
|
||||
return Array.IndexOf( _operatorsWithLetter, str ) != -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string PoolString( string str )
|
||||
{
|
||||
return _compileStringCache.GetOrAdd( str );
|
||||
}
|
||||
|
||||
public static string PoolString( ReadOnlySpan<char> str )
|
||||
{
|
||||
return _compileStringCache.GetOrAdd( str );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpOperatorPrecedence.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.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public static partial class ExpressCompile
|
||||
{
|
||||
|
||||
public static bool TryGetOperatorPrecedence( string operatorName, out int precedence )
|
||||
{
|
||||
return _operatorPrecedence.TryGetValue( operatorName, out precedence );
|
||||
}
|
||||
|
||||
public static bool TryGetSuperTypeOperatorPrecedence(
|
||||
string operatorName,
|
||||
out int precedence )
|
||||
{
|
||||
return _superTypeOperatorPrecedent.TryGetValue( operatorName, out precedence );
|
||||
}
|
||||
|
||||
private static void InitPrecedence()
|
||||
{
|
||||
KeyValuePair<string, int>[] source = [
|
||||
new KeyValuePair<string, int>( PoolString( "[" ), 1 ),
|
||||
new KeyValuePair<string, int>( PoolString( "." ), 1 ),
|
||||
new KeyValuePair<string, int>( PoolString( "\\" ), 1 ),
|
||||
new KeyValuePair<string, int>( PoolString( "unary+" ), 2 ),
|
||||
new KeyValuePair<string, int>( PoolString( "unary-" ), 2 ),
|
||||
new KeyValuePair<string, int>( PoolString( "NOT" ), 2 ),
|
||||
new KeyValuePair<string, int>( PoolString( "**" ), 3 ),
|
||||
new KeyValuePair<string, int>( PoolString( "*" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "/" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "AND" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "MOD" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "DIV" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "||" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "+" ), 5 ),
|
||||
new KeyValuePair<string, int>( PoolString( "-" ), 5 ),
|
||||
new KeyValuePair<string, int>( PoolString( "OR" ), 5 ),
|
||||
new KeyValuePair<string, int>( PoolString( "XOR" ), 5 ),
|
||||
new KeyValuePair<string, int>( PoolString( "=" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( "<>" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( "<=" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( ">=" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( ">" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( "<" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( ":=:" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( ":<>:" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( "IN" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( "LIKE" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( Keyword.Assignment ), 7 )
|
||||
];
|
||||
_operatorPrecedence = new Dictionary<string, int>( source,
|
||||
_multiplexer ).ToFrozenDictionary();
|
||||
source = [
|
||||
new KeyValuePair<string, int>( "ONEOF", 1 ),
|
||||
new KeyValuePair<string, int>( "AND", 2 ),
|
||||
new KeyValuePair<string, int>( "ANDOR", 3 ),
|
||||
];
|
||||
_superTypeOperatorPrecedent = new Dictionary<string, int>( source,
|
||||
_multiplexer ).ToFrozenDictionary(
|
||||
);
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618
|
||||
private static FrozenDictionary<string, int> _superTypeOperatorPrecedent;
|
||||
private static FrozenDictionary<string, int> _operatorPrecedence;
|
||||
#pragma warning restore CS8618
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="KeyWord.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.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public static partial class ExpressCompile
|
||||
{
|
||||
|
||||
private static HashSet<string> _keywordSet;
|
||||
|
||||
private static void PoolKeywords()
|
||||
{
|
||||
_keywordSet = new();
|
||||
|
||||
FieldInfo[] fields = typeof( Keyword ).GetFields( BindingFlags.Public );
|
||||
ParallelLoopResult result = Parallel.ForEach(
|
||||
fields, static( field ) => {
|
||||
if( field.FieldType == typeof( string ) && field.GetValue( null ) is string str )
|
||||
{
|
||||
_compileStringCache.GetOrAdd( str );
|
||||
_keywordSet.Add( str );
|
||||
}
|
||||
} );
|
||||
while( !result.IsCompleted ) { }
|
||||
}
|
||||
|
||||
public static class Keyword
|
||||
{
|
||||
|
||||
public static HashSet<string> ScopeBlock = new HashSet<string> {
|
||||
EndAlias, EndCase, EndConstant, EndEntity, EndFunction, EndIf, EndLocal, EndProcedure, EndRepeat, EndRule, EndSchema, EndSubtypeConstraint, EndType
|
||||
};
|
||||
|
||||
public static HashSet<string> Symbols = [
|
||||
Dot, Comma, Semicolon, Colon, Percent, Apostrophe,
|
||||
Backslash, IndexOf, RightBracket, LeftBrace,
|
||||
RightBrace, Pipe, LeftParen, RightParen, LeftAsterisk,
|
||||
Assignment, DoublePipe, ExpSymbol, CommentSingleLine,
|
||||
CommentStart, CommentEnd, InstanceEqual, InstanceNotEqual
|
||||
];
|
||||
|
||||
public static HashSet<string> DataTypes { get; } = [
|
||||
Array, Bag, Binary, Boolean, Enumeration, Integer, List, Logical, Number, Of, Real, Set, String
|
||||
];
|
||||
|
||||
public static HashSet<string> InternalProcess { get; } = [
|
||||
Insert, Remove
|
||||
];
|
||||
|
||||
public static HashSet<string> BuiltinFunctions { get; } = [
|
||||
Abs, Acos, Asin, Atan, BLength, Cos, Exists, Exp,
|
||||
Format, HiBound, HiIndex, Length, LoBound, Log,
|
||||
Log2, Log10, LoIndex, Nvl, Odd, Rolesof, Sin,
|
||||
Sizeof, Sqrt, Tan, Typeof, Usedin, Value,
|
||||
ValueIn, ValueUnique
|
||||
];
|
||||
|
||||
public static HashSet<string> Literals { get; } = [
|
||||
QuestionMark, Self, Const, E, Pi, False, True, Unknown
|
||||
];
|
||||
|
||||
public static HashSet<string> Operators { get; } = [
|
||||
And, AndOr, Div, In, Like, Mod, Not, Or, Xor,
|
||||
Add, Sub, Mul, Slash, Equal, NotEqual,
|
||||
LessThan, GreaterThan, LessThanOrEqual, GreaterThanOrEqual
|
||||
];
|
||||
|
||||
public static HashSet<string> Aliasing { get; } = [
|
||||
Alias, Renamed
|
||||
];
|
||||
|
||||
public static HashSet<string> ModifiersAttributes { get; } = [
|
||||
Abstract, Aggregate, As, BasedOn, By, Escape, Fixed, From, Use, With
|
||||
];
|
||||
|
||||
public static HashSet<string> QueryReference { get; } = [
|
||||
Query, Reference, Select
|
||||
];
|
||||
|
||||
public static HashSet<string> ConstraintsInheritance { get; } = [
|
||||
Oneof, Optional, Subtype, SubtypeConstraint, Supertype, TotalOver, Unique, Where
|
||||
];
|
||||
|
||||
public static HashSet<string> Declarations { get; } = [
|
||||
Constant, Derive, Entity, Extensible, Fixed, Function, Generic,
|
||||
GenericEntity, Inverse, Local, Procedure, Rule, Schema, Type, Var
|
||||
];
|
||||
|
||||
public static HashSet<string> FlowControl { get; } = [
|
||||
Begin, Case, Else, End, For, If, Otherwise, Repeat, Return, Skip, Then, To, Until, While
|
||||
];
|
||||
|
||||
#region Basic Data Type
|
||||
|
||||
public const string Array = "ARRAY";
|
||||
public const string Bag = "BAG";
|
||||
public const string Binary = "BINARY";
|
||||
public const string Boolean = "BOOLEAN";
|
||||
public const string Enumeration = "ENUMERATION";
|
||||
public const string Integer = "INTEGER";
|
||||
public const string List = "LIST";
|
||||
public const string Logical = "LOGICAL";
|
||||
public const string Number = "NUMBER";
|
||||
public const string Of = "OF";
|
||||
public const string Real = "REAL";
|
||||
public const string Set = "SET";
|
||||
public const string String = "STRING";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Flow Control
|
||||
|
||||
public const string Begin = "BEGIN";
|
||||
public const string Case = "CASE";
|
||||
public const string Else = "ELSE";
|
||||
public const string End = "END";
|
||||
public const string For = "FOR";
|
||||
public const string If = "IF";
|
||||
public const string Otherwise = "OTHERWISE";
|
||||
public const string Repeat = "REPEAT";
|
||||
public const string Return = "RETURN";
|
||||
public const string Skip = "SKIP";
|
||||
public const string Then = "THEN";
|
||||
public const string To = "TO";
|
||||
public const string Until = "UNTIL";
|
||||
public const string While = "WHILE";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Declarations
|
||||
|
||||
public const string Constant = "CONSTANT";
|
||||
public const string Derive = "DERIVE";
|
||||
public const string Entity = "ENTITY";
|
||||
public const string Extensible = "EXTENSIBLE";
|
||||
public const string Fixed = "FIXED";
|
||||
public const string Function = "FUNCTION";
|
||||
public const string Generic = "GENERIC";
|
||||
public const string GenericEntity = "GENERIC_ENTITY";
|
||||
public const string Inverse = "INVERSE";
|
||||
public const string Local = "LOCAL";
|
||||
public const string Procedure = "PROCEDURE";
|
||||
public const string Rule = "RULE";
|
||||
public const string Schema = "SCHEMA";
|
||||
public const string Type = "TYPE";
|
||||
public const string Var = "VAR";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constraints Inheritance
|
||||
|
||||
public const string Oneof = "ONEOF";
|
||||
public const string Optional = "OPTIONAL";
|
||||
public const string Subtype = "SUBTYPE";
|
||||
public const string SubtypeConstraint = "SUBTYPE CONSTRAINT";
|
||||
public const string Supertype = "SUPERTYPE";
|
||||
public const string TotalOver = "TOTAL OVER";
|
||||
public const string Unique = "UNIQUE";
|
||||
public const string Where = "WHERE";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Scope
|
||||
|
||||
public const string EndAlias = "END_ALIAS";
|
||||
public const string EndCase = "END_CASE";
|
||||
public const string EndConstant = "END_CONSTANT";
|
||||
public const string EndEntity = "END_ENTITY";
|
||||
public const string EndFunction = "END_FUNCTION";
|
||||
public const string EndIf = "END_IF";
|
||||
public const string EndLocal = "END_LOCAL";
|
||||
public const string EndProcedure = "END_PROCEDURE";
|
||||
public const string EndRepeat = "END_REPEAT";
|
||||
public const string EndRule = "END_RULE";
|
||||
public const string EndSchema = "END_SCHEMA";
|
||||
public const string EndSubtypeConstraint = "END_SUBTYPE CONSTRAINT";
|
||||
public const string EndType = "END_TYPE";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Index and Ref
|
||||
|
||||
public const string Query = "QUERY";
|
||||
public const string Reference = "REFERENCE";
|
||||
public const string Select = "SELECT";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Modifiers Attributes
|
||||
|
||||
public const string Abstract = "ABSTRACT";
|
||||
public const string Aggregate = "AGGREGATE";
|
||||
public const string As = "AS";
|
||||
public const string BasedOn = "BASED ON";
|
||||
public const string By = "BY";
|
||||
public const string Escape = "ESCAPE";
|
||||
public const string From = "FROM";
|
||||
public const string Use = "USE";
|
||||
public const string With = "WITH";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Aliasing
|
||||
|
||||
public const string Alias = "ALIAS";
|
||||
public const string Renamed = "RENAMED";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operator
|
||||
|
||||
public const string And = "AND";
|
||||
public const string AndOr = "ANDOR";
|
||||
public const string Div = "DIV";
|
||||
public const string In = "IN";
|
||||
public const string Like = "LIKE";
|
||||
public const string Mod = "MOD";
|
||||
public const string Not = "NOT";
|
||||
public const string Or = "OR";
|
||||
public const string Xor = "XOR";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constants
|
||||
|
||||
public const string QuestionMark = "?";
|
||||
public const string Self = "SELF";
|
||||
public const string Const = "CONST";
|
||||
public const string E = "E";
|
||||
public const string Pi = "PI";
|
||||
public const string False = "FALSE";
|
||||
public const string True = "TRUE";
|
||||
public const string Unknown = "UNKNOWN";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Functions
|
||||
|
||||
public const string Abs = "ABS";
|
||||
public const string Acos = "ACOS";
|
||||
public const string Asin = "ASIN";
|
||||
public const string Atan = "ATAN";
|
||||
public const string BLength = "BLENGTH";
|
||||
public const string Cos = "COS";
|
||||
public const string Exists = "EXISTS";
|
||||
public const string Exp = "EXP";
|
||||
public const string Format = "FORMAT";
|
||||
public const string HiBound = "HIBOUND";
|
||||
public const string HiIndex = "HIINDEX";
|
||||
public const string Length = "LENGTH";
|
||||
public const string LoBound = "LObound";
|
||||
public const string Log = "LOG";
|
||||
public const string Log2 = "LOG2";
|
||||
public const string Log10 = "LOG10";
|
||||
public const string LoIndex = "LOINDEX";
|
||||
public const string Nvl = "NVL";
|
||||
public const string Odd = "ODD";
|
||||
public const string Rolesof = "ROLESOF";
|
||||
public const string Sin = "SIN";
|
||||
public const string Sizeof = "SIZEOF";
|
||||
public const string Sqrt = "SQRT";
|
||||
public const string Tan = "TAN";
|
||||
public const string Typeof = "TYPEOF";
|
||||
public const string Usedin = "USEDIN";
|
||||
public const string Value = "VALUE";
|
||||
public const string ValueIn = "VALUE IN";
|
||||
public const string ValueUnique = "VALUE UNIQUE";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Procedure
|
||||
|
||||
public const string Insert = "INSERT";
|
||||
public const string Remove = "REMOVE";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Symbols
|
||||
|
||||
public const string Dot = ".";
|
||||
public const string Comma = ",";
|
||||
public const string Semicolon = ";";
|
||||
public const string Colon = ":";
|
||||
public const string Mul = "*";
|
||||
public const string Add = "+";
|
||||
public const string UnaryPlus = "+";
|
||||
public const string Sub = "-";
|
||||
public const string UnaryMinus = "-";
|
||||
public const string Equal = "=";
|
||||
public const string Percent = "%";
|
||||
public const string Apostrophe = "'";
|
||||
public const string Backslash = "\\";
|
||||
public const string Slash = "/";
|
||||
public const string LessThan = "<";
|
||||
public const string GreaterThan = ">";
|
||||
public const string IndexOf = "[";
|
||||
public const string LeftBracket = "[";
|
||||
public const string RightBracket = "]";
|
||||
public const string LeftBrace = "{";
|
||||
public const string RightBrace = "}";
|
||||
public const string Pipe = "|";
|
||||
public const string EConstant = "E";
|
||||
public const string LeftParen = "(";
|
||||
public const string RightParen = ")";
|
||||
public const string LessThanOrEqual = "<=";
|
||||
public const string NotEqual = "<>";
|
||||
public const string GreaterThanOrEqual = ">=";
|
||||
public const string LeftAsterisk = "<*";
|
||||
public const string Assignment = ":=";
|
||||
public const string DoublePipe = "||";
|
||||
public const string ExpSymbol = "**";
|
||||
public const string CommentSingleLine = "--";
|
||||
public const string CommentStart = "(*";
|
||||
public const string CommentEnd = "*)";
|
||||
public const string InstanceEqual = ":=:";
|
||||
public const string InstanceNotEqual = ":<>:";
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpConst.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;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public sealed class ExpConstantCollectionSource : ExpImmutableElement
|
||||
{
|
||||
|
||||
private Dictionary<string, ExpElementInstance> _constants;
|
||||
private IScriptSourceProvider _sourceProvider;
|
||||
|
||||
public ExpConstantCollectionSource( IScriptSourceProvider sourceProvider )
|
||||
{
|
||||
_sourceProvider = sourceProvider;
|
||||
_constants = new Dictionary<string, ExpElementInstance>( ExpressCompile.Multiplexer );
|
||||
}
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Const;
|
||||
|
||||
public override IScriptSourceProvider SourceProvider => _sourceProvider;
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get => ExpressCompile.Keyword.Constant;
|
||||
}
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode MakeReference( params object[] options )
|
||||
{
|
||||
if( options.Length == 0 || options[ 0 ] is not string str ) {
|
||||
return null!;
|
||||
}
|
||||
if( _constants.Count == 0 ) {
|
||||
return null!;
|
||||
}
|
||||
if( _constants.TryGetValue( str, out ExpElementInstance? token ) ) {
|
||||
return token;
|
||||
}
|
||||
return null!;
|
||||
}
|
||||
|
||||
public bool TryGetConstant( string name, out ExpElementInstance instance )
|
||||
{
|
||||
return _constants.TryGetValue( name, out instance );
|
||||
}
|
||||
|
||||
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
|
||||
{
|
||||
if( _constants.TryGetValue( name, out ExpElementInstance? node ) )
|
||||
{
|
||||
memberNode = node;
|
||||
return true;
|
||||
}
|
||||
memberNode = ExpSyntaxNode.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void AddConstant( string name, ExpElementInstance value )
|
||||
{
|
||||
_constants.Add( name, value );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpEntity.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.Script.Express
|
||||
{
|
||||
public class ExpEntitySource : ExpInstantiableElement
|
||||
{
|
||||
|
||||
private AbstractSyntaxTree<ExpSyntaxNode, IExpElementSource> _expressionTree;
|
||||
private ScriptSourceTransmitter _source;
|
||||
private string _name;
|
||||
|
||||
public ExpEntitySource( string name, ScriptSourceTransmitter provider )
|
||||
{
|
||||
_name = name;
|
||||
_source = provider;
|
||||
}
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Entity;
|
||||
|
||||
public override IScriptSourceProvider SourceProvider => _source;
|
||||
|
||||
public override string Name => _name;
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode CreateInstanceNode( Token t )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpFunction.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.Script.Express
|
||||
{
|
||||
public class ExpFunctionSource : ExpImmutableElement
|
||||
{
|
||||
|
||||
private ScriptSourceTransmitter _transmitter;
|
||||
private string _name;
|
||||
|
||||
public ExpFunctionSource( string name, ScriptSourceTransmitter transmitter )
|
||||
{
|
||||
_name = name;
|
||||
_transmitter = transmitter;
|
||||
}
|
||||
|
||||
public Dictionary<string, ExpElementInstance> FuncParams { get; init; } = new Dictionary<string, ExpElementInstance>(
|
||||
);
|
||||
|
||||
public Dictionary<string, ExpElementInstance> LocalVariables { get; init; } = new Dictionary<string, ExpElementInstance>(
|
||||
);
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Function;
|
||||
|
||||
public ExpInstantiableElement ReturningType { get; protected set; }
|
||||
|
||||
public override IScriptSourceProvider SourceProvider => _transmitter;
|
||||
|
||||
public override string Name => _name;
|
||||
|
||||
public string CallingFormat { get; private set; }
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
/*
|
||||
* generate parameter list,
|
||||
* generate C# code
|
||||
* generate calling syntax
|
||||
*/
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode MakeReference( params object[] options )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
|
||||
{
|
||||
if( FuncParams.TryGetValue( name, out ExpElementInstance? param ) )
|
||||
{
|
||||
memberNode = param;
|
||||
return true;
|
||||
}
|
||||
if( LocalVariables.TryGetValue( name, out ExpElementInstance? variable ) )
|
||||
{
|
||||
memberNode = variable;
|
||||
return true;
|
||||
}
|
||||
memberNode = ExpSyntaxNode.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpProcedureSource.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.Script.Express
|
||||
{
|
||||
public class ExpProcedureSource : ExpImmutableElement
|
||||
{
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Procedure;
|
||||
|
||||
public override IScriptSourceProvider SourceProvider => throw new NotImplementedException();
|
||||
|
||||
public override string Name => throw new NotImplementedException();
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode MakeReference( params object[] options )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpRule.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.Data;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpRule : ExpElementInstance
|
||||
{
|
||||
|
||||
private ExpRuleSource _source;
|
||||
|
||||
public ExpRule( Token source ) : base( source ) { }
|
||||
|
||||
public object? value => throw new NotImplementedException();
|
||||
|
||||
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
public override ExpSyntaxNode Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpSyntaxNode Right => throw new NotImplementedException();
|
||||
|
||||
public override string TypeName => _source.Name;
|
||||
|
||||
}
|
||||
|
||||
public class ExpRuleSource : ExpImmutableElement
|
||||
{
|
||||
|
||||
private ScriptSourceTransmitter _transmitter;
|
||||
private string _name;
|
||||
|
||||
public ExpRuleSource( string name, ScriptSourceTransmitter transmitter )
|
||||
{
|
||||
_name = name;
|
||||
_transmitter = transmitter;
|
||||
}
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Rule;
|
||||
|
||||
public override IScriptSourceProvider SourceProvider => _transmitter;
|
||||
|
||||
public override string Name => _name;
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode MakeReference( params object[] options )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
|
||||
{
|
||||
memberNode = ExpSyntaxNode.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpType.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.Generic;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpTypeSource : ExpInstantiableElement
|
||||
{
|
||||
|
||||
private ScriptSourceTransmitter _transmitter;
|
||||
private string _name;
|
||||
protected bool _isBuiltinType;
|
||||
|
||||
protected ExpTypeSource( string name )
|
||||
{
|
||||
_name = name;
|
||||
_transmitter = ScriptSourceTransmitter.Empty;
|
||||
_isBuiltinType = true;
|
||||
}
|
||||
|
||||
public ExpTypeSource( string name, ScriptSourceTransmitter transmitter )
|
||||
{
|
||||
_name = name;
|
||||
_transmitter = transmitter;
|
||||
_isBuiltinType = false;
|
||||
}
|
||||
|
||||
public bool IsLanguageBuiltinType
|
||||
{
|
||||
get => _isBuiltinType;
|
||||
}
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Type;
|
||||
|
||||
public static ExpTypeSource Void
|
||||
{
|
||||
get => ExpVoidType.Only;
|
||||
}
|
||||
|
||||
public override IScriptSourceProvider SourceProvider => _transmitter;
|
||||
|
||||
public override string Name => _name;
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpElementInstance CreateInstanceNode( Token t )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static bool IsNullOrVoid( IExpElementSource type )
|
||||
{
|
||||
return type == null || type == ExpVoidType.Only;
|
||||
}
|
||||
|
||||
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
|
||||
{
|
||||
memberNode = ExpSyntaxNode.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
private class ExpVoidType : ExpTypeSource
|
||||
{
|
||||
|
||||
private static readonly ExpVoidType _onlyInstance = new ExpVoidType();
|
||||
|
||||
private ExpVoidType() : base( string.Empty ) { }
|
||||
|
||||
public static ExpVoidType Only
|
||||
{
|
||||
get => _onlyInstance;
|
||||
}
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpBinaryOperatorNode.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;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpBinaryOperatorNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpInstantiableElement _returnType;
|
||||
|
||||
private ExpSyntaxNode _left;
|
||||
private ExpSyntaxNode _right;
|
||||
|
||||
private ExpBinaryOperatorNode( Token source, ExpSyntaxNode left, ExpSyntaxNode right )
|
||||
: base( source )
|
||||
{
|
||||
_left = left;
|
||||
_right = right;
|
||||
}
|
||||
|
||||
public override ExpInstantiableElement EqualityTypeConvert => _returnType;
|
||||
|
||||
public override ExpSyntaxNode Left => _left;
|
||||
|
||||
public override ExpSyntaxNode Right => _right;
|
||||
|
||||
public string Operator { get; private set; }
|
||||
|
||||
public static ExpBinaryOperatorNode Add(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException( source, "Number",
|
||||
left.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 ||
|
||||
( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
|
||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "{0} + {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode Assign(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
source, left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = ExpInstantiableElement.Void,
|
||||
_nodeFlag = ExpNodeFlag.Operator_Binary | left._nodeFlag,
|
||||
Operator = "=",
|
||||
CodeConvertTemplate = "{0} = {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode CompareInstanceEqual(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = ExpressCompile.ExpBool,
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
|
||||
CodeConvertTemplate = "!ReferenceEquals({0}, {1})",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode CompareInstanceNotEqual(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = ExpressCompile.ExpBool,
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
|
||||
CodeConvertTemplate = "ReferenceEquals({0}, {1})",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode ConvertElement(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( right is not ExpMetaRefNode metaRef ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
source, "<source of element>", right.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = metaRef.SourceRef,
|
||||
_nodeFlag = ExpNodeFlag.Operator_Binary,
|
||||
/*
|
||||
* 0. instance to convert
|
||||
* 1. target type
|
||||
*/
|
||||
CodeConvertTemplate = @"({0} as {1})"
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode Div(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException( source, "Number",
|
||||
left.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 ||
|
||||
( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
|
||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "{0} / {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode EqualTo(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
source, left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = ExpressCompile.ExpBool,
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
|
||||
CodeConvertTemplate = "{0} == {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode GreaterThan(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException( source, "Number",
|
||||
left.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = ExpressCompile.ExpBool,
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
|
||||
CodeConvertTemplate = "{0} > {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode LessThan(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException( source, "Number",
|
||||
left.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = ExpressCompile.ExpBool,
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
|
||||
CodeConvertTemplate = "{0} < {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode Mul(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException( source, "Number",
|
||||
left.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 ||
|
||||
( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
|
||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "{0} * {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode NotEqualTo(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
source, left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = ExpressCompile.ExpBool,
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
|
||||
CodeConvertTemplate = "{0} != {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode SmallerThan(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException( source, "Number",
|
||||
left.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = ExpressCompile.ExpBool,
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
|
||||
CodeConvertTemplate = "{0} < {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode Sub(
|
||||
Token source,
|
||||
ExpSyntaxNode left,
|
||||
ExpSyntaxNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException( source, "Number",
|
||||
left.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 ||
|
||||
( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
|
||||
return new ExpBinaryOperatorNode( source, left, right )
|
||||
{
|
||||
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
|
||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "{0} - {1}",
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpCollectionIndexNode.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.Script.Express
|
||||
{
|
||||
public class ExpCollectionIndexNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpCollectionInstanceBase _collection;
|
||||
|
||||
private ExpSyntaxNode _indexExpression;
|
||||
|
||||
private ExpCollectionIndexNode(
|
||||
Token source,
|
||||
ExpCollectionInstanceBase instance,
|
||||
ExpSyntaxNode indexExpression )
|
||||
: base( source )
|
||||
{
|
||||
_collection = instance;
|
||||
_indexExpression = indexExpression;
|
||||
CodeConvertTemplate = @"{0}[{1}]";
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => _collection;
|
||||
|
||||
public override ExpSyntaxNode Right => _indexExpression;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => _collection.EqualityTypeConvert;
|
||||
|
||||
public static ExpCollectionIndexNode Create(
|
||||
Token source,
|
||||
ExpCollectionInstanceBase instance,
|
||||
ExpSyntaxNode indexExpression )
|
||||
{
|
||||
if( !indexExpression.IsNumber ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
source, "Number", indexExpression.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpCollectionIndexNode( source, instance, indexExpression );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpElementInitializingNode.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.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpElementInitializingNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpMetaRefNode _type;
|
||||
private ExpSyntaxNode _init;
|
||||
|
||||
private ExpElementInitializingNode(
|
||||
Token source,
|
||||
ExpMetaRefNode type,
|
||||
ExpSyntaxNode initParameter )
|
||||
: base( source )
|
||||
{
|
||||
_type = type;
|
||||
_init = initParameter;
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => _type;
|
||||
|
||||
public override ExpSyntaxNode Right => _init;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => _type.SourceRef;
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public ExpElementInitializingNode InitializeElement(
|
||||
Token source,
|
||||
ExpMetaRefNode type,
|
||||
ExpSyntaxNode init )
|
||||
{
|
||||
if( init is ExpTupleNode tupleNode ) {
|
||||
init = tupleNode.Right;
|
||||
}
|
||||
ExpElementInitializingNode node = new ExpElementInitializingNode( source, type, init );
|
||||
return node;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpElementMemberNameNode.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.Script.Express
|
||||
{
|
||||
public class ExpElementMemberNameNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
internal ExpElementMemberNameNode( Token source )
|
||||
: base( source )
|
||||
{
|
||||
_nodeFlag = ExpNodeFlag.Name_Operator;
|
||||
CodeConvertTemplate = source.Value;
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => Empty;
|
||||
|
||||
public override ExpSyntaxNode Right => Empty;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get
|
||||
{
|
||||
ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpressCompile.Keyword.String, out ExpTypeSource? strType );
|
||||
return strType;
|
||||
}
|
||||
}
|
||||
|
||||
public static ExpElementMemberNameNode Create( Token t )
|
||||
{
|
||||
return new ExpElementMemberNameNode( t );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpEnumLiteralNode.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;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpEnumLiteralNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpEnumLiteralNode( Token t ) : base( t ) { }
|
||||
|
||||
public override ExpSyntaxNode Left => Empty;
|
||||
|
||||
public override ExpSyntaxNode Right => Empty;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => ExpInstantiableElement.Void;
|
||||
|
||||
public string Literal { get; private set; }
|
||||
|
||||
public static ExpEnumLiteralNode Create( Token t, Func<string, string> parser )
|
||||
{
|
||||
string l;
|
||||
if( parser is null )
|
||||
{
|
||||
l = t.Value;
|
||||
} else
|
||||
{
|
||||
l = parser( t.Value );
|
||||
}
|
||||
return new ExpEnumLiteralNode( t )
|
||||
{
|
||||
Literal = l,
|
||||
CodeConvertTemplate = l
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpFunctionCallingNode.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.Script.Express
|
||||
{
|
||||
public class ExpFunctionCallingNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpFunctionSource _function;
|
||||
|
||||
private ExpSyntaxNode _parameter;
|
||||
|
||||
private ExpFunctionCallingNode(
|
||||
Token source,
|
||||
ExpFunctionSource function,
|
||||
ExpSyntaxNode parameterEnumeration )
|
||||
: base( source )
|
||||
{
|
||||
if( parameterEnumeration is ExpTupleNode tuple ) {
|
||||
parameterEnumeration = tuple.Right;
|
||||
}
|
||||
_function = function;
|
||||
_parameter = parameterEnumeration;
|
||||
}
|
||||
|
||||
public ExpFunctionSource FunctionCaller => _function;
|
||||
|
||||
public override ExpInstantiableElement EqualityTypeConvert => _function.ReturningType;
|
||||
|
||||
public override ExpSyntaxNode Left => Empty;
|
||||
|
||||
public override ExpSyntaxNode Right => _parameter;
|
||||
|
||||
public void AppendParameter( ExpSyntaxNode parameter )
|
||||
{
|
||||
_parameter.AppendNode( parameter );
|
||||
}
|
||||
|
||||
public static ExpFunctionCallingNode CallFunction(
|
||||
Token source,
|
||||
ExpFunctionSource function,
|
||||
ExpSyntaxNode param )
|
||||
{
|
||||
if( param is ExpTupleNode ) {
|
||||
param = param.Right;
|
||||
}
|
||||
return new ExpFunctionCallingNode( source, function, param );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpIfNode.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.Express;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public sealed class ExpIfNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpSyntaxNode _falseOpBegin;
|
||||
private ExpSyntaxNode _rule;
|
||||
private ExpSyntaxNode _trueOpBegin ;
|
||||
|
||||
public ExpIfNode( Token source, ExpSyntaxNode rule, ExpSyntaxNode trueOpBegin )
|
||||
: base( source )
|
||||
{
|
||||
_rule = rule;
|
||||
_trueOpBegin = trueOpBegin;
|
||||
CodeConvertTemplate = ExpressCompile.PoolString(
|
||||
"""
|
||||
if ( {0} )
|
||||
{
|
||||
{1}
|
||||
}
|
||||
""" );
|
||||
}
|
||||
|
||||
public ExpIfNode(
|
||||
Token source,
|
||||
ExpSyntaxNode rule,
|
||||
ExpSyntaxNode rootOperationIfTrue,
|
||||
ExpSyntaxNode rootOperationIfFalse )
|
||||
: base( source )
|
||||
{
|
||||
_rule = rule;
|
||||
_trueOpBegin = rootOperationIfFalse;
|
||||
_falseOpBegin = rootOperationIfFalse;
|
||||
CodeConvertTemplate = ExpressCompile.PoolString(
|
||||
"""
|
||||
if( {0} )
|
||||
{
|
||||
{1}
|
||||
} else {
|
||||
{2}
|
||||
}
|
||||
""" );
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => _trueOpBegin;
|
||||
|
||||
public override ExpSyntaxNode Right => _falseOpBegin;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => null!;
|
||||
|
||||
public void AppendFalseOperation( ExpSyntaxNode expressionRoot )
|
||||
{
|
||||
_falseOpBegin.AppendNode( expressionRoot );
|
||||
}
|
||||
|
||||
public void AppendTrueOperation( ExpSyntaxNode expressionRoot )
|
||||
{
|
||||
_trueOpBegin.AppendNode( expressionRoot );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpInstanceMemberNode.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 CommunityToolkit.HighPerformance.Helpers;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpInstanceMemberNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpElementInstance _instance;
|
||||
private ExpElementMemberNameNode _memberName;
|
||||
private ExpSyntaxNode _member;
|
||||
|
||||
public ExpInstanceMemberNode(
|
||||
Token source,
|
||||
ExpElementInstance instance,
|
||||
ExpElementMemberNameNode memberName )
|
||||
: base( source )
|
||||
{
|
||||
_instance = instance;
|
||||
_memberName = memberName;
|
||||
_instance.TryGetMember( memberName.CodeConvertTemplate, out _member );
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => _instance;
|
||||
|
||||
public override ExpSyntaxNode Right => _memberName;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => _member.EqualityTypeConvert;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpInstanceReferenceNode.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.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpInstanceReferenceNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
internal ExpInstanceReferenceNode( Token source, ExpElementInstance instance )
|
||||
: base( source )
|
||||
{
|
||||
OriginObject = instance;
|
||||
_nodeFlag = ( OriginObject._nodeFlag | ( ExpNodeFlag.Name_Any | ExpNodeFlag.Collection_Any ) );
|
||||
CodeConvertTemplate = source.Value;
|
||||
}
|
||||
|
||||
internal ExpInstanceReferenceNode( Token source, ExpInstanceReferenceNode reference )
|
||||
: base( source )
|
||||
{
|
||||
OriginObject = reference.OriginObject;
|
||||
_nodeFlag = ( OriginObject._nodeFlag | ( ExpNodeFlag.Name_Any | ExpNodeFlag.Collection_Any ) );
|
||||
CodeConvertTemplate = source.Value;
|
||||
}
|
||||
|
||||
public ExpElementInstance OriginObject { get ; private set; }
|
||||
|
||||
public override ExpSyntaxNode Left => Empty;
|
||||
|
||||
public override ExpSyntaxNode Right => Empty;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => OriginObject.EqualityTypeConvert;
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static ExpInstanceReferenceNode MakeReferenceFrom(
|
||||
Token source,
|
||||
ExpElementInstance instance )
|
||||
{
|
||||
/**/
|
||||
if( instance.IsLiteral )
|
||||
{
|
||||
throw new ExpCompileException( source, "Cannot make reference to a literal." );
|
||||
}
|
||||
if( instance.CodeConvertTemplate != source.Value ) {
|
||||
throw new ExpCompileException( source, "Token point at a wrong instance" );
|
||||
}
|
||||
/**/
|
||||
return new ExpInstanceReferenceNode( source, instance );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpLiteralNode.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.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpIntNode : ExpElementInstance
|
||||
{
|
||||
|
||||
private int _value;
|
||||
|
||||
public ExpIntNode( Token source, int value, bool isLiteral )
|
||||
: base( source )
|
||||
{
|
||||
this.IsLiteral = isLiteral;
|
||||
_value = value;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Type;
|
||||
CodeConvertTemplate = IsLiteral ? value.ToString() : source.Value;
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get => ExpressCompile.ExpInt;
|
||||
}
|
||||
|
||||
public int Value => _value;
|
||||
|
||||
public override string TypeName => ExpressCompile.Keyword.Integer;
|
||||
|
||||
}
|
||||
|
||||
public class ExpStringNode : ExpElementInstance
|
||||
{
|
||||
|
||||
private readonly string _value;
|
||||
|
||||
public ExpStringNode( Token source, string value, bool isLiteral )
|
||||
: base( source )
|
||||
{
|
||||
this.IsLiteral = IsLiteral;
|
||||
_value = value;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_String | ExpNodeFlag.Element_Type;
|
||||
CodeConvertTemplate = IsLiteral ? $"\"{value}\"" : source.Value;
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get => ExpressCompile.ExpString;
|
||||
}
|
||||
|
||||
public override string TypeName => EqualityTypeConvert.Name;
|
||||
|
||||
public string Value => _value;
|
||||
|
||||
}
|
||||
|
||||
public interface IExpBooleanSyntax
|
||||
{
|
||||
|
||||
bool Value { get; }
|
||||
|
||||
}
|
||||
|
||||
public class ExpBoolNode : ExpElementInstance, IExpBooleanSyntax
|
||||
{
|
||||
|
||||
private readonly bool _value;
|
||||
|
||||
public ExpBoolNode( Token source, bool value, bool isLiteral )
|
||||
: base( source )
|
||||
{
|
||||
this.IsLiteral = isLiteral;
|
||||
_value = value;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Element_Type;
|
||||
CodeConvertTemplate = IsLiteral ? value.ToString() : source.Value;
|
||||
}
|
||||
|
||||
public bool Value => _value;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get => ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpressCompile.Keyword.Boolean, out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
}
|
||||
|
||||
public override string TypeName => EqualityTypeConvert.Name;
|
||||
|
||||
public static ExpBoolNode False( Token? t )
|
||||
{
|
||||
return new( t ?? new Token( "FALSE", 0, -1, TokenFlag.Member ), false,
|
||||
isLiteral: true );
|
||||
}
|
||||
|
||||
public static ExpBoolNode True( Token? t )
|
||||
{
|
||||
return new( t ?? new Token( "TRUE", 0, -1, TokenFlag.Member ), true, isLiteral: true );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpRealNumberNode : ExpElementInstance
|
||||
{
|
||||
|
||||
private readonly float _value;
|
||||
|
||||
public ExpRealNumberNode( Token source, float value, bool isLiteral )
|
||||
: base( source )
|
||||
{
|
||||
_value = value;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Real | ExpNodeFlag.Element_Type;
|
||||
CodeConvertTemplate = isLiteral ? $"{value:F8}f" : source.Value;
|
||||
}
|
||||
|
||||
public float Value => _value;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get => ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpressCompile.Keyword.String, out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
}
|
||||
|
||||
public override string TypeName => EqualityTypeConvert.Name;
|
||||
|
||||
}
|
||||
|
||||
public class ExpLogicValueNode : ExpElementInstance, IExpBooleanSyntax
|
||||
{
|
||||
|
||||
private readonly ExpLogic _value;
|
||||
|
||||
public ExpLogicValueNode( Token source, ExpLogic value, bool isLiteral )
|
||||
: base( source )
|
||||
{
|
||||
this.IsLiteral = isLiteral;
|
||||
_value = value;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.Element_Type;
|
||||
CodeConvertTemplate = isLiteral ? value.ToString() : source.Value;
|
||||
}
|
||||
|
||||
public ExpLogic LogicValue => _value;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get => ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpressCompile.Keyword.Logical, out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
}
|
||||
|
||||
public override string TypeName => EqualityTypeConvert.Name;
|
||||
|
||||
bool IExpBooleanSyntax.Value => _value.ToBoolean();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpMetaRefNode.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;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpMetaRefNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
internal ExpMetaRefNode( Token source, ExpInstantiableElement element )
|
||||
: base( source )
|
||||
{
|
||||
SourceRef = element;
|
||||
}
|
||||
|
||||
public ExpInstantiableElement SourceRef { get; init; }
|
||||
|
||||
public override ExpSyntaxNode Left => Empty;
|
||||
|
||||
public override ExpSyntaxNode Right => Empty;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => ExpInstantiableElement.Void;
|
||||
|
||||
public static ExpMetaRefNode RefEntity( Token position, ExpEntitySource entity )
|
||||
{
|
||||
if( position.Value != entity.Name ) {
|
||||
throw new ExpCompileException(
|
||||
position,
|
||||
$"Meta data does not match, name of source to match is {entity.Name}, but token is {position.Value}" );
|
||||
}
|
||||
ExpMetaRefNode node = new ExpMetaRefNode( position, entity )
|
||||
{
|
||||
CodeConvertTemplate = entity.Name,
|
||||
};
|
||||
return node;
|
||||
}
|
||||
|
||||
public static ExpMetaRefNode RefType( Token position, ExpTypeSource type )
|
||||
{
|
||||
if( position.Value != type.Name ) {
|
||||
throw new ExpCompileException(
|
||||
position,
|
||||
$"Meta data does not match, name of source to match is {type.Name}, but token is {position.Value}" );
|
||||
}
|
||||
ExpMetaRefNode node = new ExpMetaRefNode( position, type )
|
||||
{
|
||||
CodeConvertTemplate = type.Name,
|
||||
};
|
||||
;
|
||||
return node;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpProcedureCallingNode.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.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpProcedureCallingNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpSyntaxNode _params;
|
||||
|
||||
public ExpProcedureCallingNode(
|
||||
Token source,
|
||||
ExpProcedureSource caller,
|
||||
ExpSyntaxNode param )
|
||||
: base( source )
|
||||
{
|
||||
_params = param;
|
||||
CalledProcedure = caller;
|
||||
}
|
||||
|
||||
public ExpProcedureSource CalledProcedure { get; init; }
|
||||
|
||||
public override ExpSyntaxNode Left => Empty;
|
||||
|
||||
public override ExpSyntaxNode Right => _params;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => ExpInstantiableElement.Void;
|
||||
|
||||
public static ExpProcedureCallingNode CallProcedure(
|
||||
Token postion,
|
||||
ExpProcedureSource caller,
|
||||
ExpSyntaxNode input )
|
||||
{
|
||||
ExpProcedureCallingNode node = new ExpProcedureCallingNode( postion, caller, input )
|
||||
{
|
||||
/*
|
||||
* 0. parameters
|
||||
*/
|
||||
CodeConvertTemplate = $$"""
|
||||
{{caller.Name}}( {0} )
|
||||
"""
|
||||
};
|
||||
return node;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpProcedureControlNode.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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpProcedureControlNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpSyntaxNode _additional;
|
||||
|
||||
internal ExpProcedureControlNode( Token source ) : base( source ) { }
|
||||
|
||||
public override ExpSyntaxNode Left => Empty;
|
||||
|
||||
public override ExpSyntaxNode Right => _additional;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => ExpTypeSource.Void;
|
||||
|
||||
public static ExpProcedureControlNode Return( Token t, ExpSyntaxNode valueToReturn )
|
||||
{
|
||||
if( t.Value != ExpKeyword.Return ) {
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
ExpProcedureControlNode ret = new ExpProcedureControlNode( t )
|
||||
{
|
||||
_additional = valueToReturn ?? Empty,
|
||||
CodeConvertTemplate = IsNullOrEmpty( valueToReturn! ) ?
|
||||
ExpKeyword.Return : "return {0}",
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ExpProcedureControlNode Skip( Token t )
|
||||
{
|
||||
ExpProcedureControlNode ret = new ExpProcedureControlNode( t )
|
||||
{
|
||||
_additional = Empty,
|
||||
CodeConvertTemplate = "break"
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpRangeAndIndexNode.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.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpIndexNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private const string _codeTemplate = @"[{0}]";
|
||||
|
||||
private ExpSyntaxNode _index;
|
||||
|
||||
internal ExpIndexNode( Token t, ExpSyntaxNode node )
|
||||
: base( t )
|
||||
{
|
||||
_index = node;
|
||||
CodeConvertTemplate = _codeTemplate;
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => _index;
|
||||
|
||||
public override ExpSyntaxNode Right => Empty;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException();
|
||||
|
||||
public static ExpIndexNode IndexAt( Token position, ExpSyntaxNode expression )
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( expression );
|
||||
if( ExpNodeFlag.BuiltinType_Int.IsNotInFlag( expression.NodeFlag ) ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
position, "Integer", expression.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpIndexNode( position, expression );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpRangeNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private const string _codeTemplate = "[{0}..{1}]";
|
||||
|
||||
private ExpSyntaxNode _begin, _end;
|
||||
|
||||
internal ExpRangeNode( Token t, ExpSyntaxNode begin, ExpSyntaxNode end )
|
||||
: base( t )
|
||||
{
|
||||
_begin = begin;
|
||||
_end = end;
|
||||
CodeConvertTemplate = _codeTemplate;
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => _begin;
|
||||
|
||||
public override ExpSyntaxNode Right => _end;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => ExpInstantiableElement.Void;
|
||||
|
||||
public static ExpRangeNode RangeNode(
|
||||
Token position,
|
||||
ExpSyntaxNode beginNode,
|
||||
ExpSyntaxNode endNode )
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( beginNode );
|
||||
ArgumentNullException.ThrowIfNull( endNode );
|
||||
if( ExpNodeFlag.BuiltinType_Int.IsNotInFlag( beginNode.NodeFlag ) ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
position, "Integer", beginNode.EqualityTypeConvert.Name );
|
||||
}
|
||||
if( ExpNodeFlag.BuiltinType_Int.IsNotInFlag( endNode.NodeFlag ) ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
position, "Integer", endNode.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpRangeNode( position, beginNode, endNode );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpCollectionExpressionNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
internal ExpCollectionExpressionNode( Token t, ExpTupleNode tupleNode ) : base( t ) { }
|
||||
|
||||
public override ExpSyntaxNode Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpSyntaxNode Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpRepeatNode.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.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Channels;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpRepeatNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpElementInstance _variable;
|
||||
private ExpSyntaxNode _begin, _end, _increment, _operationBegin,_untilRule,_whileRule;
|
||||
|
||||
internal ExpRepeatNode(
|
||||
Token source,
|
||||
ExpElementInstance variable,
|
||||
ExpSyntaxNode begin,
|
||||
ExpSyntaxNode end,
|
||||
ExpSyntaxNode increment,
|
||||
ExpSyntaxNode operationBegin,
|
||||
ExpSyntaxNode untilRule,
|
||||
ExpSyntaxNode whileRule)
|
||||
: base(source)
|
||||
{
|
||||
if (variable.NodeFlag != begin.NodeFlag ||
|
||||
begin.NodeFlag != end.NodeFlag ||
|
||||
(increment != null && end.NodeFlag != increment.NodeFlag)) {
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
if (IsNullOrEmpty(increment))
|
||||
{
|
||||
switch ((ExpNodeFlag)variable.NodeFlag | ExpNodeFlag.BuiltinType_Any)
|
||||
{
|
||||
case ExpNodeFlag.BuiltinType_Real:
|
||||
increment = new ExpRealNumberNode(
|
||||
new Token(
|
||||
ExpressCompile.PoolString("1.0f"), source.Line, -1,
|
||||
TokenFlag.Number),
|
||||
1.0f, isLiteral:true);
|
||||
break;
|
||||
case ExpNodeFlag.BuiltinType_Int:
|
||||
increment = new ExpIntNode(
|
||||
new Token(
|
||||
ExpressCompile.PoolString("1"), source.Line, -1, TokenFlag.Number),
|
||||
1, isLiteral:true);
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException(variable, "Int or Real", "otherwise");
|
||||
}
|
||||
}
|
||||
_variable = variable;
|
||||
_begin = begin;
|
||||
_end = end;
|
||||
_increment = increment!;
|
||||
_operationBegin = operationBegin;
|
||||
_untilRule = untilRule;
|
||||
_whileRule = whileRule;
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpSyntaxNode Right => _operationBegin;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => null!;
|
||||
|
||||
public void AppendRepeatedOperation(ExpSyntaxNode node)
|
||||
{
|
||||
_operationBegin.AppendNode(node);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an AST node for repeat expression in EXPRESS language. The loop does not has
|
||||
/// WHILE and UNTIL regulation.
|
||||
/// </summary>
|
||||
/// <param name="t">
|
||||
/// AllocatorHandle of the loop.
|
||||
/// </param>
|
||||
/// <param name="repeatVariable">
|
||||
/// The variable recording increment by step.
|
||||
/// </param>
|
||||
/// <param name="begin">
|
||||
/// Beginning value of the loop.
|
||||
/// </param>
|
||||
/// <param name="end">
|
||||
/// When <see href="repeatVariable" /> reach the value, the loop ends.
|
||||
/// </param>
|
||||
/// <param name="repeatBody">
|
||||
/// Expressions to operate multiple times.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A <see cref="ExpRepeatNode" /> representing the repeat expression.
|
||||
/// </returns>
|
||||
public static ExpRepeatNode Create(
|
||||
Token t,
|
||||
ExpInstanceReferenceNode repeatVariable,
|
||||
ExpSyntaxNode begin,
|
||||
ExpSyntaxNode end,
|
||||
ExpSyntaxNode increment,
|
||||
ExpSyntaxNode whileRule,
|
||||
ExpSyntaxNode untilRule,
|
||||
ExpSyntaxNode body)
|
||||
{
|
||||
untilRule = ExpBoolNode.False(null);
|
||||
whileRule = ExpBoolNode.True(null);
|
||||
ExpRepeatNode ret = new ExpRepeatNode(
|
||||
t, repeatVariable.OriginObject, begin, end, increment, body, whileRule, untilRule)
|
||||
{
|
||||
/*
|
||||
* 0: variable name
|
||||
* 1: beginning value
|
||||
* 2: ending value
|
||||
* 3: increment
|
||||
* 4: body
|
||||
* 5: while
|
||||
* 6: until
|
||||
*/
|
||||
|
||||
CodeConvertTemplate = $$"""
|
||||
for( {0} = {1}; {0} <= {2}; {0} += {3})
|
||||
{
|
||||
if(!( {5} )) break;
|
||||
{4}
|
||||
if( {6} ) break;
|
||||
}
|
||||
"""
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ExpRepeatNode Create(
|
||||
Token t,
|
||||
ExpElementInstance repeatVariable,
|
||||
ExpSyntaxNode begin,
|
||||
ExpSyntaxNode end,
|
||||
ExpSyntaxNode increment,
|
||||
ExpSyntaxNode whileRule,
|
||||
ExpSyntaxNode untilRule,
|
||||
ExpSyntaxNode body)
|
||||
{
|
||||
whileRule = IsNullOrEmpty(whileRule) ? ExpBoolNode.True(t) : whileRule;
|
||||
untilRule = IsNullOrEmpty(untilRule) ? ExpBoolNode.False(t) : untilRule;
|
||||
ExpRepeatNode ret = new ExpRepeatNode(
|
||||
t, repeatVariable, begin, end, increment, body, whileRule, untilRule)
|
||||
{
|
||||
/*
|
||||
* 0: variable name
|
||||
* 1: beginning value
|
||||
* 2: ending value
|
||||
* 3: increment
|
||||
* 4: body
|
||||
* 5: while
|
||||
* 6: until
|
||||
*/
|
||||
|
||||
CodeConvertTemplate = $$"""
|
||||
for({{repeatVariable.TypeName}} {0} = {1}; {0} <= {2}; {0} += {3})
|
||||
{
|
||||
if(!( {5} )) break;
|
||||
{4}
|
||||
if( {6} ) break;
|
||||
}
|
||||
"""
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSwitchNode.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.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpSwitchNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpSyntaxNode _default;
|
||||
private ExpSyntaxNode _target;
|
||||
|
||||
private FrozenDictionary<ExpSyntaxNode, ExpSyntaxNode> _cases;
|
||||
|
||||
public ExpSwitchNode(
|
||||
Token source,
|
||||
ExpSyntaxNode target,
|
||||
ExpSyntaxNode defaultCase,
|
||||
params (ExpSyntaxNode label, ExpSyntaxNode op)[] cases )
|
||||
: base( source )
|
||||
{
|
||||
_target = target;
|
||||
_default = defaultCase;
|
||||
Dictionary<ExpSyntaxNode, ExpSyntaxNode> casesDic = new Dictionary<ExpSyntaxNode, ExpSyntaxNode>(
|
||||
);
|
||||
foreach( (ExpSyntaxNode label, ExpSyntaxNode op ) item in cases )
|
||||
{
|
||||
if( item.op == null )
|
||||
{
|
||||
casesDic.Add( item.label, null! );
|
||||
} else
|
||||
{
|
||||
casesDic.Add( item.label, item.op );
|
||||
}
|
||||
}
|
||||
_cases = casesDic.ToFrozenDictionary();
|
||||
|
||||
|
||||
string str = @"switch( {0} ){";
|
||||
StringBuilder codeFormatBuilder = new StringBuilder();
|
||||
codeFormatBuilder.AppendLine( str );
|
||||
for( int i = 0; i < casesDic.Count; i++ )
|
||||
{
|
||||
int index = i * 2 + 1;
|
||||
codeFormatBuilder.AppendLine(
|
||||
$$"""
|
||||
case {{{index}}}:
|
||||
{{{index + 1}}}
|
||||
break;
|
||||
""" );
|
||||
}
|
||||
CodeConvertTemplate = codeFormatBuilder.ToString();
|
||||
}
|
||||
|
||||
public ExpSwitchNode(
|
||||
Token source,
|
||||
ExpSyntaxNode target,
|
||||
ExpSyntaxNode defaultCase,
|
||||
IDictionary<ExpSyntaxNode, ExpSyntaxNode> cases )
|
||||
: base( source )
|
||||
{
|
||||
_target = target;
|
||||
_default = defaultCase;
|
||||
_cases = cases.ToFrozenDictionary();
|
||||
|
||||
string str = @"switch( {0} ){";
|
||||
StringBuilder codeFormatBuilder = new StringBuilder();
|
||||
codeFormatBuilder.AppendLine( str );
|
||||
for( int i = 0; i < cases.Count; i++ )
|
||||
{
|
||||
int index = i * 2 + 1;
|
||||
codeFormatBuilder.AppendLine(
|
||||
$$"""
|
||||
case {{{index}}}:
|
||||
{{{index + 1}}}
|
||||
break;
|
||||
""" );
|
||||
}
|
||||
CodeConvertTemplate = codeFormatBuilder.ToString();
|
||||
}
|
||||
|
||||
public ExpSyntaxNode this[ ExpSyntaxNode index ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( _cases.TryGetValue( index, out ExpSyntaxNode? ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => Empty;
|
||||
|
||||
public override ExpSyntaxNode Right => Empty;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => null!;
|
||||
|
||||
public bool ContainsCase( ExpSyntaxNode token )
|
||||
{
|
||||
return _cases.ContainsKey( token );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpTupleNode.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.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpTupleNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpSyntaxNode node;
|
||||
|
||||
private ExpTupleNode( ExpSyntaxNode node )
|
||||
: base( node._source )
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => Empty;
|
||||
|
||||
public override ExpSyntaxNode Right => node;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException();
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static ExpTupleNode Pack( ExpSyntaxNode node )
|
||||
{
|
||||
return new ExpTupleNode( node );
|
||||
}
|
||||
|
||||
public ExpNodePresidentEnumerator TupleAsEnumerator()
|
||||
{
|
||||
return node.ToPresidentEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpUnaryOperatorNode.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.Script.Express
|
||||
{
|
||||
public class ExpUnaryOperatorNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
private ExpSyntaxNode _operand;
|
||||
|
||||
private ExpUnaryOperatorNode( Token source ) : base( source ) { }
|
||||
|
||||
public ExpUnaryOperatorNode( Token source, ExpSyntaxNode operand, ExpSchema context )
|
||||
: base( source )
|
||||
{
|
||||
_operand = operand;
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode Left => null!;
|
||||
|
||||
public override ExpSyntaxNode Right => _operand;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => _operand.EqualityTypeConvert;
|
||||
|
||||
public static ExpUnaryOperatorNode UnaryMinus( Token source, ExpSyntaxNode operand )
|
||||
{
|
||||
if( !operand.IsNumber ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
source, "Number", operand.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
|
||||
return new ExpUnaryOperatorNode( source )
|
||||
{
|
||||
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "- {0}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpUnaryOperatorNode UnaryNot( Token source, ExpSyntaxNode operand )
|
||||
{
|
||||
if( ( operand._nodeFlag | ( ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.BuiltinType_Logic ) ) ==
|
||||
0 ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
source, "Bool or Logic", operand.EqualityTypeConvert.Name );
|
||||
}
|
||||
return new ExpUnaryOperatorNode( source )
|
||||
{
|
||||
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Logic,
|
||||
CodeConvertTemplate = "! {0}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpUnaryOperatorNode UnaryPlus( Token source, ExpSyntaxNode operand )
|
||||
{
|
||||
if( !operand.IsNumber ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
source, "Number", operand.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
|
||||
return new ExpUnaryOperatorNode( source )
|
||||
{
|
||||
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "+ {0}",
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="_ExpNode.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 CommunityToolkit.HighPerformance.Buffers;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public abstract class ExpSyntaxNode : ISyntaxNode<ExpSyntaxNode, IExpElementSource>
|
||||
{
|
||||
|
||||
protected internal ExpNodeFlag _nodeFlag;
|
||||
protected internal Token _source;
|
||||
|
||||
protected ExpSyntaxNode( Token source )
|
||||
{
|
||||
_source = source;
|
||||
Next = this;
|
||||
Previous = this;
|
||||
}
|
||||
|
||||
public bool IsNumber
|
||||
{
|
||||
get { return ( _nodeFlag | ExpNodeFlag.BuiltinType_Number ) != 0; }
|
||||
}
|
||||
|
||||
public abstract ExpSyntaxNode Left { get; }
|
||||
|
||||
public static ExpSyntaxNode Empty
|
||||
{
|
||||
get => ExpEmptyNode._only;
|
||||
}
|
||||
|
||||
public ExpSyntaxNode Next { get; set; }
|
||||
|
||||
public abstract ExpSyntaxNode Right { get; }
|
||||
|
||||
public ExpSyntaxNode Previous { get; set; }
|
||||
|
||||
public abstract IExpElementSource EqualityTypeConvert { get; }
|
||||
|
||||
public int Line => _source.Line;
|
||||
|
||||
public int Column => _source.Column;
|
||||
|
||||
public long NodeFlag => ( long )_nodeFlag;
|
||||
|
||||
public string CodeConvertTemplate { get; init; }
|
||||
|
||||
public Token Source
|
||||
{
|
||||
get => _source;
|
||||
}
|
||||
|
||||
public void AppendNode( ExpSyntaxNode nextNode )
|
||||
{
|
||||
Next.Previous = nextNode;
|
||||
nextNode.Next = Next;
|
||||
Next = nextNode;
|
||||
Next.Previous = this;
|
||||
}
|
||||
|
||||
public static bool IsNullOrEmpty( [AllowNull]ExpSyntaxNode node )
|
||||
{
|
||||
return node == ExpEmptyNode._only || node == null;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static ExpSyntaxNode NonOperation( Token source )
|
||||
{
|
||||
return new ExpEmptyNode( source.Line, source.Column );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static ExpSyntaxNode NonOperation( int line, int column )
|
||||
{
|
||||
return new ExpEmptyNode( line, column );
|
||||
}
|
||||
|
||||
public void PrependNode( ExpSyntaxNode previousNode )
|
||||
{
|
||||
Previous.Next = previousNode;
|
||||
previousNode.Previous = Previous;
|
||||
Previous = previousNode;
|
||||
previousNode.Next = this;
|
||||
}
|
||||
|
||||
public static bool VerifyTypeConvertable( ExpSyntaxNode left, ExpSyntaxNode right )
|
||||
{
|
||||
IExpElementSource tLeft = left.EqualityTypeConvert,
|
||||
tRight = right.EqualityTypeConvert;
|
||||
if( tLeft is not ExpInstantiableElement tLeftIns ||
|
||||
tRight is not ExpInstantiableElement tRightIns ) {
|
||||
return false;
|
||||
}
|
||||
if( ExpInstantiableElement.IsNullOrVoid( tLeftIns ) ||
|
||||
ExpInstantiableElement.IsNullOrVoid( tLeftIns ) ) {
|
||||
return false;
|
||||
}
|
||||
return tLeft.IsConvertable( tRight );
|
||||
}
|
||||
|
||||
private class ExpEmptyNode : ExpSyntaxNode
|
||||
{
|
||||
|
||||
internal static readonly ExpEmptyNode _only = new();
|
||||
|
||||
public ExpEmptyNode() : base( Token.Empty ) { }
|
||||
|
||||
public ExpEmptyNode( int line, int column )
|
||||
: base( new Token( string.Empty, line, column, TokenFlag.None ) ) { }
|
||||
|
||||
public override ExpInstantiableElement EqualityTypeConvert => ExpInstantiableElement.Void;
|
||||
|
||||
public override ExpSyntaxNode Left => _only;
|
||||
|
||||
public override ExpSyntaxNode Right => _only;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpElementInstance.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.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
[Flags]
|
||||
public enum ExpElementType : int
|
||||
{
|
||||
|
||||
Void = 0,
|
||||
Const = 1,
|
||||
Entity = 2,
|
||||
Type = 4,
|
||||
Function = 8,
|
||||
Section = 16,
|
||||
Expression = 32,
|
||||
Rule = 64,
|
||||
Procedure = 128,
|
||||
Collection = 256,
|
||||
|
||||
}
|
||||
|
||||
public abstract class ExpElementInstance : ExpSyntaxNode
|
||||
{
|
||||
|
||||
protected ExpElementInstance( Token source )
|
||||
: base( source )
|
||||
{
|
||||
CodeConvertTemplate = source.Value;
|
||||
}
|
||||
|
||||
public bool IsLiteral { get; init; }
|
||||
|
||||
public ExpElementType ElementType { get; }
|
||||
|
||||
public override ExpSyntaxNode Left => Empty;
|
||||
|
||||
public override ExpSyntaxNode Right => Empty;
|
||||
|
||||
public abstract string TypeName { get; }
|
||||
|
||||
public static ExpElementInstance CreateLiteral( Token t )
|
||||
{
|
||||
if( int.TryParse( t.Value, out int _int ) )
|
||||
{
|
||||
return new ExpIntNode( t, _int, true );
|
||||
} else if( float.TryParse( t.Value, out float _float ) )
|
||||
{
|
||||
return new ExpRealNumberNode( t, _float, true );
|
||||
} else if( bool.TryParse( t.Value, out bool _bool ) )
|
||||
{
|
||||
return new ExpBoolNode( t, _bool, true );
|
||||
} else if( ExpLogic.TryParse( t.Value, out ExpLogic _logic ) )
|
||||
{
|
||||
return new ExpLogicValueNode( t, _logic, true );
|
||||
} else
|
||||
{
|
||||
return new ExpStringNode( t, t.Value, true );
|
||||
}
|
||||
}
|
||||
|
||||
public ExpInstanceReferenceNode MakeReference( Token t )
|
||||
{
|
||||
return new ExpInstanceReferenceNode( t, this );
|
||||
}
|
||||
|
||||
public static bool TryCreateLiteral( Token t, out ExpElementInstance instance )
|
||||
{
|
||||
if( int.TryParse( t.Value, out int _int ) )
|
||||
{
|
||||
instance = new ExpIntNode( t, _int, true );
|
||||
return true;
|
||||
} else if( float.TryParse( t.Value, out float _float ) )
|
||||
{
|
||||
instance = new ExpRealNumberNode( t, _float, true );
|
||||
return true;
|
||||
} else if( bool.TryParse( t.Value, out bool _bool ) )
|
||||
{
|
||||
instance = new ExpBoolNode( t, _bool, true );
|
||||
return true;
|
||||
} else if( ExpLogic.TryParse( t.Value, out ExpLogic _logic ) )
|
||||
{
|
||||
instance = new ExpLogicValueNode( t, _logic, true );
|
||||
return true;
|
||||
} else if( t.Flag == TokenFlag.String )
|
||||
{
|
||||
instance = new ExpStringNode( t, t.Value, true );
|
||||
return true;
|
||||
}
|
||||
instance = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetMember( string name, out ExpSyntaxNode node )
|
||||
{
|
||||
return EqualityTypeConvert.TryGetMember( name, out node );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpElmentSource.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.Script.Express
|
||||
{
|
||||
public interface IExpElementSource : ITypeSource<IExpElementSource>
|
||||
{
|
||||
|
||||
public ExpElementType ElementType { get; }
|
||||
|
||||
IScriptSourceProvider SourceProvider { get; }
|
||||
|
||||
string Name { get; }
|
||||
|
||||
public void AddMember( string name, ExpSyntaxNode memberNode );
|
||||
|
||||
public void Analyse();
|
||||
|
||||
public bool TryGetMember( string name, out ExpSyntaxNode memberNode );
|
||||
|
||||
}
|
||||
|
||||
public abstract class ExpInstantiableElement : IExpElementSource
|
||||
{
|
||||
|
||||
private List<ExpInstantiableElement> _baseList = new List<ExpInstantiableElement>(),
|
||||
_derivationList = new List<ExpInstantiableElement>();
|
||||
|
||||
public abstract ExpElementType ElementType { get; }
|
||||
|
||||
public static ExpInstantiableElement Void
|
||||
{
|
||||
get => ExpVoidElement.Only;
|
||||
}
|
||||
|
||||
public abstract IScriptSourceProvider SourceProvider { get; }
|
||||
|
||||
public abstract string Name { get; }
|
||||
|
||||
public void AddMember( string name, ExpSyntaxNode memberNode )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public abstract void Analyse();
|
||||
|
||||
public abstract ExpSyntaxNode CreateInstanceNode( Token t );
|
||||
|
||||
public bool IsConvertable( IExpElementSource targetType )
|
||||
{
|
||||
if( targetType == null ) {
|
||||
return false;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static bool IsNullOrVoid( ExpInstantiableElement element )
|
||||
{
|
||||
return element == null || element == ExpVoidElement.Only;
|
||||
}
|
||||
|
||||
public abstract bool TryGetMember( string name, out ExpSyntaxNode memberNode );
|
||||
|
||||
private sealed class ExpVoidElement : ExpInstantiableElement
|
||||
{
|
||||
|
||||
private static readonly ExpVoidElement _only = new ExpVoidElement();
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Void;
|
||||
|
||||
public static ExpVoidElement Only => _only;
|
||||
|
||||
public override IScriptSourceProvider SourceProvider => ScriptSourceTransmitter.Empty;
|
||||
|
||||
public override string Name => "void";
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public override ExpSyntaxNode CreateInstanceNode( Token t )
|
||||
{
|
||||
return ExpSyntaxNode.Empty;
|
||||
}
|
||||
|
||||
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
|
||||
{
|
||||
memberNode = ExpSyntaxNode.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract class ExpImmutableElement : IExpElementSource
|
||||
{
|
||||
|
||||
public abstract ExpElementType ElementType { get; }
|
||||
|
||||
public abstract IScriptSourceProvider SourceProvider { get; }
|
||||
|
||||
public abstract string Name { get; }
|
||||
|
||||
public void AddMember( string name, ExpSyntaxNode memberNode )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public abstract void Analyse();
|
||||
|
||||
public bool IsConvertable( IExpElementSource targetType )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract ExpSyntaxNode MakeReference( params object[] options );
|
||||
|
||||
public abstract bool TryGetMember( string name, out ExpSyntaxNode memberNode );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpExceptions.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.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpException : Exception
|
||||
{
|
||||
|
||||
private Token _pos;
|
||||
|
||||
public ExpException( string message ) : base( message ) { }
|
||||
|
||||
public ExpException( Token position, string message )
|
||||
: base( $"Express compile error at {position.Line}-{position.Column}:\n{message}" )
|
||||
{
|
||||
_pos = position;
|
||||
}
|
||||
|
||||
public ExpException( ExpSyntaxNode node, string message )
|
||||
: base(
|
||||
$"Express compile error at {node.Source.Line}-{node.Source.Column}:\n{message}" )
|
||||
{
|
||||
_pos = node._source;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidCharException : ExpException
|
||||
{
|
||||
|
||||
public ExpInvalidCharException( char c ) : base( $"An unknown char {c} occurred." ) { }
|
||||
|
||||
public ExpInvalidCharException( int index )
|
||||
: base( $"Cannot read a token from line at {index}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpStringNotCloseException : ExpException
|
||||
{
|
||||
|
||||
public ExpStringNotCloseException( int linenum )
|
||||
: base( $"A string does not closed at end of line {linenum}." ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidSyntaxException : ExpException
|
||||
{
|
||||
|
||||
public ExpInvalidSyntaxException( string message ) : base( message ) { }
|
||||
|
||||
public static void ThrowNonCollectionIndex( Token t )
|
||||
{
|
||||
throw new ExpInvalidSyntaxException(
|
||||
$"Use a collection indexer to a non-collection variable at line {t.Line} column {t.Column}" );
|
||||
}
|
||||
|
||||
public static void ThrowNoOperator( Token t )
|
||||
{
|
||||
throw new ExpInvalidSyntaxException(
|
||||
$"No operator but more than one operand before line {t.Line} column {t.Column}" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidElementDeclareEndingExceptions : ExpException
|
||||
{
|
||||
|
||||
public ExpInvalidElementDeclareEndingExceptions( string declaredName, string endedName )
|
||||
: base(
|
||||
$"The datatype is declared with name {declaredName} but ended with {endedName}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidElementNameException : ExpException
|
||||
{
|
||||
|
||||
public ExpInvalidElementNameException( string elementName, ExpSchema schema )
|
||||
: base( $"Cannot find any element named {elementName} in {schema.Name}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidTypeException : ExpException
|
||||
{
|
||||
|
||||
public ExpInvalidTypeException( ExpSyntaxNode node, string required, string provided )
|
||||
: base(
|
||||
node,
|
||||
$"Type {required} is required at position, but a {provided} instance is provided." ) { }
|
||||
|
||||
public ExpInvalidTypeException( Token t, string required, string provided )
|
||||
: base(
|
||||
t,
|
||||
$"Type {required} is required at position, but a {provided} instance is provided." ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpCaseNotFoundException : ArgumentOutOfRangeException
|
||||
{
|
||||
|
||||
public ExpCaseNotFoundException( ExpSwitchNode token, ExpSyntaxNode label )
|
||||
: base(
|
||||
$"Attempt to read or write the label at ({token.Line},{token.Column}), that does not exist in SWITCH expression at ({token.Line},{token.Column})" ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidCollectionMemberTypeException : InvalidCastException
|
||||
{
|
||||
|
||||
public ExpInvalidCollectionMemberTypeException(
|
||||
ExpElementInstance elementInstance,
|
||||
ExpCollectionBase collection )
|
||||
: base(
|
||||
$"Attempt to add or remove an element of type: {elementInstance.ElementType} from a collection collects {collection.MemberType}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidSchemaIncludeException : InvalidOperationException
|
||||
{
|
||||
|
||||
public ExpInvalidSchemaIncludeException( ExpSchema context, ExpSchema source )
|
||||
: base(
|
||||
$"Attempted to refer to an EXPRESS language expression in the current schema context '{context.Name}', but this expression comes from another schema '{source.Name}' that has not been included." ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpElementLoadException : TypeLoadException
|
||||
{
|
||||
|
||||
public ExpElementLoadException( string typeName, ExpSchema context )
|
||||
: base(
|
||||
$"Cannot find the element {typeName} in schema {context.Name} and its included schemas" ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpCompileNotInitializedException : InvalidOperationException
|
||||
{
|
||||
|
||||
public ExpCompileNotInitializedException()
|
||||
: base( "Attempt to compile an EXPRESS script before the init of compiler." ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpCompileException : ExpException
|
||||
{
|
||||
|
||||
public ExpCompileException( Token pos, string message )
|
||||
: base(
|
||||
$"Compiler exception occur when processing token at line {pos.Line}, column {pos.Column}. Detailed message:{Environment.NewLine}{message} " ) { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpNodeFlag.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.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
[EditorBrowsable( EditorBrowsableState.Never )]
|
||||
public static class ExpNodeFlagHelper
|
||||
{
|
||||
|
||||
public static bool IsInFlag( this ExpNodeFlag flag, long target )
|
||||
{
|
||||
return ( ( long )flag & target ) != 0;
|
||||
}
|
||||
|
||||
public static bool IsInFlag( this ExpNodeFlag flag, ExpNodeFlag target )
|
||||
{
|
||||
return ( long )( flag & target ) != 0;
|
||||
}
|
||||
|
||||
public static bool IsNotInFlag( this ExpNodeFlag flag, long target )
|
||||
{
|
||||
return ( ( long )flag & target ) == 0;
|
||||
}
|
||||
|
||||
public static bool IsNotInFlag( this ExpNodeFlag flag, ExpNodeFlag target )
|
||||
{
|
||||
return ( long )( flag & target ) == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ExpNodeFlag : long
|
||||
{
|
||||
|
||||
//string as name of non-builtin variables
|
||||
None = 0,
|
||||
Name_Element = 1,
|
||||
Name_Param = 2,
|
||||
Name_Block = 4,
|
||||
Name_Keyword = 8,
|
||||
Name_Operator = 16,
|
||||
Name_Any = Name_Block | Name_Element | Name_Keyword | Name_Param | Name_Operator,
|
||||
|
||||
//any type of collections, also has NAME flag
|
||||
Collection_Set = 32,
|
||||
Collection_Bag = 64,
|
||||
Collection_Array = 128,
|
||||
Collection_List = 256,
|
||||
Collection_Any = Collection_Set | Collection_Bag | Collection_Array | Collection_List,
|
||||
|
||||
//the variable is type of element, both builtin and non-builtin has this flag
|
||||
Element_Const = 512,
|
||||
Element_Entity = 1024,
|
||||
Element_Type = 2048,
|
||||
Element_Rule = 4096,
|
||||
Element_Function = 8192,
|
||||
Element_Any = Element_Entity | Element_Const | Element_Function | Element_Rule | Element_Type,
|
||||
|
||||
//variable is one of these builtin type
|
||||
BuiltinType_Int = 16384,
|
||||
BuiltinType_Real = 32768,
|
||||
BuiltinType_String = 65536,
|
||||
BuiltinType_Boolean = 0x2000,
|
||||
BuiltinType_Binary = 0x4000,
|
||||
BuiltinType_Logic = 0x8000,
|
||||
BuiltinType_Number = BuiltinType_Real | BuiltinType_Int,
|
||||
BuiltinType_Any = BuiltinType_Int | BuiltinType_Real | BuiltinType_String | BuiltinType_Boolean | BuiltinType_Binary | BuiltinType_Logic,
|
||||
|
||||
//the token is root of a branch
|
||||
Branch_If = 0x1_000,
|
||||
Branch_Switch = 0x2_0000,
|
||||
Branch_Repeat = 0x4_0000,
|
||||
Branch_Any = Branch_If | Branch_Repeat | Branch_Switch,
|
||||
|
||||
//the token is one of separators
|
||||
Separator_Inline = 0x8_0000, //, or sth else
|
||||
Separator_Line = 0x10_0000, //; or eth else
|
||||
Separator_Block = 0x20_0000, //{}or sth else
|
||||
Separator_Range = 0x40_0000, //()or sth else
|
||||
Separator_Any = Separator_Inline | Separator_Line | Separator_Block | Separator_Range,
|
||||
|
||||
//the token is a kind of operator
|
||||
Operator_Unary = 0x40_0000,
|
||||
Operator_Binary = 0x80_0000,
|
||||
Operator_SuperType = 0x100_0000,
|
||||
Operator_Any = Operator_Unary | Operator_Binary | Operator_SuperType,
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpNodeTempEnumerator.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 System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public static class ExpNodeNextEnumeratorExtensions
|
||||
{
|
||||
|
||||
public static ExpNodeTempEnumerator AsCollectionEnumerator(
|
||||
this ExpSyntaxNode token,
|
||||
bool unpack )
|
||||
{
|
||||
ExpNodeTempEnumerator enumerator = new ExpNodeTempEnumerator( token, unpack );
|
||||
IExpElementSource type = token.EqualityTypeConvert;
|
||||
while( enumerator.MoveNext() )
|
||||
{
|
||||
if( enumerator. Current != type ) {
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
}
|
||||
return enumerator;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static ExpNodePresidentEnumerator ToPresidentEnumerator( this ExpSyntaxNode node )
|
||||
{
|
||||
return new ExpNodePresidentEnumerator( node );
|
||||
}
|
||||
|
||||
public static ExpNodePresidentEnumerator TupleToPresidentEnumerator(
|
||||
this ExpSyntaxNode tuple )
|
||||
{
|
||||
return new ExpNodePresidentEnumerator( tuple.Right );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpNodePresidentEnumerator : IEnumerator<ExpSyntaxNode>
|
||||
{
|
||||
|
||||
private int _index = -1;
|
||||
private List<ExpSyntaxNode> _begin = new List<ExpSyntaxNode>();
|
||||
|
||||
public ExpNodePresidentEnumerator( ExpSyntaxNode token )
|
||||
{
|
||||
_begin.Add( token );
|
||||
ExpSyntaxNode t = token;
|
||||
while( !ReferenceEquals( t.Next, token ) && t.Next != null )
|
||||
{
|
||||
t = t.Next;
|
||||
_begin.Add( t );
|
||||
}
|
||||
}
|
||||
|
||||
public ExpSyntaxNode this[ int index ]
|
||||
{
|
||||
get
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative( index );
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan( index, _begin.Count );
|
||||
return _begin[ index ];
|
||||
}
|
||||
}
|
||||
|
||||
public ExpSyntaxNode Current => _begin[ _index ];
|
||||
|
||||
public int Count => _begin.Count;
|
||||
|
||||
public void AssertEnumeratorCount( int count )
|
||||
{
|
||||
if( _begin.Count != count ) {
|
||||
throw new InvalidOperationException(
|
||||
$"Enumerator count mismatch. Expected {count}, but got {_begin.Count}." );
|
||||
}
|
||||
}
|
||||
|
||||
public void AssertEnumeratorCount( int min, int max )
|
||||
{
|
||||
if( _begin.Count < min || _begin.Count > max ) {
|
||||
throw new InvalidOperationException(
|
||||
$"Enumerator count mismatch. Expected between {min} and {max}, but got {_begin.Count}." );
|
||||
}
|
||||
}
|
||||
|
||||
public Span<ExpSyntaxNode> AsSpan()
|
||||
{
|
||||
return CollectionsMarshal.AsSpan( _begin );
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if( _index < _begin.Count - 1 )
|
||||
{
|
||||
_index++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
object IEnumerator.Current => this.Current;
|
||||
|
||||
}
|
||||
|
||||
public class ExpNodeTempEnumerator : IEnumerator<ExpSyntaxNode>
|
||||
{
|
||||
|
||||
private ExpSyntaxNode? _current,_begin;
|
||||
|
||||
public ExpNodeTempEnumerator( ExpSyntaxNode node )
|
||||
{
|
||||
_current = null;
|
||||
_begin = node;
|
||||
}
|
||||
|
||||
public ExpNodeTempEnumerator( ExpSyntaxNode node, bool unpack )
|
||||
{
|
||||
_current = null;
|
||||
_begin = unpack ? node.Right : node;
|
||||
}
|
||||
|
||||
public ExpSyntaxNode Current => _current!;
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if( _current == null )
|
||||
{
|
||||
_current = _begin;
|
||||
return true;
|
||||
}
|
||||
ExpSyntaxNode next = _current.Next;
|
||||
if( ReferenceEquals( next, _begin ) || next == null ) {
|
||||
return false;
|
||||
}
|
||||
_current = next;
|
||||
return true;
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void IEnumerator.Reset()
|
||||
{
|
||||
_current = null;
|
||||
}
|
||||
|
||||
object IEnumerator.Current => _current;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpPostProcessor.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;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpPostProcessor
|
||||
{
|
||||
|
||||
private readonly string _interfaceName /*= typeof( )/**/;
|
||||
private readonly string _sourcePath;
|
||||
|
||||
public string Process( string filePath )
|
||||
{
|
||||
Dictionary<string, string> factoryMethods = new Dictionary<string, string>();
|
||||
|
||||
FileStream file = File.OpenRead( filePath );
|
||||
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText( File.ReadAllText( filePath ) );
|
||||
|
||||
CSharpCompilation compilation = CSharpCompilation.Create( "Analysis" )
|
||||
.AddSyntaxTrees( syntaxTree )
|
||||
.AddReferences(
|
||||
MetadataReference.CreateFromFile(
|
||||
typeof( object ).Assembly.Location ) );
|
||||
|
||||
INamedTypeSymbol? interfaceSymbol = compilation.GetTypeByMetadataName( _interfaceName );
|
||||
|
||||
if( interfaceSymbol == null ) {
|
||||
throw new InvalidOperationException( $"Interface '{_interfaceName}' not found." );
|
||||
}
|
||||
|
||||
SemanticModel semanticModel = compilation.GetSemanticModel( syntaxTree );
|
||||
SyntaxNode root = syntaxTree.GetRoot();
|
||||
|
||||
IEnumerable<ClassDeclarationSyntax> classDeclarations = root.DescendantNodes()
|
||||
.OfType<ClassDeclarationSyntax>(
|
||||
)
|
||||
.Where(
|
||||
cls => cls.BaseList?.Types.Any(
|
||||
t => SymbolEqualityComparer.Default
|
||||
.Equals(
|
||||
semanticModel.GetTypeInfo(
|
||||
t.Type )
|
||||
.Type,
|
||||
interfaceSymbol ) ) ??
|
||||
false );
|
||||
|
||||
foreach( ClassDeclarationSyntax classDeclaration in classDeclarations )
|
||||
{
|
||||
string className = classDeclaration.Identifier.Text;
|
||||
IMethodSymbol? factoryMethod = interfaceSymbol.GetMembers()
|
||||
.OfType<IMethodSymbol>()
|
||||
.FirstOrDefault(
|
||||
m => m.IsStatic &&
|
||||
m.Name == "CreateInstance" );
|
||||
|
||||
if( factoryMethod != null ) {
|
||||
factoryMethods[ className ] = $"() => {interfaceSymbol.Name}.CreateInstance()";
|
||||
}
|
||||
}
|
||||
|
||||
string code = "var factoryMethods = new Dictionary<string, Func<object>>\n{\n";
|
||||
code += string.Join(
|
||||
",\n", factoryMethods.Select( kvp => $" {{ \"{kvp.Key}\", {kvp.Value} }}" ) );
|
||||
code += "\n};";
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSchemaBase.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.Collections;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public abstract class ExpSchema
|
||||
{
|
||||
|
||||
public static ExpSchema BuiltinSchema
|
||||
{
|
||||
get => ExpSchema_Builtin.Only;
|
||||
}
|
||||
|
||||
public string Name { get; internal set; }
|
||||
|
||||
public abstract void LoadFromSource( ExpSchemaSource source );
|
||||
|
||||
public abstract bool TryGetConst( string name, out ExpElementInstance c );
|
||||
|
||||
public abstract bool TryGetEntity( string name, out ExpEntitySource e );
|
||||
|
||||
public abstract bool TryGetFunction( string name, out ExpFunctionSource f );
|
||||
|
||||
public abstract bool TryGetProcedure( string name, out ExpProcedureSource p );
|
||||
|
||||
public abstract bool TryGetRule( string name, out ExpRuleSource r );
|
||||
|
||||
public abstract bool TryGetSchemaInclude( string name, out ExpSchema include );
|
||||
|
||||
public abstract bool TryGetType( string name, out ExpTypeSource t );
|
||||
|
||||
#pragma warning disable CS8618
|
||||
protected FrozenDictionary<string, ExpElementInstance> ConstDict { get; set; }
|
||||
|
||||
public IEnumerable<ExpSchema> IncludedSchema => IncludedSchema;
|
||||
|
||||
protected FrozenDictionary<string, ExpEntitySource> EntityDict { get; set; }
|
||||
|
||||
protected FrozenDictionary<string, ExpFunctionSource> FunctionDict { get; set; }
|
||||
|
||||
protected ConcurrentStringHashMultiplexer StringMultiplexer => ExpressCompile.Multiplexer;
|
||||
|
||||
protected ConcurrentDictionary<string, ExpProcedureSource> ProcedureDict { get; set; }
|
||||
|
||||
protected FrozenDictionary<string, ExpRuleSource> RuleDict { get; set; }
|
||||
|
||||
protected FrozenDictionary<string, ExpSchema> SchemaInclude { get; set; }
|
||||
|
||||
protected FrozenDictionary<string, ExpTypeSource> TypeDict { get; set; }
|
||||
#pragma warning restore CS8618
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSchemaSource.Compile.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.Script.Express
|
||||
{
|
||||
public enum ExpressCompileOption
|
||||
{
|
||||
|
||||
Default = 0,
|
||||
Translate = 1,
|
||||
Compile = 2,
|
||||
|
||||
}
|
||||
|
||||
public partial class ExpSchemaSource
|
||||
{
|
||||
|
||||
public ExpSchema Compile( ExpressCompileOption option )
|
||||
{
|
||||
switch( option )
|
||||
{
|
||||
case ExpressCompileOption.Default:
|
||||
return Compile_Translate( option );
|
||||
case ExpressCompileOption.Translate:
|
||||
return Compile_Translate( option );
|
||||
case ExpressCompileOption.Compile:
|
||||
throw new NotSupportedException();
|
||||
default:
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
internal GeneratedExpSchema Compile_Translate( ExpressCompileOption option )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSchemaSource.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.Collections;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpSchemaSource
|
||||
{
|
||||
|
||||
private static Regex
|
||||
_constDefineBegin = GetConstDefineBegin(),
|
||||
_constDefineEnd = GetConstDefineEnd(),
|
||||
_schemaBegin = GetSchemaBegin(),
|
||||
_schemaEnd = GetSchemaEnd(),
|
||||
_entityDefineBegin = GetEntityDefineBegin(),
|
||||
_entityDefineEnd = GetEntityDefineEnd(),
|
||||
_typeDefineBegin = GetTypeDefineBegin(),
|
||||
_typeDefineEnd = GetTypeDefineEnd(),
|
||||
_functionDefineBegin = GetFunctionDefineBegin(),
|
||||
_functionDefineEnd = GetFunctionDefineEnd(),
|
||||
_ruleDefineBegin = GetRuleDefineBegin(),
|
||||
_ruleDefineEnd = GetRuleDefineEnd();
|
||||
|
||||
private readonly GeneratedExpSchema _compileResult = new GeneratedExpSchema();
|
||||
|
||||
private List<IExpElementSource> _sourceCache = [];
|
||||
|
||||
private string name;
|
||||
|
||||
public ExpSchemaSource() { }
|
||||
|
||||
public List<IExpElementSource> Cache
|
||||
{
|
||||
get => _sourceCache;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _compileResult.Name;
|
||||
internal set => _compileResult.Name = value;
|
||||
}
|
||||
|
||||
public ExpSchema Organize()
|
||||
{
|
||||
_compileResult.LoadFromSource( this );
|
||||
return _compileResult;
|
||||
}
|
||||
|
||||
public void ReadSchema( ExpFileSource reader )
|
||||
{
|
||||
string line = reader.ReadLine();
|
||||
while( !_schemaBegin.IsMatch( line ) ) {
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
name = _schemaBegin.Match( line ).Groups[ "namespace" ].Value;
|
||||
|
||||
while( !_schemaEnd.IsMatch( line ) )
|
||||
{
|
||||
if( TryReadConst( line, reader, out IExpElementSource source ) )
|
||||
{
|
||||
_sourceCache.Add( source );
|
||||
} else if( TryReadType( line, reader, out source ) )
|
||||
{
|
||||
_sourceCache.Add( source );
|
||||
} else if( TryReadEntity( line, reader, out source ) )
|
||||
{
|
||||
_sourceCache.Add( source );
|
||||
} else if( TryReadRule( line, reader, out source ) )
|
||||
{
|
||||
_sourceCache.Add( source );
|
||||
} else if( TryReadFunction( line, reader, out source ) ) {
|
||||
_sourceCache.Add( source );
|
||||
}
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryReadSchema(
|
||||
string firstLine,
|
||||
ExpFileSource reader,
|
||||
out ExpSchemaSource source )
|
||||
{
|
||||
if( !_schemaBegin.IsMatch( firstLine ) )
|
||||
{
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
ExpSchemaSource _source = new ExpSchemaSource();
|
||||
_source.name = _schemaBegin.Match( firstLine ).Groups[ "namespace" ].Value;
|
||||
|
||||
while( !_schemaEnd.IsMatch( firstLine ) )
|
||||
{
|
||||
if( _source.TryReadConst( firstLine, reader,
|
||||
out IExpElementSource _elementSource ) )
|
||||
{
|
||||
_source._sourceCache.Add( _elementSource );
|
||||
} else if( _source.TryReadType( firstLine, reader, out _elementSource ) )
|
||||
{
|
||||
_source._sourceCache.Add( _elementSource );
|
||||
} else if( _source.TryReadEntity( firstLine, reader, out _elementSource ) )
|
||||
{
|
||||
_source._sourceCache.Add( _elementSource );
|
||||
} else if( _source.TryReadRule( firstLine, reader, out _elementSource ) )
|
||||
{
|
||||
_source._sourceCache.Add( _elementSource );
|
||||
} else if( _source.TryReadFunction( firstLine, reader, out _elementSource ) ) {
|
||||
_source._sourceCache.Add( _elementSource );
|
||||
}
|
||||
firstLine = reader.ReadLine();
|
||||
}
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
|
||||
[GeneratedRegex( @"\s*CONSTANT" )]
|
||||
private static partial Regex GetConstDefineBegin();
|
||||
|
||||
[GeneratedRegex( @"\s*END_CONSTANT;" )]
|
||||
private static partial Regex GetConstDefineEnd();
|
||||
|
||||
[GeneratedRegex( @"\s*ENTITY\s*(?<TypeName>[A-Za-z0-9_]+)\s*", RegexOptions.Compiled )]
|
||||
private static partial Regex GetEntityDefineBegin();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"\s*END_ENTITY;\s*--\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
|
||||
RegexOptions.Compiled )]
|
||||
private static partial Regex GetEntityDefineEnd();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"\s*FUNCTION\s*\s*(?<FunctionName>[a-zA-Z0-9_]+)\s*(?<Remaining>.*)",
|
||||
RegexOptions.Compiled )]
|
||||
private static partial Regex GetFunctionDefineBegin();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"\s*END_FUNCTION\s*;\s*--\s*(?<FunctionName>[a-zA-Z0-9_]+)",
|
||||
RegexOptions.Compiled )]
|
||||
private static partial Regex GetFunctionDefineEnd();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"\s*RULE\s*(?<RuleName>[a-zA-Z0-9_]+)\s*FOR\s*\((?<Target>[a-zA-Z0-9_]*(?:\s*\)\s*;)?)",
|
||||
RegexOptions.Compiled )]
|
||||
private static partial Regex GetRuleDefineBegin();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"\s*END_RULE\s*;\s*--\s*(?<RuleName>[A-Za-z0-9_]+)",
|
||||
RegexOptions.Compiled )]
|
||||
private static partial Regex GetRuleDefineEnd();
|
||||
|
||||
[GeneratedRegex( @"\s*SCHEMA\s*(?<namespace>[A-Za-z0-9_]+)\s?;" )]
|
||||
private static partial Regex GetSchemaBegin();
|
||||
|
||||
[GeneratedRegex( @"END_SCHEMA;\s*--\s*(?<namespace>[A-Za-z0-9_]+)", RegexOptions.Compiled )]
|
||||
private static partial Regex GetSchemaEnd();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"\s*TYPE\s+(?<TypeName>[A-Za-z0-9_]+)\s*=\s*(?<Remaining>[A-Z]+)",
|
||||
RegexOptions.Compiled )]
|
||||
private static partial Regex GetTypeDefineBegin();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"\s*END_TYPE\s*;\s*--\s*(?<TypeName>[a-zA-Z0-9_]+)",
|
||||
RegexOptions.Compiled )]
|
||||
private static partial Regex GetTypeDefineEnd();
|
||||
|
||||
private bool TryReadConst(
|
||||
string firstLine,
|
||||
ExpFileSource reader,
|
||||
out IExpElementSource source )
|
||||
{
|
||||
Match match = _constDefineBegin.Match( firstLine );
|
||||
if( match.Success )
|
||||
{
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||
"END_CONSTANT", reader.Location );
|
||||
ExpConstantCollectionSource _source = new ExpConstantCollectionSource( transmitter );
|
||||
string line = reader.ReadLine();
|
||||
while( !_constDefineEnd.IsMatch( line ) )
|
||||
{
|
||||
transmitter.WriteLine( line );
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
transmitter.WriteLine( "END_CONSTANT" );
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryReadEntity(
|
||||
string firstLine,
|
||||
ExpFileSource reader,
|
||||
out IExpElementSource source )
|
||||
{
|
||||
Match match = _entityDefineBegin.Match( firstLine );
|
||||
if( match.Success )
|
||||
{
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||
"END_ENTITY", reader.Location );
|
||||
ExpEntitySource _source = new ExpEntitySource(
|
||||
match.Groups[ "TypeName" ].ToString(), transmitter );
|
||||
string line = reader.ReadLine();
|
||||
match = _entityDefineEnd.Match( line );
|
||||
while( !match.Success )
|
||||
{
|
||||
transmitter.WriteLine( line );
|
||||
line = reader.ReadLine();
|
||||
match = _entityDefineEnd.Match( line );
|
||||
}
|
||||
string endedName = match.Groups[ "TypeName" ].ToString();
|
||||
if( !string.Equals( endedName, _source.Name ) ) {
|
||||
throw new ExpInvalidElementDeclareEndingExceptions( _source.Name, endedName );
|
||||
}
|
||||
transmitter.WriteLine( "END_ENTITY" );
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryReadFunction(
|
||||
string firstLine,
|
||||
ExpFileSource reader,
|
||||
out IExpElementSource source )
|
||||
{
|
||||
Match match = _functionDefineBegin.Match( firstLine );
|
||||
if( match.Success )
|
||||
{
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||
"END_FUNCTION", reader.Location );
|
||||
ExpFunctionSource _source = new ExpFunctionSource(
|
||||
match.Groups[ "FunctionName" ].ToString(), transmitter );
|
||||
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
|
||||
string line = reader.ReadLine();
|
||||
match = _functionDefineEnd.Match( line );
|
||||
while( !match.Success )
|
||||
{
|
||||
transmitter.WriteLine( line );
|
||||
line = reader.ReadLine();
|
||||
match = _functionDefineEnd.Match( line );
|
||||
}
|
||||
string endedName = match.Groups[ "FunctionName" ].ToString();
|
||||
if( !string.Equals( endedName, _source.Name ) ) {
|
||||
throw new ExpInvalidElementDeclareEndingExceptions( _source.Name, endedName );
|
||||
}
|
||||
transmitter.WriteLine( "END_FUNCTION" );
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryReadRule(
|
||||
string firstLine,
|
||||
ExpFileSource reader,
|
||||
out IExpElementSource source )
|
||||
{
|
||||
Match match = _ruleDefineBegin.Match( firstLine );
|
||||
if( match.Success )
|
||||
{
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||
"END_RULE", reader.Location );
|
||||
ExpRuleSource _source = new ExpRuleSource(
|
||||
match.Groups[ "RuleName" ].ToString(), transmitter );
|
||||
string target = match.Groups[ "Target" ].ToString();
|
||||
if( !string.IsNullOrEmpty( target ) ) {
|
||||
transmitter.WriteLine( target );
|
||||
}
|
||||
string line = reader.ReadLine();
|
||||
match = _ruleDefineEnd.Match( line );
|
||||
while( !match.Success )
|
||||
{
|
||||
transmitter.WriteLine( line );
|
||||
line = reader.ReadLine();
|
||||
match = _ruleDefineEnd.Match( line );
|
||||
}
|
||||
string endedName = match.Groups[ "RuleName" ].ToString();
|
||||
if( !string.Equals( endedName, _source.Name ) ) {
|
||||
throw new ExpInvalidElementDeclareEndingExceptions( _source.Name, endedName );
|
||||
}
|
||||
transmitter.WriteLine( "END_RULE" );
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryReadType(
|
||||
string firstLine,
|
||||
ExpFileSource reader,
|
||||
out IExpElementSource source )
|
||||
{
|
||||
Match match = _typeDefineBegin.Match( firstLine );
|
||||
if( match.Success )
|
||||
{
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||
"END_ENTITY", reader.Location );
|
||||
ExpTypeSource _source = new ExpTypeSource(
|
||||
match.Groups[ "TypeName" ].ToString(), transmitter );
|
||||
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
|
||||
string line = reader.ReadLine();
|
||||
match = _typeDefineEnd.Match( line );
|
||||
while( !match.Success )
|
||||
{
|
||||
transmitter.WriteLine( line );
|
||||
line = reader.ReadLine();
|
||||
match = _typeDefineEnd.Match( line );
|
||||
}
|
||||
string endedName = match.Groups[ "TypeName" ].ToString();
|
||||
if( !string.Equals( endedName, _source.Name ) ) {
|
||||
throw new ExpInvalidElementDeclareEndingExceptions( _source.Name, endedName );
|
||||
}
|
||||
transmitter.WriteLine( "END_ENTITY" );
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSource.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.IO;
|
||||
using System.IO.MemoryMappedFiles;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpFileSource : IDisposable, IScriptSourceProvider
|
||||
{
|
||||
|
||||
private bool disposedValue;
|
||||
private FileStream _expFileStream;
|
||||
private int _location;
|
||||
private MemoryMappedFile _expMemoryMappedFile;
|
||||
private MemoryMappedViewStream _expMemoryMappedStream;
|
||||
|
||||
private SemaphoreSlim readLineSemaphore = new SemaphoreSlim( 1, 1 );
|
||||
private StreamReader _memoryReader;
|
||||
|
||||
public ExpFileSource( string path )
|
||||
{
|
||||
if( !File.Exists( path ) ) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
_expFileStream = new FileStream( path, FileMode.Open, FileAccess.Read );
|
||||
_expMemoryMappedFile = MemoryMappedFile.CreateFromFile(
|
||||
_expFileStream, null, 0, MemoryMappedFileAccess.Read, HandleInheritability.None,
|
||||
true );
|
||||
_expMemoryMappedStream = _expMemoryMappedFile.CreateViewStream(
|
||||
offset: 0, size: 0, access: MemoryMappedFileAccess.Read );
|
||||
_memoryReader = new StreamReader( _expMemoryMappedStream );
|
||||
}
|
||||
|
||||
public bool IsEmpty => _memoryReader.EndOfStream;
|
||||
|
||||
public int Location => _location;
|
||||
|
||||
// ~ExpFileSource()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose( disposing: true );
|
||||
GC.SuppressFinalize( this );
|
||||
}
|
||||
|
||||
public void EndWriting() { }
|
||||
|
||||
public string ReadLine()
|
||||
{
|
||||
readLineSemaphore.Wait();
|
||||
string line = _memoryReader.ReadLine()!;
|
||||
_location++;
|
||||
readLineSemaphore.Release();
|
||||
return line;
|
||||
}
|
||||
|
||||
public string ReadLine( out int position )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ResetToBegin()
|
||||
{
|
||||
readLineSemaphore.Wait();
|
||||
_expMemoryMappedStream.Seek( 0, SeekOrigin.Begin );
|
||||
_location = 0;
|
||||
readLineSemaphore.Release();
|
||||
}
|
||||
|
||||
protected virtual void Dispose( bool disposing )
|
||||
{
|
||||
if( !disposedValue )
|
||||
{
|
||||
if( disposing )
|
||||
{
|
||||
_expFileStream.Dispose();
|
||||
_expMemoryMappedFile.Dispose();
|
||||
_expMemoryMappedStream.Dispose();
|
||||
_memoryReader.Dispose();
|
||||
}
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
IScriptSourceProvider IScriptSourceProvider.Slice( int location, int count )
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSyntaxAnalyzer.CaseOf.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.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
private bool AppendToken_CaseOf( Token t )
|
||||
{
|
||||
Token op;
|
||||
ExpSyntaxNode root;
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.Case:
|
||||
CaseOfStateCache state = new CaseOfStateCache( t );
|
||||
_cache.CurrentDepthMark.StateCache = state;
|
||||
state.CurrentState = t.Value;
|
||||
return true;
|
||||
case ExpKeyword.Of:
|
||||
state = _cache.StateOfCurrentDepth<CaseOfStateCache>();
|
||||
while( _cache.TryPopOperator( out op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
_cache.PopOperand( out _, out root );
|
||||
state.CaseExpression = root;
|
||||
state.CurrentState = t.Value;
|
||||
return true;
|
||||
case ":":
|
||||
state = _cache.StateOfCurrentDepth<CaseOfStateCache>();
|
||||
if( state.CurrentState != ExpKeyword.Of &&
|
||||
state.CurrentState != ExpKeyword.Otherwise )
|
||||
{
|
||||
root = _cache.PackAllStatements();
|
||||
state.CloseCurrentCase( root );
|
||||
}
|
||||
while( _cache.TryPopOperator( out op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
if( !_cache.PopOperand( out _, out root ) )
|
||||
{
|
||||
// sth wrong, case expression cannot generate;
|
||||
}
|
||||
state.CurrentCase = root;
|
||||
return true;
|
||||
case ExpKeyword.Otherwise:
|
||||
state = _cache.StateOfCurrentDepth<CaseOfStateCache>();
|
||||
root = _cache.PackAllStatements();
|
||||
state.CloseCurrentCase( root );
|
||||
state.CurrentState = t.Value;
|
||||
return true;
|
||||
case ExpKeyword.EndCase:
|
||||
state = _cache.StateOfCurrentDepth<CaseOfStateCache>();
|
||||
root = _cache.PackAllStatements();
|
||||
state.CloseCurrentCase( root );
|
||||
root = new ExpSwitchNode(
|
||||
state.Begin, state.CaseExpression, state.DefaultCase, state.Cases );
|
||||
_cache.DecreaseDepth();
|
||||
_cache.StatementsInDepth.Push( root );
|
||||
return true;
|
||||
default:
|
||||
AppendToken_Common( t );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class CaseOfStateCache : ICompileDepthState
|
||||
{
|
||||
|
||||
public CaseOfStateCache( Token t )
|
||||
{
|
||||
Begin = t;
|
||||
}
|
||||
|
||||
public Dictionary<ExpSyntaxNode, ExpSyntaxNode> Cases { get; } = new Dictionary<ExpSyntaxNode, ExpSyntaxNode>(
|
||||
);
|
||||
|
||||
public ExpSyntaxNode CaseExpression { get; set; }
|
||||
|
||||
public ExpSyntaxNode DefaultCase { get; set; }
|
||||
|
||||
public ExpSyntaxNode CurrentCase { get; set; }
|
||||
|
||||
public string CurrentState { get; set; }
|
||||
|
||||
public Token Begin { get; init; }
|
||||
|
||||
public void CloseCurrentCase( ExpSyntaxNode root )
|
||||
{
|
||||
Cases.Add( CurrentCase, root );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSyntaxAnalyzer.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 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.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
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 ExpSyntaxNode? 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 ExpSyntaxNode? expNode );
|
||||
if( !_cache.PopOperand( out Token colleToken, out ExpSyntaxNode? 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 );
|
||||
ExpSyntaxNode node = ConvertAndPushOneOperator( op );
|
||||
}
|
||||
switch( _cache.OperandAheadOfDepth )
|
||||
{
|
||||
case 0:
|
||||
if( t.Value == ";" ) {
|
||||
return true;
|
||||
}
|
||||
_cache.StatementsInDepth.Push( ExpSyntaxNode.Empty );
|
||||
goto case 1;
|
||||
case 1:
|
||||
_cache.PopOperand( out _, out ExpSyntaxNode? 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();
|
||||
ExpSyntaxNode 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 ExpSyntaxNode? node ) &&
|
||||
node is ExpElementInstance instance )
|
||||
{
|
||||
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
|
||||
return true;
|
||||
} else if( _tempVariableInLoops.TryGetValue( t.Value, out instance! ) )
|
||||
{
|
||||
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
|
||||
return true;
|
||||
} else if( _cache.IsLastAddedOperator )
|
||||
{
|
||||
if( _cache.PeekOperand( out _,
|
||||
out ExpSyntaxNode? 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,69 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSyntaxAnalyzer.DepthEnter.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.Diagnostics;
|
||||
|
||||
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.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
internal void AttemptEnterNewDepth( Token t )
|
||||
{
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.If:
|
||||
_cache.IncreaseDepth( ( int )ExpCompileStateCode.IfBranch );
|
||||
return;
|
||||
case ExpKeyword.Case:
|
||||
_cache.IncreaseDepth( ( int )ExpCompileStateCode.CaseBranch );
|
||||
return;
|
||||
case ExpKeyword.Repeat:
|
||||
_cache.IncreaseDepth( ( int )ExpCompileStateCode.RepeatLoop );
|
||||
return;
|
||||
case ExpKeyword.While:
|
||||
_cache.IncreaseDepth( ( int )ExpCompileStateCode.UntilLoop );
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
public void ThrowCompileException( int errorCode )
|
||||
{
|
||||
switch( errorCode )
|
||||
{
|
||||
case 0 or 1:
|
||||
return;
|
||||
case TokenTypeNotMatch:
|
||||
throw new Exception();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSyntaxAnalyzer.If.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;
|
||||
using System.Xml.Linq;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
private bool AppendToken_IfBranch( Token t )
|
||||
{
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.If:
|
||||
IfBranchStateCache state = new IfBranchStateCache();
|
||||
_cache.CurrentDepthMark.StateCache = state;
|
||||
state.CurrentState = t.Value;
|
||||
return true;
|
||||
case ExpKeyword.Then:
|
||||
state = _cache.StateOfCurrentDepth<IfBranchStateCache>();
|
||||
if( state.CurrentState == ExpKeyword.If )
|
||||
{
|
||||
while( _cache.TryPopOperator( out Token op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
_cache.PopOperand( out _, out ExpSyntaxNode? node );
|
||||
state.CurrentState = t.Value;
|
||||
state.BoolExpression = node;
|
||||
} else
|
||||
{
|
||||
throw new ExpCompileException(
|
||||
t, $"Keyword {t.Value} should be after keyword {ExpKeyword.Then}" );
|
||||
}
|
||||
return true;
|
||||
case ExpKeyword.Else:
|
||||
state = _cache.StateOfCurrentDepth<IfBranchStateCache>();
|
||||
if( state.CurrentState == ExpKeyword.Then )
|
||||
{
|
||||
ExpSyntaxNode node = _cache.PackAllStatements();
|
||||
state.CurrentState = t.Value;
|
||||
state.ExpressionIfTrue = node;
|
||||
} else
|
||||
{
|
||||
throw new ExpCompileException(
|
||||
t, $"Keyword {t.Value} should be after keyword {ExpKeyword.Then}" );
|
||||
}
|
||||
return true;
|
||||
|
||||
case ExpKeyword.EndIf:
|
||||
state = _cache.StateOfCurrentDepth<IfBranchStateCache>();
|
||||
if( state.CurrentState == ExpKeyword.Then )
|
||||
{
|
||||
ExpSyntaxNode trueNode = _cache.PackAllStatements();
|
||||
state.CurrentState = t.Value;
|
||||
state.ExpressionIfTrue = trueNode;
|
||||
state.ExpressionIfFalse = ExpSyntaxNode.Empty;
|
||||
} else if( state.CurrentState == ExpKeyword.Else )
|
||||
{
|
||||
ExpSyntaxNode falseNode = _cache.PackAllStatements();
|
||||
state.CurrentState = t.Value;
|
||||
state.ExpressionIfFalse = falseNode;
|
||||
} else
|
||||
{
|
||||
throw new ExpCompileException(
|
||||
t,
|
||||
$"Keyword {t.Value} should be after keyword {ExpKeyword.Then} or {ExpKeyword.Else}" );
|
||||
}
|
||||
ExpIfNode ifNode = new ExpIfNode(
|
||||
state.Begin, state.BoolExpression, state.ExpressionIfTrue,
|
||||
state.ExpressionIfFalse );
|
||||
_cache.DecreaseDepth();
|
||||
_cache.StatementsInDepth.Push( ifNode );
|
||||
return true;
|
||||
default:
|
||||
AppendToken_Common( t );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class IfBranchStateCache : ICompileDepthState
|
||||
{
|
||||
|
||||
public ExpSyntaxNode BoolExpression { get; set; }
|
||||
|
||||
public ExpSyntaxNode ExpressionIfTrue { get; set; }
|
||||
|
||||
public ExpSyntaxNode ExpressionIfFalse { get; set; }
|
||||
|
||||
public string CurrentState { get; set; }
|
||||
|
||||
public Token Begin { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
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 ExpSyntaxNode node )
|
||||
{
|
||||
ExpSyntaxNode 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 = ExpSyntaxNode.Empty;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WARNING: This method cannot process INDEXOF, FUNCTION CALLING, LOOP and any ENDING
|
||||
/// SYMBOLS.
|
||||
/// </summary>
|
||||
private ExpSyntaxNode ConvertAndPushOneOperator( Token op )
|
||||
{
|
||||
switch( op.Flag )
|
||||
{
|
||||
case TokenFlag.Symbol_Unary:
|
||||
TryGenerateUnaryNode( op, out ExpSyntaxNode? 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 ExpSyntaxNode? 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 ExpSyntaxNode? 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 ExpSyntaxNode? 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 ExpSyntaxNode node )
|
||||
{
|
||||
ExpSyntaxNode right = GetNextOperandCache();
|
||||
ExpSyntaxNode 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 = ExpSyntaxNode.Empty;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSyntaxAnalyzer.RangeAndIndex.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.Operations;
|
||||
|
||||
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.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
private void AppendToken_RangeAndIndex( Token t )
|
||||
{
|
||||
ExpSyntaxNode root;
|
||||
switch( t.Value )
|
||||
{
|
||||
case "[":
|
||||
RangeAndIndexState state = new RangeAndIndexState();
|
||||
state.CurrentState = t.Value;
|
||||
_cache.CurrentDepthMark.StateCache = state;
|
||||
break;
|
||||
case "]":
|
||||
state = _cache.StateOfCurrentDepth<RangeAndIndexState>();
|
||||
|
||||
//Generate range or index object
|
||||
if( _cache.StatementsInDepth.Count != 0 )
|
||||
{
|
||||
throw new ExpInvalidSyntaxException(
|
||||
"Range and index syntax error: expected one statement to define range beginning." );
|
||||
}
|
||||
ReverseAnalyzeStatement();
|
||||
root = _cache.StatementsInDepth.Pop();
|
||||
if( ExpNodeFlag.BuiltinType_Int.IsNotInFlag( root.NodeFlag ) ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
root, "integer", root.EqualityTypeConvert?.Name ?? string.Empty );
|
||||
}
|
||||
if( state.CurrentState == "[" ) { } else { }
|
||||
break;
|
||||
case ":":
|
||||
state = _cache.StateOfCurrentDepth<RangeAndIndexState>();
|
||||
if( state.CurrentState != "[" ) {
|
||||
throw new ExpInvalidSyntaxException(
|
||||
"Range and index syntax error: wrong position of :" );
|
||||
}
|
||||
if( _cache.StatementsInDepth.Count != 0 ) {
|
||||
throw new ExpInvalidSyntaxException(
|
||||
"Range and index syntax error: expected one statement to define range beginning." );
|
||||
}
|
||||
ReverseAnalyzeStatement();
|
||||
root = _cache.StatementsInDepth.Pop();
|
||||
if( ExpNodeFlag.BuiltinType_Int.IsNotInFlag( root.NodeFlag ) ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
root, "integer", root.EqualityTypeConvert?.Name ?? string.Empty );
|
||||
}
|
||||
state.RangeStart = root;
|
||||
break;
|
||||
default:
|
||||
state = _cache.StateOfCurrentDepth<RangeAndIndexState>();
|
||||
if( t.Value == "?" )
|
||||
{
|
||||
switch( state.CurrentState )
|
||||
{
|
||||
case ":":
|
||||
_cache.PushOperand( new ExpIntNode( t, int.MaxValue, true ) );
|
||||
break;
|
||||
case "[":
|
||||
_cache.PushOperand( new ExpIntNode( t, int.MaxValue, true ) );
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidSyntaxException(
|
||||
"Range and index syntax error: \"?\" can only be used in range or index" );
|
||||
}
|
||||
}
|
||||
AppendToken_Common( t );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private class RangeAndIndexState : ICompileDepthState
|
||||
{
|
||||
|
||||
public ExpSyntaxNode RangeStart { get; set; }
|
||||
|
||||
public string CurrentState { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSyntaxAnalyzer.RepeatLoop.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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design.Serialization;
|
||||
using System.Linq;
|
||||
using System.Resources;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
private Dictionary<string, ExpElementInstance> _tempVariableInLoops { get; }
|
||||
= new Dictionary<string, ExpElementInstance>();
|
||||
|
||||
private bool AppendToken_RepeatLoop( Token t )
|
||||
{
|
||||
RepeatLoopState state = _cache.StateOfCurrentDepth<RepeatLoopState>();
|
||||
if( state == null )
|
||||
{
|
||||
state = new RepeatLoopState( t );
|
||||
_cache.CurrentDepthMark.StateCache = state;
|
||||
state.CurrentState = t.Value;
|
||||
return true;
|
||||
}
|
||||
switch( state.CurrentState )
|
||||
{
|
||||
case ExpKeyword.Repeat:
|
||||
return TryParseRepeatVariable( state, t );
|
||||
case ExpKeyword.To:
|
||||
return TryParseRepeatEnding( state, t );
|
||||
case ExpKeyword.By:
|
||||
return TryParseRepeatVariable( state, t );
|
||||
case ExpKeyword.Until:
|
||||
return TryParseRepeatUntilRegulation( state, t );
|
||||
case ExpKeyword.Assignment:
|
||||
return TryParseRepeatBeginning( state, t );
|
||||
case ExpKeyword.While:
|
||||
return TryParseRepeatWhileRegulation( state, t );
|
||||
case ExpKeyword.Semicolon:
|
||||
if( t.Value != ExpKeyword.EndRepeat )
|
||||
{
|
||||
AppendToken_Common( t );
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
AppendToken_Common( t );
|
||||
return false;
|
||||
}
|
||||
ExpSyntaxNode root = _cache.PackAllStatements();
|
||||
state.Body = root;
|
||||
_cache.DecreaseDepth();
|
||||
if( ExpTypeSource.IsNullOrVoid( state.IncrementVariableType ) )
|
||||
{
|
||||
root = ExpRepeatNode.Create(
|
||||
state.Position, state.IncrementVariable, state.Begin, state.End,
|
||||
state.IncrementVariable, state.Body, state.UntilExpression,
|
||||
state.WhileExpression );
|
||||
} else
|
||||
{
|
||||
root = ExpRepeatNode.Create(
|
||||
state.Position, state.IncrementVariable.OriginObject, state.Begin, state.End,
|
||||
state.IncrementVariable, state.Body, state.UntilExpression,
|
||||
state.WhileExpression );
|
||||
}
|
||||
_cache.StatementsInDepth.Push( root );
|
||||
_tempVariableInLoops.Remove( state.IncrementVariable.CodeConvertTemplate );
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryParseRepeatBeginning( RepeatLoopState state, Token t )
|
||||
{
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.To:
|
||||
state.CurrentState = ExpKeyword.To;
|
||||
while( _cache.TryPopOperator( out Token op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
_cache.PopOperand( out _, out ExpSyntaxNode? root );
|
||||
state.Begin = root;
|
||||
return true;
|
||||
default:
|
||||
AppendToken_Common( t );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryParseRepeatEnding( RepeatLoopState state, Token t )
|
||||
{
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.By:
|
||||
state.CurrentState = ExpKeyword.By;
|
||||
break;
|
||||
case ExpKeyword.Until:
|
||||
state.CurrentState = ExpKeyword.Until;
|
||||
break;
|
||||
case ExpKeyword.While:
|
||||
state.CurrentState = ExpKeyword.While;
|
||||
break;
|
||||
default:
|
||||
AppendToken_Common( t );
|
||||
return true;
|
||||
}
|
||||
while( _cache.TryPopOperator( out Token op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
_cache.PopOperand( out _, out ExpSyntaxNode? root );
|
||||
state.End = root;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryParseRepeatIncrement( RepeatLoopState state, Token t )
|
||||
{
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.Semicolon:
|
||||
state.CurrentState = ExpKeyword.Semicolon;
|
||||
break;
|
||||
case ExpKeyword.Until:
|
||||
state.CurrentState = ExpKeyword.Until;
|
||||
break;
|
||||
case ExpKeyword.While:
|
||||
state.CurrentState = ExpKeyword.While;
|
||||
break;
|
||||
default:
|
||||
AppendToken_Common( t );
|
||||
return true;
|
||||
}
|
||||
while( _cache.TryPopOperator( out Token op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
_cache.PopOperand( out _, out ExpSyntaxNode? root );
|
||||
state.StepIncrement = root;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryParseRepeatUntilRegulation( RepeatLoopState state, Token t )
|
||||
{
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.Semicolon:
|
||||
state.CurrentState = ExpKeyword.Semicolon;
|
||||
break;
|
||||
default:
|
||||
AppendToken_Common( t );
|
||||
return true;
|
||||
}
|
||||
while( _cache.TryPopOperator( out Token op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
_cache.PopOperand( out _, out ExpSyntaxNode? root );
|
||||
state.UntilExpression = root;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryParseRepeatVariable( RepeatLoopState state, Token t )
|
||||
{
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.Integer:
|
||||
state.IncrementVariableType = ExpressCompile.ExpInt;
|
||||
return true;
|
||||
case
|
||||
ExpKeyword.Real:
|
||||
state.IncrementVariableType = ExpressCompile.ExpReal;
|
||||
return true;
|
||||
case ExpKeyword.Assignment:
|
||||
state.CurrentState = ExpKeyword.Assignment;
|
||||
return true;
|
||||
default:
|
||||
if( ExpTypeSource.IsNullOrVoid( state.IncrementVariableType ) )
|
||||
{
|
||||
if( ( _local.TryGetMember( t.Value,
|
||||
out ExpSyntaxNode? node ) &&
|
||||
node is ExpElementInstance instance ) ||
|
||||
_tempVariableInLoops.TryGetValue( t.Value, out instance ) )
|
||||
{
|
||||
state.IncrementVariable = ExpInstanceReferenceNode.MakeReferenceFrom(
|
||||
t, instance );
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidSyntaxException(
|
||||
$"Variable {t.Value} is not declared or initialized." );
|
||||
}
|
||||
} else
|
||||
{
|
||||
ExpElementInstance variable = state.IncrementVariableType
|
||||
.CreateInstanceNode( t );
|
||||
_tempVariableInLoops.Add( t.Value, variable );
|
||||
state.IncrementVariable = ExpInstanceReferenceNode.MakeReferenceFrom(
|
||||
t, variable );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryParseRepeatWhileRegulation( RepeatLoopState state, Token t )
|
||||
{
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.Until:
|
||||
state.CurrentState = ExpKeyword.Until;
|
||||
break;
|
||||
default:
|
||||
AppendToken_Common( t );
|
||||
return true;
|
||||
}
|
||||
while( _cache.TryPopOperator( out Token op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
_cache.PopOperand( out _, out ExpSyntaxNode? root );
|
||||
state.WhileExpression = root;
|
||||
return true;
|
||||
}
|
||||
|
||||
private class RepeatLoopState : ICompileDepthState
|
||||
{
|
||||
|
||||
public RepeatLoopState( Token t )
|
||||
{
|
||||
Position = t;
|
||||
UntilExpression = ExpSyntaxNode.Empty;
|
||||
WhileExpression = ExpSyntaxNode.Empty;
|
||||
}
|
||||
|
||||
public ExpInstanceReferenceNode IncrementVariable { get; set; }
|
||||
|
||||
public ExpSyntaxNode StepIncrement { get; set; }
|
||||
|
||||
public ExpSyntaxNode Begin { get; set; }
|
||||
|
||||
public ExpSyntaxNode End { get; set; }
|
||||
|
||||
public ExpSyntaxNode UntilExpression { get; set; }
|
||||
|
||||
public ExpSyntaxNode WhileExpression { get; set; }
|
||||
|
||||
public ExpSyntaxNode Body { get; set; }
|
||||
|
||||
public ExpTypeSource IncrementVariableType { get; set; }
|
||||
|
||||
public string CurrentState { get; set; }
|
||||
|
||||
public Token Position { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSyntaxAnalyzer.ReverseAnalysing.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.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
private void ClosePrefixReverse( Token rightSeparator )
|
||||
{
|
||||
ExpSyntaxNode root;
|
||||
ReverseAnalyzeStatement();
|
||||
root = _cache.PackAllStatements();
|
||||
if( rightSeparator.Value == ")" ) {
|
||||
root = ExpTupleNode.Pack( root );
|
||||
}
|
||||
_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" );
|
||||
}
|
||||
}
|
||||
|
||||
private void ReverseAnalyzeStatement()
|
||||
{
|
||||
ExpSyntaxNode root;
|
||||
if( _cache.OperatorAheadOfDepth == 0 )
|
||||
{
|
||||
switch( _cache.OperandAheadOfDepth )
|
||||
{
|
||||
case 1:
|
||||
_cache.PopOperand( out _, out ExpSyntaxNode? statement );
|
||||
_cache.StatementsInDepth.Push( statement );
|
||||
break;
|
||||
case 0:
|
||||
_cache.StatementsInDepth.Push( ExpSyntaxNode.Empty );
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidSyntaxException(
|
||||
"More than one operand but no operator provided." );
|
||||
}
|
||||
} else
|
||||
{
|
||||
while( _cache.TryPopOperator( out Token op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
_cache.PopOperand( out _, out root );
|
||||
_cache.StatementsInDepth.Push( root );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSyntaxAnalyzer.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.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.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer : ISyntaxAnalyzer
|
||||
{
|
||||
|
||||
private const int EndLine = 1;
|
||||
private const int TokenGenerated = 0;
|
||||
private const int TokenTypeNotMatch = -1;
|
||||
|
||||
private CompileStack<ExpSyntaxNode, IExpElementSource> _cache;
|
||||
private ExpSchema _context;
|
||||
private ExpSyntaxNode _lastStatement;
|
||||
private IExpElementSource _local;
|
||||
|
||||
public ExpSyntaxAnalyzer()
|
||||
{
|
||||
_cache = new CompileStack<ExpSyntaxNode, IExpElementSource>();
|
||||
}
|
||||
|
||||
public ExpSyntaxAnalyzer( ExpSchema context, IExpElementSource local )
|
||||
{
|
||||
_cache = new CompileStack<ExpSyntaxNode, IExpElementSource>();
|
||||
ArgumentNullException.ThrowIfNull( context );
|
||||
if( context is not ExpSchema_Builtin )
|
||||
{
|
||||
_context = context;
|
||||
} else
|
||||
{
|
||||
throw new InvalidCastException( "Not a valid Schema type" );
|
||||
}
|
||||
_local = local;
|
||||
}
|
||||
|
||||
/**/
|
||||
public void AppendToken( Token expToken )
|
||||
{
|
||||
switch( ( ExpCompileStateCode )TryEnterBranch( expToken ).Usage )
|
||||
{
|
||||
case ExpCompileStateCode.IfBranch:
|
||||
AppendToken_IfBranch( expToken );
|
||||
break;
|
||||
case ExpCompileStateCode.CaseBranch:
|
||||
AppendToken_CaseOf( expToken );
|
||||
break;
|
||||
case ExpCompileStateCode.RepeatLoop:
|
||||
AppendToken_RepeatLoop( expToken );
|
||||
break;
|
||||
default:
|
||||
AppendToken_Common( expToken );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public ExpSyntaxNode GetNextOperandCache()
|
||||
{
|
||||
if( _cache.PopOperand( out Token t, out ExpSyntaxNode? n ) )
|
||||
{
|
||||
return n;
|
||||
} else
|
||||
{
|
||||
// process some rare case here
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append a token to top of cache. This method will automatically convert token to node
|
||||
/// if meets separators or operators.
|
||||
/// </summary>
|
||||
private void AppendToken_Common( 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;
|
||||
}
|
||||
}
|
||||
|
||||
private CompileDepthMark TryEnterBranch( Token t )
|
||||
{
|
||||
if( t.Flag == TokenFlag.String ) {
|
||||
return _cache.CurrentDepthMark;
|
||||
}
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.Case:
|
||||
return _cache.IncreaseDepth( ( int )ExpCompileStateCode.CaseBranch );
|
||||
case ExpKeyword.If:
|
||||
return _cache.IncreaseDepth( ( int )ExpCompileStateCode.IfBranch );
|
||||
case ExpKeyword.Repeat:
|
||||
return _cache.IncreaseDepth( ( int )ExpCompileStateCode.RepeatLoop );
|
||||
default:
|
||||
return _cache.CurrentDepthMark;
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
public enum ExpCompileStateCode
|
||||
{
|
||||
|
||||
Common,
|
||||
ForLoop,
|
||||
RepeatLoop,
|
||||
UntilLoop,
|
||||
IfBranch,
|
||||
CaseBranch,
|
||||
CollectionIndex,
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,423 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpTokenReader.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 CommunityToolkit.HighPerformance;
|
||||
|
||||
using StgSharp.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public abstract class ExpTokenReaderPreProcessor
|
||||
{
|
||||
|
||||
public static ExpTokenReaderPreProcessor Default { get; } = new DefaultProcessor();
|
||||
|
||||
public abstract bool Process( string codeLine, int line, ref int current, out Token t );
|
||||
|
||||
private class DefaultProcessor : ExpTokenReaderPreProcessor
|
||||
{
|
||||
|
||||
public override bool Process( string codeLine, int line, ref int current, out Token t )
|
||||
{
|
||||
t = Token.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class ExpTokenReader : IScriptTokenReader
|
||||
{
|
||||
|
||||
private const int
|
||||
MultiLineEnd = 0x0029002A; // *)
|
||||
|
||||
private const string TokenMark = "token", EndMark = "end", RestMark = "rest";
|
||||
|
||||
private bool _isReadingMultiLineComment;
|
||||
private int _current, _lineNum;
|
||||
private IScriptSourceProvider _provider;
|
||||
|
||||
private Regex
|
||||
_nextWordTokenPattern = GetNextWordTokenPattern(),
|
||||
_nextStringLiteralPattern = GetStringLiteralPattern(),
|
||||
_nextNumberLiteralPattern = GetNumberLiteralPattern(),
|
||||
_nextStringLiteralPatternWithSingle = GetStringLiteralPatternWithSingle(),
|
||||
_skipBlankPattern = GetSkipBlankPattern(),
|
||||
_nextSymbolPattern = GetSymbolPattern();
|
||||
private string _lineCache;
|
||||
private Token _last;
|
||||
|
||||
public ExpTokenReader( IScriptSourceProvider provider )
|
||||
{
|
||||
_provider = provider;
|
||||
_current = 0;
|
||||
_lineCache = string.Empty;
|
||||
_isReadingMultiLineComment = false;
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get => ( ( string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length ) ) &&
|
||||
_provider.IsEmpty;
|
||||
}
|
||||
|
||||
public ExpTokenReaderPreProcessor TokenReaderPreProcessor { get; set; } = ExpTokenReaderPreProcessor.Default;
|
||||
|
||||
public int LineNumber
|
||||
{
|
||||
get => _provider.Location;
|
||||
}
|
||||
|
||||
public unsafe ReadOnlySpan<char> ReadLine()
|
||||
{
|
||||
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length;
|
||||
while( lineOver || _isReadingMultiLineComment )
|
||||
{
|
||||
if( IsEmpty ) {
|
||||
return ReadOnlySpan<char>.Empty;
|
||||
}
|
||||
if( lineOver )
|
||||
{
|
||||
do
|
||||
{
|
||||
_lineCache = _provider.ReadLine( out _lineNum );
|
||||
} while (string.IsNullOrEmpty( _lineCache ) && !_provider.IsEmpty);
|
||||
_current = 0;
|
||||
}
|
||||
if( _isReadingMultiLineComment )
|
||||
{
|
||||
int index;
|
||||
fixed( char* cPtr = _lineCache.AsSpan( _current ) ) {
|
||||
index = UnsafeCompute.IndexOfCharPair(
|
||||
cPtr, MultiLineEnd, _lineCache.Length );
|
||||
}
|
||||
if( index == -1 )
|
||||
{
|
||||
_lineCache = string.Empty;
|
||||
} else
|
||||
{
|
||||
_isReadingMultiLineComment = false;
|
||||
_current += index + 2;
|
||||
}
|
||||
}
|
||||
lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length;
|
||||
}
|
||||
return _lineCache.AsSpan().Slice( _current );
|
||||
}
|
||||
|
||||
public unsafe Token ReadToken()
|
||||
{
|
||||
int begin, end, rest;
|
||||
readLine:
|
||||
ReadOnlySpan<char> source;
|
||||
if( !TryReadLine( out source ) ) {
|
||||
return Token.Empty;
|
||||
}
|
||||
if( TokenReaderPreProcessor.Process( _lineCache, LineNumber, ref _current,
|
||||
out Token t ) ) {
|
||||
return t;
|
||||
}
|
||||
char c = source[ 0 ];
|
||||
if( char.IsLetter( c ) )
|
||||
{
|
||||
Match match = _nextWordTokenPattern.Match( _lineCache, _current );
|
||||
if( match.Success )
|
||||
{
|
||||
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 );
|
||||
return _last;
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidCharException( _current );
|
||||
}
|
||||
} else if( char.IsPunctuation( c ) || char.IsSymbol( c ) )
|
||||
{
|
||||
Match match;
|
||||
switch( c )
|
||||
{
|
||||
case '\'':
|
||||
char cNext = source[ 1 ];
|
||||
if( cNext == '\'' ) //empty string
|
||||
{
|
||||
begin = _current;
|
||||
_current += 2;
|
||||
return new( string.Empty, _lineNum, begin, TokenFlag.String );
|
||||
}
|
||||
match = _nextStringLiteralPatternWithSingle.Match( _lineCache, _current );
|
||||
if( match.Success )
|
||||
{
|
||||
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 );
|
||||
return _last;
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidCharException( '\"' );
|
||||
}
|
||||
case '"':
|
||||
cNext = source[ 1 ];
|
||||
if( cNext == '\"' ) //empty string
|
||||
{
|
||||
begin = _current;
|
||||
_current += 2;
|
||||
return new( string.Empty, _lineNum, begin, TokenFlag.String );
|
||||
}
|
||||
match = _nextStringLiteralPattern.Match( _lineCache, _current );
|
||||
if( match.Success )
|
||||
{
|
||||
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 );
|
||||
return _last;
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidCharException( '\"' );
|
||||
}
|
||||
case '(':
|
||||
begin = _current;
|
||||
_current++;
|
||||
_last = new(
|
||||
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;
|
||||
case '-':
|
||||
|
||||
// 1. - number
|
||||
// 2. -- comment
|
||||
// 3. - number type param(UNARY)
|
||||
// 4. param - param(BINARY)
|
||||
cNext = source[ 1 ];
|
||||
if( char.IsNumber( cNext ) )
|
||||
{
|
||||
match = _nextNumberLiteralPattern.Match( _lineCache, _current );
|
||||
if( match.Success )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
} else if( cNext == '-' )
|
||||
{
|
||||
_lineCache = string.Empty;
|
||||
_current = 0;
|
||||
goto readLine;
|
||||
} else
|
||||
{
|
||||
begin = _current;
|
||||
_current++;
|
||||
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
|
||||
{
|
||||
_last = new(
|
||||
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
|
||||
TokenFlag.Symbol_Unary );
|
||||
}
|
||||
return _last;
|
||||
}
|
||||
case '{':
|
||||
begin = _current;
|
||||
_current++;
|
||||
_last = new Token(
|
||||
ExpressCompile.PoolString( "{" ), _lineNum, begin,
|
||||
TokenFlag.Separator_Left );
|
||||
return _last;
|
||||
case '[':
|
||||
begin = _current;
|
||||
_current++;
|
||||
_last = new Token(
|
||||
ExpressCompile.PoolString( "[" ), _lineNum, begin,
|
||||
TokenFlag.Index_Left );
|
||||
return _last;
|
||||
case ']':
|
||||
begin = _current;
|
||||
_current++;
|
||||
_last = new Token(
|
||||
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 );
|
||||
return _last;
|
||||
case ':':
|
||||
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 )
|
||||
{
|
||||
_last = new Token(
|
||||
ExpressCompile.Keyword.Colon, _lineNum, begin,
|
||||
TokenFlag.Separator_Middle );
|
||||
} else
|
||||
{
|
||||
_last = new Token(
|
||||
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;
|
||||
_current = rest;
|
||||
_last = new Token(
|
||||
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 );
|
||||
return _last;
|
||||
default:
|
||||
throw new ExpInvalidCharException( c );
|
||||
}
|
||||
} else if( char.IsNumber( c ) )
|
||||
{
|
||||
Match match = _nextNumberLiteralPattern.Match( _lineCache, _current );
|
||||
if( match.Success )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
} 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
|
||||
{
|
||||
throw new ExpInvalidCharException( c );
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryReadLine( out ReadOnlySpan<char> line )
|
||||
{
|
||||
line = ReadLine();
|
||||
return line != ReadOnlySpan<char>.Empty;
|
||||
}
|
||||
|
||||
public bool TryReadToken( out Token t )
|
||||
{
|
||||
t = ReadToken();
|
||||
return !IsEmpty;
|
||||
}
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>[a-zA-Z][a-zA-Z0-9_]*)(?<end>\s*?)(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetNextWordTokenPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>-?\s*?[0-9]+(?:\.[0-9]*)?E?(?:[+-]?[0-9]+)?)(?<end>\s*?)(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetNumberLiteralPattern();
|
||||
|
||||
[GeneratedRegex( @"(?:\s+?)(?<rest>\S|$)", RegexOptions.Singleline )]
|
||||
private static partial Regex GetSkipBlankPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>"")(?>\\\\|\\""|(?!')[^""])*(?<end>""|$)\s*?(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetStringLiteralPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>')(?>\\\\|\\'|''|(?!')[^'])*(?<end>')\s*?(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetStringLiteralPatternWithSingle();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>[:<>=+\-*\/\.]+)(?<end>\s?)\s*?(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetSymbolPattern();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GeneratedExpSchema.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 CommunityToolkit.HighPerformance.Helpers;
|
||||
|
||||
using StgSharp.Collections;
|
||||
|
||||
using System;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
internal class GeneratedExpSchema : ExpSchema
|
||||
{
|
||||
|
||||
public GeneratedExpSchema() { }
|
||||
|
||||
public static ExpSchema DefaultSchema
|
||||
{
|
||||
get => ExpSchema_Builtin.Only;
|
||||
}
|
||||
|
||||
public ExpTypeSource GetExpType( string typeName )
|
||||
{
|
||||
if( BuiltinSchema.TryGetType( typeName, out ExpTypeSource? ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
if( TypeDict.TryGetValue( typeName, out ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
foreach( GeneratedExpSchema item in SchemaInclude.Values )
|
||||
{
|
||||
if( item.TypeDict.TryGetValue( typeName, out ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
throw new ExpElementLoadException( typeName, this );
|
||||
}
|
||||
|
||||
public bool HasSchemaInclude( GeneratedExpSchema schema )
|
||||
{
|
||||
return SchemaInclude.ContainsKey( schema.Name );
|
||||
}
|
||||
|
||||
public override void LoadFromSource( ExpSchemaSource source )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool TryGetConst( string name, out ExpElementInstance c )
|
||||
{
|
||||
return ConstDict.TryGetValue( name, out c! );
|
||||
}
|
||||
|
||||
public override bool TryGetEntity( string name, out ExpEntitySource e )
|
||||
{
|
||||
return EntityDict.TryGetValue( name, out e! );
|
||||
}
|
||||
|
||||
public override bool TryGetFunction( string name, out ExpFunctionSource f )
|
||||
{
|
||||
return FunctionDict.TryGetValue( name, out f! );
|
||||
}
|
||||
|
||||
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 element )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IExpConvertableFrom.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.Script.Express
|
||||
{
|
||||
// Base interface with one generic parameter renamed to T0
|
||||
public interface IExpConvertableFrom<T0> where T0: IExpConvertableFrom<T0>
|
||||
{
|
||||
|
||||
void FromInstance( T0 entity );
|
||||
|
||||
bool IsConvertableTo( string entityTypeName );
|
||||
|
||||
}
|
||||
|
||||
// 2 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1> : IExpConvertableFrom<T0>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
{
|
||||
|
||||
void FromInstance( T1 entity );
|
||||
|
||||
}
|
||||
|
||||
// 3 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2> : IExpConvertableFrom<T0, T1>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
{
|
||||
|
||||
void FromInstance( T2 entity );
|
||||
|
||||
}
|
||||
|
||||
// 4 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3> : IExpConvertableFrom<T0, T1, T2>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
{
|
||||
|
||||
void FromInstance( T3 entity );
|
||||
|
||||
}
|
||||
|
||||
// 5 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4> : IExpConvertableFrom<T0, T1, T2, T3>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
{
|
||||
|
||||
void FromInstance( T4 entity );
|
||||
|
||||
}
|
||||
|
||||
// 6 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5> : IExpConvertableFrom<T0, T1, T2, T3, T4>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
{
|
||||
|
||||
void FromInstance( T5 entity );
|
||||
|
||||
}
|
||||
|
||||
// 7 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
where T6: IExpConvertableFrom<T6>
|
||||
{
|
||||
|
||||
void FromInstance( T6 entity );
|
||||
|
||||
}
|
||||
|
||||
// 8 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
where T6: IExpConvertableFrom<T6>
|
||||
where T7: IExpConvertableFrom<T7>
|
||||
{
|
||||
|
||||
void FromInstance( T7 entity );
|
||||
|
||||
}
|
||||
|
||||
// 9 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
where T6: IExpConvertableFrom<T6>
|
||||
where T7: IExpConvertableFrom<T7>
|
||||
where T8: IExpConvertableFrom<T8>
|
||||
{
|
||||
|
||||
void FromInstance( T8 entity );
|
||||
|
||||
}
|
||||
|
||||
// 10 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
where T6: IExpConvertableFrom<T6>
|
||||
where T7: IExpConvertableFrom<T7>
|
||||
where T8: IExpConvertableFrom<T8>
|
||||
where T9: IExpConvertableFrom<T9>
|
||||
{
|
||||
|
||||
void FromInstance( T9 entity );
|
||||
|
||||
}
|
||||
|
||||
// 11 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
where T6: IExpConvertableFrom<T6>
|
||||
where T7: IExpConvertableFrom<T7>
|
||||
where T8: IExpConvertableFrom<T8>
|
||||
where T9: IExpConvertableFrom<T9>
|
||||
where T10: IExpConvertableFrom<T10>
|
||||
{
|
||||
|
||||
void FromInstance( T10 entity );
|
||||
|
||||
}
|
||||
|
||||
// 12 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
where T6: IExpConvertableFrom<T6>
|
||||
where T7: IExpConvertableFrom<T7>
|
||||
where T8: IExpConvertableFrom<T8>
|
||||
where T9: IExpConvertableFrom<T9>
|
||||
where T10: IExpConvertableFrom<T10>
|
||||
where T11: IExpConvertableFrom<T11>
|
||||
{
|
||||
|
||||
void FromInstance( T11 entity );
|
||||
|
||||
}
|
||||
|
||||
// 13 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
where T6: IExpConvertableFrom<T6>
|
||||
where T7: IExpConvertableFrom<T7>
|
||||
where T8: IExpConvertableFrom<T8>
|
||||
where T9: IExpConvertableFrom<T9>
|
||||
where T10: IExpConvertableFrom<T10>
|
||||
where T11: IExpConvertableFrom<T11>
|
||||
where T12: IExpConvertableFrom<T12>
|
||||
{
|
||||
|
||||
void FromInstance( T12 entity );
|
||||
|
||||
}
|
||||
|
||||
// 14 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
where T6: IExpConvertableFrom<T6>
|
||||
where T7: IExpConvertableFrom<T7>
|
||||
where T8: IExpConvertableFrom<T8>
|
||||
where T9: IExpConvertableFrom<T9>
|
||||
where T10: IExpConvertableFrom<T10>
|
||||
where T11: IExpConvertableFrom<T11>
|
||||
where T12: IExpConvertableFrom<T12>
|
||||
where T13: IExpConvertableFrom<T13>
|
||||
{
|
||||
|
||||
void FromInstance( T13 entity );
|
||||
|
||||
}
|
||||
|
||||
// 15 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
where T6: IExpConvertableFrom<T6>
|
||||
where T7: IExpConvertableFrom<T7>
|
||||
where T8: IExpConvertableFrom<T8>
|
||||
where T9: IExpConvertableFrom<T9>
|
||||
where T10: IExpConvertableFrom<T10>
|
||||
where T11: IExpConvertableFrom<T11>
|
||||
where T12: IExpConvertableFrom<T12>
|
||||
where T13: IExpConvertableFrom<T13>
|
||||
where T14: IExpConvertableFrom<T14>
|
||||
{
|
||||
|
||||
void FromInstance( T14 entity );
|
||||
|
||||
}
|
||||
|
||||
// 16 generic parameters
|
||||
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>
|
||||
where T0: IExpConvertableFrom<T0>
|
||||
where T1: IExpConvertableFrom<T1>
|
||||
where T2: IExpConvertableFrom<T2>
|
||||
where T3: IExpConvertableFrom<T3>
|
||||
where T4: IExpConvertableFrom<T4>
|
||||
where T5: IExpConvertableFrom<T5>
|
||||
where T6: IExpConvertableFrom<T6>
|
||||
where T7: IExpConvertableFrom<T7>
|
||||
where T8: IExpConvertableFrom<T8>
|
||||
where T9: IExpConvertableFrom<T9>
|
||||
where T10: IExpConvertableFrom<T10>
|
||||
where T11: IExpConvertableFrom<T11>
|
||||
where T12: IExpConvertableFrom<T12>
|
||||
where T13: IExpConvertableFrom<T13>
|
||||
where T14: IExpConvertableFrom<T14>
|
||||
where T15: IExpConvertableFrom<T15>
|
||||
{
|
||||
|
||||
void FromInstance( T15 entity );
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user