daily update on 20250220 by nitload youmu, building AST generator, correct type naming
This commit is contained in:
@@ -37,37 +37,27 @@ using System.Xml.Schema;
|
||||
|
||||
namespace StgSharp.Script
|
||||
{
|
||||
public class AbstractSyntaxTree<TToken, TType>
|
||||
where TToken: IExpressionToken<TToken, TType>
|
||||
public sealed class AbstractSyntaxTree<TNode, TType>
|
||||
where TNode: IASTNode<TNode, TType>
|
||||
where TType: ITypeSource<TType>
|
||||
{
|
||||
|
||||
private bool _cacheAvailable;
|
||||
private HashSet<TToken> _allToken = new();
|
||||
private TToken _root;
|
||||
private List<TNode> _allToken = new();
|
||||
private TNode _root;
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
if( !_cacheAvailable ) {
|
||||
MakeCache();
|
||||
}
|
||||
return _allToken.Count;
|
||||
}
|
||||
get { return _allToken.Count; }
|
||||
}
|
||||
|
||||
public TToken Root => _root;
|
||||
public TNode Root => _root;
|
||||
|
||||
public bool Contains( TToken node )
|
||||
public bool Contains( TNode node )
|
||||
{
|
||||
if( !_cacheAvailable ) {
|
||||
MakeCache();
|
||||
}
|
||||
return _allToken.Contains( node );
|
||||
}
|
||||
|
||||
public virtual void MakeCache() { }
|
||||
public List<List<TNode>> SortByDepth() { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ using System;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpBuiltinConstant<T> : ExpLiteralToken<T>
|
||||
public class ExpBuiltinConstant<T> : ExpLiteralNode<T>
|
||||
{
|
||||
|
||||
internal ExpBuiltinConstant( string name, T value )
|
||||
|
||||
@@ -34,7 +34,7 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public abstract class ExpCollectionInstanceBase : ExpToken
|
||||
public abstract class ExpCollectionInstanceBase : ExpBaseNode
|
||||
{
|
||||
|
||||
protected internal (int min, int max) _range;
|
||||
@@ -53,11 +53,9 @@ namespace StgSharp.Script.Express
|
||||
get => _memberType;
|
||||
}
|
||||
|
||||
public override ExpToken Left => null!;
|
||||
public override ExpBaseNode Left => null!;
|
||||
|
||||
public override ExpToken Right => null!;
|
||||
|
||||
public override ExpToken Next => null!;
|
||||
public override ExpBaseNode Right => null!;
|
||||
|
||||
public int MinCapacity => _range.min;
|
||||
|
||||
@@ -78,11 +76,6 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
@@ -101,11 +94,6 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
@@ -124,11 +112,6 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
@@ -150,11 +133,6 @@ 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,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,90 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.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;
|
||||
}
|
||||
|
||||
private 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ using CommunityToolkit.HighPerformance.Buffers;
|
||||
using StgSharp.Collections;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -44,10 +45,11 @@ 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, ExpOperandToken> _operators;
|
||||
private static FrozenDictionary<string, ExpBinaryOperatorNode> _operators;
|
||||
private static StringPool _compileStringCache;
|
||||
|
||||
public static FrozenDictionary<string, ExpElementInstanceBase> BuiltinConst => _builtinConst;
|
||||
@@ -82,30 +84,38 @@ namespace StgSharp.Script.Express
|
||||
_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();
|
||||
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 ) ) ),
|
||||
|
||||
_operators = new Dictionary<string, ExpOperandToken>( _multiplexer )
|
||||
];
|
||||
|
||||
_builtinType = new Dictionary<string, ExpTypeSource>(
|
||||
builtinTypeSource, _multiplexer ) .ToFrozenDictionary();
|
||||
|
||||
_operators = new Dictionary<string, ExpBinaryOperatorNode>(
|
||||
_multiplexer )
|
||||
{
|
||||
{ PoolString( KeyWord.ADD ), new ExpOperandToken( KeyWord.ADD ) },
|
||||
{ PoolString( KeyWord.SUB ), new ExpOperandToken( KeyWord.SUB ) }
|
||||
{ PoolString( KeyWord.ADD ), new ExpBinaryOperatorNode(
|
||||
KeyWord.ADD ) },
|
||||
{ PoolString( KeyWord.SUB ), new ExpBinaryOperatorNode(
|
||||
KeyWord.SUB ) }
|
||||
}.ToFrozenDictionary();
|
||||
|
||||
_builtinConst = new Dictionary<string, ExpElementInstanceBase>(
|
||||
@@ -116,7 +126,28 @@ namespace StgSharp.Script.Express
|
||||
PoolString( "E" ), MathF.E ) },
|
||||
}.ToFrozenDictionary();
|
||||
|
||||
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 )
|
||||
@@ -124,6 +155,11 @@ namespace StgSharp.Script.Express
|
||||
return _compileStringCache.GetOrAdd( str );
|
||||
}
|
||||
|
||||
public static string PoolString( ReadOnlySpan<char> str )
|
||||
{
|
||||
return _compileStringCache.GetOrAdd( str );
|
||||
}
|
||||
|
||||
public static void SkipComment( IScriptSourceProvider source ) { }
|
||||
|
||||
public static bool TryGetBuiltinConst(
|
||||
|
||||
@@ -40,42 +40,67 @@ namespace StgSharp.Script.Express
|
||||
public static partial class ExpCompile
|
||||
{
|
||||
|
||||
private static FrozenDictionary<string, int> _operatorPrecedence;
|
||||
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>( "[]", 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 ),
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -39,6 +40,23 @@ 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 ) ) {
|
||||
string? str =
|
||||
field.GetValue( null ) as string;
|
||||
if( str != null ) {
|
||||
_compileStringCache.GetOrAdd( str );
|
||||
}
|
||||
}
|
||||
} );
|
||||
while( !result.IsCompleted ) { }
|
||||
}
|
||||
|
||||
public static class KeyWord
|
||||
{
|
||||
|
||||
@@ -56,6 +74,7 @@ namespace StgSharp.Script.Express
|
||||
SUB = "SUB",
|
||||
MUL = "MUL",
|
||||
DIV = "DIV",
|
||||
NOT = "NOT",
|
||||
Assignment = ":=",
|
||||
Equal = "=",
|
||||
Mod = "MOD",
|
||||
@@ -66,9 +85,9 @@ namespace StgSharp.Script.Express
|
||||
Insert = "INSERT",
|
||||
Remove = "REMOVE",
|
||||
ANDOR = "ANDOR",
|
||||
GetIndex = "[]",
|
||||
UnaryAdd = "unary+",
|
||||
UnarySub = "unary-",
|
||||
GetIndex = "[",
|
||||
UnaryAdd = "+",
|
||||
UnarySub = "-",
|
||||
Exp = "**";
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpToken MakeReference( params object[] options )
|
||||
public override ExpBaseNode MakeReference( params object[] options )
|
||||
{
|
||||
if( options.Length == 0 || options[ 0 ] is not string str ) {
|
||||
return null!;
|
||||
|
||||
@@ -34,21 +34,15 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpEntity : ExpToken
|
||||
public class ExpEntity : ExpBaseNode
|
||||
{
|
||||
|
||||
public ExpEntity( string name, ExpSchema context )
|
||||
: base( name, context ) { }
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
public override ExpBaseNode 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 ExpBaseNode Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
@@ -79,7 +73,7 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpToken CreateInstanceToken()
|
||||
public override ExpBaseNode CreateInstanceToken()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -34,33 +34,27 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpFunction : ExpToken
|
||||
public class ExpFunction : ExpBaseNode
|
||||
{
|
||||
|
||||
private ExpFunctionSource _source;
|
||||
private readonly ExpToken _return;
|
||||
private readonly List<KeyValuePair<string, ExpToken>> _parameterList
|
||||
= new List<KeyValuePair<string, ExpToken>>();
|
||||
private readonly ExpBaseNode _return;
|
||||
private readonly List<KeyValuePair<string, ExpBaseNode>> _parameterList
|
||||
= new List<KeyValuePair<string, ExpBaseNode>>();
|
||||
|
||||
public ExpFunction( string name, ExpSchema context )
|
||||
: base( name, context ) { }
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Function;
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
public override ExpBaseNode 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 ExpBaseNode Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
public void CallThisFunction( params ExpToken[] parameters ) { }
|
||||
public void CallThisFunction( params ExpBaseNode[] parameters ) { }
|
||||
|
||||
}
|
||||
|
||||
@@ -89,7 +83,7 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpToken MakeReference( params object[] options )
|
||||
public override ExpBaseNode MakeReference( params object[] options )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -46,15 +46,9 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public object? value => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpToken Next
|
||||
{
|
||||
get => null!;
|
||||
set { }
|
||||
}
|
||||
|
||||
public override ExpToken Right => throw new NotImplementedException();
|
||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
@@ -86,7 +80,7 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpToken MakeReference( params object[] options )
|
||||
public override ExpBaseNode MakeReference( params object[] options )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -41,15 +41,9 @@ namespace StgSharp.Script.Express
|
||||
public ExpType( string name, ExpSchema context )
|
||||
: base( name, context ) { }
|
||||
|
||||
public override ExpToken Left => throw new NotImplementedException();
|
||||
public override ExpBaseNode 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 ExpBaseNode Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 _tokenType;
|
||||
protected internal string _name;
|
||||
|
||||
protected ExpBaseNode( string name, ExpSchema context )
|
||||
{
|
||||
_name = name;
|
||||
NameSpace = context;
|
||||
Next = this;
|
||||
Previous = this;
|
||||
}
|
||||
|
||||
public abstract ExpBaseNode Left
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
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 TokenTypeCode => ( long )_tokenType;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
protected void AssertSchemaInclude( ExpBaseNode expressionRoot )
|
||||
{
|
||||
if( expressionRoot.NameSpace != NameSpace && NameSpace.HasSchemaInclude(
|
||||
expressionRoot.NameSpace ) ) {
|
||||
throw new ExpInvalidSchemaIncludeException(
|
||||
NameSpace, expressionRoot.NameSpace );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.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.EqualityTypeConvert
|
||||
.IsConvertable( ExpBuiltinConstant<int> ) ) { }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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,63 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 ExpCollectionInstanceBase _collection;
|
||||
private ExpBaseNode _indexExpression;
|
||||
|
||||
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,96 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpLiteralNode.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpLiteralNode<T> : ExpElementInstanceBase
|
||||
{
|
||||
|
||||
private readonly ExpBuiltinType _type;
|
||||
private readonly T _value;
|
||||
|
||||
public ExpLiteralNode( string name, ExpSchema context, T value )
|
||||
: base( name, context )
|
||||
{
|
||||
_value = value;
|
||||
switch( value ) {
|
||||
case float f:
|
||||
ExpCompile.TryGetBuiltinType(
|
||||
ExpCompile.KeyWord.Real, out ExpTypeSource? type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_tokenType = ExpNodeFlag.BuiltinType_Float | ExpNodeFlag.Element_Const;
|
||||
break;
|
||||
case int i:
|
||||
ExpCompile.TryGetBuiltinType(
|
||||
ExpCompile.KeyWord.Int, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_tokenType = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
|
||||
break;
|
||||
case BitArray b:
|
||||
ExpCompile.TryGetBuiltinType(
|
||||
ExpCompile.KeyWord.Binary, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_tokenType = ExpNodeFlag.BuiltinType_Binary | ExpNodeFlag.Element_Const;
|
||||
break;
|
||||
case string s:
|
||||
ExpCompile.TryGetBuiltinType(
|
||||
ExpCompile.KeyWord.String, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_tokenType = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
|
||||
break;
|
||||
case ExpLogic l:
|
||||
ExpCompile.TryGetBuiltinType(
|
||||
ExpCompile.KeyWord.Logic, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_tokenType = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException(
|
||||
"Builtin Type", value!.GetType().Name );
|
||||
}
|
||||
}
|
||||
|
||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
||||
|
||||
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,95 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 ExpElementInstanceBase _variable, _begin, _end, _increment;
|
||||
private ExpBaseNode _operationBegin;
|
||||
|
||||
public ExpRepeatToken(
|
||||
string name,
|
||||
ExpSchema context,
|
||||
ExpBaseNode operationBegin,
|
||||
ExpElementInstanceBase variable,
|
||||
ExpElementInstanceBase begin,
|
||||
ExpElementInstanceBase end,
|
||||
ExpElementInstanceBase increment )
|
||||
: base( name, context )
|
||||
{
|
||||
if( variable.TokenTypeCode != begin.TokenTypeCode || begin.TokenTypeCode !=
|
||||
end.TokenTypeCode || ( increment != null && end.TokenTypeCode !=
|
||||
increment.TokenTypeCode ) ) {
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
if( increment == null ) {
|
||||
switch( ( ExpNodeFlag )variable.TokenTypeCode | ExpNodeFlag.BuiltinType_Any ) {
|
||||
case ExpNodeFlag.BuiltinType_Float:
|
||||
increment = new ExpLiteralNode<float>(
|
||||
$"{name}_defaultIncrement", context, 1.0f );
|
||||
break;
|
||||
case ExpNodeFlag.BuiltinType_Int:
|
||||
increment = new ExpLiteralNode<int>(
|
||||
$"{name}_defaultIncrement", context, 1 );
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException(
|
||||
"Int or Real", "otherwise" );
|
||||
}
|
||||
}
|
||||
_begin = begin;
|
||||
_variable = variable;
|
||||
_end = end;
|
||||
_increment = increment;
|
||||
_tokenType = 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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
}
|
||||
|
||||
public abstract class ExpElementInstanceBase : ExpToken
|
||||
public abstract class ExpElementInstanceBase : ExpBaseNode
|
||||
{
|
||||
|
||||
protected ExpElementInstanceBase( string name, ExpSchema context )
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public abstract void Analyse();
|
||||
|
||||
public abstract ExpToken CreateInstanceToken();
|
||||
public abstract ExpBaseNode CreateInstanceToken();
|
||||
|
||||
public abstract bool IsConvertable( IExpElementSource targetType );
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace StgSharp.Script.Express
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract ExpToken MakeReference( params object[] options );
|
||||
public abstract ExpBaseNode MakeReference( params object[] options );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" ) { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -34,10 +34,10 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpExpressionTree : AbstractSyntaxTree<ExpToken, IExpElementSource>
|
||||
public class ExpExpressionTree : AbstractSyntaxTree<ExpBaseNode, IExpElementSource>
|
||||
{
|
||||
|
||||
public ExpToken RootToken
|
||||
public ExpBaseNode RootToken
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
|
||||
@@ -33,36 +33,20 @@ using CommunityToolkit.HighPerformance.Helpers;
|
||||
using StgSharp.Collections;
|
||||
|
||||
using System;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpSchema
|
||||
public class ExpSchema : ExpSchemaBase
|
||||
{
|
||||
|
||||
private readonly ConcurrentStringHashMultiplexer _multiplexer = ExpCompile.Multiplexer;
|
||||
private Dictionary<string, ExpConstantCollectionSource> _constDict;
|
||||
private Dictionary<string, ExpEntitySource> _entityDict;
|
||||
private Dictionary<string, ExpFunctionSource> _functionDict;
|
||||
private Dictionary<string, ExpRuleSource> _ruleDict;
|
||||
private Dictionary<string, ExpSchema> _schemaInclude;
|
||||
private Dictionary<string, ExpTypeSource> _typeDict;
|
||||
public ExpSchema() { }
|
||||
|
||||
public ExpSchema()
|
||||
public static ExpSchema DefaultSchema
|
||||
{
|
||||
_constDict = new Dictionary<string, ExpConstantCollectionSource>(
|
||||
ExpCompile.Multiplexer );
|
||||
_entityDict = new Dictionary<string, ExpEntitySource>(
|
||||
ExpCompile.Multiplexer );
|
||||
_functionDict = new Dictionary<string, ExpFunctionSource>(
|
||||
ExpCompile.Multiplexer );
|
||||
_ruleDict = new Dictionary<string, ExpRuleSource>(
|
||||
ExpCompile.Multiplexer );
|
||||
_schemaInclude = new Dictionary<string, ExpSchema>(
|
||||
ExpCompile.Multiplexer );
|
||||
_typeDict = new Dictionary<string, ExpTypeSource>(
|
||||
ExpCompile.Multiplexer );
|
||||
get => ExpSchema_Nitload.Only;
|
||||
}
|
||||
|
||||
public string Name
|
||||
@@ -77,11 +61,11 @@ namespace StgSharp.Script.Express
|
||||
out ExpTypeSource? ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
if( _typeDict.TryGetValue( typeName, out ret ) ) {
|
||||
if( TypeDict.TryGetValue( typeName, out ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
foreach( ExpSchema item in _schemaInclude.Values ) {
|
||||
if( item._typeDict.TryGetValue( typeName, out ret ) ) {
|
||||
foreach( ExpSchema item in SchemaInclude.Values ) {
|
||||
if( item.TypeDict.TryGetValue( typeName, out ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -90,7 +74,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public bool HasSchemaInclude( ExpSchema schema )
|
||||
{
|
||||
return _schemaInclude.ContainsKey( schema.Name );
|
||||
return SchemaInclude.ContainsKey( schema.Name );
|
||||
}
|
||||
|
||||
public bool TryGetConstant(
|
||||
@@ -101,7 +85,7 @@ namespace StgSharp.Script.Express
|
||||
out constInstance ) ) {
|
||||
return true;
|
||||
}
|
||||
foreach( ExpConstantCollectionSource item in _constDict.Values ) {
|
||||
foreach( ExpConstantCollectionSource item in ConstDict.Values ) {
|
||||
if( item.TryGetConstant( name, out constInstance ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public abstract class ExpSchemaBase
|
||||
{
|
||||
|
||||
public void LoadFromSource( ExpSchemaSource source )
|
||||
{
|
||||
ConstDict = source.
|
||||
|
||||
}
|
||||
|
||||
public abstract bool TryGetConst( string name, out ExpBaseNode 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 element );
|
||||
|
||||
#pragma warning disable CS8618
|
||||
protected FrozenDictionary<string, ExpConstantCollectionSource> ConstDict
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
protected FrozenDictionary<string, ExpEntitySource> EntityDict
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
protected FrozenDictionary<string, ExpFunctionSource> FunctionDict
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
protected ConcurrentStringHashMultiplexer Multiplexer => 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
|
||||
}
|
||||
}
|
||||
@@ -44,10 +44,32 @@ namespace StgSharp.Script.Express
|
||||
public partial class ExpSchemaSource
|
||||
{
|
||||
|
||||
private Dictionary<string, IExpElementSource> _sourceCache = new();
|
||||
private static Regex
|
||||
_constDefineBegin = GetConstDefineBegin(),
|
||||
_constDefineEnd = GetConstDefineEnd(),
|
||||
_schemaBegin = GetSchemaBegin(),
|
||||
_schemaEnd = GetSchemaEnd(),
|
||||
_entityDefineBegin = GetEntityDefineBegin(),
|
||||
_entityDefineEnd = GetEntityDefineEnd(),
|
||||
_typeDefineBegin = GetTypeDefineBegin(),
|
||||
_typeDefineEnd = new Regex(
|
||||
@"\s*END_TYPE\s*;\s*--\s*(?<TypeName>[a-zA-Z0-9_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_functionDefineBegin = new Regex(
|
||||
@"\s*FUNCTION\s*\s*(?<FunctionName>[a-zA-Z0-9_]+)\s*(?<Remaining>.*)",
|
||||
RegexOptions.Compiled ),
|
||||
_functionDefineEnd = new Regex(
|
||||
@"\s*END_FUNCTION\s*;\s*--\s*(?<FunctionName>[a-zA-Z0-9_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_ruleDefineBegin = new Regex(
|
||||
@"\s*RULE\s*(?<RuleName>[a-zA-Z0-9_]+)\s*FOR\s*\((?<Target>[a-zA-Z0-9_]*(\s*\)\s*;)?)",
|
||||
RegexOptions.Compiled ),
|
||||
_ruleDefineEnd = GetRuleDefineEnd();
|
||||
|
||||
private readonly ExpSchema _compileResult = new ExpSchema();
|
||||
|
||||
private List<IExpElementSource> _sourceCache = new();
|
||||
|
||||
private string name;
|
||||
|
||||
public ExpSchemaSource() { }
|
||||
@@ -69,15 +91,15 @@ namespace StgSharp.Script.Express
|
||||
while( !_schemaEnd.IsMatch( line ) ) {
|
||||
if( TryReadConst( line, reader,
|
||||
out IExpElementSource source ) ) {
|
||||
_sourceCache.Add( source.Name, source );
|
||||
_sourceCache.Add( source );
|
||||
} else if( TryReadType( line, reader, out source ) ) {
|
||||
_sourceCache.Add( source.Name, source );
|
||||
_sourceCache.Add( source );
|
||||
} else if( TryReadEntity( line, reader, out source ) ) {
|
||||
_sourceCache.Add( source.Name, source );
|
||||
_sourceCache.Add( source );
|
||||
} else if( TryReadRule( line, reader, out source ) ) {
|
||||
_sourceCache.Add( source.Name, source );
|
||||
_sourceCache.Add( source );
|
||||
} else if( TryReadFunction( line, reader, out source ) ) {
|
||||
_sourceCache.Add( source.Name, source );
|
||||
_sourceCache.Add( source );
|
||||
}
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
@@ -99,24 +121,19 @@ namespace StgSharp.Script.Express
|
||||
if( _source.TryReadConst(
|
||||
firstLine, reader,
|
||||
out IExpElementSource _elementSource ) ) {
|
||||
_source._sourceCache
|
||||
.Add( _elementSource.Name, _elementSource );
|
||||
_source._sourceCache.Add( _elementSource );
|
||||
} else if( _source.TryReadType(
|
||||
firstLine, reader, out _elementSource ) ) {
|
||||
_source._sourceCache
|
||||
.Add( _elementSource.Name, _elementSource );
|
||||
_source._sourceCache.Add( _elementSource );
|
||||
} else if( _source.TryReadEntity(
|
||||
firstLine, reader, out _elementSource ) ) {
|
||||
_source._sourceCache
|
||||
.Add( _elementSource.Name, _elementSource );
|
||||
_source._sourceCache.Add( _elementSource );
|
||||
} else if( _source.TryReadRule(
|
||||
firstLine, reader, out _elementSource ) ) {
|
||||
_source._sourceCache
|
||||
.Add( _elementSource.Name, _elementSource );
|
||||
_source._sourceCache.Add( _elementSource );
|
||||
} else if( _source.TryReadFunction(
|
||||
firstLine, reader, out _elementSource ) ) {
|
||||
_source._sourceCache
|
||||
.Add( _elementSource.Name, _elementSource );
|
||||
_source._sourceCache.Add( _elementSource );
|
||||
}
|
||||
firstLine = reader.ReadLine();
|
||||
}
|
||||
@@ -130,9 +147,34 @@ namespace StgSharp.Script.Express
|
||||
[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*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();
|
||||
|
||||
private bool TryReadConst(
|
||||
string firstLine,
|
||||
ExpFileSource reader,
|
||||
@@ -287,37 +329,5 @@ namespace StgSharp.Script.Express
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Regex
|
||||
_constDefineBegin = GetConstDefineBegin(),
|
||||
_constDefineEnd = GetConstDefineEnd(),
|
||||
_schemaBegin = GetSchemaBegin(),
|
||||
_schemaEnd = new Regex(
|
||||
@"END_SCHEMA;\s*--\s*(?<namespace>[A-Za-z0-9_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_entityDefineBegin = new Regex(
|
||||
@"\s*ENTITY\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
|
||||
RegexOptions.Compiled ),
|
||||
_entityDefineEnd = new Regex(
|
||||
@"\s*END_ENTITY;\s*--\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
|
||||
RegexOptions.Compiled ),
|
||||
_typeDefineBegin = new Regex(
|
||||
@"\s*TYPE\s+(?<TypeName>[A-Za-z0-9_]+)\s*=\s*(?<Remaining>[A-Z]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_typeDefineEnd = new Regex(
|
||||
@"\s*END_TYPE\s*;\s*--\s*(?<TypeName>[a-zA-Z0-9_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_functionDefineBegin = new Regex(
|
||||
@"\s*FUNCTION\s*\s*(?<FunctionName>[a-zA-Z0-9_]+)\s*(?<Remaining>.*)",
|
||||
RegexOptions.Compiled ),
|
||||
_functionDefineEnd = new Regex(
|
||||
@"\s*END_FUNCTION\s*;\s*--\s*(?<FunctionName>[a-zA-Z0-9_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_ruleDefineBegin = new Regex(
|
||||
@"\s*RULE\s*(?<RuleName>[a-zA-Z0-9_]+)\s*FOR\s*\((?<Target>[a-zA-Z0-9_]*(\s*\)\s*;)?)",
|
||||
RegexOptions.Compiled ),
|
||||
_ruleDefineEnd = new Regex(
|
||||
@"\s*END_RULE\s*;\s*--\s*(?<RuleName>[A-Za-z0-9_]+)",
|
||||
RegexOptions.Compiled );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,13 @@ namespace StgSharp.Script.Express
|
||||
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 )
|
||||
{
|
||||
@@ -75,10 +81,10 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para> Read code until end of a line. Lines in multi-line comment will be ignored. Line
|
||||
/// <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>
|
||||
/// 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()
|
||||
@@ -111,7 +117,7 @@ namespace StgSharp.Script.Express
|
||||
return _lineCache.AsSpan().Slice( _current );
|
||||
}
|
||||
|
||||
public unsafe TokenSource ReadToken()
|
||||
public unsafe Token ReadToken()
|
||||
{
|
||||
int begin, end, rest;
|
||||
readLine:
|
||||
@@ -126,9 +132,10 @@ namespace StgSharp.Script.Express
|
||||
end = match.Groups[ End ].Index;
|
||||
rest = match.Groups[ Rest ].Index;
|
||||
_current = rest;
|
||||
return new(
|
||||
source[ .. ( end - begin ) ], _lineNum, begin,
|
||||
PreprocessingMask.Names );
|
||||
_last = new(
|
||||
ExpCompile.PoolString( source[ .. ( end - begin ) ] ),
|
||||
_lineNum, begin, TokenFlag.Member );
|
||||
return _last;
|
||||
} else {
|
||||
throw new ExpInvalidTokenException( _current );
|
||||
}
|
||||
@@ -141,8 +148,8 @@ namespace StgSharp.Script.Express
|
||||
begin = _current;
|
||||
_current += 2;
|
||||
return new(
|
||||
ReadOnlySpan<char>.Empty, _lineNum, begin,
|
||||
PreprocessingMask.String );
|
||||
string.Empty, _lineNum, begin,
|
||||
TokenFlag.String );
|
||||
}
|
||||
Match match = _nextStringLiteralPattern.Match(
|
||||
_lineCache, _current );
|
||||
@@ -151,9 +158,11 @@ namespace StgSharp.Script.Express
|
||||
end = match.Groups[ "end" ].Index;
|
||||
rest = match.Groups[ "rest" ].Index;
|
||||
_current = rest;
|
||||
return new(
|
||||
source[ 1..( end - begin ) ], _lineNum, begin,
|
||||
PreprocessingMask.String );
|
||||
_last = new(
|
||||
ExpCompile.PoolString(
|
||||
source[ 1..( end - begin ) ] ),
|
||||
_lineNum, begin, TokenFlag.String );
|
||||
return _last;
|
||||
} else {
|
||||
throw new ExpInvalidCharException( '\"' );
|
||||
}
|
||||
@@ -166,15 +175,24 @@ namespace StgSharp.Script.Express
|
||||
} else {
|
||||
begin = _current;
|
||||
_current++;
|
||||
return new(
|
||||
source[ ..1 ], _lineNum, begin,
|
||||
PreprocessingMask.Symbol );
|
||||
_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
|
||||
// 3. - number type param(UNARY)
|
||||
// 4. param - param(BINARY)
|
||||
cNext = source[ 1 ];
|
||||
if( char.IsNumber( cNext ) ) {
|
||||
match = _nextNumberLiteralPattern.Match(
|
||||
@@ -185,8 +203,9 @@ namespace StgSharp.Script.Express
|
||||
rest = match.Groups[ Rest ].Index;
|
||||
_current = rest;
|
||||
return new(
|
||||
source[ ..( end - begin ) ], _lineNum,
|
||||
begin, PreprocessingMask.Number );
|
||||
ExpCompile.PoolString(
|
||||
source[ ..( end - begin ) ] ),
|
||||
_lineNum, begin, TokenFlag.Number );
|
||||
} else {
|
||||
throw new ExpInvalidTokenException( _current );
|
||||
}
|
||||
@@ -197,17 +216,47 @@ namespace StgSharp.Script.Express
|
||||
} else {
|
||||
begin = _current;
|
||||
_current++;
|
||||
return new(
|
||||
source[ ..1 ], _lineNum, begin,
|
||||
PreprocessingMask.Symbol );
|
||||
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 ')' or '[' or ']' or '{' or '}' or ':' or ';' or
|
||||
'+' or '/' or '\\' or '*' or '.' or ',':
|
||||
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(
|
||||
source[ ..1 ], _lineNum, begin,
|
||||
PreprocessingMask.Symbol );
|
||||
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
|
||||
begin, TokenFlag.Symbol_Binary );
|
||||
default:
|
||||
throw new ExpInvalidCharException( c );
|
||||
}
|
||||
@@ -219,9 +268,16 @@ namespace StgSharp.Script.Express
|
||||
end = match.Groups[ End ].Index;
|
||||
rest = match.Groups[ Rest ].Index;
|
||||
_current = rest;
|
||||
return new(
|
||||
source[ ..( end - begin ) ], _lineNum, begin,
|
||||
PreprocessingMask.Number );
|
||||
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 );
|
||||
}
|
||||
@@ -257,10 +313,5 @@ namespace StgSharp.Script.Express
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetStringLiteralPattern();
|
||||
|
||||
private Regex _nextWordTokenPattern = GetNextWordTokenPattern(),
|
||||
_nextStringLiteralPattern = GetStringLiteralPattern(),
|
||||
_nextNumberLiteralPattern = GetNumberLiteralPattern(),
|
||||
_skipBlankPattern = GetSkipBlankPattern();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ExpSchema _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(
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IASTNode.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.Script.Express;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script
|
||||
{
|
||||
public interface IASTNode<TNode, TType> where TNode: IASTNode<TNode, TType>
|
||||
where TType: ITypeSource<TType>
|
||||
{
|
||||
|
||||
long TokenTypeCode
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
string Name
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
TNode Previous
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
TNode Next
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
TNode Left
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
TNode Right
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
TType EqualityTypeConvert
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
void AppendNode( TNode nextToken );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -48,15 +48,17 @@ namespace StgSharp.Script
|
||||
}
|
||||
|
||||
void EndWriting();
|
||||
|
||||
|
||||
string ReadLine();
|
||||
string ReadLine(out int position);
|
||||
|
||||
string ReadLine( out int position );
|
||||
|
||||
/// <summary>
|
||||
/// Return part of current provider.
|
||||
/// </summary>
|
||||
/// <param name="count">Count of lines to be sliced</param>
|
||||
/// <param name="count"> Count of lines to be sliced </param>
|
||||
/// <returns></returns>
|
||||
public IScriptSourceProvider Slice(int location, int count);
|
||||
public IScriptSourceProvider Slice( int location, int count );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ namespace StgSharp.Script
|
||||
public interface ITypeSource<in TConvert>
|
||||
where TConvert: ITypeSource<TConvert>
|
||||
{
|
||||
|
||||
|
||||
bool IsConvertable( TConvert targetType );
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Token.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 struct Token
|
||||
{
|
||||
|
||||
public readonly int Column;
|
||||
public readonly int Line;
|
||||
public readonly string Value;
|
||||
public readonly TokenFlag Flag;
|
||||
|
||||
public Token(
|
||||
string chars,
|
||||
int lineNumber,
|
||||
int columnNumber,
|
||||
TokenFlag flag )
|
||||
{
|
||||
Value = chars;
|
||||
Line = lineNumber;
|
||||
Column = columnNumber;
|
||||
Flag = flag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum TokenFlag : int
|
||||
{
|
||||
|
||||
Symbol_Unary = 1,
|
||||
Symbol_Binary = 2,
|
||||
Number = 3,
|
||||
String = 4,
|
||||
Member = 5,
|
||||
Separator_Single = 6,
|
||||
Separator_Left = 7,
|
||||
Separator_Right = 8,
|
||||
Index_Left = 9,
|
||||
Index_Right = 10,
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
|
||||
@@ -0,0 +1,22 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// 由 MSBuild WriteCodeFragment 类生成。
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c23b640cae59b9ee7dcfd8f026b8970a084ddbd7")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/c23b640cae59b9ee7dcfd8f026b8970a084ddbd7/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/ccef0de6f686f94da655b0e7d854d0acaf907d04/*"}}
|
||||
Reference in New Issue
Block a user