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:
Nitload
2025-03-25 16:47:02 +08:00
parent ffd5825a05
commit 469cb88472
29 changed files with 414 additions and 273 deletions
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")] [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [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.AssemblyProductAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [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 namespace StgSharp.Script.Express
{ {
public sealed class ExpBuiltinType : ExpTypeSource internal sealed class ExpBuiltinType : ExpTypeSource
{ {
private Type _marshalType; private Type _marshalType;
@@ -37,7 +37,7 @@ using System.Text;
namespace StgSharp.Script.Express namespace StgSharp.Script.Express
{ {
public abstract class ExpCollectionBase : ExpInstantiableElement, IEnumerable<ExpElementInstanceBase> public abstract class ExpCollectionBase : ExpInstantiableElement, IEnumerable<ExpElementInstance>
{ {
protected internal string _accurateType; protected internal string _accurateType;
@@ -49,10 +49,7 @@ namespace StgSharp.Script.Express
public override ExpElementType ElementType => ExpElementType.Collection; public override ExpElementType ElementType => ExpElementType.Collection;
public abstract int Count public abstract int Count { get; }
{
get;
}
public override sealed IScriptSourceProvider SourceProvider => ScriptSourceTransmitter.Empty; public override sealed IScriptSourceProvider SourceProvider => ScriptSourceTransmitter.Empty;
@@ -66,7 +63,7 @@ namespace StgSharp.Script.Express
return; return;
} }
public abstract IEnumerator<ExpElementInstanceBase> GetEnumerator(); public abstract IEnumerator<ExpElementInstance> GetEnumerator();
public override bool TryGetMember( string name, out ExpNode memberNode ) public override bool TryGetMember( string name, out ExpNode memberNode )
{ {
@@ -84,18 +81,17 @@ namespace StgSharp.Script.Express
public class ExpArray : ExpCollectionBase public class ExpArray : ExpCollectionBase
{ {
private ExpElementInstanceBase[] _collection; private ExpElementInstance[] _collection;
public ExpArray( string accurateType ) : base( accurateType ) { } public ExpArray( string accurateType ) : base( accurateType ) { }
public ExpElementInstanceBase this[ int index ] public ExpElementInstance this[ int index ]
{ {
get { return _collection[ index ]; } get { return _collection[ index ]; }
set set
{ {
if( value.TypeName != MemberType ) { if( value.TypeName != MemberType ) {
throw new ExpInvalidCollectionMemberTypeException( throw new ExpInvalidCollectionMemberTypeException( value, this );
value, this );
} }
_collection[ index ] = value; _collection[ index ] = value;
} }
@@ -110,9 +106,9 @@ namespace StgSharp.Script.Express
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override IEnumerator<ExpElementInstanceBase> GetEnumerator() public override IEnumerator<ExpElementInstance> GetEnumerator()
{ {
return ( ( IEnumerable<ExpElementInstanceBase> )_collection ) return ( ( IEnumerable<ExpElementInstance> )_collection )
.GetEnumerator(); .GetEnumerator();
} }
@@ -121,7 +117,7 @@ namespace StgSharp.Script.Express
public class ExpBag : ExpCollectionBase public class ExpBag : ExpCollectionBase
{ {
private ConcurrentBag<ExpElementInstanceBase> _collection = new ConcurrentBag<ExpElementInstanceBase>( private ConcurrentBag<ExpElementInstance> _collection = new ConcurrentBag<ExpElementInstance>(
); );
public ExpBag( string accurateType ) : base( accurateType ) { } public ExpBag( string accurateType ) : base( accurateType ) { }
@@ -135,7 +131,7 @@ namespace StgSharp.Script.Express
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override IEnumerator<ExpElementInstanceBase> GetEnumerator() public override IEnumerator<ExpElementInstance> GetEnumerator()
{ {
return _collection.GetEnumerator(); return _collection.GetEnumerator();
} }
@@ -145,8 +141,7 @@ namespace StgSharp.Script.Express
public sealed class ExpList : ExpCollectionBase 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 ) { } public ExpList( string accurateType ) : base( accurateType ) { }
@@ -159,7 +154,7 @@ namespace StgSharp.Script.Express
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override IEnumerator<ExpElementInstanceBase> GetEnumerator() public override IEnumerator<ExpElementInstance> GetEnumerator()
{ {
return _collection.GetEnumerator(); return _collection.GetEnumerator();
} }
@@ -169,7 +164,7 @@ namespace StgSharp.Script.Express
public class ExpSet : ExpCollectionBase public class ExpSet : ExpCollectionBase
{ {
private HashSet<ExpElementInstanceBase> _collection = new(); private HashSet<ExpElementInstance> _collection = new();
public ExpSet( string accurateType ) : base( accurateType ) { } public ExpSet( string accurateType ) : base( accurateType ) { }
@@ -177,11 +172,10 @@ namespace StgSharp.Script.Express
public override string Name => ExpressCompile.PoolString( "SET" ); public override string Name => ExpressCompile.PoolString( "SET" );
public void Add( ExpElementInstanceBase token ) public void Add( ExpElementInstance token )
{ {
if( token.TypeName != MemberType ) { if( token.TypeName != MemberType ) {
throw new ExpInvalidCollectionMemberTypeException( token, throw new ExpInvalidCollectionMemberTypeException( token, this );
this );
} }
_collection.Add( token ); _collection.Add( token );
} }
@@ -191,10 +185,9 @@ namespace StgSharp.Script.Express
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override sealed IEnumerator<ExpElementInstanceBase> GetEnumerator( public override sealed IEnumerator<ExpElementInstance> GetEnumerator()
)
{ {
return ( ( IEnumerable<ExpElementInstanceBase> )_collection ) return ( ( IEnumerable<ExpElementInstance> )_collection )
.GetEnumerator(); .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 partial class ExpressCompile
{ {
public static ExpTypeSource ExpInt public static ExpTypeSource ExpInt { get; private set; }
{
get;
private set;
}
public static ExpTypeSource ExpReal public static ExpTypeSource ExpReal { get; private set; }
{
get;
private set;
}
public static ExpTypeSource ExpBool public static ExpTypeSource ExpBool { get; private set; }
{
get; public static ExpTypeSource ExpString { get; private set; }
private set;
}
} }
} }
@@ -59,7 +59,7 @@ namespace StgSharp.Script.Express
return; 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 ); return ConstDict.TryGetValue( name, out c );
} }
@@ -118,11 +118,11 @@ namespace StgSharp.Script.Express
Multiplexer ).ToFrozenDictionary(); Multiplexer ).ToFrozenDictionary();
ConstDict = new Dictionary<string, ExpElementInstanceBase>( Multiplexer ) { ConstDict = new Dictionary<string, ExpElementInstance>( Multiplexer ) {
{ PoolString( "PI" ), new ExpRealNumberNode( { 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( { 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(); }.ToFrozenDictionary();
} }
@@ -47,7 +47,7 @@ namespace StgSharp.Script.Express
private static string[] _operatorsWithLetter; private static string[] _operatorsWithLetter;
private static ConcurrentStringHashMultiplexer _multiplexer; 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, ExpTypeSource> _builtinType;
private static FrozenDictionary<string, ExpBinaryOperatorNode> _operators; private static FrozenDictionary<string, ExpBinaryOperatorNode> _operators;
private static StringPool _compileStringCache,_emptyCache; private static StringPool _compileStringCache,_emptyCache;
@@ -112,6 +112,12 @@ namespace StgSharp.Script.Express
PoolString( Keyword.Boolean ), out ExpTypeSource? _expBool ); PoolString( Keyword.Boolean ), out ExpTypeSource? _expBool );
ExpBool = _expBool; ExpBool = _expBool;
ExpSchema_Builtin.Only
.TryGetType(
PoolString( Keyword.Boolean ), out ExpTypeSource? _expString );
ExpString = _expString;
_emptyCache = new StringPool(); _emptyCache = new StringPool();
/* /*
foreach( string str in _compileStringCache ) { foreach( string str in _compileStringCache ) {
+6 -7
View File
@@ -42,14 +42,13 @@ namespace StgSharp.Script.Express
public sealed class ExpConstantCollectionSource : ExpImmutableElement public sealed class ExpConstantCollectionSource : ExpImmutableElement
{ {
private Dictionary<string, ExpElementInstanceBase> _constants; private Dictionary<string, ExpElementInstance> _constants;
private IScriptSourceProvider _sourceProvider; private IScriptSourceProvider _sourceProvider;
public ExpConstantCollectionSource( IScriptSourceProvider sourceProvider ) public ExpConstantCollectionSource( IScriptSourceProvider sourceProvider )
{ {
_sourceProvider = sourceProvider; _sourceProvider = sourceProvider;
_constants = new Dictionary<string, ExpElementInstanceBase>( _constants = new Dictionary<string, ExpElementInstance>( ExpressCompile.Multiplexer );
ExpressCompile.Multiplexer );
} }
public override ExpElementType ElementType => ExpElementType.Const; public override ExpElementType ElementType => ExpElementType.Const;
@@ -74,20 +73,20 @@ namespace StgSharp.Script.Express
if( _constants.Count == 0 ) { if( _constants.Count == 0 ) {
return null!; return null!;
} }
if( _constants.TryGetValue( str, out ExpElementInstanceBase? token ) ) { if( _constants.TryGetValue( str, out ExpElementInstance? token ) ) {
return token; return token;
} }
return null!; return null!;
} }
public bool TryGetConstant( string name, out ExpElementInstanceBase instance ) public bool TryGetConstant( string name, out ExpElementInstance instance )
{ {
return _constants.TryGetValue( name, out instance ); return _constants.TryGetValue( name, out instance );
} }
public override bool TryGetMember( string name, out ExpNode memberNode ) 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; memberNode = node;
return true; return true;
@@ -96,7 +95,7 @@ namespace StgSharp.Script.Express
return false; return false;
} }
internal void AddConstant( string name, ExpElementInstanceBase value ) internal void AddConstant( string name, ExpElementInstance value )
{ {
_constants.Add( name, value ); _constants.Add( name, value );
} }
+10 -22
View File
@@ -40,25 +40,17 @@ namespace StgSharp.Script.Express
private ScriptSourceTransmitter _transmitter; private ScriptSourceTransmitter _transmitter;
private string _name; private string _name;
public ExpFunctionSource( public ExpFunctionSource( string name, ScriptSourceTransmitter transmitter )
string name,
ScriptSourceTransmitter transmitter )
{ {
_name = name; _name = name;
_transmitter = transmitter; _transmitter = transmitter;
} }
public Dictionary<string, ExpElementInstanceBase> FuncParams public Dictionary<string, ExpElementInstance> FuncParams { get; init; } = new Dictionary<string, ExpElementInstance>(
{ );
get;
init;
} = new Dictionary<string, ExpElementInstanceBase>();
public Dictionary<string, ExpElementInstanceBase> LocalVariables public Dictionary<string, ExpElementInstance> LocalVariables { get; init; } = new Dictionary<string, ExpElementInstance>(
{ );
get;
init;
} = new Dictionary<string, ExpElementInstanceBase>();
public override ExpElementType ElementType => ExpElementType.Function; public override ExpElementType ElementType => ExpElementType.Function;
@@ -66,11 +58,7 @@ namespace StgSharp.Script.Express
public override string Name => _name; public override string Name => _name;
public string CallingFormat public string CallingFormat { get; private set; }
{
get;
private set;
}
public override void Analyse() public override void Analyse()
{ {
@@ -89,13 +77,13 @@ namespace StgSharp.Script.Express
public override bool TryGetMember( string name, out ExpNode memberNode ) public override bool TryGetMember( string name, out ExpNode memberNode )
{ {
if( FuncParams.TryGetValue( if( FuncParams.TryGetValue( name, out ExpElementInstance? param ) )
name, out ExpElementInstanceBase? param ) ) { {
memberNode = param; memberNode = param;
return true; return true;
} }
if( LocalVariables.TryGetValue( if( LocalVariables.TryGetValue( name, out ExpElementInstance? variable ) )
name, out ExpElementInstanceBase? variable ) ) { {
memberNode = variable; memberNode = variable;
return true; return true;
} }
+1 -1
View File
@@ -36,7 +36,7 @@ using System.Text;
namespace StgSharp.Script.Express namespace StgSharp.Script.Express
{ {
public class ExpRule : ExpElementInstanceBase public class ExpRule : ExpElementInstance
{ {
private ExpRuleSource _source; private ExpRuleSource _source;
+2 -3
View File
@@ -77,7 +77,7 @@ namespace StgSharp.Script.Express
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override ExpElementInstanceBase CreateInstanceNode() public override ExpElementInstance CreateInstanceNode()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@@ -96,8 +96,7 @@ namespace StgSharp.Script.Express
private class ExpVoidType : ExpTypeSource private class ExpVoidType : ExpTypeSource
{ {
private static readonly ExpVoidType _onlyInstance = new ExpVoidType( private static readonly ExpVoidType _onlyInstance = new ExpVoidType();
);
private ExpVoidType() : base( string.Empty ) { } private ExpVoidType() : base( string.Empty ) { }
@@ -41,20 +41,19 @@ namespace StgSharp.Script.Express
public class ExpInstanceMemberNode : ExpNode public class ExpInstanceMemberNode : ExpNode
{ {
private ExpElementInstanceBase _instance; private ExpElementInstance _instance;
private ExpElementMemberNameNode _memberName; private ExpElementMemberNameNode _memberName;
private ExpNode _member; private ExpNode _member;
public ExpInstanceMemberNode( public ExpInstanceMemberNode(
Token source, Token source,
ExpElementInstanceBase instance, ExpElementInstance instance,
ExpElementMemberNameNode memberName ) ExpElementMemberNameNode memberName )
: base( source ) : base( source )
{ {
_instance = instance; _instance = instance;
_memberName = memberName; _memberName = memberName;
_instance.TryGetMember( _instance.TryGetMember( memberName.CodeConvertTemplate, out _member );
memberName.CodeConvertTemplate, out _member );
} }
public override ExpNode Left => _instance; public override ExpNode Left => _instance;
@@ -40,13 +40,14 @@ namespace StgSharp.Script.Express
public class ExpInstanceReferenceNode : ExpNode public class ExpInstanceReferenceNode : ExpNode
{ {
private ExpElementInstanceBase _instance; private ExpElementInstance _instance;
internal ExpInstanceReferenceNode( Token source, ExpElementInstanceBase instance ) internal ExpInstanceReferenceNode( Token source, ExpElementInstance instance )
: base( source ) : base( source )
{ {
_instance = instance; _instance = instance;
_nodeFlag = ( _instance._nodeFlag | ( ExpNodeFlag.Name_Any | ExpNodeFlag.Collection_Any ) ); _nodeFlag = ( _instance._nodeFlag | ( ExpNodeFlag.Name_Any | ExpNodeFlag.Collection_Any ) );
CodeConvertTemplate = source.Value;
} }
internal ExpInstanceReferenceNode( Token source, ExpInstanceReferenceNode reference ) internal ExpInstanceReferenceNode( Token source, ExpInstanceReferenceNode reference )
@@ -64,11 +65,15 @@ namespace StgSharp.Script.Express
public override IExpElementSource EqualityTypeConvert => _instance.EqualityTypeConvert; public override IExpElementSource EqualityTypeConvert => _instance.EqualityTypeConvert;
[MethodImpl( MethodImplOptions.AggressiveInlining )] [MethodImpl( MethodImplOptions.AggressiveInlining )]
public static ExpInstanceReferenceNode Create( public static ExpInstanceReferenceNode MakeReferenceFrom(
Token source, Token source,
ExpElementInstanceBase instance ) ExpElementInstance instance )
{ {
/* /**/
if( instance.IsLiteral )
{
throw new ExpCompileException( source, "Cannot make reference to a literal." );
}
if( instance.CodeConvertTemplate != source.Value ) { if( instance.CodeConvertTemplate != source.Value ) {
throw new ExpCompileException( source, "Token point at a wrong instance" ); throw new ExpCompileException( source, "Token point at a wrong instance" );
} }
@@ -34,26 +34,28 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
namespace StgSharp.Script.Express namespace StgSharp.Script.Express
{ {
public class ExpIntNode : ExpElementInstanceBase public class ExpIntNode : ExpElementInstance
{ {
private int _value; private int _value;
public ExpIntNode( Token source, int value ) public ExpIntNode( Token source, int value, bool isLiteral )
: base( source ) : base( source )
{ {
this.IsLiteral = isLiteral;
_value = value; _value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Type; _nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Type;
CodeConvertTemplate = IsLiteral ? value.ToString() : source.Value;
} }
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema public override IExpElementSource EqualityTypeConvert
.TryGetType( {
ExpressCompile.Keyword.Integer, get => ExpressCompile.ExpInt;
out ExpTypeSource? type ) ? }
type : throw new ExpCompileNotInitializedException();
public int Value => _value; public int Value => _value;
@@ -61,23 +63,24 @@ namespace StgSharp.Script.Express
} }
public class ExpStringNode : ExpElementInstanceBase public class ExpStringNode : ExpElementInstance
{ {
private readonly string _value; private readonly string _value;
public ExpStringNode( Token source, string value ) public ExpStringNode( Token source, string value, bool isLiteral )
: base( source ) : base( source )
{ {
this.IsLiteral = IsLiteral;
_value = value; _value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_String | ExpNodeFlag.Element_Type; _nodeFlag = ExpNodeFlag.BuiltinType_String | ExpNodeFlag.Element_Type;
CodeConvertTemplate = IsLiteral ? $"\"{value}\"" : source.Value;
} }
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema public override IExpElementSource EqualityTypeConvert
.TryGetType( {
ExpressCompile.Keyword.String, get => ExpressCompile.ExpString;
out ExpTypeSource? type ) ? }
type : throw new ExpCompileNotInitializedException();
public override string TypeName => EqualityTypeConvert.Name; 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; private readonly bool _value;
public ExpBoolNode( Token source, bool value ) public ExpBoolNode( Token source, bool value, bool isLiteral )
: base( source ) : base( source )
{ {
this.IsLiteral = isLiteral;
_value = value; _value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Element_Type; _nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Element_Type;
CodeConvertTemplate = IsLiteral ? value.ToString() : source.Value;
} }
public bool Value => _value; public bool Value => _value;
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema public override IExpElementSource EqualityTypeConvert
.TryGetType( {
ExpressCompile.Keyword.Boolean, get => ExpSchema.BuiltinSchema
out ExpTypeSource? type ) ? .TryGetType( ExpressCompile.Keyword.Boolean, out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException(); type : throw new ExpCompileNotInitializedException();
}
public override string TypeName => EqualityTypeConvert.Name; public override string TypeName => EqualityTypeConvert.Name;
} }
public class ExpRealNumberNode : ExpElementInstanceBase public class ExpRealNumberNode : ExpElementInstance
{ {
private readonly float _value; private readonly float _value;
public ExpRealNumberNode( Token source, float value ) public ExpRealNumberNode( Token source, float value, bool isLiteral )
: base( source ) : base( source )
{ {
_value = value; _value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Real | ExpNodeFlag.Element_Type; _nodeFlag = ExpNodeFlag.BuiltinType_Real | ExpNodeFlag.Element_Type;
CodeConvertTemplate = isLiteral ? $"{value:F8}f" : source.Value;
} }
public float Value => _value; public float Value => _value;
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema public override IExpElementSource EqualityTypeConvert
.TryGetType( {
ExpressCompile.Keyword.String, get => ExpSchema.BuiltinSchema
out ExpTypeSource? type ) ? .TryGetType( ExpressCompile.Keyword.String, out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException(); type : throw new ExpCompileNotInitializedException();
}
public override string TypeName => EqualityTypeConvert.Name; public override string TypeName => EqualityTypeConvert.Name;
} }
public class ExpLogicValueNode : ExpElementInstanceBase public class ExpLogicValueNode : ExpElementInstance
{ {
private readonly ExpLogic _value; private readonly ExpLogic _value;
public ExpLogicValueNode( Token source, ExpLogic value ) public ExpLogicValueNode( Token source, ExpLogic value, bool isLiteral )
: base( source ) : base( source )
{ {
this.IsLiteral = isLiteral;
_value = value; _value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.Element_Type; _nodeFlag = ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.Element_Type;
CodeConvertTemplate = isLiteral ? value.ToString() : source.Value;
} }
public ExpLogic Value => _value; public ExpLogic Value => _value;
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema public override IExpElementSource EqualityTypeConvert
.TryGetType( {
ExpressCompile.Keyword.Logical, get => ExpSchema.BuiltinSchema
out ExpTypeSource? type ) ? .TryGetType( ExpressCompile.Keyword.Logical, out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException(); type : throw new ExpCompileNotInitializedException();
}
public override string TypeName => EqualityTypeConvert.Name; 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. //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; private ExpNode _operationBegin;
public ExpRepeatNode( public ExpRepeatNode(
Token source, Token source,
ExpNode operationBegin, ExpNode operationBegin,
ExpElementInstanceBase variable, ExpElementInstance variable,
ExpElementInstanceBase begin, ExpElementInstance begin,
ExpElementInstanceBase end, ExpElementInstance end,
ExpElementInstanceBase increment ) ExpElementInstance increment )
: base( source ) : base( source )
{ {
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag != if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag != end.NodeFlag || ( increment !=
end.NodeFlag || ( increment != null && end.NodeFlag != null && end.NodeFlag !=
increment.NodeFlag ) ) { increment.NodeFlag ) ) {
throw new InvalidCastException(); throw new InvalidCastException();
} }
if( increment == null ) { if( increment == null )
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any ) { {
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any )
{
case ExpNodeFlag.BuiltinType_Real: case ExpNodeFlag.BuiltinType_Real:
increment = new ExpRealNumberNode( increment = new ExpRealNumberNode(
new Token( new Token(
ExpressCompile.PoolString( "1.0f" ), source.Line, ExpressCompile.PoolString( "1.0f" ), source.Line, -1,
-1, TokenFlag.Number ), TokenFlag.Number ),
1.0f ); 1.0f, isLiteral: true );
break; break;
case ExpNodeFlag.BuiltinType_Int: case ExpNodeFlag.BuiltinType_Int:
increment = new ExpIntNode( increment = new ExpIntNode(
new Token( new Token(
ExpressCompile.PoolString( "1" ), source.Line, -1, ExpressCompile.PoolString( "1" ), source.Line, -1,
TokenFlag.Number ), TokenFlag.Number ),
1 ); 1, isLiteral: true );
break; break;
default: default:
throw new ExpInvalidTypeException( throw new ExpInvalidTypeException( "Int or Real", "otherwise" );
"Int or Real", "otherwise" );
} }
} }
_begin = begin; _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 );
}
}
}
+14 -23
View File
@@ -42,19 +42,18 @@ namespace StgSharp.Script.Express
public class ExpInvalidCharException : Exception public class ExpInvalidCharException : Exception
{ {
public ExpInvalidCharException( char c ) public ExpInvalidCharException( char c ) : base( $"An unknown char {c} occurred." ) { }
: base( $"An unknown char {c} occurred." ) { }
public ExpInvalidCharException( int index )
: base( $"Cannot read a token from line at {index}" ) { }
} }
/// <summary> public class ExpStringNotCloseException : Exception
/// Exception when cannot reading a token from a line.
/// </summary>
public class ExpInvalidTokenException : Exception
{ {
public ExpInvalidTokenException( int index ) public ExpStringNotCloseException( int linenum )
: base( $"Cannot read a token from line at {index}" ) { } : base( $"A string does not closed at end of line {linenum}." ) { }
} }
@@ -80,9 +79,7 @@ namespace StgSharp.Script.Express
public class ExpInvalidElementDeclareEndingExceptions : Exception public class ExpInvalidElementDeclareEndingExceptions : Exception
{ {
public ExpInvalidElementDeclareEndingExceptions( public ExpInvalidElementDeclareEndingExceptions( string declaredName, string endedName )
string declaredName,
string endedName )
: base( : base(
$"The datatype is declared with name {declaredName} but ended with {endedName}" ) { } $"The datatype is declared with name {declaredName} but ended with {endedName}" ) { }
@@ -91,11 +88,8 @@ namespace StgSharp.Script.Express
public class ExpInvalidElementNameException : Exception public class ExpInvalidElementNameException : Exception
{ {
public ExpInvalidElementNameException( public ExpInvalidElementNameException( string elementName, ExpSchema schema )
string elementName, : base( $"Cannot find any element named {elementName} in {schema.Name}" ) { }
ExpSchema schema )
: base(
$"Cannot find any element named {elementName} in {schema.Name}" ) { }
} }
@@ -121,7 +115,7 @@ namespace StgSharp.Script.Express
{ {
public ExpInvalidCollectionMemberTypeException( public ExpInvalidCollectionMemberTypeException(
ExpElementInstanceBase elementInstance, ExpElementInstance elementInstance,
ExpCollectionBase collection ) ExpCollectionBase collection )
: base( : base(
$"Attempt to add or remove an element of type: {elementInstance.ElementType} from a collection collects {collection.MemberType}" ) { } $"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 class ExpInvalidSchemaIncludeException : InvalidOperationException
{ {
public ExpInvalidSchemaIncludeException( public ExpInvalidSchemaIncludeException( ExpSchema context, ExpSchema source )
ExpSchema context,
ExpSchema source )
: base( : 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." ) { } $"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() public ExpCompileNotInitializedException()
: base( : base( "Attempt to compile an EXPRESS script before the init of compiler." ) { }
"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 ) public ExpCompileException( Token pos, string message )
: base( : 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.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Schema;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword; using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
@@ -114,12 +115,26 @@ namespace StgSharp.Script.Express
if( t.Flag != TokenFlag.Separator_Middle ) { if( t.Flag != TokenFlag.Separator_Middle ) {
return false; return false;
} }
processOperator:
if( _cache.OperatorAheadOfDepth == 0 ) if( _cache.OperatorAheadOfDepth == 0 )
{ {
if( _cache.OperandAheadOfDepth == 1 ) 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.PushOperand( t );
_cache.PushOperator( t ); _cache.PushOperator( t );
_cache.IncreaseDepth( ( int )ExpCompileStateCode.Common );
return true; return true;
} else } else
{ {
@@ -127,7 +142,6 @@ namespace StgSharp.Script.Express
} }
} }
Token op; Token op;
processOperator:
if( _cache.TryPopOperator( out op ) ) if( _cache.TryPopOperator( out op ) )
{ {
if( op.Value == t.Value ) if( op.Value == t.Value )
@@ -151,7 +165,7 @@ namespace StgSharp.Script.Express
if( ( t.Flag & ( TokenFlag.String | TokenFlag.Number ) ) == 0 ) { if( ( t.Flag & ( TokenFlag.String | TokenFlag.Number ) ) == 0 ) {
return false; return false;
} }
_cache.PushOperand( ExpElementInstanceBase.CreateLiteral( t ) ); _cache.PushOperand( ExpElementInstance.CreateLiteral( t ) );
return true; return true;
} }
@@ -189,7 +203,6 @@ namespace StgSharp.Script.Express
{ {
_cache.PopOperator(); _cache.PopOperator();
ExpNode node = ConvertAndPushOneOperator( tmp ); ExpNode node = ConvertAndPushOneOperator( tmp );
_cache.PushOperand( node );
goto processPrecedence; goto processPrecedence;
} }
} }
@@ -199,17 +212,23 @@ namespace StgSharp.Script.Express
private bool TryParseConstant( Token t ) private bool TryParseConstant( Token t )
{ {
if( t.Value == ExpKeyword.True ) switch( t.Value )
{ {
_cache.PushOperand( new ExpBoolNode( t, true ) ); case ExpKeyword.E:
_cache.PushOperand( new ExpRealNumberNode( t, MathF.E, true ) );
return true; return true;
} else if( t.Value == ExpKeyword.False ) case ExpKeyword.Pi:
_cache.PushOperand( new ExpRealNumberNode( t, MathF.PI, true ) );
return true;
default:
if( ExpElementInstance.TryCreateLiteral( t, out ExpElementInstance? node ) )
{ {
_cache.PushOperand( new ExpBoolNode( t, false ) ); _cache.PushOperand( node );
return true; return true;
} }
return false; return false;
} }
}
private bool TryParseFunction( Token t ) private bool TryParseFunction( Token t )
{ {
@@ -228,9 +247,9 @@ namespace StgSharp.Script.Express
private bool TryParseInstance( Token t ) private bool TryParseInstance( Token t )
{ {
if( _local.TryGetMember( t.Value, 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 true;
} }
return false; return false;
@@ -108,6 +108,10 @@ namespace StgSharp.Script.Express
case TokenFlag.Index_Right: case TokenFlag.Index_Right:
TryAppendIndexRight( expToken ); TryAppendIndexRight( expToken );
break; break;
case TokenFlag.Number or TokenFlag.String:
ExpElementInstance node = ExpElementInstance.CreateLiteral( expToken );
_cache.PushOperand( node );
break;
default: default:
break; break;
} }
+10 -44
View File
@@ -46,72 +46,38 @@ namespace StgSharp.Script.Express
get => ExpSchema_Builtin.Only; get => ExpSchema_Builtin.Only;
} }
public string Name public string Name { get; internal set; }
{
get;
internal set;
}
public abstract void LoadFromSource( ExpSchemaSource source ); public abstract void LoadFromSource( ExpSchemaSource source );
public abstract bool TryGetConst( public abstract bool TryGetConst( string name, out ExpElementInstance c );
string name,
out ExpElementInstanceBase c );
public abstract bool TryGetEntity( string name, out ExpEntitySource e ); public abstract bool TryGetEntity( string name, out ExpEntitySource e );
public abstract bool TryGetFunction( public abstract bool TryGetFunction( string name, out ExpFunctionSource f );
string name,
out ExpFunctionSource f );
public abstract bool TryGetRule( string name, out ExpRuleSource r ); public abstract bool TryGetRule( string name, out ExpRuleSource r );
public abstract bool TryGetSchemaInclude( public abstract bool TryGetSchemaInclude( string name, out ExpSchema include );
string name,
out ExpSchema include );
public abstract bool TryGetType( string name, out ExpTypeSource t ); public abstract bool TryGetType( string name, out ExpTypeSource t );
#pragma warning disable CS8618 #pragma warning disable CS8618
protected FrozenDictionary<string, ExpElementInstanceBase> ConstDict protected FrozenDictionary<string, ExpElementInstance> ConstDict { get; set; }
{
get;
set;
}
public IEnumerable<ExpSchema> IncludedSchema => IncludedSchema; public IEnumerable<ExpSchema> IncludedSchema => IncludedSchema;
protected FrozenDictionary<string, ExpEntitySource> EntityDict protected FrozenDictionary<string, ExpEntitySource> EntityDict { get; set; }
{
get;
set;
}
protected FrozenDictionary<string, ExpFunctionSource> FunctionDict protected FrozenDictionary<string, ExpFunctionSource> FunctionDict { get; set; }
{
get;
set;
}
protected ConcurrentStringHashMultiplexer StringMultiplexer => ExpressCompile.Multiplexer; protected ConcurrentStringHashMultiplexer StringMultiplexer => ExpressCompile.Multiplexer;
protected FrozenDictionary<string, ExpRuleSource> RuleDict protected FrozenDictionary<string, ExpRuleSource> RuleDict { get; set; }
{
get;
set;
}
protected FrozenDictionary<string, ExpSchema> SchemaInclude protected FrozenDictionary<string, ExpSchema> SchemaInclude { get; set; }
{
get;
set;
}
protected FrozenDictionary<string, ExpTypeSource> TypeDict protected FrozenDictionary<string, ExpTypeSource> TypeDict { get; set; }
{
get;
set;
}
#pragma warning restore CS8618 #pragma warning restore CS8618
} }
} }
+20 -9
View File
@@ -53,6 +53,7 @@ namespace StgSharp.Script.Express
private Regex _nextWordTokenPattern = GetNextWordTokenPattern(), private Regex _nextWordTokenPattern = GetNextWordTokenPattern(),
_nextStringLiteralPattern = GetStringLiteralPattern(), _nextStringLiteralPattern = GetStringLiteralPattern(),
_nextNumberLiteralPattern = GetNumberLiteralPattern(), _nextNumberLiteralPattern = GetNumberLiteralPattern(),
_nextStringLiteralPatternWithSingle = GetStringLiteralPatternWithSingle(),
_skipBlankPattern = GetSkipBlankPattern(); _skipBlankPattern = GetSkipBlankPattern();
private string _lineCache; private string _lineCache;
private Token _last; private Token _last;
@@ -76,10 +77,10 @@ namespace StgSharp.Script.Express
} }
/// <summary> /// <summary>
/// <para> Read code until end of a line. Lines in multi-line comment will be ignored. /// <para>Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// Line begins with part of multi-line comment will automatically remove the comment /// begins with part of multi-line comment will automatically remove the comment part,
/// part, but beginning with a full multi-line comment will not causing removing. </para> /// but beginning with a full multi-line comment will not causing removing.</para> <para>
/// <para> (*Just Like The Comment Here*) Will Not Be Removed</para> /// (*Just Like The Comment Here*) Will Not Be Removed </para>
/// </summary> /// </summary>
/// <returns> /// <returns>
/// ///
@@ -130,6 +131,9 @@ namespace StgSharp.Script.Express
Match match = _nextWordTokenPattern.Match( _lineCache, _current ); Match match = _nextWordTokenPattern.Match( _lineCache, _current );
if( match.Success ) if( match.Success )
{ {
if( match.Groups[ EndMark ].Index >= _lineCache.Length ) {
throw new ExpStringNotCloseException( _lineNum );
}
begin = match.Groups[ TokenMark ].Index; begin = match.Groups[ TokenMark ].Index;
end = match.Groups[ EndMark ].Index; end = match.Groups[ EndMark ].Index;
rest = match.Groups[ RestMark ].Index; rest = match.Groups[ RestMark ].Index;
@@ -140,12 +144,14 @@ namespace StgSharp.Script.Express
return _last; return _last;
} else } else
{ {
throw new ExpInvalidTokenException( _current ); throw new ExpInvalidCharException( _current );
} }
} else if( char.IsPunctuation( c ) || char.IsSymbol( c ) ) } else if( char.IsPunctuation( c ) || char.IsSymbol( c ) )
{ {
switch( c ) switch( c )
{ {
case '\'':
case '"': case '"':
char cNext = source[ 1 ]; char cNext = source[ 1 ];
if( cNext == '\"' ) //empty string if( cNext == '\"' ) //empty string
@@ -213,7 +219,7 @@ namespace StgSharp.Script.Express
_lineNum, begin, TokenFlag.Number ); _lineNum, begin, TokenFlag.Number );
} else } else
{ {
throw new ExpInvalidTokenException( _current ); throw new ExpInvalidCharException( _current );
} }
} else if( cNext == '-' ) } else if( cNext == '-' )
{ {
@@ -297,7 +303,7 @@ namespace StgSharp.Script.Express
return new( str, _lineNum, begin, TokenFlag.Number ); return new( str, _lineNum, begin, TokenFlag.Number );
} else } else
{ {
throw new ExpInvalidTokenException( _current ); throw new ExpInvalidCharException( _current );
} }
} else if( char.IsWhiteSpace( c ) ) } else if( char.IsWhiteSpace( c ) )
{ {
@@ -309,7 +315,7 @@ namespace StgSharp.Script.Express
goto readLine; goto readLine;
} else } else
{ {
throw new ExpInvalidTokenException( _current ); throw new ExpInvalidCharException( _current );
} }
} else } else
{ {
@@ -342,9 +348,14 @@ namespace StgSharp.Script.Express
private static partial Regex GetSkipBlankPattern(); private static partial Regex GetSkipBlankPattern();
[GeneratedRegex( [GeneratedRegex(
@"(?<token>"")(?:.*?[^\\](?:\\\\)*?)(?<end>"")\s*?(?<rest>\S|$)", @"(?<token>"")(?>\\\\|\\""|(?!')[^""])*(?<end>""|$)\s*?(?<rest>\S|$)",
RegexOptions.Singleline )] RegexOptions.Singleline )]
private static partial Regex GetStringLiteralPattern(); private static partial Regex GetStringLiteralPattern();
[GeneratedRegex(
@"(?<token>')(?>\\\\|\\'|''|(?!')[^'])*(?<end>')\s*?(?<rest>\S|$)",
RegexOptions.Singleline )]
private static partial Regex GetStringLiteralPatternWithSingle();
} }
} }
+6 -13
View File
@@ -57,7 +57,8 @@ namespace StgSharp.Script.Express
if( TypeDict.TryGetValue( typeName, out ret ) ) { if( TypeDict.TryGetValue( typeName, out ret ) ) {
return ret; return ret;
} }
foreach( GeneratedExpSchema item in SchemaInclude.Values ) { foreach( GeneratedExpSchema item in SchemaInclude.Values )
{
if( item.TypeDict.TryGetValue( typeName, out ret ) ) { if( item.TypeDict.TryGetValue( typeName, out ret ) ) {
return ret; return ret;
} }
@@ -75,9 +76,7 @@ namespace StgSharp.Script.Express
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override bool TryGetConst( public override bool TryGetConst( string name, out ExpElementInstance c )
string name,
out ExpElementInstanceBase c )
{ {
return ConstDict.TryGetValue( name, out c ); return ConstDict.TryGetValue( name, out c );
} }
@@ -87,9 +86,7 @@ namespace StgSharp.Script.Express
return EntityDict.TryGetValue( name, out e ); return EntityDict.TryGetValue( name, out e );
} }
public override bool TryGetFunction( public override bool TryGetFunction( string name, out ExpFunctionSource f )
string name,
out ExpFunctionSource f )
{ {
return FunctionDict.TryGetValue( name, out f ); return FunctionDict.TryGetValue( name, out f );
} }
@@ -99,16 +96,12 @@ namespace StgSharp.Script.Express
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override bool TryGetSchemaInclude( public override bool TryGetSchemaInclude( string name, out ExpSchema include )
string name,
out ExpSchema include )
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override bool TryGetType( public override bool TryGetType( string name, out ExpTypeSource element )
string name,
out ExpTypeSource element )
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")] [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [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.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [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/*"}}
+9 -11
View File
@@ -47,17 +47,13 @@ namespace StgSharp
: base( name, source ) : base( name, source )
{ {
LocalVariables.Add( LocalVariables.Add(
"a", "a", new ExpIntNode( new Token( "a", 0, 0, TokenFlag.Number ), 1, false ) );
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
LocalVariables.Add( LocalVariables.Add(
"b", "b", new ExpIntNode( new Token( "b", 0, 0, TokenFlag.Number ), 1, false ) );
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
LocalVariables.Add( LocalVariables.Add(
"c", "c", new ExpIntNode( new Token( "c", 0, 0, TokenFlag.Number ), 1, false ) );
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
LocalVariables.Add( LocalVariables.Add(
"d", "d", new ExpIntNode( new Token( "d", 0, 0, TokenFlag.Number ), 1, false ) );
ExpElementInstanceBase.CreateLiteral( new Token( "1", 0, 0, TokenFlag.Number ) ) );
} }
} }
@@ -77,7 +73,7 @@ namespace StgSharp
return; return;
} }
public override bool TryGetConst( string name, out ExpElementInstanceBase c ) public override bool TryGetConst( string name, out ExpElementInstance c )
{ {
c = null; c = null;
return false; return false;
@@ -127,9 +123,11 @@ namespace StgSharp
{ {
ExpressCompile.InitCompile(); ExpressCompile.InitCompile();
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter( "END", 0 ); 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(); transmitter.EndWriting();
ExpSourceReader reader = new ExpSourceReader( transmitter ); ExpSourceReader reader = new ExpSourceReader( transmitter );
/**/ /**/
+1 -11
View File
@@ -48,20 +48,10 @@ namespace StgSharp
StgSharp.InitGL( 4, 6 ); StgSharp.InitGL( 4, 6 );
StgSharp.GlobalSetting.VSyncActivated = false; StgSharp.GlobalSetting.VSyncActivated = false;
ViewPort vp = new ViewPort( ViewPort vp = new ViewPort( 800, 600, "Hello StgSharp!", IntPtr.Zero );
800, 600, "Hello StgSharp!", IntPtr.Zero );
//throw new NotImplementedException(); //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 ); ViewModelBase mainModel = new ViewModelMain( vp );
mainModel.CreateAndBindView<ViewMain>( "MainView", (1, 1, 1) ); mainModel.CreateAndBindView<ViewMain>( "MainView", (1, 1, 1) );
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")] [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [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.AssemblyProductAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [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/*"}}