Daily update 2 on 20240228 by nitload youmu

This commit is contained in:
Nitload
2025-03-01 04:58:46 +08:00
parent 90d5f76511
commit f22862dfc4
983 changed files with 180004 additions and 0 deletions
@@ -0,0 +1,42 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpBuiltinConstant.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;
namespace StgSharp.Script.Express
{
public class ExpBuiltinConstant<T> : ExpLiteralGenericNode<T>
{
internal ExpBuiltinConstant( string name, T value )
: base( name, null!, value ) { }
}
}
@@ -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
{
public 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,203 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 : IExpElementSource, IEnumerable<ExpElementInstanceBase>
{
protected internal string _accurateType;
protected ExpCollectionBase( string accurateType )
{
_accurateType = accurateType;
}
public ExpElementType ElementType => ExpElementType.Collection;
public abstract int Count
{
get;
}
public string MemberType
{
get => _accurateType;
}
public abstract string Name
{
get;
}
public void Analyse()
{
return;
}
public abstract IEnumerator<ExpElementInstanceBase> GetEnumerator();
public abstract bool IsConvertable( IExpElementSource targetType );
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
IScriptSourceProvider IExpElementSource.SourceProvider => null!;
}
public class ExpArray : ExpCollectionBase
{
private ExpElementInstanceBase[] _collection;
public ExpArray( string accurateType ) : base( accurateType ) { }
public ExpElementInstanceBase 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 => ExpCompile.PoolString( "ARRAY" );
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
{
return ( ( IEnumerable<ExpElementInstanceBase> )_collection )
.GetEnumerator();
}
public override bool IsConvertable( IExpElementSource targetType )
{
throw new NotImplementedException();
}
}
public class ExpBag : ExpCollectionBase
{
private ConcurrentBag<ExpElementInstanceBase> _collection = new ConcurrentBag<ExpElementInstanceBase>(
);
public ExpBag( string accurateType ) : base( accurateType ) { }
public override int Count => _collection.Count;
public override string Name => ExpCompile.PoolString( "BAG" );
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
{
return _collection.GetEnumerator();
}
public override bool IsConvertable( IExpElementSource targetType )
{
throw new NotImplementedException();
}
}
public sealed class ExpList : ExpCollectionBase
{
private List<ExpElementInstanceBase> _collection = new List<ExpElementInstanceBase>(
);
public ExpList( string accurateType ) : base( accurateType ) { }
public override int Count => _collection.Count;
public override string Name => ExpCompile.PoolString( "LIST" );
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
{
return _collection.GetEnumerator();
}
public override bool IsConvertable( IExpElementSource targetType )
{
throw new NotImplementedException();
}
}
public class ExpSet : ExpCollectionBase
{
private HashSet<ExpElementInstanceBase> _collection = new();
public ExpSet( string accurateType ) : base( accurateType ) { }
public override int Count => _collection.Count;
public override string Name => ExpCompile.PoolString( "SET" );
public void Add( ExpElementInstanceBase token )
{
if( token.TypeName != MemberType ) {
throw new ExpInvalidCollectionMemberTypeException( token,
this );
}
_collection.Add( token );
}
public override sealed IEnumerator<ExpElementInstanceBase> GetEnumerator(
)
{
return ( ( IEnumerable<ExpElementInstanceBase> )_collection )
.GetEnumerator();
}
public override bool IsConvertable( IExpElementSource targetType )
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,139 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 : ExpBaseNode
{
protected internal (int min, int max) _range;
protected internal ExpElementType _memberType;
protected ExpCollectionInstanceBase( string name, ExpSchema context )
: base( name, context ) { }
public override ExpBaseNode Left => null!;
public override ExpBaseNode Right => null!;
public abstract ExpCollectionBase CollectionValue
{
get;
}
public ExpElementType MemberType
{
get => _memberType;
}
public int MinCapacity => _range.min;
public int MaxCapacity => _range.max;
}
public sealed class ExpSetInstance : ExpCollectionInstanceBase
{
private ExpSet _collection;
public ExpSetInstance( string name, ExpSet set, ExpSchema context )
: base( name, context )
{
_collection = set;
}
public override ExpCollectionBase CollectionValue => _collection;
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpBagInstance : ExpCollectionInstanceBase
{
private ExpBag _collection;
public ExpBagInstance( string name, ExpBag bag, ExpSchema context )
: base( name, context )
{
_collection = bag;
}
public override ExpCollectionBase CollectionValue => _collection;
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpListInstance : ExpCollectionInstanceBase
{
private ExpList _collection;
public ExpListInstance( string name, ExpList list, ExpSchema context )
: base( name, context )
{
_collection = list;
}
public override ExpCollectionBase CollectionValue => _collection;
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpArrayInstance : ExpCollectionInstanceBase
{
private ExpArray _collection;
public ExpArrayInstance(
string name,
ExpArray array,
ExpSchema context )
: base( name, context )
{
_collection = array;
}
public override ExpCollectionBase CollectionValue => _collection;
public override IExpElementSource EqualityTypeConvert => _collection;
}
}
@@ -0,0 +1,73 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Text;
namespace StgSharp.Script.Express
{
public enum ExpLogic
{
Unknown = 0,
False = 1,
True = 2,
}
public static class LogicConverter
{
public static bool? AsNullableBool(this ExpLogic l)
{
switch (l)
{
case ExpLogic.Unknown:
return null;
case ExpLogic.False:
return false;
case ExpLogic.True:
return true;
default:
throw new ArgumentException();
}
}
public static ExpLogic AsNullableInt(this bool? b)
{
return b switch
{
null => ExpLogic.Unknown,
true => ExpLogic.True,
false => ExpLogic.False,
};
}
}
}
@@ -0,0 +1,142 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using static StgSharp.Script.Express.ExpCompile;
namespace StgSharp.Script.Express
{
internal partial class ExpSchema_Nitload : ExpSchema
{
private static readonly ExpSchema_Nitload _onlyInstance = new ExpSchema_Nitload(
);
private ExpSchema_Nitload()
: base()
{
Name = "Nitload";
}
public static ExpSchema Only
{
get => _onlyInstance;
}
public override void LoadFromSource( ExpSchemaSource source )
{
return;
}
public override bool TryGetConst(
string name,
out ExpElementInstanceBase 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 )
{
throw new NotImplementedException();
}
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.Int ),
new ExpBuiltinType( KeyWord.Int, typeof( int ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Real ),
new ExpBuiltinType( KeyWord.Real, typeof( float ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Bool ),
new ExpBuiltinType( KeyWord.Bool, typeof( bool ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Logic ),
new ExpBuiltinType( KeyWord.Logic, 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, ExpElementInstanceBase>(
Multiplexer ) {
{ PoolString( "PI" ), new ExpBuiltinConstant<float>(
PoolString( "PI" ), MathF.PI ) },
{ PoolString( "E" ), new ExpBuiltinConstant<float>(
PoolString( "E" ), MathF.E ) },
}.ToFrozenDictionary();
}
}
}
@@ -0,0 +1,120 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 ExpCompile
{
private static string[] _operatorsWithLetter;
private static ConcurrentStringHashMultiplexer _multiplexer;
private static FrozenDictionary<string, ExpElementInstanceBase> _builtinConst;
private static FrozenDictionary<string, ExpTypeSource> _builtinType;
private static FrozenDictionary<string, ExpBinaryOperatorNode> _operators;
private static StringPool _compileStringCache;
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();
PoolKeywords();
InitPrecedence();
_operatorsWithLetter = [
KeyWord.ADD,
KeyWord.SUB,
KeyWord.MUL,
KeyWord.DIV,
KeyWord.AND,
KeyWord.OR,
KeyWord.XOR,
KeyWord.ANDOR,
KeyWord.NOT,
];
}
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,106 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 ExpCompile
{
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 ),
];
_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,93 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 ExpCompile
{
private static void PoolKeywords()
{
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 );
}
} );
while( !result.IsCompleted ) { }
}
public static class KeyWord
{
public const string Int = "INTAGER",
Real = "REAL",
Bool = "BOOLEAN",
String = "STRING",
Logic = "LOGIC",
Binary = "BINARY",
Constant = "CONSTANT",
AND = "AND",
OR = "OR",
XOR = "XOR",
ADD = "+",
SUB = "-",
MUL = "*",
DIV = "/",
NOT = "NOT",
Assignment = ":=",
Equal = "=",
Mod = "MOD",
Self = "SELF",
Pi = "PI",
True = "TRUE",
False = "FALSE",
Insert = "INSERT",
Remove = "REMOVE",
ANDOR = "ANDOR",
GetIndex = "[",
UnaryAdd = "+",
UnarySub = "-",
Exp = "**";
}
}
}
@@ -0,0 +1,97 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Script.Express
{
public sealed class ExpConstantCollectionSource : ExpImmutableElementBase
{
private Dictionary<string, ExpElementInstanceBase> _constants;
private IScriptSourceProvider _sourceProvider;
public ExpConstantCollectionSource(
IScriptSourceProvider sourceProvider )
{
_sourceProvider = sourceProvider;
_constants = new Dictionary<string, ExpElementInstanceBase>(
ExpCompile.Multiplexer );
}
public override ExpElementType ElementType => ExpElementType.Const;
public override IScriptSourceProvider SourceProvider => _sourceProvider;
public override string Name
{
get => ExpCompile.KeyWord.Constant;
}
public override void Analyse()
{
throw new NotImplementedException();
}
public override ExpBaseNode 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 ExpElementInstanceBase? token ) ) {
return token;
}
return null!;
}
public bool TryGetConstant(
string name,
out ExpElementInstanceBase instance )
{
return _constants.TryGetValue( name, out instance );
}
internal void AddConstant( string name, ExpElementInstanceBase value )
{
_constants.Add( name, value );
}
}
}
@@ -0,0 +1,87 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 ExpEntity : ExpBaseNode
{
public ExpEntity( string name, ExpSchema context )
: base( name, context ) { }
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
}
public class ExpEntitySource : ExpInstantiableElementBase
{
private AbstractSyntaxTree<ExpBaseNode, 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 ExpBaseNode CreateInstanceToken()
{
throw new NotImplementedException();
}
public override bool IsConvertable( IExpElementSource targetType )
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,104 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 ExpFunction : ExpBaseNode
{
private readonly ExpBaseNode _return;
private ExpFunctionSource _source;
private readonly List<KeyValuePair<string, ExpBaseNode>> _parameterList
= new List<KeyValuePair<string, ExpBaseNode>>();
public ExpFunction( string name, ExpSchema context )
: base( name, context ) { }
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public ExpElementType ElementType => ExpElementType.Function;
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
public void CallThisFunction( params ExpBaseNode[] parameters ) { }
}
public class ExpFunctionSource : ExpImmutableElementBase
{
private ScriptSourceTransmitter _transmitter;
private string _name;
public ExpFunctionSource(
string name,
ScriptSourceTransmitter transmitter )
{
_name = name;
_transmitter = transmitter;
}
public override ExpElementType ElementType => ExpElementType.Function;
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 ExpBaseNode MakeReference( params object[] options )
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,89 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 : ExpElementInstanceBase
{
private ExpRuleSource _source;
public ExpRule( string name, ExpSchema context )
: base( name, context ) { }
public object? value => throw new NotImplementedException();
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
public override string TypeName => _source.Name;
}
public class ExpRuleSource : ExpImmutableElementBase
{
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 ExpBaseNode MakeReference( params object[] options )
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,98 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 ExpType : ExpElementInstanceBase
{
public ExpType( string name, ExpSchema context )
: base( name, context ) { }
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
public override string TypeName => throw new NotImplementedException();
}
public class ExpTypeSource : IExpElementSource
{
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 ExpElementType ElementType => ExpElementType.Type;
public IScriptSourceProvider SourceProvider => _transmitter;
public string Name => _name;
public virtual void Analyse()
{
throw new NotImplementedException();
}
public bool IsConvertable( IExpElementSource targetType )
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,158 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpBaseNode.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.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpBaseNode : IASTNode<ExpBaseNode, IExpElementSource>
{
protected internal ExpNodeFlag _nodeFlag;
protected internal string _name;
protected ExpBaseNode( string name, ExpSchema context )
{
_name = name;
NameSpace = context;
Next = this;
Previous = this;
}
public bool IsNumber
{
get { return ( _nodeFlag | ExpNodeFlag.BuiltinType_Number ) != 0; }
}
public abstract ExpBaseNode Left
{
get;
}
public static ExpBaseNode Empty
{
get => ExpEmptyNode._only;
}
public ExpBaseNode Next
{
get;
set;
}
public abstract ExpBaseNode Right
{
get;
}
public ExpBaseNode Previous
{
get;
set;
}
public ExpSchema NameSpace
{
get;
private set;
}
public abstract IExpElementSource EqualityTypeConvert
{
get;
}
public long NodeFlag => ( long )_nodeFlag;
public string CodeConvertTemplate
{
get;
internal set;
}
public string Name => _name;
public virtual void AppendNode( ExpBaseNode nextToken )
{
Next.Previous = nextToken;
nextToken.Next = Next;
Next = nextToken;
Next.Previous = this;
}
public ExpNodeNextEnumerator GetEnumerator()
{
return new ExpNodeNextEnumerator( this );
}
public static bool VerifyTypeConvertable(
ExpBaseNode left,
ExpBaseNode right )
{
IExpElementSource tLeft = left.EqualityTypeConvert,
tRight = right.EqualityTypeConvert;
if( tLeft == null || tRight == null ) {
return false;
}
return tLeft.IsConvertable( tRight );
}
protected void AssertSchemaInclude( ExpBaseNode expressionRoot )
{
if( expressionRoot.NameSpace != NameSpace && NameSpace.TryGetSchemaInclude(
expressionRoot.NameSpace.Name, out _ ) ) {
throw new ExpInvalidSchemaIncludeException(
NameSpace, expressionRoot.NameSpace );
}
}
private class ExpEmptyNode : ExpBaseNode
{
internal static readonly ExpEmptyNode _only = new();
public ExpEmptyNode()
: base( string.Empty, ExpSchema.BuiltinSchema ) { }
public override ExpBaseNode Left => _only;
public override ExpBaseNode Right => _only;
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
}
}
}
@@ -0,0 +1,148 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 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 ExpBinaryOperatorNode : ExpBaseNode
{
private ExpBaseNode _left;
private ExpBaseNode _right;
private ExpTypeSource _returnType;
public ExpBinaryOperatorNode( string name ) : base( name, null! ) { }
public ExpBinaryOperatorNode(
string source,
ExpSchema context,
ExpBaseNode left,
ExpBaseNode right )
: base( source, context )
{
if( !left.EqualityTypeConvert
.IsConvertable( right.EqualityTypeConvert ) ) {
throw new InvalidCastException(
$"Cannot convert element {left.EqualityTypeConvert} to {right.EqualityTypeConvert}" );
}
_left = left;
_right = right;
}
public override ExpBaseNode Left => _left;
public override ExpBaseNode Right => _right;
public override IExpElementSource EqualityTypeConvert => _returnType;
public static ExpBinaryOperatorNode Add(
ExpBaseNode left,
ExpBaseNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
0;
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.ADD )
{
_returnType = isFloat ? null : null,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} + {1}",
};
}
public static ExpBinaryOperatorNode Div(
ExpBaseNode left,
ExpBaseNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
0;
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.DIV )
{
_returnType = isFloat ? null : null,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} / {1}",
};
}
public static ExpBinaryOperatorNode Mul(
ExpBaseNode left,
ExpBaseNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
0;
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.MUL )
{
_returnType = isFloat ? null : null,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} * {1}",
};
}
public static ExpBinaryOperatorNode Sub(
ExpBaseNode left,
ExpBaseNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
0;
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.SUB )
{
_returnType = isFloat ? : null,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} - {1}",
};
}
}
}
@@ -0,0 +1,67 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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
{
internal class ExpFunctionCallingNode : ExpBaseNode
{
private ExpBaseNode _parameter;
private ExpFunctionSource _function;
public ExpFunctionCallingNode(
string functionName,
int line,
int column,
ExpSchema context,
ExpBaseNode firstParameter )
: base( $"{functionName}_{line}_{column}", context )
{
_parameter = firstParameter;
if( !context.TryGetFunction( functionName, out _function ) ) {
foreach( var item in context. ) { }
}
}
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => _parameter;
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
}
}
@@ -0,0 +1,78 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 : ExpBaseNode
{
private ExpBaseNode _falseOpBegin;
private ExpBaseNode _rule;
private ExpBaseNode _trueOpBegin ;
public ExpIfNode(
string name,
ExpSchema context,
ExpBaseNode rule,
ExpBaseNode rootOperationIfTrue,
ExpBaseNode rootOperationIfFalse )
: base( name, context )
{
_rule = rule;
_trueOpBegin = rootOperationIfFalse;
_falseOpBegin = rootOperationIfFalse;
}
public override ExpBaseNode Left => _trueOpBegin;
public override ExpBaseNode Right => _falseOpBegin;
public override IExpElementSource EqualityTypeConvert => null!;
public void AppendFalseOperation( ExpBaseNode expressionRoot )
{
AssertSchemaInclude( expressionRoot );
_falseOpBegin.AppendNode( expressionRoot );
}
public void AppendTrueOperation( ExpBaseNode expressionRoot )
{
AssertSchemaInclude( expressionRoot );
_trueOpBegin.AppendNode( expressionRoot );
}
}
}
@@ -0,0 +1,64 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpIndexOfNode.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 ExpIndexOfNode : ExpBaseNode
{
private ExpBaseNode _indexExpression;
private ExpCollectionInstanceBase _collection;
public ExpIndexOfNode(
ExpSchema context,
ExpCollectionInstanceBase instance,
ExpBaseNode indexExpression )
: base( ExpCompile.PoolString( "[" ), context )
{
_collection = instance;
_indexExpression = indexExpression;
}
public override ExpBaseNode Left => _collection;
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
}
}
@@ -0,0 +1,107 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpLiteralGenericNode.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;
namespace StgSharp.Script.Express
{
public class ExpLiteralNode
{
private readonly IValueBox box;
}
public class ExpLiteralGenericNode<T> : ExpElementInstanceBase
{
private readonly ExpBuiltinType _type;
private readonly T _value;
public ExpLiteralGenericNode( string name, ExpSchema context, T value )
: base( name, context )
{
_value = value;
switch( value ) {
case float f:
ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.Real,
out ExpTypeSource? type );
_type = ( type as ExpBuiltinType )!;
_nodeFlag = ExpNodeFlag.BuiltinType_Float | ExpNodeFlag.Element_Const;
break;
case int i:
ExpSchema.BuiltinSchema
.TryGetType( ExpCompile.KeyWord.Int, out type );
_type = ( type as ExpBuiltinType )!;
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
break;
case BitArray b:
ExpSchema.BuiltinSchema
.TryGetType( ExpCompile.KeyWord.Binary, out type );
_type = ( type as ExpBuiltinType )!;
_nodeFlag = ExpNodeFlag.BuiltinType_Binary | ExpNodeFlag.Element_Const;
break;
case string s:
ExpSchema.BuiltinSchema
.TryGetType( ExpCompile.KeyWord.String, out type );
_type = ( type as ExpBuiltinType )!;
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
break;
case ExpLogic l:
ExpSchema.BuiltinSchema
.TryGetType( ExpCompile.KeyWord.Logic, out type );
_type = ( type as ExpBuiltinType )!;
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
break;
default:
throw new ExpInvalidTypeException(
"Builtin Type", value!.GetType().Name );
}
}
public override ExpBaseNode Left => ExpBaseNode;
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => _type;
public override string TypeName => _type.Name;
public T value => _value;
}
}
@@ -0,0 +1,96 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
namespace StgSharp.Script.Express
{
public class ExpRepeatToken : ExpBaseNode
{
private ExpBaseNode _operationBegin;
private ExpElementInstanceBase _variable, _begin, _end, _increment;
public ExpRepeatToken(
string name,
ExpSchema context,
ExpBaseNode operationBegin,
ExpElementInstanceBase variable,
ExpElementInstanceBase begin,
ExpElementInstanceBase end,
ExpElementInstanceBase increment )
: base( name, context )
{
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag !=
end.NodeFlag || ( increment != null && end.NodeFlag !=
increment.NodeFlag ) ) {
throw new InvalidCastException();
}
if( increment == null ) {
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any ) {
case ExpNodeFlag.BuiltinType_Float:
increment = new ExpLiteralGenericNode<float>(
$"{name}_defaultIncrement", context, 1.0f );
break;
case ExpNodeFlag.BuiltinType_Int:
increment = new ExpLiteralGenericNode<int>(
$"{name}_defaultIncrement", context, 1 );
break;
default:
throw new ExpInvalidTypeException(
"Int or Real", "otherwise" );
}
}
_begin = begin;
_variable = variable;
_end = end;
_increment = increment;
_nodeFlag = ExpNodeFlag.Branch_Repeat;
_operationBegin = operationBegin;
}
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => _operationBegin;
public override IExpElementSource EqualityTypeConvert => null!;
public void AppendRepeatedOperation( ExpBaseNode node )
{
_operationBegin.AppendNode( node );
}
}
}
@@ -0,0 +1,113 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public class ExpSwitchNode : ExpBaseNode
{
private Dictionary<ExpBaseNode, ExpBaseNode> _cases;
private ExpBaseNode _default;
private ExpBaseNode _target;
public ExpSwitchNode(
string name,
ExpSchema context,
ExpBaseNode target,
ExpBaseNode defaultCase,
params (ExpBaseNode label, ExpBaseNode op)[] cases )
: base( name, context )
{
_target = target;
_default = defaultCase;
_cases = new Dictionary<ExpBaseNode, ExpBaseNode>();
foreach( (ExpBaseNode label, ExpBaseNode op ) item in cases ) {
if( item.op == null ) {
_cases.Add( item.label, null! );
} else {
_cases.Add( item.label, item.op );
}
}
}
public ExpBaseNode this[ ExpBaseNode index ]
{
get
{
if( _cases.TryGetValue( index, out ExpBaseNode? ret ) ) {
return ret;
}
return _default;
}
}
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => null!;
public void AddOperationToDefault( ExpBaseNode expressionRoot )
{
if( expressionRoot != null ) {
_default.AppendNode( expressionRoot );
}
}
/// <summary>
/// Adds an expression to certain <see langword="case" />. The added expression will be run
/// at last.
/// </summary>
/// <param name="label"> Label of case to add operation </param>
/// <param name="expressionRoot"> Root token of the expression to be added. </param>
/// <exception cref="ExpCaseNotFoundException"> Cannot fine the case label in current witch expression. </exception>
public void AppendOperationToCase(
ExpBaseNode label,
ExpBaseNode expressionRoot )
{
AssertSchemaInclude( expressionRoot );
if( _cases.TryGetValue( label, out ExpBaseNode? op ) ) {
op.AppendNode( expressionRoot );
} else {
throw new ExpCaseNotFoundException( this, label );
}
}
public bool ContainsCase( ExpBaseNode token )
{
return _cases.ContainsKey( token );
}
}
}
@@ -0,0 +1,60 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 : ExpBaseNode
{
private ExpBaseNode _operand;
public ExpUnaryOperatorNode(
string name,
ExpBaseNode operand,
ExpSchema context )
: base( name, context )
{
_operand = operand;
}
public override ExpBaseNode Left => null!;
public override ExpBaseNode Right => _operand;
public override IExpElementSource EqualityTypeConvert => _operand.EqualityTypeConvert;
}
}
@@ -0,0 +1,72 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpElementInstanceBase.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
{
Const = 0,
Entity = 1,
Type = 2,
Function = 4,
Section = 8,
Expression = 16,
Rule = 32,
Procedure = 64,
Collection = 128 | Type,
}
public abstract class ExpElementInstanceBase : ExpBaseNode
{
protected ExpElementInstanceBase( string name, ExpSchema context )
: base( name, context ) { }
public ExpElementType ElementType
{
get;
}
public abstract string TypeName
{
get;
}
}
}
+115
View File
@@ -0,0 +1,115 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 Analyse();
}
public abstract class ExpInstantiableElementBase : IExpElementSource
{
public abstract ExpElementType ElementType
{
get;
}
public abstract IScriptSourceProvider SourceProvider
{
get;
}
public abstract string Name
{
get;
}
public abstract void Analyse();
public abstract ExpBaseNode CreateInstanceToken();
public abstract bool IsConvertable( IExpElementSource targetType );
}
public abstract class ExpImmutableElementBase : IExpElementSource
{
public abstract ExpElementType ElementType
{
get;
}
public abstract IScriptSourceProvider SourceProvider
{
get;
}
public abstract string Name
{
get;
}
public abstract void Analyse();
public bool IsConvertable( IExpElementSource targetType )
{
return false;
}
public abstract ExpBaseNode MakeReference( params object[] options );
}
}
+135
View File
@@ -0,0 +1,135 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.IO;
using System.Text;
namespace StgSharp.Script.Express
{
public class ExpCompileNotInitializedException : InvalidOperationException
{
public ExpCompileNotInitializedException()
: base(
"Attempt to compile an EXPRESS script before the init of compiler." ) { }
}
public class ExpInvalidCharException : Exception
{
public ExpInvalidCharException( char c )
: base( $"An unknown char {c} occurred." ) { }
}
public class ExpInvalidTokenException : Exception
{
public ExpInvalidTokenException( int index )
: base( $"Cannot read a token from line at {index}" ) { }
}
public class ExpInvalidTypeDeclareEndingExceptions : Exception
{
public ExpInvalidTypeDeclareEndingExceptions(
string declaredName,
string endedName )
: base(
$"The datatype is declared with name {declaredName} but ended with {endedName}" ) { }
}
public class ExpInvalidElementNameException : Exception
{
public ExpInvalidElementNameException(
string elementName,
ExpSchema schema )
: base(
$"Cannot find any element named {elementName} in {schema.Name}" ) { }
}
public class ExpInvalidTypeException : InvalidCastException
{
public ExpInvalidTypeException( string required, string provided )
: base(
$"Type {required} is required at position, but a {provided} instance is provided." ) { }
}
public class ExpInvalidCollectionMemberTypeException : InvalidCastException
{
public ExpInvalidCollectionMemberTypeException(
ExpElementInstanceBase 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 reference 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 ExpCaseNotFoundException : ArgumentOutOfRangeException
{
public ExpCaseNotFoundException(
ExpSwitchNode token,
ExpBaseNode label )
: base(
$"Attempt to read or write the label {label.Name} not exist in SWITCH expression {token.Name}" ) { }
}
public class ExpTypeNotFoundException : Exception
{
public ExpTypeNotFoundException( string typeName, ExpSchema context )
: base(
$"Cannot find the type {typeName} in schema {context.Name} and its included schemas" ) { }
}
}
+113
View File
@@ -0,0 +1,113 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Frozen;
using System.Linq;
namespace StgSharp.Script.Express
{
public abstract class ExpSchema
{
public static ExpSchema BuiltinSchema
{
get => ExpSchema_Nitload.Only;
}
public string Name
{
get;
internal set;
}
public abstract void LoadFromSource( ExpSchemaSource source );
public abstract bool TryGetConst(
string name,
out ExpElementInstanceBase c );
public abstract bool TryGetEntity( string name, out ExpEntitySource e );
public abstract bool TryGetFunction(
string name,
out ExpFunctionSource f );
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, ExpElementInstanceBase> ConstDict
{
get;
set;
}
protected FrozenDictionary<string, ExpEntitySource> EntityDict
{
get;
set;
}
protected FrozenDictionary<string, ExpFunctionSource> FunctionDict
{
get;
set;
}
protected ConcurrentStringHashMultiplexer StringMultiplexer => ExpCompile.Multiplexer;
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
}
}
+357
View File
@@ -0,0 +1,357 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 ExpInvalidTypeDeclareEndingExceptions(
_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 ExpInvalidTypeDeclareEndingExceptions(
_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 ExpInvalidTypeDeclareEndingExceptions(
_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 ExpInvalidTypeDeclareEndingExceptions(
_source.Name, endedName );
}
transmitter.WriteLine( "END_ENTITY" );
source = _source;
return true;
}
source = null!;
return false;
}
}
}
+127
View File
@@ -0,0 +1,127 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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();
}
IScriptSourceProvider IScriptSourceProvider.Slice(int location, int count)
{
throw new NotSupportedException();
}
protected virtual void Dispose( bool disposing )
{
if( !disposedValue ) {
if( disposing ) {
_expFileStream.Dispose();
_expMemoryMappedFile.Dispose();
_expMemoryMappedStream.Dispose();
_memoryReader.Dispose();
}
disposedValue = true;
}
}
}
}
+313
View File
@@ -0,0 +1,313 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSourceReader.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 partial class ExpSourceReader
{
private const int
MultiLineEnd = 0x0029002A; // *)
private const string Token = "token", End = "end", Rest = "rest";
private bool _isReadingMultiLineComment;
private int _current, _lineNum;
private IScriptSourceProvider _provider;
private Regex _nextWordTokenPattern = GetNextWordTokenPattern(),
_nextStringLiteralPattern = GetStringLiteralPattern(),
_nextNumberLiteralPattern = GetNumberLiteralPattern(),
_skipBlankPattern = GetSkipBlankPattern();
private string _lineCache;
private Token _last;
public ExpSourceReader( IScriptSourceProvider provider )
{
_provider = provider;
_current = 0;
_lineCache = string.Empty;
_isReadingMultiLineComment = false;
}
public bool IsEmpty
{
get => ( ( string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length ) ) && _provider.IsEmpty;
}
public int LineNumber
{
get => _provider.Location;
}
/// <summary>
/// <para>Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// begins with part of multi-line comment will automatically remove the comment part, but
/// beginning with a full multi-line comment will not causing removing.</para> <para> (*Just
/// Like The Comment Here*) Will Not Be Removed </para>
/// </summary>
/// <returns></returns>
public unsafe ReadOnlySpan<char> ReadLine()
{
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length;
while( lineOver || _isReadingMultiLineComment ) {
if( lineOver ) {
do {
_lineCache = _provider.ReadLine( out _lineNum );
} while (string.IsNullOrEmpty( _lineCache ));
_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 = ReadLine();
char c = source[ 0 ];
if( char.IsLetter( c ) ) {
Match match = _nextWordTokenPattern.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(
ExpCompile.PoolString( source[ .. ( end - begin ) ] ),
_lineNum, begin, TokenFlag.Member );
return _last;
} else {
throw new ExpInvalidTokenException( _current );
}
} else if( char.IsPunctuation( c ) || char.IsSymbol( c ) ) {
switch( c ) {
case '"':
char cNext = source[ 1 ];
if( cNext == '\"' ) //empty string
{
begin = _current;
_current += 2;
return new(
string.Empty, _lineNum, begin,
TokenFlag.String );
}
Match 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(
ExpCompile.PoolString(
source[ 1..( end - begin ) ] ),
_lineNum, begin, TokenFlag.String );
return _last;
} else {
throw new ExpInvalidCharException( '\"' );
}
case '(':
cNext = source[ 1 ];
if( cNext == '*' ) {
_isReadingMultiLineComment = true;
_current += 2;
goto readLine;
} else {
begin = _current;
_current++;
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Separator_Left );
return _last;
}
case ')' or '}':
begin = _current;
_current++;
_last = new Token(
ExpCompile.PoolString( ")" ), _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[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return new(
ExpCompile.PoolString(
source[ ..( end - begin ) ] ),
_lineNum, begin, TokenFlag.Number );
} else {
throw new ExpInvalidTokenException( _current );
}
} else if( cNext == '-' ) {
_lineCache = string.Empty;
_current = 0;
goto readLine;
} else {
begin = _current;
_current++;
if( _last.Flag != TokenFlag.Member ) {
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Symbol_Unary );
} else {
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Symbol_Binary );
}
return _last;
}
case '{':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "{" ), _lineNum, begin,
TokenFlag.Separator_Left );
case '[':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "[" ), _lineNum, begin,
TokenFlag.Index_Left );
case ']':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "]" ), _lineNum, begin,
TokenFlag.Index_Right );
case ';' or ',':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
begin, TokenFlag.Separator_Single );
case ':' or '+' or '/' or '\\' or '*' or '.':
begin = _current;
_current++;
return new(
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
begin, TokenFlag.Symbol_Binary );
default:
throw new ExpInvalidCharException( c );
}
} else if( char.IsNumber( c ) ) {
Match match = _nextNumberLiteralPattern.Match(
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
string str = ExpCompile.PoolString(
source[ ..( end - begin ) ] );
TokenFlag flag;
if( ReferenceEquals( str, ExpCompile.KeyWord.NOT ) ) {
flag = TokenFlag.Symbol_Unary;
} else {
flag = ExpCompile.LetterIsOperator( str ) ?
TokenFlag.Symbol_Binary : TokenFlag.Member;
}
return new( str, _lineNum, begin, flag );
} else {
throw new ExpInvalidTokenException( _current );
}
} else if( char.IsWhiteSpace( c ) ) {
Match match = _skipBlankPattern.Match( _lineCache, _current );
if( match.Success ) {
rest = match.Groups[ Rest ].Index;
_current = rest;
goto readLine;
} else {
throw new ExpInvalidTokenException( _current );
}
} else {
throw new ExpInvalidCharException( c );
}
}
[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]*)?)(?<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();
}
}
@@ -0,0 +1,118 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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_Nitload.Only;
}
public ExpTypeSource GetExpType( string typeName )
{
if( ExpCompile.TryGetBuiltinType( 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 ExpTypeNotFoundException( 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 ExpElementInstanceBase 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 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,55 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpErrorThrow.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 ExpNodeGenerator
{
public void ThrowCompileException( int errorCode )
{
switch( errorCode ) {
case 0 or 1:
return;
case TokenTypeNotMatch:
throw new Exception();
default:
break;
}
}
}
}
@@ -0,0 +1,155 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpNodeGenerator.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.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public partial class ExpNodeGenerator
{
private const int EndLine = 1;
private const int TokenGenerated = 0;
private const int TokenTypeNotMatch = -1;
private ExpBaseNode _lastStatement;
private GeneratedExpSchema _context;
private IExpElementSource _local;
private List<ExpBaseNode> _cache;
private Stack<ExpBaseNode> _operandsNode;
private Stack<Token> _operandsToken;
private Stack<Token> _operators;
public ExpNodeGenerator()
{
_operators = new Stack<Token>();
_operandsToken = new Stack<Token>();
}
/// <summary>
/// Append a token to top of cache. This method will automatically convert token to node if
/// meets separators or operators.
/// </summary>
/// <param name="expToken"></param>
public void AppendToken( Token expToken )
{
switch( expToken.Flag ) {
case TokenFlag.Symbol_Unary or TokenFlag.Symbol_Binary:
_operandsToken.Push( expToken );
break;
case TokenFlag.Number or TokenFlag.String or TokenFlag.Member:
break;
case TokenFlag.Separator_Single:
break;
case TokenFlag.Separator_Left:
break;
case TokenFlag.Separator_Right:
break;
case TokenFlag.Index_Left:
break;
case TokenFlag.Index_Right:
break;
default:
break;
}
}
public void CacheNextOperandNode( ExpBaseNode node )
{
_operandsNode.Push( node );
}
public AbstractSyntaxTree<ExpBaseNode, IExpElementSource> CloseAndDispose(
)
{
if( _operandsToken.Count != 0 ) {
// convert rest to AST
}
return new AbstractSyntaxTree<ExpBaseNode, IExpElementSource>();
}
public ExpBaseNode GenerateNode( Token t )
{
switch( t.Flag ) {
case TokenFlag.Symbol_Unary:
break;
case TokenFlag.Symbol_Binary:
break;
case TokenFlag.Number:
break;
case TokenFlag.String:
break;
case TokenFlag.Member:
break;
case TokenFlag.Separator_Single:
break;
case TokenFlag.Separator_Left:
break;
case TokenFlag.Separator_Right:
break;
case TokenFlag.Index_Left:
break;
case TokenFlag.Index_Right:
break;
default:
break;
}
}
public int GetNextOperandCache(
out Token? token,
out ExpBaseNode? node )
{
if( _operandsNode.Count != 0 ) {
node = _operandsNode.Pop();
token = null!;
return 2;
}
if( _operandsToken.Count != 0 ) {
token = _operandsToken.Pop();
node = null!;
return 1;
}
token = null;
node = null!;
return 0;
}
}
}
@@ -0,0 +1,57 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GenerateUnaryToken.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 ExpNodeGenerator
{
public ExpBaseNode GenerateUnaryToken( Token t )
{
switch( t.Value ) {
case ExpCompile.KeyWord.UnaryAdd:
break;
case ExpCompile.KeyWord.UnarySub:
break;
case ExpCompile.KeyWord.NOT:
break;
default:
break;
}
}
}
}
@@ -0,0 +1,67 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="LeftSperatorProcess.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.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public partial class ExpNodeGenerator
{
private int _lbToken = 0; // [ count
private int _lcbCount = 0; // { count
private int _lpCount = 0; // ( count
private void ProcessLeftSeparator( Token t )
{
switch( t.Value ) {
case "[":
_lbToken++;
break;
case "{":
_lcbCount++;
break;
case "(":
_lpCount++;
break;
default:
break;
}
}
}
}
@@ -0,0 +1,97 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
[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_Float = 32768,
BuiltinType_String = 65536,
BuiltinType_Boolean = 0x2000,
BuiltinType_Binary = 0x4000,
BuiltinType_Logic = 0x8000,
BuiltinType_Number = BuiltinType_Float | BuiltinType_Int,
BuiltinType_Any = BuiltinType_Int | BuiltinType_Float | 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,78 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpNodeNextEnumerator.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.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpNodeNextEnumerator : IEnumerator<ExpBaseNode>
{
private ExpBaseNode _begin;
private ExpBaseNode _current;
public ExpNodeNextEnumerator( ExpBaseNode token )
{
_begin = token;
_current = token;
}
void IDisposable.Dispose()
{
return;
}
bool IEnumerator.MoveNext()
{
ExpBaseNode next = _current.Next;
if( ReferenceEquals( next, _begin ) || next == null ) {
return false;
}
_current = next;
return true;
}
void IEnumerator.Reset()
{
_current = _begin;
}
object IEnumerator.Current => throw new NotImplementedException();
ExpBaseNode IEnumerator<ExpBaseNode>.Current => throw new NotImplementedException(
);
}
}