daily update on 20250214 by nitload youmu, building syntax analysor[D[D[D[D[D[C[C[C[C[C, tough!
This commit is contained in:
@@ -33,10 +33,13 @@ using StgSharp.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Xml.Schema;
|
||||
|
||||
namespace StgSharp.Script
|
||||
{
|
||||
public class AbstractSyntaxTree<TToken> where TToken: IExpressionToken
|
||||
public class AbstractSyntaxTree<TToken, TType>
|
||||
where TToken: IExpressionToken<TToken, TType>
|
||||
where TType: ITypeSource<TType>
|
||||
{
|
||||
|
||||
private bool _cacheAvailable;
|
||||
@@ -64,11 +67,7 @@ namespace StgSharp.Script
|
||||
return _allToken.Contains( node );
|
||||
}
|
||||
|
||||
public void MakeCache()
|
||||
{
|
||||
Root.TryGetNextLevel( out ICollection<IExpressionToken>? nextLevel );
|
||||
foreach( TToken node in nextLevel ) { }
|
||||
}
|
||||
public virtual void MakeCache() { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,8 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public abstract IEnumerator<ExpElementInstanceBase> GetEnumerator();
|
||||
|
||||
public abstract bool IsConvertable( IExpElementSource targetType );
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
@@ -102,7 +104,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override int Count => _collection.Length;
|
||||
|
||||
public override string Name => ExpCompile.AddOrGetString( "ARRAY" );
|
||||
public override string Name => ExpCompile.PoolString( "ARRAY" );
|
||||
|
||||
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
|
||||
{
|
||||
@@ -110,6 +112,11 @@ namespace StgSharp.Script.Express
|
||||
.GetEnumerator();
|
||||
}
|
||||
|
||||
public override bool IsConvertable( IExpElementSource targetType )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpBag : ExpCollectionBase
|
||||
@@ -122,13 +129,18 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override string Name => ExpCompile.AddOrGetString( "BAG" );
|
||||
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
|
||||
@@ -141,13 +153,18 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override string Name => ExpCompile.AddOrGetString( "LIST" );
|
||||
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
|
||||
@@ -159,7 +176,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override string Name => ExpCompile.AddOrGetString( "SET" );
|
||||
public override string Name => ExpCompile.PoolString( "SET" );
|
||||
|
||||
public void Add( ExpElementInstanceBase token )
|
||||
{
|
||||
@@ -177,5 +194,10 @@ namespace StgSharp.Script.Express
|
||||
.GetEnumerator();
|
||||
}
|
||||
|
||||
public override bool IsConvertable( IExpElementSource targetType )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,12 @@ namespace StgSharp.Script.Express
|
||||
get => _memberType;
|
||||
}
|
||||
|
||||
public override ExpToken Left => null!;
|
||||
|
||||
public override ExpToken Right => null!;
|
||||
|
||||
public override ExpToken Next => null!;
|
||||
|
||||
public int MinCapacity => _range.min;
|
||||
|
||||
public int MaxCapacity => _range.max;
|
||||
@@ -72,6 +78,14 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpBagInstance : ExpCollectionInstanceBase
|
||||
@@ -87,6 +101,14 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpListInstance : ExpCollectionInstanceBase
|
||||
@@ -102,6 +124,14 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpArrayInstance : ExpCollectionInstanceBase
|
||||
@@ -120,5 +150,12 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => _collection;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.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 ConcurrentStringHashMultiplexer _multiplexer;
|
||||
private static FrozenDictionary<string, ExpElementInstanceBase> _builtinConst;
|
||||
private static FrozenDictionary<string, ExpTypeSource> _builtinType;
|
||||
private static FrozenDictionary<string, ExpOperandToken> _operators;
|
||||
private static StringPool _compileStringCache;
|
||||
|
||||
public static FrozenDictionary<string, ExpElementInstanceBase> BuiltinConst => _builtinConst;
|
||||
|
||||
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();
|
||||
|
||||
_builtinType = new Dictionary<string, ExpTypeSource>( _multiplexer ) {
|
||||
{ PoolString( KeyWord.Int ), new ExpBuiltinType(
|
||||
KeyWord.Int,
|
||||
typeof( int ) ) }, { PoolString( KeyWord.Real ), new ExpBuiltinType(
|
||||
KeyWord.Real,
|
||||
typeof( float ) ) }, { PoolString(
|
||||
KeyWord.Bool ), new ExpBuiltinType(
|
||||
KeyWord.Bool,
|
||||
typeof( bool ) ) }, { PoolString(
|
||||
KeyWord.Binary ), new ExpBuiltinType(
|
||||
KeyWord.Binary,
|
||||
typeof( bool ) ) }, { PoolString(
|
||||
KeyWord.String ), new ExpBuiltinType(
|
||||
KeyWord.String,
|
||||
typeof( string ) ) }, { PoolString(
|
||||
KeyWord.Logic ), new ExpBuiltinType(
|
||||
KeyWord.Logic,
|
||||
typeof( ExpLogic ) ) }
|
||||
}.ToFrozenDictionary();
|
||||
|
||||
_operators = new Dictionary<string, ExpOperandToken>( _multiplexer )
|
||||
{
|
||||
{ PoolString( KeyWord.ADD ), new ExpOperandToken( KeyWord.ADD ) },
|
||||
{ PoolString( KeyWord.SUB ), new ExpOperandToken( KeyWord.SUB ) }
|
||||
}.ToFrozenDictionary();
|
||||
|
||||
_builtinConst = new Dictionary<string, ExpElementInstanceBase>(
|
||||
_multiplexer ) {
|
||||
{ PoolString( "PI" ), new ExpBuiltinConstant<float>(
|
||||
PoolString( "PI" ), MathF.PI ) },
|
||||
{ PoolString( "E" ), new ExpBuiltinConstant<float>(
|
||||
PoolString( "E" ), MathF.E ) },
|
||||
}.ToFrozenDictionary();
|
||||
|
||||
InitPrecedence();
|
||||
}
|
||||
|
||||
public static string PoolString( string str )
|
||||
{
|
||||
return _compileStringCache.GetOrAdd( str );
|
||||
}
|
||||
|
||||
public static void SkipComment( IScriptSourceProvider source ) { }
|
||||
|
||||
public static bool TryGetBuiltinConst(
|
||||
string constName,
|
||||
out ExpElementInstanceBase source )
|
||||
{
|
||||
return _builtinConst.TryGetValue( constName, out source );
|
||||
}
|
||||
|
||||
public static bool TryGetBuiltinType(
|
||||
string typename,
|
||||
out ExpTypeSource typeSource )
|
||||
{
|
||||
return _builtinType.TryGetValue( typename, out typeSource );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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
|
||||
{
|
||||
|
||||
private static FrozenDictionary<string, int> _operatorPrecedence;
|
||||
|
||||
private static void InitPrecedence()
|
||||
{
|
||||
KeyValuePair<string, int>[] source = [
|
||||
new KeyValuePair<string, int>( "[]", 1 ),
|
||||
new KeyValuePair<string, int>( ".", 1 ),
|
||||
new KeyValuePair<string, int>( "\\", 1 ),
|
||||
new KeyValuePair<string, int>( "unary+", 2 ),
|
||||
new KeyValuePair<string, int>( "unary-", 2 ),
|
||||
new KeyValuePair<string, int>( "NOT", 2 ),
|
||||
new KeyValuePair<string, int>( "**", 3 ),
|
||||
new KeyValuePair<string, int>( "*", 4 ),
|
||||
new KeyValuePair<string, int>( "/", 4 ),
|
||||
new KeyValuePair<string, int>( "AND", 4 ),
|
||||
new KeyValuePair<string, int>( "MOD", 4 ),
|
||||
new KeyValuePair<string, int>( "DIV", 4 ),
|
||||
new KeyValuePair<string, int>( "||", 4 ),
|
||||
new KeyValuePair<string, int>( "+", 5 ),
|
||||
new KeyValuePair<string, int>( "-", 5 ),
|
||||
new KeyValuePair<string, int>( "OR", 5 ),
|
||||
new KeyValuePair<string, int>( "XOR", 5 ),
|
||||
new KeyValuePair<string, int>( "=", 6 ),
|
||||
new KeyValuePair<string, int>( "<>", 6 ),
|
||||
new KeyValuePair<string, int>( "<=", 6 ),
|
||||
new KeyValuePair<string, int>( ">=", 6 ),
|
||||
new KeyValuePair<string, int>( ">", 6 ),
|
||||
new KeyValuePair<string, int>( "<", 6 ),
|
||||
new KeyValuePair<string, int>( ":=:", 6 ),
|
||||
new KeyValuePair<string, int>( ":<>:", 6 ),
|
||||
new KeyValuePair<string, int>( "IN", 6 ),
|
||||
new KeyValuePair<string, int>( "LIKE", 6 ),
|
||||
];
|
||||
_operatorPrecedence = new Dictionary<string, int>(
|
||||
source, _multiplexer ).ToFrozenDictionary();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public static partial class ExpCompile
|
||||
{
|
||||
|
||||
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 = "ADD",
|
||||
SUB = "SUB",
|
||||
MUL = "MUL",
|
||||
DIV = "DIV",
|
||||
Assignment = ":=",
|
||||
Equal = "=",
|
||||
Mod = "MOD",
|
||||
Self = "SELF",
|
||||
Pi = "PI",
|
||||
True = "TRUE",
|
||||
False = "FALSE",
|
||||
Insert = "INSERT",
|
||||
Remove = "REMOVE",
|
||||
ANDOR = "ANDOR",
|
||||
GetIndex = "[]",
|
||||
UnaryAdd = "unary+",
|
||||
UnarySub = "unary-",
|
||||
Exp = "**";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -30,13 +30,15 @@
|
||||
//-----------------------------------------------------------------------
|
||||
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 class ExpConstantCollectionSource : IExpImmutableElement
|
||||
public sealed class ExpConstantCollectionSource : ExpImmutableElementBase
|
||||
{
|
||||
|
||||
private Dictionary<string, ExpElementInstanceBase> _constants;
|
||||
@@ -50,23 +52,23 @@ namespace StgSharp.Script.Express
|
||||
ExpCompile.Multiplexer );
|
||||
}
|
||||
|
||||
public static Dictionary<string, ExpElementInstanceBase> BuiltinConst => ExpCompile.BuiltinConst;
|
||||
public override ExpElementType ElementType => ExpElementType.Const;
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Const;
|
||||
public static FrozenDictionary<string, ExpElementInstanceBase> BuiltinConst => ExpCompile.BuiltinConst;
|
||||
|
||||
public IScriptSourceProvider SourceProvider => _sourceProvider;
|
||||
public override IScriptSourceProvider SourceProvider => _sourceProvider;
|
||||
|
||||
public string Name
|
||||
public override string Name
|
||||
{
|
||||
get => ExpCompile.KeyWord.Constant;
|
||||
}
|
||||
|
||||
public virtual void Analyse()
|
||||
public override void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ExpToken MakeReference( params object[] options )
|
||||
public override ExpToken MakeReference( params object[] options )
|
||||
{
|
||||
if( options.Length == 0 || options[ 0 ] is not string str ) {
|
||||
return null!;
|
||||
|
||||
@@ -40,9 +40,22 @@ namespace StgSharp.Script.Express
|
||||
public ExpEntity( string name, ExpSchema context )
|
||||
: base( name, context ) { }
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public class ExpEntitySource : IExpInstantiableElement
|
||||
public class ExpEntitySource : ExpInstantiableElementBase
|
||||
{
|
||||
|
||||
private ExpExpressionTree _expressionTree;
|
||||
@@ -55,18 +68,23 @@ namespace StgSharp.Script.Express
|
||||
_source = provider;
|
||||
}
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Entity;
|
||||
public override ExpElementType ElementType => ExpElementType.Entity;
|
||||
|
||||
public IScriptSourceProvider SourceProvider => _source;
|
||||
public override IScriptSourceProvider SourceProvider => _source;
|
||||
|
||||
public string Name => _name;
|
||||
public override string Name => _name;
|
||||
|
||||
public void Analyse()
|
||||
public override void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ExpToken CreateInstanceToken()
|
||||
public override ExpToken CreateInstanceToken()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool IsConvertable( IExpElementSource targetType )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -47,11 +47,24 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Function;
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
public void CallThisFunction( params ExpToken[] parameters ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpFunctionSource : IExpImmutableElement
|
||||
public class ExpFunctionSource : ExpImmutableElementBase
|
||||
{
|
||||
|
||||
private ScriptSourceTransmitter _transmitter;
|
||||
@@ -65,18 +78,18 @@ namespace StgSharp.Script.Express
|
||||
_transmitter = transmitter;
|
||||
}
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Function;
|
||||
public override ExpElementType ElementType => ExpElementType.Function;
|
||||
|
||||
public IScriptSourceProvider SourceProvider => _transmitter;
|
||||
public override IScriptSourceProvider SourceProvider => _transmitter;
|
||||
|
||||
public string Name => _name;
|
||||
public override string Name => _name;
|
||||
|
||||
public void Analyse()
|
||||
public override void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ExpToken MakeReference( params object[] options )
|
||||
public override ExpToken MakeReference( params object[] options )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
@@ -45,11 +46,24 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public object? value => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
get => null!;
|
||||
set { }
|
||||
}
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
public override string TypeName => _source.Name;
|
||||
|
||||
}
|
||||
|
||||
public class ExpRuleSource : IExpImmutableElement
|
||||
public class ExpRuleSource : ExpImmutableElementBase
|
||||
{
|
||||
|
||||
private ScriptSourceTransmitter _transmitter;
|
||||
@@ -61,18 +75,18 @@ namespace StgSharp.Script.Express
|
||||
_transmitter = transmitter;
|
||||
}
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Rule;
|
||||
public override ExpElementType ElementType => ExpElementType.Rule;
|
||||
|
||||
public IScriptSourceProvider SourceProvider => _transmitter;
|
||||
public override IScriptSourceProvider SourceProvider => _transmitter;
|
||||
|
||||
public string Name => _name;
|
||||
public override string Name => _name;
|
||||
|
||||
public void Analyse()
|
||||
public override void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ExpToken MakeReference( params object[] options )
|
||||
public override ExpToken MakeReference( params object[] options )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -41,6 +41,19 @@ namespace StgSharp.Script.Express
|
||||
public ExpType( string name, ExpSchema context )
|
||||
: base( name, context ) { }
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
public override string TypeName => throw new NotImplementedException();
|
||||
|
||||
}
|
||||
@@ -68,5 +81,10 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsConvertable( IExpElementSource targetType )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,19 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
}
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
public void AddFalseOperation( ExpToken expressionRoot )
|
||||
{
|
||||
AssertSchemaInclude( expressionRoot );
|
||||
|
||||
@@ -82,16 +82,22 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
}
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
public override string TypeName => _type.Name;
|
||||
|
||||
public T value => _value;
|
||||
|
||||
public override bool TryGetNextLevel(
|
||||
out ICollection<IExpressionToken> nextLevel )
|
||||
{
|
||||
nextLevel = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpOperandToken.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 ExpOperandToken : ExpToken
|
||||
{
|
||||
|
||||
public ExpOperandToken( string source ) : base( source, null! ) { }
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -42,18 +42,31 @@ namespace StgSharp.Script.Express
|
||||
public ExpRepeat( string name, ExpSchema context )
|
||||
: base( name, context ) { }
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public class ExpRepeatRule : ExpToken
|
||||
{
|
||||
|
||||
private ExpElementInstanceBase _variable, _begin, _end, _increment;
|
||||
private List<ExpToken> _token = new List<ExpToken>();
|
||||
private ExpToken _token;
|
||||
|
||||
public ExpRepeatRule(
|
||||
string name,
|
||||
ExpSchema context,
|
||||
IEnumerable<ExpToken> operation,
|
||||
ExpToken firstOperation,
|
||||
ExpElementInstanceBase variable,
|
||||
ExpElementInstanceBase begin,
|
||||
ExpElementInstanceBase end,
|
||||
@@ -69,11 +82,11 @@ namespace StgSharp.Script.Express
|
||||
switch( ( ExpTokenFlag )variable.TokenTypeCode | ExpTokenFlag.BuiltinType_Any ) {
|
||||
case ExpTokenFlag.BuiltinType_Float:
|
||||
increment = new ExpLiteralToken<float>(
|
||||
$"{name}_defaultincrement", context, 1.0f );
|
||||
$"{name}_defaultIncrement", context, 1.0f );
|
||||
break;
|
||||
case ExpTokenFlag.BuiltinType_Int:
|
||||
increment = new ExpLiteralToken<int>(
|
||||
$"{name}_defaultincrement", context, 1 );
|
||||
$"{name}_defaultIncrement", context, 1 );
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException(
|
||||
@@ -87,12 +100,18 @@ namespace StgSharp.Script.Express
|
||||
_tokenType = ExpTokenFlag.Branch_Repeat;
|
||||
}
|
||||
|
||||
public override bool TryGetNextLevel(
|
||||
out ICollection<IExpressionToken> nextLevel )
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
nextLevel = ( _token.ToList() as ICollection<IExpressionToken> )!;
|
||||
return true;
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,45 +37,61 @@ namespace StgSharp.Script.Express
|
||||
public class ExpSwitchToken : ExpToken
|
||||
{
|
||||
|
||||
private Dictionary<ExpToken, List<ExpToken>> _cases;
|
||||
private Dictionary<ExpToken, ExpToken> _cases;
|
||||
private ExpToken _default;
|
||||
private ExpToken _target;
|
||||
private List<ExpToken> _default;
|
||||
|
||||
public ExpSwitchToken(
|
||||
string name,
|
||||
ExpSchema context,
|
||||
ExpToken target,
|
||||
IEnumerable<ExpToken> @default,
|
||||
params (ExpToken label, IEnumerable<ExpToken> op)[] cases )
|
||||
ExpToken defaultCase,
|
||||
params (ExpToken label, ExpToken op)[] cases )
|
||||
: base( name, context )
|
||||
{
|
||||
_target = target;
|
||||
if( @default == null ) {
|
||||
_default = new List<ExpToken>();
|
||||
} else {
|
||||
_default = new List<ExpToken>( @default );
|
||||
}
|
||||
_cases = new Dictionary<ExpToken, List<ExpToken>>();
|
||||
foreach( (ExpToken label, IEnumerable<ExpToken> op) item in cases ) {
|
||||
_default = defaultCase;
|
||||
_cases = new Dictionary<ExpToken, ExpToken>();
|
||||
foreach( (ExpToken label, ExpToken op ) item in cases ) {
|
||||
if( item.op == null ) {
|
||||
_cases.Add( item.label, new List<ExpToken>() );
|
||||
_cases.Add( item.label, null! );
|
||||
} else {
|
||||
_cases.Add( item.label, new List<ExpToken>( item.op ) );
|
||||
_cases.Add( item.label, item.op );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ExpToken> this[ ExpToken index ]
|
||||
public ExpToken this[ ExpToken index ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( _cases.TryGetValue( index, out List<ExpToken>? ret ) ) {
|
||||
if( _cases.TryGetValue( index, out ExpToken? ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
}
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
public void AddOperationToDefault( ExpToken expressionRoot )
|
||||
{
|
||||
if( expressionRoot != null ) {
|
||||
_default.AppendToken( expressionRoot );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an expression to certain <see langword="case" />. The added expression will be run
|
||||
/// at last.
|
||||
@@ -83,25 +99,18 @@ namespace StgSharp.Script.Express
|
||||
/// <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 AddOperationToCase(
|
||||
public void AppendOperationToCase(
|
||||
ExpToken label,
|
||||
ExpToken expressionRoot )
|
||||
{
|
||||
AssertSchemaInclude( expressionRoot );
|
||||
if( _cases.TryGetValue( label, out List<ExpToken>? op ) ) {
|
||||
op.Add( expressionRoot );
|
||||
if( _cases.TryGetValue( label, out ExpToken? op ) ) {
|
||||
op.AppendToken( expressionRoot );
|
||||
} else {
|
||||
throw new ExpCaseNotFoundException( this, label );
|
||||
}
|
||||
}
|
||||
|
||||
public void AddOperationToDefault( ExpToken expressionRoot )
|
||||
{
|
||||
if( expressionRoot != null ) {
|
||||
_default.Add( expressionRoot );
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsCase( ExpToken token )
|
||||
{
|
||||
return _cases.ContainsKey( token );
|
||||
|
||||
@@ -36,90 +36,66 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
[Flags]
|
||||
public enum ExpTokenFlag : long
|
||||
{
|
||||
|
||||
None = 0,
|
||||
Name_Element = 1,
|
||||
Name_Param = 2,
|
||||
Name_Block = 4,
|
||||
Name_Keyword = 8,
|
||||
Name_Any = Name_Block | Name_Element | Name_Keyword | Name_Param,
|
||||
Collection_Set = 16,
|
||||
Collection_Bag = 32,
|
||||
Collection_Array = 64,
|
||||
Collection_List = 128,
|
||||
Collection_Any = Collection_Set | Collection_Bag | Collection_Array | Collection_List,
|
||||
Element_Const = 256,
|
||||
Element_Entity = 512,
|
||||
Element_type = 1024,
|
||||
Element_Rule = 2048,
|
||||
Element_Function = 4096,
|
||||
Element_Any = Element_Entity | Element_Const | Element_Function | Element_Rule | Element_type,
|
||||
BuiltinType_Int = 8192,
|
||||
BuiltinType_Float = 16384,
|
||||
BuiltinType_String = 32768,
|
||||
BuiltinType_Boolean = 65536,
|
||||
BuiltinType_Binary = 0x2000,
|
||||
BuiltinType_Logic = 0x4000,
|
||||
BuiltinType_Any = BuiltinType_Int | BuiltinType_Float | BuiltinType_String | BuiltinType_Boolean | BuiltinType_Binary | BuiltinType_Logic,
|
||||
Branch_If = 0x8000,
|
||||
Branch_Switch = 0x1_0000,
|
||||
Branch_Repeat = 0x2_0000,
|
||||
|
||||
}
|
||||
|
||||
public ref struct ExpTokenSource
|
||||
{
|
||||
public ReadOnlySpan<char> Value;
|
||||
public readonly int Line;
|
||||
public readonly int Column;
|
||||
|
||||
public ExpTokenSource(ReadOnlySpan<char> chars, int lineNumber, int columnNumber)
|
||||
{
|
||||
Value = chars; Line = lineNumber; Column = columnNumber;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class ExpToken : IExpressionToken
|
||||
public abstract class ExpToken : IExpressionToken<ExpToken, IExpElementSource>
|
||||
{
|
||||
|
||||
protected internal ExpToken _previousToken;
|
||||
protected internal ExpTokenFlag _tokenType;
|
||||
protected internal List<ExpToken> _nextLevelTokens
|
||||
= new List<ExpToken>();
|
||||
protected internal string _name;
|
||||
|
||||
protected ExpToken( string name, ExpSchema context )
|
||||
{
|
||||
_name = name;
|
||||
Context = context;
|
||||
NameSpace = context;
|
||||
}
|
||||
|
||||
public ExpSchema Context
|
||||
public ExpSchema NameSpace
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public abstract ExpToken Left
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract ExpToken Next
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public abstract ExpToken Right
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public long TokenTypeCode => ( long )_tokenType;
|
||||
|
||||
public string Name => _name;
|
||||
|
||||
public virtual bool TryGetNextLevel(
|
||||
out ICollection<IExpressionToken> nextLevel )
|
||||
public virtual void AppendToken( ExpToken nextToken )
|
||||
{
|
||||
nextLevel = ( _nextLevelTokens as ICollection<IExpressionToken> )!;
|
||||
return true;
|
||||
Next = nextToken;
|
||||
}
|
||||
|
||||
public ExpTokenEnumerator GetEnumerator()
|
||||
{
|
||||
return new ExpTokenEnumerator( this );
|
||||
}
|
||||
|
||||
protected void AssertSchemaInclude( ExpToken expressionRoot )
|
||||
{
|
||||
if( expressionRoot.Context != Context && Context.HasSchemaInclude(
|
||||
expressionRoot.Context ) ) {
|
||||
if( expressionRoot.NameSpace != NameSpace && NameSpace.HasSchemaInclude(
|
||||
expressionRoot.NameSpace ) ) {
|
||||
throw new ExpInvalidSchemaIncludeException(
|
||||
Context, expressionRoot.Context );
|
||||
NameSpace, expressionRoot.NameSpace );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpTokenEnumerator.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 ExpTokenEnumerator : IEnumerator<ExpToken>
|
||||
{
|
||||
|
||||
private ExpToken _begin;
|
||||
private ExpToken _current;
|
||||
|
||||
public ExpTokenEnumerator( ExpToken token )
|
||||
{
|
||||
_begin = token;
|
||||
_current = token;
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool IEnumerator.MoveNext()
|
||||
{
|
||||
ExpToken next = _current.Next;
|
||||
if( next == null ) {
|
||||
return false;
|
||||
}
|
||||
_current = next;
|
||||
return true;
|
||||
}
|
||||
|
||||
void IEnumerator.Reset()
|
||||
{
|
||||
_current = _begin;
|
||||
}
|
||||
|
||||
object IEnumerator.Current => throw new NotImplementedException();
|
||||
|
||||
ExpToken IEnumerator<ExpToken>.Current => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
[Flags]
|
||||
public enum ExpTokenFlag : 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,
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
@@ -68,40 +69,4 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface IExpElementSource
|
||||
{
|
||||
|
||||
public ExpElementType ElementType
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
IScriptSourceProvider SourceProvider
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
string Name
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public void Analyse();
|
||||
|
||||
}
|
||||
|
||||
public interface IExpInstantiableElement : IExpElementSource
|
||||
{
|
||||
|
||||
public abstract ExpToken CreateInstanceToken();
|
||||
|
||||
}
|
||||
|
||||
public interface IExpImmutableElement : IExpElementSource
|
||||
{
|
||||
|
||||
public abstract ExpToken MakeReference( params object[] options );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ExpToken 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 ExpToken MakeReference( params object[] options );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpExpressionTree : AbstractSyntaxTree<ExpToken>
|
||||
public class ExpExpressionTree : AbstractSyntaxTree<ExpToken, IExpElementSource>
|
||||
{
|
||||
|
||||
public ExpToken RootToken
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public ExpFileSource( string path )
|
||||
{
|
||||
if( !File.Exists( path ) ) {
|
||||
if ( !File.Exists( path ) ) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
_expFileStream = new FileStream(
|
||||
@@ -92,6 +92,11 @@ namespace StgSharp.Script.Express
|
||||
return line;
|
||||
}
|
||||
|
||||
public string ReadLine(out int position)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ResetToBegin()
|
||||
{
|
||||
readLineSemaphore.Wait();
|
||||
@@ -100,9 +105,9 @@ namespace StgSharp.Script.Express
|
||||
readLineSemaphore.Release();
|
||||
}
|
||||
|
||||
public IScriptSourceProvider Slice(int location, int count)
|
||||
IScriptSourceProvider IScriptSourceProvider.Slice(int location, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
protected virtual void Dispose( bool disposing )
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace StgSharp.Script.Express
|
||||
private const string Token = "token", End = "end", Rest = "rest";
|
||||
|
||||
private bool _isReadingMultiLineComment;
|
||||
private int _current;
|
||||
private int _current, _lineNum;
|
||||
private IScriptSourceProvider _provider;
|
||||
private string _lineCache;
|
||||
|
||||
@@ -63,17 +63,17 @@ namespace StgSharp.Script.Express
|
||||
_isReadingMultiLineComment = false;
|
||||
}
|
||||
|
||||
public int LineNumber
|
||||
{
|
||||
get => _provider.Location;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -88,7 +88,7 @@ namespace StgSharp.Script.Express
|
||||
while( lineOver || _isReadingMultiLineComment ) {
|
||||
if( lineOver ) {
|
||||
do {
|
||||
_lineCache = _provider.ReadLine();
|
||||
_lineCache = _provider.ReadLine( out _lineNum );
|
||||
} while (string.IsNullOrEmpty( _lineCache ));
|
||||
_current = 0;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ namespace StgSharp.Script.Express
|
||||
return _lineCache.AsSpan().Slice( _current );
|
||||
}
|
||||
|
||||
public unsafe ReadOnlySpan<char> ReadToken()
|
||||
public unsafe TokenSource ReadToken()
|
||||
{
|
||||
int begin, end, rest;
|
||||
readLine:
|
||||
@@ -126,13 +126,24 @@ namespace StgSharp.Script.Express
|
||||
end = match.Groups[ End ].Index;
|
||||
rest = match.Groups[ Rest ].Index;
|
||||
_current = rest;
|
||||
return source.Slice( 0, end - begin );
|
||||
return new(
|
||||
source[ .. ( end - begin ) ], _lineNum, begin,
|
||||
PreprocessingMask.Names );
|
||||
} 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(
|
||||
ReadOnlySpan<char>.Empty, _lineNum, begin,
|
||||
PreprocessingMask.String );
|
||||
}
|
||||
Match match = _nextStringLiteralPattern.Match(
|
||||
_lineCache, _current );
|
||||
if( match.Success ) {
|
||||
@@ -140,18 +151,24 @@ namespace StgSharp.Script.Express
|
||||
end = match.Groups[ "end" ].Index;
|
||||
rest = match.Groups[ "rest" ].Index;
|
||||
_current = rest;
|
||||
return source[ ..( end - begin ) ];
|
||||
return new(
|
||||
source[ 1..( end - begin ) ], _lineNum, begin,
|
||||
PreprocessingMask.String );
|
||||
} else {
|
||||
throw new ExpInvalidCharException( '\"' );
|
||||
}
|
||||
case '(':
|
||||
char cNext = source[ 1 ];
|
||||
cNext = source[ 1 ];
|
||||
if( cNext == '*' ) {
|
||||
_isReadingMultiLineComment = true;
|
||||
_current += 2;
|
||||
goto readLine;
|
||||
} else {
|
||||
return source[ ..1 ];
|
||||
begin = _current;
|
||||
_current++;
|
||||
return new(
|
||||
source[ ..1 ], _lineNum, begin,
|
||||
PreprocessingMask.Symbol );
|
||||
}
|
||||
case '-':
|
||||
|
||||
@@ -167,7 +184,9 @@ namespace StgSharp.Script.Express
|
||||
end = match.Groups[ End ].Index;
|
||||
rest = match.Groups[ Rest ].Index;
|
||||
_current = rest;
|
||||
return source[ ..( end - begin ) ];
|
||||
return new(
|
||||
source[ ..( end - begin ) ], _lineNum,
|
||||
begin, PreprocessingMask.Number );
|
||||
} else {
|
||||
throw new ExpInvalidTokenException( _current );
|
||||
}
|
||||
@@ -176,13 +195,19 @@ namespace StgSharp.Script.Express
|
||||
_current = 0;
|
||||
goto readLine;
|
||||
} else {
|
||||
begin = _current;
|
||||
_current++;
|
||||
return source[ ..1 ];
|
||||
return new(
|
||||
source[ ..1 ], _lineNum, begin,
|
||||
PreprocessingMask.Symbol );
|
||||
}
|
||||
case ')' or '[' or ']' or '{' or '}' or ':' or ';' or
|
||||
'+' or '/' or '\\' or '*' or '.' or ',':
|
||||
begin = _current;
|
||||
_current++;
|
||||
return source[ ..1 ];
|
||||
return new(
|
||||
source[ ..1 ], _lineNum, begin,
|
||||
PreprocessingMask.Symbol );
|
||||
default:
|
||||
throw new ExpInvalidCharException( c );
|
||||
}
|
||||
@@ -194,7 +219,9 @@ namespace StgSharp.Script.Express
|
||||
end = match.Groups[ End ].Index;
|
||||
rest = match.Groups[ Rest ].Index;
|
||||
_current = rest;
|
||||
return source[ ..( end - begin ) ];
|
||||
return new(
|
||||
source[ ..( end - begin ) ], _lineNum, begin,
|
||||
PreprocessingMask.Number );
|
||||
} else {
|
||||
throw new ExpInvalidTokenException( _current );
|
||||
}
|
||||
@@ -226,7 +253,7 @@ namespace StgSharp.Script.Express
|
||||
private static partial Regex GetSkipBlankPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>"")(?:.*?[^""\\](\\\\)*)?(?<end>"")\s*?(?<next>\S|$)",
|
||||
@"(?<token>"")(?:.*?[^\\](?:\\\\)*?)(?<end>"")\s*?(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetStringLiteralPattern();
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpInfixExpressionProcessor.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 ExpTokenGenerator
|
||||
{
|
||||
|
||||
public List<ExpToken> SortInfixExpression(
|
||||
IEnumerable<ExpToken> origin )
|
||||
{
|
||||
Queue<ExpToken> PostfixExpressionQueue = new Queue<ExpToken>();
|
||||
Stack<ExpToken> operandStack = new Stack<ExpToken>();
|
||||
foreach( ExpToken token in origin ) {
|
||||
long paramToken = token.TokenTypeCode | ( long )
|
||||
( ExpTokenFlag.Name_Any );
|
||||
long operandToken = token.TokenTypeCode | ( long )
|
||||
( ExpTokenFlag.Name_Operator );
|
||||
if( paramToken != 0 ) {
|
||||
PostfixExpressionQueue.Enqueue( token );
|
||||
} else if( operandToken != 0 ) {
|
||||
ExpToken previousOperand = operandStack.Pop();
|
||||
}
|
||||
}
|
||||
return PostfixExpressionQueue.ToList();
|
||||
}
|
||||
|
||||
internal bool CompareOperatorPriority( ExpToken left, ExpToken right ) { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpTokenGenerator.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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpTokenGenerator
|
||||
{
|
||||
private const int TokenGenerated = 0;
|
||||
private const int TokenTypeNotMatch = -1;
|
||||
|
||||
private Exception _compileException;
|
||||
private ExpExpressionTree _localContext;
|
||||
private ExpSchema _mainContext;
|
||||
private List<ExpToken> _contextLevelList;
|
||||
|
||||
public ExpTokenGenerator()
|
||||
{
|
||||
}
|
||||
|
||||
public int GenerateToken(TokenSource source)
|
||||
{
|
||||
ExpToken token;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void ThrowCompileException(int errorCode)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Collections;
|
||||
using StgSharp.Script.Express;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -37,7 +38,9 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Script
|
||||
{
|
||||
public interface IExpressionToken
|
||||
public interface IExpressionToken<TToken, TType>
|
||||
where TToken: IExpressionToken<TToken, TType>
|
||||
where TType: ITypeSource<TType>
|
||||
{
|
||||
|
||||
long TokenTypeCode
|
||||
@@ -50,7 +53,28 @@ namespace StgSharp.Script
|
||||
get;
|
||||
}
|
||||
|
||||
bool TryGetNextLevel( out ICollection<IExpressionToken> nextLevel );
|
||||
TToken Next
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
TToken Left
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
TToken Right
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
TType EqualityTypeConvert
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
void AppendToken( TToken nextToken );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,9 @@ namespace StgSharp.Script
|
||||
}
|
||||
|
||||
void EndWriting();
|
||||
|
||||
string ReadLine();
|
||||
string ReadLine(out int position);
|
||||
|
||||
/// <summary>
|
||||
/// Return part of current provider.
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ITypeSource.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
|
||||
{
|
||||
public interface ITypeSource<in TConvert>
|
||||
where TConvert: ITypeSource<TConvert>
|
||||
{
|
||||
|
||||
|
||||
bool IsConvertable( TConvert targetType );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ namespace StgSharp.Script
|
||||
|
||||
public bool IsEmpty => _isWriting ?
|
||||
(_cache.Count == 0) :
|
||||
(_buffer.Length == 0) || (_index >= _buffer.Length - 1);
|
||||
(_buffer.Length == 0) || (_index >= _buffer.Length);
|
||||
|
||||
public int Location => _begin + _index;
|
||||
|
||||
@@ -87,6 +87,10 @@ namespace StgSharp.Script
|
||||
{
|
||||
throw new InvalidOperationException("Cannot read before all writing operation.");
|
||||
}
|
||||
if (_index >= _buffer.Length)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = _buffer[_index];
|
||||
_index++;
|
||||
return str;
|
||||
@@ -98,6 +102,11 @@ namespace StgSharp.Script
|
||||
{
|
||||
throw new InvalidOperationException("Cannot read before all writing operation.");
|
||||
}
|
||||
if (_index >= _buffer.Length)
|
||||
{
|
||||
position = -1;
|
||||
return string.Empty;
|
||||
}
|
||||
position = _begin + _index;
|
||||
var str = _buffer[_index];
|
||||
_index++;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="TokenSource.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
|
||||
{
|
||||
public readonly ref struct TokenSource
|
||||
{
|
||||
|
||||
public readonly int Column;
|
||||
public readonly int Line;
|
||||
public readonly PreprocessingMask Mask;
|
||||
public readonly ReadOnlySpan<char> Value;
|
||||
|
||||
public TokenSource(
|
||||
ReadOnlySpan<char> chars,
|
||||
int lineNumber,
|
||||
int columnNumber,
|
||||
PreprocessingMask mask )
|
||||
{
|
||||
Value = chars;
|
||||
Line = lineNumber;
|
||||
Column = columnNumber;
|
||||
Mask = mask;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum PreprocessingMask : int
|
||||
{
|
||||
|
||||
Symbol = 1,
|
||||
Number = 2,
|
||||
String = 3,
|
||||
Names = 4,
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,3 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="StgSharp.Script.AssemblyInfo.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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
@@ -41,14 +11,13 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute( "StgSharp.Script" )]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute( "Debug" )]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute( "1.0.0.0" )]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute(
|
||||
"1.0.0+ae94c265ae77870ea6498b624b6f71b78fb94e51" )]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute( "StgSharp.Script" )]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute( "StgSharp.Script" )]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute( "1.0.0.0" )]
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c23b640cae59b9ee7dcfd8f026b8970a084ddbd7")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// 由 MSBuild WriteCodeFragment 类生成。
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/ae94c265ae77870ea6498b624b6f71b78fb94e51/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/c23b640cae59b9ee7dcfd8f026b8970a084ddbd7/*"}}
|
||||
Reference in New Issue
Block a user