Daily update on 20250325-164701 by Nitload Youmu. Additional Message : Lineaar line and multi-linear line compile full function. String literal parsing improve.
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+148b0fed4a1abaaeaa3a28e7c7b088590805ebef")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ffd5825a051f04f4105ac5ed02e754176ce6f608")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Model")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")]
|
||||
[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/148b0fed4a1abaaeaa3a28e7c7b088590805ebef/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/ffd5825a051f04f4105ac5ed02e754176ce6f608/*"}}
|
||||
@@ -36,7 +36,7 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public sealed class ExpBuiltinType : ExpTypeSource
|
||||
internal sealed class ExpBuiltinType : ExpTypeSource
|
||||
{
|
||||
|
||||
private Type _marshalType;
|
||||
|
||||
@@ -37,7 +37,7 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public abstract class ExpCollectionBase : ExpInstantiableElement, IEnumerable<ExpElementInstanceBase>
|
||||
public abstract class ExpCollectionBase : ExpInstantiableElement, IEnumerable<ExpElementInstance>
|
||||
{
|
||||
|
||||
protected internal string _accurateType;
|
||||
@@ -49,10 +49,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Collection;
|
||||
|
||||
public abstract int Count
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract int Count { get; }
|
||||
|
||||
public override sealed IScriptSourceProvider SourceProvider => ScriptSourceTransmitter.Empty;
|
||||
|
||||
@@ -66,7 +63,7 @@ namespace StgSharp.Script.Express
|
||||
return;
|
||||
}
|
||||
|
||||
public abstract IEnumerator<ExpElementInstanceBase> GetEnumerator();
|
||||
public abstract IEnumerator<ExpElementInstance> GetEnumerator();
|
||||
|
||||
public override bool TryGetMember( string name, out ExpNode memberNode )
|
||||
{
|
||||
@@ -84,18 +81,17 @@ namespace StgSharp.Script.Express
|
||||
public class ExpArray : ExpCollectionBase
|
||||
{
|
||||
|
||||
private ExpElementInstanceBase[] _collection;
|
||||
private ExpElementInstance[] _collection;
|
||||
|
||||
public ExpArray( string accurateType ) : base( accurateType ) { }
|
||||
|
||||
public ExpElementInstanceBase this[ int index ]
|
||||
public ExpElementInstance this[ int index ]
|
||||
{
|
||||
get { return _collection[ index ]; }
|
||||
set
|
||||
{
|
||||
if( value.TypeName != MemberType ) {
|
||||
throw new ExpInvalidCollectionMemberTypeException(
|
||||
value, this );
|
||||
throw new ExpInvalidCollectionMemberTypeException( value, this );
|
||||
}
|
||||
_collection[ index ] = value;
|
||||
}
|
||||
@@ -110,9 +106,9 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
|
||||
public override IEnumerator<ExpElementInstance> GetEnumerator()
|
||||
{
|
||||
return ( ( IEnumerable<ExpElementInstanceBase> )_collection )
|
||||
return ( ( IEnumerable<ExpElementInstance> )_collection )
|
||||
.GetEnumerator();
|
||||
}
|
||||
|
||||
@@ -121,7 +117,7 @@ namespace StgSharp.Script.Express
|
||||
public class ExpBag : ExpCollectionBase
|
||||
{
|
||||
|
||||
private ConcurrentBag<ExpElementInstanceBase> _collection = new ConcurrentBag<ExpElementInstanceBase>(
|
||||
private ConcurrentBag<ExpElementInstance> _collection = new ConcurrentBag<ExpElementInstance>(
|
||||
);
|
||||
|
||||
public ExpBag( string accurateType ) : base( accurateType ) { }
|
||||
@@ -135,7 +131,7 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
|
||||
public override IEnumerator<ExpElementInstance> GetEnumerator()
|
||||
{
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
@@ -145,8 +141,7 @@ namespace StgSharp.Script.Express
|
||||
public sealed class ExpList : ExpCollectionBase
|
||||
{
|
||||
|
||||
private List<ExpElementInstanceBase> _collection = new List<ExpElementInstanceBase>(
|
||||
);
|
||||
private List<ExpElementInstance> _collection = new List<ExpElementInstance>();
|
||||
|
||||
public ExpList( string accurateType ) : base( accurateType ) { }
|
||||
|
||||
@@ -159,7 +154,7 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
|
||||
public override IEnumerator<ExpElementInstance> GetEnumerator()
|
||||
{
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
@@ -169,7 +164,7 @@ namespace StgSharp.Script.Express
|
||||
public class ExpSet : ExpCollectionBase
|
||||
{
|
||||
|
||||
private HashSet<ExpElementInstanceBase> _collection = new();
|
||||
private HashSet<ExpElementInstance> _collection = new();
|
||||
|
||||
public ExpSet( string accurateType ) : base( accurateType ) { }
|
||||
|
||||
@@ -177,11 +172,10 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override string Name => ExpressCompile.PoolString( "SET" );
|
||||
|
||||
public void Add( ExpElementInstanceBase token )
|
||||
public void Add( ExpElementInstance token )
|
||||
{
|
||||
if( token.TypeName != MemberType ) {
|
||||
throw new ExpInvalidCollectionMemberTypeException( token,
|
||||
this );
|
||||
throw new ExpInvalidCollectionMemberTypeException( token, this );
|
||||
}
|
||||
_collection.Add( token );
|
||||
}
|
||||
@@ -191,10 +185,9 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override sealed IEnumerator<ExpElementInstanceBase> GetEnumerator(
|
||||
)
|
||||
public override sealed IEnumerator<ExpElementInstance> GetEnumerator()
|
||||
{
|
||||
return ( ( IEnumerable<ExpElementInstanceBase> )_collection )
|
||||
return ( ( IEnumerable<ExpElementInstance> )_collection )
|
||||
.GetEnumerator();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IExpBuiltinType.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public interface IExpBuiltinType<TSelf> where TSelf: ExpElementInstance, IExpBuiltinType<TSelf>
|
||||
{
|
||||
|
||||
static abstract ExpElementInstance CreateInstance();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -39,23 +39,13 @@ namespace StgSharp.Script.Express
|
||||
public static partial class ExpressCompile
|
||||
{
|
||||
|
||||
public static ExpTypeSource ExpInt
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public static ExpTypeSource ExpInt { get; private set; }
|
||||
|
||||
public static ExpTypeSource ExpReal
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public static ExpTypeSource ExpReal { get; private set; }
|
||||
|
||||
public static ExpTypeSource ExpBool
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public static ExpTypeSource ExpBool { get; private set; }
|
||||
|
||||
public static ExpTypeSource ExpString { get; private set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace StgSharp.Script.Express
|
||||
return;
|
||||
}
|
||||
|
||||
public override bool TryGetConst( string name, out ExpElementInstanceBase c )
|
||||
public override bool TryGetConst( string name, out ExpElementInstance c )
|
||||
{
|
||||
return ConstDict.TryGetValue( name, out c );
|
||||
}
|
||||
@@ -118,11 +118,11 @@ namespace StgSharp.Script.Express
|
||||
Multiplexer ).ToFrozenDictionary();
|
||||
|
||||
|
||||
ConstDict = new Dictionary<string, ExpElementInstanceBase>( Multiplexer ) {
|
||||
ConstDict = new Dictionary<string, ExpElementInstance>( Multiplexer ) {
|
||||
{ PoolString( "PI" ), new ExpRealNumberNode(
|
||||
new Token( PoolString( "PI" ), -1, -1, TokenFlag.Number ), MathF.PI ) },
|
||||
new Token( PoolString( "PI" ), -1, -1, TokenFlag.Number ), MathF.PI, true ) },
|
||||
{ PoolString( "E" ), new ExpRealNumberNode(
|
||||
new Token( PoolString( "E" ), -1, -1, TokenFlag.Number ), MathF.E ) },
|
||||
new Token( PoolString( "E" ), -1, -1, TokenFlag.Number ), MathF.E, true ) },
|
||||
}.ToFrozenDictionary();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
private static string[] _operatorsWithLetter;
|
||||
private static ConcurrentStringHashMultiplexer _multiplexer;
|
||||
private static FrozenDictionary<string, ExpElementInstanceBase> _builtinConst;
|
||||
private static FrozenDictionary<string, ExpElementInstance> _builtinConst;
|
||||
private static FrozenDictionary<string, ExpTypeSource> _builtinType;
|
||||
private static FrozenDictionary<string, ExpBinaryOperatorNode> _operators;
|
||||
private static StringPool _compileStringCache,_emptyCache;
|
||||
@@ -112,6 +112,12 @@ namespace StgSharp.Script.Express
|
||||
PoolString( Keyword.Boolean ), out ExpTypeSource? _expBool );
|
||||
ExpBool = _expBool;
|
||||
|
||||
ExpSchema_Builtin.Only
|
||||
.TryGetType(
|
||||
PoolString( Keyword.Boolean ), out ExpTypeSource? _expString );
|
||||
ExpString = _expString;
|
||||
|
||||
|
||||
_emptyCache = new StringPool();
|
||||
/*
|
||||
foreach( string str in _compileStringCache ) {
|
||||
|
||||
@@ -42,14 +42,13 @@ namespace StgSharp.Script.Express
|
||||
public sealed class ExpConstantCollectionSource : ExpImmutableElement
|
||||
{
|
||||
|
||||
private Dictionary<string, ExpElementInstanceBase> _constants;
|
||||
private Dictionary<string, ExpElementInstance> _constants;
|
||||
private IScriptSourceProvider _sourceProvider;
|
||||
|
||||
public ExpConstantCollectionSource( IScriptSourceProvider sourceProvider )
|
||||
{
|
||||
_sourceProvider = sourceProvider;
|
||||
_constants = new Dictionary<string, ExpElementInstanceBase>(
|
||||
ExpressCompile.Multiplexer );
|
||||
_constants = new Dictionary<string, ExpElementInstance>( ExpressCompile.Multiplexer );
|
||||
}
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Const;
|
||||
@@ -74,20 +73,20 @@ namespace StgSharp.Script.Express
|
||||
if( _constants.Count == 0 ) {
|
||||
return null!;
|
||||
}
|
||||
if( _constants.TryGetValue( str, out ExpElementInstanceBase? token ) ) {
|
||||
if( _constants.TryGetValue( str, out ExpElementInstance? token ) ) {
|
||||
return token;
|
||||
}
|
||||
return null!;
|
||||
}
|
||||
|
||||
public bool TryGetConstant( string name, out ExpElementInstanceBase instance )
|
||||
public bool TryGetConstant( string name, out ExpElementInstance instance )
|
||||
{
|
||||
return _constants.TryGetValue( name, out instance );
|
||||
}
|
||||
|
||||
public override bool TryGetMember( string name, out ExpNode memberNode )
|
||||
{
|
||||
if( _constants.TryGetValue( name, out ExpElementInstanceBase? node ) )
|
||||
if( _constants.TryGetValue( name, out ExpElementInstance? node ) )
|
||||
{
|
||||
memberNode = node;
|
||||
return true;
|
||||
@@ -96,7 +95,7 @@ namespace StgSharp.Script.Express
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void AddConstant( string name, ExpElementInstanceBase value )
|
||||
internal void AddConstant( string name, ExpElementInstance value )
|
||||
{
|
||||
_constants.Add( name, value );
|
||||
}
|
||||
|
||||
@@ -40,25 +40,17 @@ namespace StgSharp.Script.Express
|
||||
private ScriptSourceTransmitter _transmitter;
|
||||
private string _name;
|
||||
|
||||
public ExpFunctionSource(
|
||||
string name,
|
||||
ScriptSourceTransmitter transmitter )
|
||||
public ExpFunctionSource( string name, ScriptSourceTransmitter transmitter )
|
||||
{
|
||||
_name = name;
|
||||
_transmitter = transmitter;
|
||||
}
|
||||
|
||||
public Dictionary<string, ExpElementInstanceBase> FuncParams
|
||||
{
|
||||
get;
|
||||
init;
|
||||
} = new Dictionary<string, ExpElementInstanceBase>();
|
||||
public Dictionary<string, ExpElementInstance> FuncParams { get; init; } = new Dictionary<string, ExpElementInstance>(
|
||||
);
|
||||
|
||||
public Dictionary<string, ExpElementInstanceBase> LocalVariables
|
||||
{
|
||||
get;
|
||||
init;
|
||||
} = new Dictionary<string, ExpElementInstanceBase>();
|
||||
public Dictionary<string, ExpElementInstance> LocalVariables { get; init; } = new Dictionary<string, ExpElementInstance>(
|
||||
);
|
||||
|
||||
public override ExpElementType ElementType => ExpElementType.Function;
|
||||
|
||||
@@ -66,11 +58,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override string Name => _name;
|
||||
|
||||
public string CallingFormat
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public string CallingFormat { get; private set; }
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
@@ -89,13 +77,13 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public override bool TryGetMember( string name, out ExpNode memberNode )
|
||||
{
|
||||
if( FuncParams.TryGetValue(
|
||||
name, out ExpElementInstanceBase? param ) ) {
|
||||
if( FuncParams.TryGetValue( name, out ExpElementInstance? param ) )
|
||||
{
|
||||
memberNode = param;
|
||||
return true;
|
||||
}
|
||||
if( LocalVariables.TryGetValue(
|
||||
name, out ExpElementInstanceBase? variable ) ) {
|
||||
if( LocalVariables.TryGetValue( name, out ExpElementInstance? variable ) )
|
||||
{
|
||||
memberNode = variable;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpRule : ExpElementInstanceBase
|
||||
public class ExpRule : ExpElementInstance
|
||||
{
|
||||
|
||||
private ExpRuleSource _source;
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExpElementInstanceBase CreateInstanceNode()
|
||||
public override ExpElementInstance CreateInstanceNode()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -96,8 +96,7 @@ namespace StgSharp.Script.Express
|
||||
private class ExpVoidType : ExpTypeSource
|
||||
{
|
||||
|
||||
private static readonly ExpVoidType _onlyInstance = new ExpVoidType(
|
||||
);
|
||||
private static readonly ExpVoidType _onlyInstance = new ExpVoidType();
|
||||
|
||||
private ExpVoidType() : base( string.Empty ) { }
|
||||
|
||||
|
||||
@@ -41,20 +41,19 @@ namespace StgSharp.Script.Express
|
||||
public class ExpInstanceMemberNode : ExpNode
|
||||
{
|
||||
|
||||
private ExpElementInstanceBase _instance;
|
||||
private ExpElementInstance _instance;
|
||||
private ExpElementMemberNameNode _memberName;
|
||||
private ExpNode _member;
|
||||
|
||||
public ExpInstanceMemberNode(
|
||||
Token source,
|
||||
ExpElementInstanceBase instance,
|
||||
ExpElementMemberNameNode memberName )
|
||||
Token source,
|
||||
ExpElementInstance instance,
|
||||
ExpElementMemberNameNode memberName )
|
||||
: base( source )
|
||||
{
|
||||
_instance = instance;
|
||||
_memberName = memberName;
|
||||
_instance.TryGetMember(
|
||||
memberName.CodeConvertTemplate, out _member );
|
||||
_instance.TryGetMember( memberName.CodeConvertTemplate, out _member );
|
||||
}
|
||||
|
||||
public override ExpNode Left => _instance;
|
||||
|
||||
@@ -40,13 +40,14 @@ namespace StgSharp.Script.Express
|
||||
public class ExpInstanceReferenceNode : ExpNode
|
||||
{
|
||||
|
||||
private ExpElementInstanceBase _instance;
|
||||
private ExpElementInstance _instance;
|
||||
|
||||
internal ExpInstanceReferenceNode( Token source, ExpElementInstanceBase instance )
|
||||
internal ExpInstanceReferenceNode( Token source, ExpElementInstance instance )
|
||||
: base( source )
|
||||
{
|
||||
_instance = instance;
|
||||
_nodeFlag = ( _instance._nodeFlag | ( ExpNodeFlag.Name_Any | ExpNodeFlag.Collection_Any ) );
|
||||
CodeConvertTemplate = source.Value;
|
||||
}
|
||||
|
||||
internal ExpInstanceReferenceNode( Token source, ExpInstanceReferenceNode reference )
|
||||
@@ -64,11 +65,15 @@ namespace StgSharp.Script.Express
|
||||
public override IExpElementSource EqualityTypeConvert => _instance.EqualityTypeConvert;
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static ExpInstanceReferenceNode Create(
|
||||
public static ExpInstanceReferenceNode MakeReferenceFrom(
|
||||
Token source,
|
||||
ExpElementInstanceBase instance )
|
||||
ExpElementInstance instance )
|
||||
{
|
||||
/*
|
||||
/**/
|
||||
if( instance.IsLiteral )
|
||||
{
|
||||
throw new ExpCompileException( source, "Cannot make reference to a literal." );
|
||||
}
|
||||
if( instance.CodeConvertTemplate != source.Value ) {
|
||||
throw new ExpCompileException( source, "Token point at a wrong instance" );
|
||||
}
|
||||
|
||||
@@ -34,26 +34,28 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpIntNode : ExpElementInstanceBase
|
||||
public class ExpIntNode : ExpElementInstance
|
||||
{
|
||||
|
||||
private int _value;
|
||||
|
||||
public ExpIntNode( Token source, int value )
|
||||
public ExpIntNode( Token source, int value, bool isLiteral )
|
||||
: base( source )
|
||||
{
|
||||
this.IsLiteral = isLiteral;
|
||||
_value = value;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Type;
|
||||
CodeConvertTemplate = IsLiteral ? value.ToString() : source.Value;
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
|
||||
.TryGetType(
|
||||
ExpressCompile.Keyword.Integer,
|
||||
out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get => ExpressCompile.ExpInt;
|
||||
}
|
||||
|
||||
public int Value => _value;
|
||||
|
||||
@@ -61,23 +63,24 @@ namespace StgSharp.Script.Express
|
||||
|
||||
}
|
||||
|
||||
public class ExpStringNode : ExpElementInstanceBase
|
||||
public class ExpStringNode : ExpElementInstance
|
||||
{
|
||||
|
||||
private readonly string _value;
|
||||
|
||||
public ExpStringNode( Token source, string value )
|
||||
public ExpStringNode( Token source, string value, bool isLiteral )
|
||||
: base( source )
|
||||
{
|
||||
this.IsLiteral = IsLiteral;
|
||||
_value = value;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_String | ExpNodeFlag.Element_Type;
|
||||
CodeConvertTemplate = IsLiteral ? $"\"{value}\"" : source.Value;
|
||||
}
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
|
||||
.TryGetType(
|
||||
ExpressCompile.Keyword.String,
|
||||
out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get => ExpressCompile.ExpString;
|
||||
}
|
||||
|
||||
public override string TypeName => EqualityTypeConvert.Name;
|
||||
|
||||
@@ -85,73 +88,81 @@ namespace StgSharp.Script.Express
|
||||
|
||||
}
|
||||
|
||||
public class ExpBoolNode : ExpElementInstanceBase
|
||||
public class ExpBoolNode : ExpElementInstance
|
||||
{
|
||||
|
||||
private readonly bool _value;
|
||||
|
||||
public ExpBoolNode( Token source, bool value )
|
||||
public ExpBoolNode( Token source, bool value, bool isLiteral )
|
||||
: base( source )
|
||||
{
|
||||
this.IsLiteral = isLiteral;
|
||||
_value = value;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Element_Type;
|
||||
CodeConvertTemplate = IsLiteral ? value.ToString() : source.Value;
|
||||
}
|
||||
|
||||
public bool Value => _value;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
|
||||
.TryGetType(
|
||||
ExpressCompile.Keyword.Boolean,
|
||||
out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get => ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpressCompile.Keyword.Boolean, out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
}
|
||||
|
||||
public override string TypeName => EqualityTypeConvert.Name;
|
||||
|
||||
}
|
||||
|
||||
public class ExpRealNumberNode : ExpElementInstanceBase
|
||||
public class ExpRealNumberNode : ExpElementInstance
|
||||
{
|
||||
|
||||
private readonly float _value;
|
||||
|
||||
public ExpRealNumberNode( Token source, float value )
|
||||
public ExpRealNumberNode( Token source, float value, bool isLiteral )
|
||||
: base( source )
|
||||
{
|
||||
_value = value;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Real | ExpNodeFlag.Element_Type;
|
||||
CodeConvertTemplate = isLiteral ? $"{value:F8}f" : source.Value;
|
||||
}
|
||||
|
||||
public float Value => _value;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
|
||||
.TryGetType(
|
||||
ExpressCompile.Keyword.String,
|
||||
out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get => ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpressCompile.Keyword.String, out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
}
|
||||
|
||||
public override string TypeName => EqualityTypeConvert.Name;
|
||||
|
||||
}
|
||||
|
||||
public class ExpLogicValueNode : ExpElementInstanceBase
|
||||
public class ExpLogicValueNode : ExpElementInstance
|
||||
{
|
||||
|
||||
private readonly ExpLogic _value;
|
||||
|
||||
public ExpLogicValueNode( Token source, ExpLogic value )
|
||||
public ExpLogicValueNode( Token source, ExpLogic value, bool isLiteral )
|
||||
: base( source )
|
||||
{
|
||||
this.IsLiteral = isLiteral;
|
||||
_value = value;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.Element_Type;
|
||||
CodeConvertTemplate = isLiteral ? value.ToString() : source.Value;
|
||||
}
|
||||
|
||||
public ExpLogic Value => _value;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
|
||||
.TryGetType(
|
||||
ExpressCompile.Keyword.Logical,
|
||||
out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
public override IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get => ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpressCompile.Keyword.Logical, out ExpTypeSource? type ) ?
|
||||
type : throw new ExpCompileNotInitializedException();
|
||||
}
|
||||
|
||||
public override string TypeName => EqualityTypeConvert.Name;
|
||||
|
||||
|
||||
@@ -41,43 +41,44 @@ namespace StgSharp.Script.Express
|
||||
|
||||
//TODO: Current code cannot represent full functionality defined in ISO10303, need rewrite.
|
||||
|
||||
private ExpElementInstanceBase _variable, _begin, _end, _increment;
|
||||
private ExpElementInstance _variable, _begin, _end, _increment;
|
||||
|
||||
private ExpNode _operationBegin;
|
||||
|
||||
public ExpRepeatNode(
|
||||
Token source,
|
||||
ExpNode operationBegin,
|
||||
ExpElementInstanceBase variable,
|
||||
ExpElementInstanceBase begin,
|
||||
ExpElementInstanceBase end,
|
||||
ExpElementInstanceBase increment )
|
||||
Token source,
|
||||
ExpNode operationBegin,
|
||||
ExpElementInstance variable,
|
||||
ExpElementInstance begin,
|
||||
ExpElementInstance end,
|
||||
ExpElementInstance increment )
|
||||
: base( source )
|
||||
{
|
||||
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag !=
|
||||
end.NodeFlag || ( increment != null && end.NodeFlag !=
|
||||
increment.NodeFlag ) ) {
|
||||
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag != end.NodeFlag || ( increment !=
|
||||
null && end.NodeFlag !=
|
||||
increment.NodeFlag ) ) {
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
if( increment == null ) {
|
||||
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any ) {
|
||||
if( increment == null )
|
||||
{
|
||||
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any )
|
||||
{
|
||||
case ExpNodeFlag.BuiltinType_Real:
|
||||
increment = new ExpRealNumberNode(
|
||||
new Token(
|
||||
ExpressCompile.PoolString( "1.0f" ), source.Line,
|
||||
-1, TokenFlag.Number ),
|
||||
1.0f );
|
||||
ExpressCompile.PoolString( "1.0f" ), source.Line, -1,
|
||||
TokenFlag.Number ),
|
||||
1.0f, isLiteral: true );
|
||||
break;
|
||||
case ExpNodeFlag.BuiltinType_Int:
|
||||
increment = new ExpIntNode(
|
||||
new Token(
|
||||
ExpressCompile.PoolString( "1" ), source.Line, -1,
|
||||
TokenFlag.Number ),
|
||||
1 );
|
||||
1, isLiteral: true );
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException(
|
||||
"Int or Real", "otherwise" );
|
||||
throw new ExpInvalidTypeException( "Int or Real", "otherwise" );
|
||||
}
|
||||
}
|
||||
_begin = begin;
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpElementInstance.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
[Flags]
|
||||
public enum ExpElementType : int
|
||||
{
|
||||
|
||||
Void = 0,
|
||||
Const = 1,
|
||||
Entity = 2,
|
||||
Type = 4,
|
||||
Function = 8,
|
||||
Section = 16,
|
||||
Expression = 32,
|
||||
Rule = 64,
|
||||
Procedure = 128,
|
||||
Collection = 256,
|
||||
|
||||
}
|
||||
|
||||
public abstract class ExpElementInstance : ExpNode
|
||||
{
|
||||
|
||||
protected ExpElementInstance( Token source )
|
||||
: base( source )
|
||||
{
|
||||
CodeConvertTemplate = source.Value;
|
||||
}
|
||||
|
||||
public bool IsLiteral { get; init; }
|
||||
|
||||
public ExpElementType ElementType { get; }
|
||||
|
||||
public override ExpNode Left => Empty;
|
||||
|
||||
public override ExpNode Right => Empty;
|
||||
|
||||
public abstract string TypeName { get; }
|
||||
|
||||
public static ExpElementInstance CreateLiteral( Token t )
|
||||
{
|
||||
if( int.TryParse( t.Value, out int _int ) )
|
||||
{
|
||||
return new ExpIntNode( t, _int, true );
|
||||
} else if( float.TryParse( t.Value, out float _float ) )
|
||||
{
|
||||
return new ExpRealNumberNode( t, _float, true );
|
||||
} else if( bool.TryParse( t.Value, out bool _bool ) )
|
||||
{
|
||||
return new ExpBoolNode( t, _bool, true );
|
||||
} else if( ExpLogic.TryParse( t.Value, out ExpLogic _logic ) )
|
||||
{
|
||||
return new ExpLogicValueNode( t, _logic, true );
|
||||
} else
|
||||
{
|
||||
return new ExpStringNode( t, t.Value, true );
|
||||
}
|
||||
}
|
||||
|
||||
public ExpInstanceReferenceNode MakeReference( Token t )
|
||||
{
|
||||
return new ExpInstanceReferenceNode( t, this );
|
||||
}
|
||||
|
||||
public static bool TryCreateLiteral( Token t, out ExpElementInstance instance )
|
||||
{
|
||||
if( int.TryParse( t.Value, out int _int ) )
|
||||
{
|
||||
instance = new ExpIntNode( t, _int, true );
|
||||
return true;
|
||||
} else if( float.TryParse( t.Value, out float _float ) )
|
||||
{
|
||||
instance = new ExpRealNumberNode( t, _float, true );
|
||||
return true;
|
||||
} else if( bool.TryParse( t.Value, out bool _bool ) )
|
||||
{
|
||||
instance = new ExpBoolNode( t, _bool, true );
|
||||
return true;
|
||||
} else if( ExpLogic.TryParse( t.Value, out ExpLogic _logic ) )
|
||||
{
|
||||
instance = new ExpLogicValueNode( t, _logic, true );
|
||||
return true;
|
||||
} else if( t.Flag == TokenFlag.String )
|
||||
{
|
||||
instance = new ExpStringNode( t, t.Value, true );
|
||||
return true;
|
||||
}
|
||||
instance = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetMember( string name, out ExpNode node )
|
||||
{
|
||||
return EqualityTypeConvert.TryGetMember( name, out node );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -42,19 +42,18 @@ namespace StgSharp.Script.Express
|
||||
public class ExpInvalidCharException : Exception
|
||||
{
|
||||
|
||||
public ExpInvalidCharException( char c )
|
||||
: base( $"An unknown char {c} occurred." ) { }
|
||||
public ExpInvalidCharException( char c ) : base( $"An unknown char {c} occurred." ) { }
|
||||
|
||||
public ExpInvalidCharException( int index )
|
||||
: base( $"Cannot read a token from line at {index}" ) { }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exception when cannot reading a token from a line.
|
||||
/// </summary>
|
||||
public class ExpInvalidTokenException : Exception
|
||||
public class ExpStringNotCloseException : Exception
|
||||
{
|
||||
|
||||
public ExpInvalidTokenException( int index )
|
||||
: base( $"Cannot read a token from line at {index}" ) { }
|
||||
public ExpStringNotCloseException( int linenum )
|
||||
: base( $"A string does not closed at end of line {linenum}." ) { }
|
||||
|
||||
}
|
||||
|
||||
@@ -80,9 +79,7 @@ namespace StgSharp.Script.Express
|
||||
public class ExpInvalidElementDeclareEndingExceptions : Exception
|
||||
{
|
||||
|
||||
public ExpInvalidElementDeclareEndingExceptions(
|
||||
string declaredName,
|
||||
string endedName )
|
||||
public ExpInvalidElementDeclareEndingExceptions( string declaredName, string endedName )
|
||||
: base(
|
||||
$"The datatype is declared with name {declaredName} but ended with {endedName}" ) { }
|
||||
|
||||
@@ -91,11 +88,8 @@ namespace StgSharp.Script.Express
|
||||
public class ExpInvalidElementNameException : Exception
|
||||
{
|
||||
|
||||
public ExpInvalidElementNameException(
|
||||
string elementName,
|
||||
ExpSchema schema )
|
||||
: base(
|
||||
$"Cannot find any element named {elementName} in {schema.Name}" ) { }
|
||||
public ExpInvalidElementNameException( string elementName, ExpSchema schema )
|
||||
: base( $"Cannot find any element named {elementName} in {schema.Name}" ) { }
|
||||
|
||||
}
|
||||
|
||||
@@ -121,8 +115,8 @@ namespace StgSharp.Script.Express
|
||||
{
|
||||
|
||||
public ExpInvalidCollectionMemberTypeException(
|
||||
ExpElementInstanceBase elementInstance,
|
||||
ExpCollectionBase collection )
|
||||
ExpElementInstance elementInstance,
|
||||
ExpCollectionBase collection )
|
||||
: base(
|
||||
$"Attempt to add or remove an element of type: {elementInstance.ElementType} from a collection collects {collection.MemberType}" ) { }
|
||||
|
||||
@@ -131,9 +125,7 @@ namespace StgSharp.Script.Express
|
||||
public class ExpInvalidSchemaIncludeException : InvalidOperationException
|
||||
{
|
||||
|
||||
public ExpInvalidSchemaIncludeException(
|
||||
ExpSchema context,
|
||||
ExpSchema source )
|
||||
public ExpInvalidSchemaIncludeException( ExpSchema context, ExpSchema source )
|
||||
: base(
|
||||
$"Attempted to refer to an EXPRESS language expression in the current schema context '{context.Name}', but this expression comes from another schema '{source.Name}' that has not been included." ) { }
|
||||
|
||||
@@ -152,8 +144,7 @@ namespace StgSharp.Script.Express
|
||||
{
|
||||
|
||||
public ExpCompileNotInitializedException()
|
||||
: base(
|
||||
"Attempt to compile an EXPRESS script before the init of compiler." ) { }
|
||||
: base( "Attempt to compile an EXPRESS script before the init of compiler." ) { }
|
||||
|
||||
}
|
||||
|
||||
@@ -162,7 +153,7 @@ namespace StgSharp.Script.Express
|
||||
|
||||
public ExpCompileException( Token pos, string message )
|
||||
: base(
|
||||
$"Compiler exception occour when processing token at line {pos.Line}, column {pos.Column}. Detailed message:{Environment.NewLine}{message} " ) { }
|
||||
$"Compiler exception occur when processing token at line {pos.Line}, column {pos.Column}. Detailed message:{Environment.NewLine}{message} " ) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Schema;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
@@ -114,12 +115,26 @@ namespace StgSharp.Script.Express
|
||||
if( t.Flag != TokenFlag.Separator_Middle ) {
|
||||
return false;
|
||||
}
|
||||
processOperator:
|
||||
if( _cache.OperatorAheadOfDepth == 0 )
|
||||
{
|
||||
if( _cache.OperandAheadOfDepth == 1 )
|
||||
{
|
||||
if( _cache.Depth != 1 )
|
||||
{
|
||||
_cache.DecreaseDepth();
|
||||
if( _cache.PeekOperator().Value == t.Value )
|
||||
{
|
||||
_cache.PopOperand( out _, out ExpNode? currentExpression );
|
||||
_cache.PopOperand( out Token valToken, out _ );
|
||||
_cache.PopOperand( out _, out ExpNode? previousExpression );
|
||||
currentExpression.PrependNode( previousExpression );
|
||||
_cache.PushOperand( previousExpression );
|
||||
}
|
||||
}
|
||||
_cache.PushOperand( t );
|
||||
_cache.PushOperator( t );
|
||||
_cache.IncreaseDepth( ( int )ExpCompileStateCode.Common );
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
@@ -127,7 +142,6 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
}
|
||||
Token op;
|
||||
processOperator:
|
||||
if( _cache.TryPopOperator( out op ) )
|
||||
{
|
||||
if( op.Value == t.Value )
|
||||
@@ -151,7 +165,7 @@ namespace StgSharp.Script.Express
|
||||
if( ( t.Flag & ( TokenFlag.String | TokenFlag.Number ) ) == 0 ) {
|
||||
return false;
|
||||
}
|
||||
_cache.PushOperand( ExpElementInstanceBase.CreateLiteral( t ) );
|
||||
_cache.PushOperand( ExpElementInstance.CreateLiteral( t ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -189,7 +203,6 @@ namespace StgSharp.Script.Express
|
||||
{
|
||||
_cache.PopOperator();
|
||||
ExpNode node = ConvertAndPushOneOperator( tmp );
|
||||
_cache.PushOperand( node );
|
||||
goto processPrecedence;
|
||||
}
|
||||
}
|
||||
@@ -199,16 +212,22 @@ namespace StgSharp.Script.Express
|
||||
|
||||
private bool TryParseConstant( Token t )
|
||||
{
|
||||
if( t.Value == ExpKeyword.True )
|
||||
switch( t.Value )
|
||||
{
|
||||
_cache.PushOperand( new ExpBoolNode( t, true ) );
|
||||
return true;
|
||||
} else if( t.Value == ExpKeyword.False )
|
||||
{
|
||||
_cache.PushOperand( new ExpBoolNode( t, false ) );
|
||||
return true;
|
||||
case ExpKeyword.E:
|
||||
_cache.PushOperand( new ExpRealNumberNode( t, MathF.E, true ) );
|
||||
return true;
|
||||
case ExpKeyword.Pi:
|
||||
_cache.PushOperand( new ExpRealNumberNode( t, MathF.PI, true ) );
|
||||
return true;
|
||||
default:
|
||||
if( ExpElementInstance.TryCreateLiteral( t, out ExpElementInstance? node ) )
|
||||
{
|
||||
_cache.PushOperand( node );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryParseFunction( Token t )
|
||||
@@ -228,9 +247,9 @@ namespace StgSharp.Script.Express
|
||||
private bool TryParseInstance( Token t )
|
||||
{
|
||||
if( _local.TryGetMember( t.Value,
|
||||
out ExpNode? node ) && node is ExpElementInstanceBase instance )
|
||||
out ExpNode? node ) && node is ExpElementInstance instance )
|
||||
{
|
||||
_cache.PushOperand( ExpInstanceReferenceNode.Create( t, instance ) );
|
||||
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -108,6 +108,10 @@ namespace StgSharp.Script.Express
|
||||
case TokenFlag.Index_Right:
|
||||
TryAppendIndexRight( expToken );
|
||||
break;
|
||||
case TokenFlag.Number or TokenFlag.String:
|
||||
ExpElementInstance node = ExpElementInstance.CreateLiteral( expToken );
|
||||
_cache.PushOperand( node );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -46,72 +46,38 @@ namespace StgSharp.Script.Express
|
||||
get => ExpSchema_Builtin.Only;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
public string Name { get; internal set; }
|
||||
|
||||
public abstract void LoadFromSource( ExpSchemaSource source );
|
||||
|
||||
public abstract bool TryGetConst(
|
||||
string name,
|
||||
out ExpElementInstanceBase c );
|
||||
public abstract bool TryGetConst( string name, out ExpElementInstance c );
|
||||
|
||||
public abstract bool TryGetEntity( string name, out ExpEntitySource e );
|
||||
|
||||
public abstract bool TryGetFunction(
|
||||
string name,
|
||||
out ExpFunctionSource f );
|
||||
public abstract bool 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 TryGetSchemaInclude( string name, out ExpSchema include );
|
||||
|
||||
public abstract bool TryGetType( string name, out ExpTypeSource t );
|
||||
|
||||
#pragma warning disable CS8618
|
||||
protected FrozenDictionary<string, ExpElementInstanceBase> ConstDict
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
protected FrozenDictionary<string, ExpElementInstance> ConstDict { get; set; }
|
||||
|
||||
public IEnumerable<ExpSchema> IncludedSchema => IncludedSchema;
|
||||
|
||||
protected FrozenDictionary<string, ExpEntitySource> EntityDict
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
protected FrozenDictionary<string, ExpEntitySource> EntityDict { get; set; }
|
||||
|
||||
protected FrozenDictionary<string, ExpFunctionSource> FunctionDict
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
protected FrozenDictionary<string, ExpFunctionSource> FunctionDict { get; set; }
|
||||
|
||||
protected ConcurrentStringHashMultiplexer StringMultiplexer => ExpressCompile.Multiplexer;
|
||||
|
||||
protected FrozenDictionary<string, ExpRuleSource> RuleDict
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
protected FrozenDictionary<string, ExpRuleSource> RuleDict { get; set; }
|
||||
|
||||
protected FrozenDictionary<string, ExpSchema> SchemaInclude
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
protected FrozenDictionary<string, ExpSchema> SchemaInclude { get; set; }
|
||||
|
||||
protected FrozenDictionary<string, ExpTypeSource> TypeDict
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
protected FrozenDictionary<string, ExpTypeSource> TypeDict { get; set; }
|
||||
#pragma warning restore CS8618
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace StgSharp.Script.Express
|
||||
private Regex _nextWordTokenPattern = GetNextWordTokenPattern(),
|
||||
_nextStringLiteralPattern = GetStringLiteralPattern(),
|
||||
_nextNumberLiteralPattern = GetNumberLiteralPattern(),
|
||||
_nextStringLiteralPatternWithSingle = GetStringLiteralPatternWithSingle(),
|
||||
_skipBlankPattern = GetSkipBlankPattern();
|
||||
private string _lineCache;
|
||||
private Token _last;
|
||||
@@ -76,10 +77,10 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para> Read code until end of a line. Lines in multi-line comment will be ignored.
|
||||
/// Line begins with part of multi-line comment will automatically remove the comment
|
||||
/// part, but beginning with a full multi-line comment will not causing removing. </para>
|
||||
/// <para> (*Just Like The Comment Here*) Will Not Be Removed</para>
|
||||
/// <para>Read code until end of a line. Lines in multi-line comment will be ignored. Line
|
||||
/// begins with part of multi-line comment will automatically remove the comment part,
|
||||
/// but beginning with a full multi-line comment will not causing removing.</para> <para>
|
||||
/// (*Just Like The Comment Here*) Will Not Be Removed </para>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
///
|
||||
@@ -130,6 +131,9 @@ namespace StgSharp.Script.Express
|
||||
Match match = _nextWordTokenPattern.Match( _lineCache, _current );
|
||||
if( match.Success )
|
||||
{
|
||||
if( match.Groups[ EndMark ].Index >= _lineCache.Length ) {
|
||||
throw new ExpStringNotCloseException( _lineNum );
|
||||
}
|
||||
begin = match.Groups[ TokenMark ].Index;
|
||||
end = match.Groups[ EndMark ].Index;
|
||||
rest = match.Groups[ RestMark ].Index;
|
||||
@@ -140,12 +144,14 @@ namespace StgSharp.Script.Express
|
||||
return _last;
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidTokenException( _current );
|
||||
throw new ExpInvalidCharException( _current );
|
||||
}
|
||||
} else if( char.IsPunctuation( c ) || char.IsSymbol( c ) )
|
||||
{
|
||||
switch( c )
|
||||
{
|
||||
case '\'':
|
||||
|
||||
case '"':
|
||||
char cNext = source[ 1 ];
|
||||
if( cNext == '\"' ) //empty string
|
||||
@@ -213,7 +219,7 @@ namespace StgSharp.Script.Express
|
||||
_lineNum, begin, TokenFlag.Number );
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidTokenException( _current );
|
||||
throw new ExpInvalidCharException( _current );
|
||||
}
|
||||
} else if( cNext == '-' )
|
||||
{
|
||||
@@ -297,7 +303,7 @@ namespace StgSharp.Script.Express
|
||||
return new( str, _lineNum, begin, TokenFlag.Number );
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidTokenException( _current );
|
||||
throw new ExpInvalidCharException( _current );
|
||||
}
|
||||
} else if( char.IsWhiteSpace( c ) )
|
||||
{
|
||||
@@ -309,7 +315,7 @@ namespace StgSharp.Script.Express
|
||||
goto readLine;
|
||||
} else
|
||||
{
|
||||
throw new ExpInvalidTokenException( _current );
|
||||
throw new ExpInvalidCharException( _current );
|
||||
}
|
||||
} else
|
||||
{
|
||||
@@ -342,9 +348,14 @@ namespace StgSharp.Script.Express
|
||||
private static partial Regex GetSkipBlankPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>"")(?:.*?[^\\](?:\\\\)*?)(?<end>"")\s*?(?<rest>\S|$)",
|
||||
@"(?<token>"")(?>\\\\|\\""|(?!')[^""])*(?<end>""|$)\s*?(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetStringLiteralPattern();
|
||||
|
||||
[GeneratedRegex(
|
||||
@"(?<token>')(?>\\\\|\\'|''|(?!')[^'])*(?<end>')\s*?(?<rest>\S|$)",
|
||||
RegexOptions.Singleline )]
|
||||
private static partial Regex GetStringLiteralPatternWithSingle();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,8 @@ namespace StgSharp.Script.Express
|
||||
if( TypeDict.TryGetValue( typeName, out ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
foreach( GeneratedExpSchema item in SchemaInclude.Values ) {
|
||||
foreach( GeneratedExpSchema item in SchemaInclude.Values )
|
||||
{
|
||||
if( item.TypeDict.TryGetValue( typeName, out ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
@@ -75,9 +76,7 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool TryGetConst(
|
||||
string name,
|
||||
out ExpElementInstanceBase c )
|
||||
public override bool TryGetConst( string name, out ExpElementInstance c )
|
||||
{
|
||||
return ConstDict.TryGetValue( name, out c );
|
||||
}
|
||||
@@ -87,9 +86,7 @@ namespace StgSharp.Script.Express
|
||||
return EntityDict.TryGetValue( name, out e );
|
||||
}
|
||||
|
||||
public override bool TryGetFunction(
|
||||
string name,
|
||||
out ExpFunctionSource f )
|
||||
public override bool TryGetFunction( string name, out ExpFunctionSource f )
|
||||
{
|
||||
return FunctionDict.TryGetValue( name, out f );
|
||||
}
|
||||
@@ -99,16 +96,12 @@ namespace StgSharp.Script.Express
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool TryGetSchemaInclude(
|
||||
string name,
|
||||
out ExpSchema include )
|
||||
public override bool TryGetSchemaInclude( string name, out ExpSchema include )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool TryGetType(
|
||||
string name,
|
||||
out ExpTypeSource element )
|
||||
public override bool TryGetType( string name, out ExpTypeSource element )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -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+148b0fed4a1abaaeaa3a28e7c7b088590805ebef")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ffd5825a051f04f4105ac5ed02e754176ce6f608")]
|
||||
[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/148b0fed4a1abaaeaa3a28e7c7b088590805ebef/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/ffd5825a051f04f4105ac5ed02e754176ce6f608/*"}}
|
||||
@@ -47,17 +47,13 @@ namespace StgSharp
|
||||
: base( name, source )
|
||||
{
|
||||
LocalVariables.Add(
|
||||
"a",
|
||||
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
|
||||
"a", new ExpIntNode( new Token( "a", 0, 0, TokenFlag.Number ), 1, false ) );
|
||||
LocalVariables.Add(
|
||||
"b",
|
||||
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
|
||||
"b", new ExpIntNode( new Token( "b", 0, 0, TokenFlag.Number ), 1, false ) );
|
||||
LocalVariables.Add(
|
||||
"c",
|
||||
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
|
||||
"c", new ExpIntNode( new Token( "c", 0, 0, TokenFlag.Number ), 1, false ) );
|
||||
LocalVariables.Add(
|
||||
"d",
|
||||
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
|
||||
"d", new ExpIntNode( new Token( "d", 0, 0, TokenFlag.Number ), 1, false ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -77,7 +73,7 @@ namespace StgSharp
|
||||
return;
|
||||
}
|
||||
|
||||
public override bool TryGetConst( string name, out ExpElementInstanceBase c )
|
||||
public override bool TryGetConst( string name, out ExpElementInstance c )
|
||||
{
|
||||
c = null;
|
||||
return false;
|
||||
@@ -127,9 +123,11 @@ namespace StgSharp
|
||||
{
|
||||
ExpressCompile.InitCompile();
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter( "END", 0 );
|
||||
transmitter.WriteLine( @"a := ( b + c + d * 2 ) * d;" );
|
||||
|
||||
//transmitter.WriteLine( @"a := b + (c + d) * a;" );
|
||||
//Console.WriteLine( @$"a := ( b * E + d * 2 ) * d;" );
|
||||
transmitter.WriteLine( @$"a := ( b * E + d * 2 ) * d;" );
|
||||
|
||||
transmitter.WriteLine( @"a := b + (c + d) * a;" );
|
||||
transmitter.EndWriting();
|
||||
ExpSourceReader reader = new ExpSourceReader( transmitter );
|
||||
/**/
|
||||
|
||||
@@ -48,20 +48,10 @@ namespace StgSharp
|
||||
StgSharp.InitGL( 4, 6 );
|
||||
StgSharp.GlobalSetting.VSyncActivated = false;
|
||||
|
||||
ViewPort vp = new ViewPort(
|
||||
800, 600, "Hello StgSharp!", IntPtr.Zero );
|
||||
ViewPort vp = new ViewPort( 800, 600, "Hello StgSharp!", IntPtr.Zero );
|
||||
|
||||
//throw new NotImplementedException();
|
||||
|
||||
StringHashMultiplexer mul = new StringHashMultiplexer();
|
||||
IEqualityComparer<string> com = mul;
|
||||
string str = "1234567012345670";
|
||||
for( int i = 1; i < 100; i++ ) {
|
||||
str += $"{(i % 8)}";
|
||||
int hash = mul.ForceComputeHash( str );
|
||||
Thread.Sleep( 20 );
|
||||
}
|
||||
|
||||
ViewModelBase mainModel = new ViewModelMain( vp );
|
||||
mainModel.CreateAndBindView<ViewMain>( "MainView", (1, 1, 1) );
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+148b0fed4a1abaaeaa3a28e7c7b088590805ebef")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ffd5825a051f04f4105ac5ed02e754176ce6f608")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
|
||||
[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/148b0fed4a1abaaeaa3a28e7c7b088590805ebef/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/ffd5825a051f04f4105ac5ed02e754176ce6f608/*"}}
|
||||
Reference in New Issue
Block a user