daily update on 20240202 by nitload youmu, keep on writing xpree[D[D[D[D[De[C[C[Css compiler
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="BuiltinType.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public sealed class ExpBuiltinType : ExpTypeSource
|
||||
{
|
||||
|
||||
private Type _marshalType;
|
||||
|
||||
internal ExpBuiltinType( string name, Type origin )
|
||||
: base( name, null! )
|
||||
{
|
||||
_marshalType = origin;
|
||||
}
|
||||
|
||||
public override void Analyse()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpCollection.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public abstract class ExpCollectionBase : IExpElementSource, IEnumerable<ExpElementInstanceBase>
|
||||
{
|
||||
protected internal string _accurateType;
|
||||
|
||||
protected ExpCollectionBase(
|
||||
string accurateType )
|
||||
{
|
||||
_accurateType = accurateType;
|
||||
}
|
||||
|
||||
public string MemberType
|
||||
{
|
||||
get => _accurateType;
|
||||
}
|
||||
|
||||
public abstract int Count { get; }
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Collection;
|
||||
|
||||
IScriptSourceProvider IExpElementSource.SourceProvider => null!;
|
||||
|
||||
public abstract string Name { get; }
|
||||
|
||||
public void Analyse()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public abstract IEnumerator<ExpElementInstanceBase> GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpArray : ExpCollectionBase
|
||||
{
|
||||
|
||||
private ExpElementInstanceBase[] _collection;
|
||||
|
||||
public ExpArray( string accurateType )
|
||||
: base( accurateType ) { }
|
||||
|
||||
public ExpElementInstanceBase this[ int index ]
|
||||
{
|
||||
get { return _collection[ index ]; }
|
||||
set
|
||||
{
|
||||
if( value.TypeName != MemberType ) {
|
||||
throw new ExpInvalidCollectionMemberTypeException(
|
||||
value, this );
|
||||
}
|
||||
_collection[ index ] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override int Count => _collection.Length;
|
||||
|
||||
public override string Name => ExpCompile.AddOrGetString("ARRAY");
|
||||
|
||||
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
|
||||
{
|
||||
return ( ( IEnumerable<ExpElementInstanceBase> )_collection )
|
||||
.GetEnumerator( );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpBag : ExpCollectionBase
|
||||
{
|
||||
|
||||
private ConcurrentBag<ExpElementInstanceBase> _collection = new ConcurrentBag<ExpElementInstanceBase>(
|
||||
);
|
||||
|
||||
public ExpBag( string accurateType )
|
||||
: base( accurateType ) { }
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override string Name => ExpCompile.AddOrGetString("BAG");
|
||||
|
||||
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
|
||||
{
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
public sealed class ExpList : ExpCollectionBase
|
||||
{
|
||||
public ExpList(string accurateType ):base(accurateType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private List<ExpElementInstanceBase> _collection = new List<ExpElementInstanceBase>();
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override string Name => ExpCompile.AddOrGetString("LIST");
|
||||
|
||||
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
|
||||
{
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
public class ExpSet : ExpCollectionBase
|
||||
{
|
||||
|
||||
private HashSet<ExpElementInstanceBase> _collection = new();
|
||||
|
||||
public ExpSet( string accurateType )
|
||||
: base( accurateType ) { }
|
||||
|
||||
public void Add( ExpElementInstanceBase token )
|
||||
{
|
||||
if( token.TypeName != MemberType ) {
|
||||
throw new ExpInvalidCollectionMemberTypeException( token,
|
||||
this );
|
||||
}
|
||||
_collection.Add( token );
|
||||
}
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override string Name => ExpCompile.AddOrGetString("SET");
|
||||
|
||||
public override sealed IEnumerator<ExpElementInstanceBase> GetEnumerator()
|
||||
{
|
||||
return ( ( IEnumerable<ExpElementInstanceBase> )_collection )
|
||||
.GetEnumerator( );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpCollectionInstance.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public abstract class ExpCollectionInstanceBase : ExpToken
|
||||
{
|
||||
|
||||
protected internal (int min, int max) _range;
|
||||
protected internal ExpElementType _memberType;
|
||||
|
||||
protected ExpCollectionInstanceBase( string name, ExpSchema context )
|
||||
: base( name, context ) { }
|
||||
|
||||
public abstract ExpCollectionBase CollectionValue
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public ExpElementType MemberType
|
||||
{
|
||||
get => _memberType;
|
||||
}
|
||||
|
||||
public int MinCapacity => _range.min;
|
||||
|
||||
public int MaxCapacity => _range.max;
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpSetInstance : ExpCollectionInstanceBase
|
||||
{
|
||||
|
||||
private ExpSet _collection;
|
||||
|
||||
public ExpSetInstance( string name, ExpSet set, ExpSchema context )
|
||||
: base( name, context )
|
||||
{
|
||||
_collection = set;
|
||||
}
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpBagInstance : ExpCollectionInstanceBase
|
||||
{
|
||||
|
||||
private ExpBag _collection;
|
||||
|
||||
public ExpBagInstance( string name, ExpBag bag, ExpSchema context )
|
||||
: base( name, context )
|
||||
{
|
||||
_collection = bag;
|
||||
}
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpListInstance : ExpCollectionInstanceBase
|
||||
{
|
||||
|
||||
private ExpList _collection;
|
||||
|
||||
public ExpListInstance( string name, ExpList list, ExpSchema context )
|
||||
: base( name, context )
|
||||
{
|
||||
_collection = list;
|
||||
}
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpArrayInstance : ExpCollectionInstanceBase
|
||||
{
|
||||
|
||||
private ExpArray _collection;
|
||||
|
||||
public ExpArrayInstance(
|
||||
string name,
|
||||
ExpArray array,
|
||||
ExpSchema context )
|
||||
: base( name, context )
|
||||
{
|
||||
_collection = array;
|
||||
}
|
||||
|
||||
public override ExpCollectionBase CollectionValue => _collection;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using StgSharp.Script.Express;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public sealed class ExpIfToken : ExpToken
|
||||
{
|
||||
private ExpToken _rule;
|
||||
private List<ExpToken> _trueOp;
|
||||
private List<ExpToken> _falseOp;
|
||||
|
||||
public ExpIfToken(string name, ExpSchema context, ExpToken rule,
|
||||
IEnumerable<ExpToken> operationIfTrue,
|
||||
IEnumerable<ExpToken> operationIfFalse):
|
||||
base(name,context)
|
||||
{
|
||||
_rule = rule;
|
||||
if (operationIfFalse == null)
|
||||
{
|
||||
_trueOp = new List<ExpToken>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_trueOp = new List<ExpToken>(operationIfFalse);
|
||||
}
|
||||
if (operationIfFalse == null)
|
||||
{
|
||||
_falseOp = new List<ExpToken>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_falseOp = new List<ExpToken>(operationIfFalse);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddTrueOperation(ExpToken expressionRoot)
|
||||
{
|
||||
AssertSchemaInclude(expressionRoot);
|
||||
_trueOp.Add(expressionRoot);
|
||||
}
|
||||
|
||||
public void AddFalseOperation(ExpToken expressionRoot)
|
||||
{
|
||||
AssertSchemaInclude(expressionRoot);
|
||||
_falseOp.Add(expressionRoot);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpLiteralToken.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpLiteralToken<T> : ExpElementInstanceBase
|
||||
{
|
||||
|
||||
private readonly ExpBuiltinType _type;
|
||||
private readonly T _value;
|
||||
|
||||
public ExpLiteralToken( string name, ExpSchema context, T value )
|
||||
: base( name, context )
|
||||
{
|
||||
_value = value;
|
||||
switch( value ) {
|
||||
case float f:
|
||||
ExpCompile.TryGetBuiltinType(
|
||||
ExpCompile.KeyWord.Real, out ExpTypeSource? type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_tokenType = ExpTokenFlag.BuiltinType_Float | ExpTokenFlag.Element_Const;
|
||||
break;
|
||||
case int i:
|
||||
ExpCompile.TryGetBuiltinType(
|
||||
ExpCompile.KeyWord.Int, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_tokenType = ExpTokenFlag.BuiltinType_Int | ExpTokenFlag.Element_Const;
|
||||
break;
|
||||
case BitArray b:
|
||||
ExpCompile.TryGetBuiltinType(
|
||||
ExpCompile.KeyWord.Binary, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_tokenType = ExpTokenFlag.BuiltinType_Binary | ExpTokenFlag.Element_Const;
|
||||
break;
|
||||
case string s:
|
||||
ExpCompile.TryGetBuiltinType(
|
||||
ExpCompile.KeyWord.String, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_tokenType = ExpTokenFlag.BuiltinType_Int | ExpTokenFlag.Element_Const;
|
||||
break;
|
||||
case Logic l:
|
||||
ExpCompile.TryGetBuiltinType(
|
||||
ExpCompile.KeyWord.Logic, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_tokenType = ExpTokenFlag.BuiltinType_Int | ExpTokenFlag.Element_Const;
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException(
|
||||
"Builtin Type", value!.GetType().Name );
|
||||
}
|
||||
}
|
||||
|
||||
public T value => _value;
|
||||
|
||||
public override string TypeName => _type.Name;
|
||||
|
||||
public override bool TryGetNextLevel(
|
||||
out ICollection<IExpressionToken> nextLevel )
|
||||
{
|
||||
nextLevel = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpRepeat.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpRepeat : ExpToken
|
||||
{
|
||||
|
||||
public ExpRepeat( string name, ExpSchema context )
|
||||
: base( name, context ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpRepeatRule : ExpToken
|
||||
{
|
||||
private List<ExpToken> _token = new List<ExpToken>();
|
||||
private ExpElementInstanceBase _variable, _begin, _end, _increment;
|
||||
|
||||
public ExpRepeatRule(
|
||||
string name,
|
||||
ExpSchema context,
|
||||
IEnumerable<ExpToken> operation,
|
||||
ExpElementInstanceBase variable,
|
||||
ExpElementInstanceBase begin,
|
||||
ExpElementInstanceBase end,
|
||||
ExpElementInstanceBase increment )
|
||||
: base( name, context )
|
||||
{
|
||||
if( variable.TokenTypeCode != begin.TokenTypeCode || begin.TokenTypeCode !=
|
||||
end.TokenTypeCode || ( increment != null && end.TokenTypeCode !=
|
||||
increment.TokenTypeCode ) ) {
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
if( increment == null ) {
|
||||
switch( ( ExpTokenFlag )variable.TokenTypeCode | ExpTokenFlag.BuiltinType_Any ) {
|
||||
case ExpTokenFlag.BuiltinType_Float:
|
||||
increment = new ExpLiteralToken<float>(
|
||||
$"{name}_defaultincrement", context, 1.0f );
|
||||
break;
|
||||
case ExpTokenFlag.BuiltinType_Int:
|
||||
increment = new ExpLiteralToken<int>(
|
||||
$"{name}_defaultincrement", context, 1 );
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException(
|
||||
"Int or Real", "otherwise" );
|
||||
}
|
||||
}
|
||||
_begin = begin;
|
||||
_variable = variable;
|
||||
_end = end;
|
||||
_increment = increment;
|
||||
_tokenType = ExpTokenFlag.Branch_Repeat;
|
||||
}
|
||||
|
||||
public override bool TryGetNextLevel(
|
||||
out ICollection<IExpressionToken> nextLevel )
|
||||
{
|
||||
nextLevel = ( _token.ToList() as ICollection<IExpressionToken> )!;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpSwitchToken : ExpToken
|
||||
{
|
||||
private ExpToken _target;
|
||||
private List<ExpToken> _default;
|
||||
private Dictionary<ExpToken, List<ExpToken>> _cases;
|
||||
|
||||
public List<ExpToken> this[ExpToken index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cases.TryGetValue(index, out var ret))
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
}
|
||||
|
||||
public ExpSwitchToken(string name, ExpSchema context,
|
||||
ExpToken target, IEnumerable<ExpToken> @default ,
|
||||
params (ExpToken label, IEnumerable<ExpToken> op)[] cases
|
||||
) : base(name, context)
|
||||
{
|
||||
_target = target;
|
||||
if (@default == null)
|
||||
{
|
||||
_default = new List<ExpToken>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_default = new List<ExpToken>(@default);
|
||||
}
|
||||
_cases = new Dictionary<ExpToken, List<ExpToken>>();
|
||||
foreach (var item in cases)
|
||||
{
|
||||
if (item.op == null)
|
||||
{
|
||||
_cases.Add(item.label, new List<ExpToken>());
|
||||
}
|
||||
else
|
||||
{
|
||||
_cases.Add(item.label, new List<ExpToken>(item.op));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsCase(ExpToken token)
|
||||
{
|
||||
return _cases.ContainsKey(token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an expression to certain <see langword="case"/>.
|
||||
/// The added expression will be run at last.
|
||||
/// </summary>
|
||||
/// <param name="label">Label of case to add operation</param>
|
||||
/// <param name="expressionRoot">Root token of the expression to be added.</param>
|
||||
/// <exception cref="ExpCaseNotFoundException">Cannot fine the case label in current witch expression.</exception>
|
||||
public void AddOperationToCase(ExpToken label, ExpToken expressionRoot)
|
||||
{
|
||||
AssertSchemaInclude(expressionRoot);
|
||||
if (_cases.TryGetValue(label,out var op))
|
||||
{
|
||||
op.Add(expressionRoot);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ExpCaseNotFoundException(this, label);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddOperationToDefault(ExpToken expressionRoot)
|
||||
{
|
||||
if (expressionRoot != null)
|
||||
{
|
||||
_default.Add(expressionRoot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpConst.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpConstantCollectionSource : IExpImmutableElement
|
||||
{
|
||||
private IScriptSourceProvider _sourceProvider;
|
||||
private string _name;
|
||||
private Dictionary<string, ExpElementInstanceBase> _constants;
|
||||
|
||||
public ExpConstantCollectionSource(
|
||||
string name,
|
||||
IScriptSourceProvider sourceProvider )
|
||||
{
|
||||
_name = name;
|
||||
_sourceProvider = sourceProvider;
|
||||
_constants = new Dictionary<string, ExpElementInstanceBase>(
|
||||
ExpCompile.Multiplexer);
|
||||
}
|
||||
|
||||
internal void AddConstant(string name, ExpElementInstanceBase value)
|
||||
{
|
||||
_constants.Add(name, value);
|
||||
}
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Const;
|
||||
|
||||
public IScriptSourceProvider SourceProvider => _sourceProvider;
|
||||
|
||||
public static Dictionary<string, ExpConstantCollectionSource> BuiltinConst => ExpCompile.BuiltinConst;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
}
|
||||
|
||||
public virtual void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ExpToken MakeReference(params object[] options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpEntity.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpEntity : ExpToken
|
||||
{
|
||||
|
||||
public ExpEntity( string name ,ExpSchema context):
|
||||
base(name, context)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpEntitySource : IExpInstantiableElement
|
||||
{
|
||||
|
||||
private ExpExpressionTree _expressionTree;
|
||||
private ScriptSourceTransmitter _source;
|
||||
private string _name;
|
||||
|
||||
public ExpEntitySource( string name, ScriptSourceTransmitter provider )
|
||||
{
|
||||
_name = name;
|
||||
_source = provider;
|
||||
}
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Entity;
|
||||
|
||||
public IScriptSourceProvider SourceProvider => _source;
|
||||
|
||||
public string Name => _name;
|
||||
|
||||
public void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ExpToken CreateInstanceToken()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpFunction.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpFunction : ExpToken
|
||||
{
|
||||
private ExpFunctionSource _source;
|
||||
private readonly ExpToken _return;
|
||||
private readonly List<KeyValuePair<string, ExpToken>> _parameterList
|
||||
= new List<KeyValuePair<string, ExpToken>>();
|
||||
|
||||
public ExpFunction(string name, ExpSchema context) : base(name, context)
|
||||
{ }
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Function;
|
||||
|
||||
public void CallThisFunction( params ExpToken[] parameters ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpFunctionSource : IExpImmutableElement
|
||||
{
|
||||
|
||||
private ScriptSourceTransmitter _transmitter;
|
||||
private string _name;
|
||||
|
||||
public ExpFunctionSource(
|
||||
string name,
|
||||
ScriptSourceTransmitter transmitter )
|
||||
{
|
||||
_name = name;
|
||||
_transmitter = transmitter;
|
||||
}
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Function;
|
||||
|
||||
public IScriptSourceProvider SourceProvider => _transmitter;
|
||||
|
||||
public string Name => _name;
|
||||
|
||||
public void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ExpToken MakeReference(params object[] options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpRule.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpRule : ExpElementInstanceBase
|
||||
{
|
||||
private ExpRuleSource _source;
|
||||
|
||||
public ExpRule(string name, ExpSchema context) : base(name,context)
|
||||
{
|
||||
}
|
||||
|
||||
public object? value => throw new NotImplementedException();
|
||||
|
||||
public override string TypeName => _source.Name;
|
||||
}
|
||||
|
||||
public class ExpRuleSource : IExpImmutableElement
|
||||
{
|
||||
|
||||
private ScriptSourceTransmitter _transmitter;
|
||||
private string _name;
|
||||
|
||||
public ExpRuleSource( string name, ScriptSourceTransmitter transmitter )
|
||||
{
|
||||
_name = name;
|
||||
_transmitter = transmitter;
|
||||
}
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Rule;
|
||||
|
||||
public IScriptSourceProvider SourceProvider => _transmitter;
|
||||
|
||||
public string Name => _name;
|
||||
|
||||
public void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ExpToken MakeReference(params object[] options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpType.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the ¡°Software¡±), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED ¡°AS IS¡±,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Script;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpType : ExpElementInstanceBase
|
||||
{
|
||||
public override string TypeName => throw new NotImplementedException();
|
||||
|
||||
public ExpType(string name, ExpSchema context) : base(name, context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class ExpTypeSource : IExpElementSource
|
||||
{
|
||||
|
||||
private ScriptSourceTransmitter _transmitter;
|
||||
private string _name;
|
||||
|
||||
public ExpTypeSource( string name, ScriptSourceTransmitter transmitter )
|
||||
{
|
||||
_name = name;
|
||||
_transmitter = transmitter;
|
||||
}
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Type;
|
||||
|
||||
public IScriptSourceProvider SourceProvider => _transmitter;
|
||||
|
||||
public string Name => _name;
|
||||
|
||||
public virtual void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Exceptions.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpCompileNotInitializedException : InvalidOperationException
|
||||
{
|
||||
|
||||
public ExpCompileNotInitializedException()
|
||||
: base(
|
||||
"Attempt to compile an EXPRESS script before the init of compiler." ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidTypeDeclareEndingExceptions : Exception
|
||||
{
|
||||
public ExpInvalidTypeDeclareEndingExceptions(
|
||||
string declaredName,
|
||||
string endedName )
|
||||
: base(
|
||||
$"The datatype is declared with name {declaredName} " +
|
||||
$"but ended with {endedName}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidElementNameException : Exception
|
||||
{
|
||||
|
||||
public ExpInvalidElementNameException(
|
||||
string elementName,
|
||||
ExpSchema schema )
|
||||
: base(
|
||||
$"Cannot find any element named {elementName} in {schema.Name}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidTypeException : InvalidCastException
|
||||
{
|
||||
|
||||
public ExpInvalidTypeException( string required, string provided )
|
||||
: base(
|
||||
$"Type {required} is required at position, but a {provided} instance is provided." ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidCollectionMemberTypeException : InvalidCastException
|
||||
{
|
||||
|
||||
public ExpInvalidCollectionMemberTypeException(
|
||||
ExpElementInstanceBase elementInstance,
|
||||
ExpCollectionBase collection )
|
||||
: base(
|
||||
$"Attempt to add or remove an element of type: {elementInstance.ElementType} " + $"from a collection collects {collection.MemberType}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpInvalidSchemaIncludeException : InvalidOperationException
|
||||
{
|
||||
|
||||
public ExpInvalidSchemaIncludeException(
|
||||
ExpSchema context,
|
||||
ExpSchema source )
|
||||
: base(
|
||||
$"Attempted to reference an EXPRESS language expression in the current schema context '{context.Name}', " + $"but this expression comes from another schema '{source.Name}' that has not been included." ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpCaseNotFoundException : ArgumentOutOfRangeException
|
||||
{
|
||||
|
||||
public ExpCaseNotFoundException( ExpSwitchToken token, ExpToken label )
|
||||
: base(
|
||||
$"Attempt to read or write the label {label.Name} not exist in " + $"SWITCH expression {token.Name}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpTypeNotFoundException : Exception
|
||||
{
|
||||
|
||||
public ExpTypeNotFoundException( string typeName, ExpSchema context )
|
||||
: base(
|
||||
$"Cannot find the type {typeName} in schema {context.Name} and " + $"its included schemas" ) { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpInit.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using CommunityToolkit.HighPerformance.Buffers;
|
||||
|
||||
using StgSharp.Collections;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public static partial class ExpCompile
|
||||
{
|
||||
|
||||
private static ConcurrentStringHashMultiplexer _multiplexer;
|
||||
private static Dictionary<string, ExpConstantCollectionSource> _builtinConst;
|
||||
private static Dictionary<string, ExpTypeSource> _builtinType;
|
||||
private static StringPool _compileStringCache;
|
||||
|
||||
public static Dictionary<string, ExpConstantCollectionSource> BuiltinConst => _builtinConst;
|
||||
|
||||
public static string AddOrGetString( string str )
|
||||
{
|
||||
return _compileStringCache.GetOrAdd( str );
|
||||
}
|
||||
|
||||
public static void ClearStringCache()
|
||||
{
|
||||
_compileStringCache.Reset();
|
||||
}
|
||||
|
||||
public static bool TryGetBuiltinType(string typename, out ExpTypeSource typeSource)
|
||||
{
|
||||
return _builtinType.TryGetValue( typename, out typeSource );
|
||||
}
|
||||
|
||||
public static bool TryGetBuiltinConst(string constName, out ExpConstantCollectionSource source)
|
||||
{
|
||||
return _builtinConst.TryGetValue(constName, out source);
|
||||
}
|
||||
|
||||
internal static ConcurrentStringHashMultiplexer Multiplexer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_multiplexer == null)
|
||||
{
|
||||
throw new ExpCompileNotInitializedException();
|
||||
}
|
||||
return _multiplexer;
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitCompile()
|
||||
{
|
||||
_compileStringCache = new StringPool();
|
||||
_multiplexer = new ConcurrentStringHashMultiplexer();
|
||||
_builtinConst = new Dictionary<string, ExpConstantCollectionSource>(_multiplexer){
|
||||
{ AddOrGetString( "PI" ), new ExpBuiltinConst<float>(
|
||||
AddOrGetString( "PI" ), MathF.PI ) },
|
||||
{ AddOrGetString( "E" ), new ExpBuiltinConst<float>(
|
||||
AddOrGetString( "E" ), MathF.E ) },
|
||||
};
|
||||
//TODO keep on here
|
||||
_builtinType = new Dictionary<string, ExpTypeSource>(_multiplexer){
|
||||
{ AddOrGetString( KeyWord.Int ), new ExpBuiltinType(
|
||||
AddOrGetString( KeyWord.Int ), typeof( int ) ) },
|
||||
{ AddOrGetString( KeyWord.Real ), new ExpBuiltinType(
|
||||
AddOrGetString( KeyWord.Real ), typeof( float ) ) },
|
||||
{ AddOrGetString( KeyWord.Bool ), new ExpBuiltinType(
|
||||
AddOrGetString( KeyWord.Bool ), typeof( bool ) ) },
|
||||
{ AddOrGetString( KeyWord.Binary ), new ExpBuiltinType(
|
||||
AddOrGetString( KeyWord.Binary ), typeof( bool ) ) },
|
||||
{ AddOrGetString( KeyWord.String ), new ExpBuiltinType(
|
||||
AddOrGetString( KeyWord.String ), typeof( string ) ) },
|
||||
{ AddOrGetString(KeyWord.Logic),new ExpBuiltinType(
|
||||
AddOrGetString(KeyWord.Logic), typeof(Logic)) }
|
||||
};
|
||||
}
|
||||
|
||||
public static class KeyWord
|
||||
{
|
||||
public const string Int = "INTAGER",
|
||||
Real = "REAL",
|
||||
Bool = "BOOLEAN",
|
||||
String = "STRING",
|
||||
Logic = "LOGIC",
|
||||
Binary = "BINARY";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpElementInstanceBase.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
[Flags]
|
||||
public enum ExpElementType : int
|
||||
{
|
||||
|
||||
Const = 0,
|
||||
Entity = 1,
|
||||
Type = 2,
|
||||
Function = 4,
|
||||
Section = 8,
|
||||
Expression = 16,
|
||||
Rule = 32,
|
||||
Procedure = 64,
|
||||
Collection = 128 | Type,
|
||||
|
||||
}
|
||||
|
||||
public abstract class ExpElementInstanceBase : ExpToken
|
||||
{
|
||||
|
||||
protected ExpElementInstanceBase( string name, ExpSchema context )
|
||||
: base( name, context ) { }
|
||||
|
||||
public ExpElementType ElementType
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract string TypeName
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface IExpElementSource
|
||||
{
|
||||
|
||||
public ExpElementType ElementType
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
IScriptSourceProvider SourceProvider
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
string Name
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public void Analyse();
|
||||
|
||||
}
|
||||
|
||||
public interface IExpInstantiableElement : IExpElementSource
|
||||
{
|
||||
|
||||
public abstract ExpToken CreateInstanceToken();
|
||||
|
||||
}
|
||||
|
||||
public interface IExpImmutableElement : IExpElementSource
|
||||
{
|
||||
public abstract ExpToken MakeReference(params object[] options);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpExpressionTree.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpExpressionTree : AbstractSyntaxTree<ExpToken>
|
||||
{
|
||||
public ExpToken RootToken { get; private set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public enum Logic
|
||||
{
|
||||
Unknown = 0,
|
||||
False = 1,
|
||||
True = 2,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpReader.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.MemoryMappedFiles;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpFileReader : IDisposable, IScriptSourceProvider
|
||||
{
|
||||
|
||||
private bool disposedValue;
|
||||
private FileStream _expFileStream;
|
||||
private int _location;
|
||||
private MemoryMappedFile _expMemoryMappedFile;
|
||||
private MemoryMappedViewStream _expMemoryMappedStream;
|
||||
|
||||
private SemaphoreSlim readLineSemaphore = new SemaphoreSlim( 1, 1 );
|
||||
private StreamReader _memoryReader;
|
||||
|
||||
public ExpFileReader( string path )
|
||||
{
|
||||
if( !File.Exists( path ) ) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
_expFileStream = new FileStream(
|
||||
path, FileMode.Open, FileAccess.Read );
|
||||
_expMemoryMappedFile = MemoryMappedFile.CreateFromFile(
|
||||
_expFileStream, null, 0, MemoryMappedFileAccess.Read,
|
||||
HandleInheritability.None, true );
|
||||
_expMemoryMappedStream = _expMemoryMappedFile.CreateViewStream(
|
||||
offset: 0, size: 0, access: MemoryMappedFileAccess.Read );
|
||||
_memoryReader = new StreamReader( _expMemoryMappedStream );
|
||||
}
|
||||
|
||||
public int Location => _location;
|
||||
|
||||
// ~ExpFileReader()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose( disposing: true );
|
||||
GC.SuppressFinalize( this );
|
||||
}
|
||||
|
||||
public string ReadLine()
|
||||
{
|
||||
readLineSemaphore.Wait();
|
||||
string line = _memoryReader.ReadLine();
|
||||
_location++;
|
||||
readLineSemaphore.Release();
|
||||
return line;
|
||||
}
|
||||
|
||||
public void ResetToBegin()
|
||||
{
|
||||
readLineSemaphore.Wait();
|
||||
_expMemoryMappedStream.Seek( 0, SeekOrigin.Begin );
|
||||
_location = 0;
|
||||
readLineSemaphore.Release();
|
||||
}
|
||||
|
||||
protected virtual void Dispose( bool disposing )
|
||||
{
|
||||
if( !disposedValue ) {
|
||||
if( disposing ) {
|
||||
_expFileStream.Dispose();
|
||||
_expMemoryMappedFile.Dispose();
|
||||
_expMemoryMappedStream.Dispose();
|
||||
_memoryReader.Dispose();
|
||||
}
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSchema.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Collections;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpSchema
|
||||
{
|
||||
private readonly ConcurrentStringHashMultiplexer _multiplexer = ExpCompile.Multiplexer;
|
||||
private Dictionary<string, ExpConstantCollectionSource> _constDict;
|
||||
private Dictionary<string, ExpEntitySource> _entityDict;
|
||||
private Dictionary<string, ExpFunctionSource> _functionDict;
|
||||
private Dictionary<string, ExpRuleSource> _ruleDict;
|
||||
private Dictionary<string, ExpSchema> _schemaInclude;
|
||||
private Dictionary<string, ExpTypeSource> _typeDict;
|
||||
|
||||
public ExpSchema()
|
||||
{
|
||||
_constDict = new Dictionary<string, ExpConstantCollectionSource>(ExpCompile.Multiplexer);
|
||||
_entityDict = new Dictionary<string, ExpEntitySource>(ExpCompile.Multiplexer);
|
||||
_functionDict = new Dictionary<string, ExpFunctionSource>(ExpCompile.Multiplexer);
|
||||
_ruleDict = new Dictionary<string, ExpRuleSource>(ExpCompile.Multiplexer);
|
||||
_schemaInclude = new Dictionary<string, ExpSchema>(ExpCompile.Multiplexer);
|
||||
_typeDict = new Dictionary<string, ExpTypeSource>(ExpCompile.Multiplexer);
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public ExpTypeSource GetExpType( string typeName )
|
||||
{
|
||||
if( ExpCompile.TryGetBuiltinType(
|
||||
typeName, out ExpTypeSource? ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
if( _typeDict.TryGetValue( typeName, out ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
foreach( ExpSchema item in _schemaInclude.Values ) {
|
||||
if( item._typeDict.TryGetValue( typeName, out ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
throw new ExpTypeNotFoundException( typeName, this );
|
||||
}
|
||||
|
||||
public bool HasSchemaInclude( ExpSchema schema )
|
||||
{
|
||||
return _schemaInclude.ContainsKey( schema.Name );
|
||||
}
|
||||
|
||||
public bool TryGetConst(string name, out ExpElementInstanceBase constInstance)
|
||||
{
|
||||
if (ExpCompile.BuiltinConst.TryGetValue(name, out constInstance))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ExpToken SearchConstDeclare( string typeName )
|
||||
{
|
||||
ExpToken constant;
|
||||
foreach (var item in ExpCompile.BuiltinConst.Values)
|
||||
{
|
||||
|
||||
}
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSchema.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Collections;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpSchemaSource
|
||||
{
|
||||
|
||||
private static Regex
|
||||
_constDefineBegin = new Regex(
|
||||
@"\s*CONSTANT", RegexOptions.Compiled ),
|
||||
_constDefineEnd = new Regex(
|
||||
@"\s*END_CONSTANT;", RegexOptions.Compiled ),
|
||||
_schemaBegin = new Regex(
|
||||
@"\s*SCHEMA\s*(?<namespace>[A-Za-z0-9_]+)\s?;",
|
||||
RegexOptions.Compiled ),
|
||||
_schemaEnd = new Regex(
|
||||
@"END_SCHEMA;\s*--\s*(?<namespace>[A-Za-z0-9_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_entityDefineBegin = new Regex(
|
||||
@"\s*ENTITY\s*(?<TypeName>[A-Za-z0-9_]+)\s*", RegexOptions.Compiled ),
|
||||
_entityDefineEnd = new Regex(
|
||||
@"\s*END_ENTITY;\s*--\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
|
||||
RegexOptions.Compiled ),
|
||||
_typeDefineBegin = new Regex(
|
||||
@"\s*TYPE\s+(?<TypeName>[A-Za-z0-9_]+)\s*=\s*(?<Remaining>[A-Z]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_typeDefineEnd = new Regex(
|
||||
@"\s*END_TYPE\s*;\s*--\s*(?<TypeName>[a-zA-Z0-9_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_functionDefineBegin = new Regex(
|
||||
@"\s*FUNCTION\s*\s*(?<FunctionName>[a-zA-Z0-9_]+)\s*(?<Remaining>.*)",
|
||||
RegexOptions.Compiled ),
|
||||
_functionDefineEnd = new Regex(
|
||||
@"\s*END_FUNCTION\s*;\s*--\s*(?<FunctionName>[a-zA-Z0-9_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_ruleDefineBegin = new Regex(
|
||||
@"\s*RULE\s*(?<RuleName>[a-zA-Z0-9_]+)\s*FOR\s*\((?<Target>[a-zA-Z0-9_]*(\s*\)\s*;)?)",
|
||||
RegexOptions.Compiled ),
|
||||
_ruleDefineEnd = new Regex(
|
||||
@"\s*END_RULE\s*;\s*--\s*(?<RuleName>[A-Za-z0-9_]+)",
|
||||
RegexOptions.Compiled );
|
||||
|
||||
private Dictionary<string, IExpElementSource> _sourceCache = new();
|
||||
|
||||
private readonly ExpSchema _compileResult = new ExpSchema();
|
||||
|
||||
private string name;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _compileResult.Name;
|
||||
internal set => _compileResult.Name = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ExpSchemaSource() { }
|
||||
|
||||
public void ReadSchema( ExpFileReader reader )
|
||||
{
|
||||
string line = reader.ReadLine();
|
||||
while( !_schemaBegin.IsMatch( line ) ) {
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
name = _schemaBegin.Match( line ).Groups[ "namespace" ].Value;
|
||||
|
||||
while( !_schemaEnd.IsMatch( line ) ) {
|
||||
if( TryReadConst( line, reader,
|
||||
out IExpElementSource source ) ) {
|
||||
_sourceCache.Add( source.Name, source );
|
||||
} else if( TryReadType( line, reader, out source ) ) {
|
||||
_sourceCache.Add( source.Name, source );
|
||||
} else if( TryReadEntity( line, reader, out source ) ) {
|
||||
_sourceCache.Add( source.Name, source );
|
||||
} else if( TryReadRule( line, reader, out source ) ) {
|
||||
_sourceCache.Add( source.Name, source );
|
||||
} else if( TryReadFunction( line, reader, out source ) ) {
|
||||
_sourceCache.Add( source.Name, source );
|
||||
}
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryReadSchema(
|
||||
string firstLine,
|
||||
ExpFileReader reader,
|
||||
out ExpSchemaSource source )
|
||||
{
|
||||
if( !_schemaBegin.IsMatch( firstLine ) ) {
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
ExpSchemaSource _source = new ExpSchemaSource();
|
||||
_source.name = _schemaBegin.Match( firstLine ).Groups[ "namespace" ].Value;
|
||||
|
||||
while( !_schemaEnd.IsMatch( firstLine ) ) {
|
||||
if( _source.TryReadConst(
|
||||
firstLine, reader,
|
||||
out IExpElementSource _elementSource ) ) {
|
||||
_source._sourceCache
|
||||
.Add( _elementSource.Name, _elementSource );
|
||||
} else if( _source.TryReadType(
|
||||
firstLine, reader, out _elementSource ) ) {
|
||||
_source._sourceCache
|
||||
.Add( _elementSource.Name, _elementSource );
|
||||
} else if( _source.TryReadEntity(
|
||||
firstLine, reader, out _elementSource ) ) {
|
||||
_source._sourceCache
|
||||
.Add( _elementSource.Name, _elementSource );
|
||||
} else if( _source.TryReadRule(
|
||||
firstLine, reader, out _elementSource ) ) {
|
||||
_source._sourceCache
|
||||
.Add( _elementSource.Name, _elementSource );
|
||||
} else if( _source.TryReadFunction(
|
||||
firstLine, reader, out _elementSource ) ) {
|
||||
_source._sourceCache
|
||||
.Add( _elementSource.Name, _elementSource );
|
||||
}
|
||||
firstLine = reader.ReadLine();
|
||||
}
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryReadConst(
|
||||
string firstLine,
|
||||
ExpFileReader reader,
|
||||
out IExpElementSource source )
|
||||
{
|
||||
Match match = _constDefineBegin.Match( firstLine );
|
||||
if( match.Success ) {
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||
"END_CONSTANT" );
|
||||
ExpConstantCollectionSource _source = new ExpConstantCollectionSource(
|
||||
"Constant", transmitter );
|
||||
string line = reader.ReadLine();
|
||||
while( !_constDefineEnd.IsMatch( line ) ) {
|
||||
transmitter.WriteLine( line );
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
transmitter.WriteLine( "END_CONSTANT" );
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryReadEntity(
|
||||
string firstLine,
|
||||
ExpFileReader reader,
|
||||
out IExpElementSource source )
|
||||
{
|
||||
Match match = _entityDefineBegin.Match( firstLine );
|
||||
if( match.Success ) {
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||
"END_ENTITY" );
|
||||
ExpEntitySource _source = new ExpEntitySource(
|
||||
match.Groups[ "TypeName" ].ToString(), transmitter );
|
||||
string line = reader.ReadLine();
|
||||
match = _entityDefineEnd.Match( line );
|
||||
while( !match.Success ) {
|
||||
transmitter.WriteLine( line );
|
||||
line = reader.ReadLine();
|
||||
match = _entityDefineEnd.Match( line );
|
||||
}
|
||||
string endedName = match.Groups[ "TypeName" ].ToString();
|
||||
if( !string.Equals( endedName, _source.Name ) ) {
|
||||
throw new ExpInvalidTypeDeclareEndingExceptions(
|
||||
_source.Name, endedName );
|
||||
}
|
||||
transmitter.WriteLine( "END_ENTITY" );
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryReadFunction(
|
||||
string firstLine,
|
||||
ExpFileReader reader,
|
||||
out IExpElementSource source )
|
||||
{
|
||||
Match match = _functionDefineBegin.Match( firstLine );
|
||||
if( match.Success ) {
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||
"END_FUNCTION" );
|
||||
ExpFunctionSource _source = new ExpFunctionSource(
|
||||
match.Groups[ "FunctionName" ].ToString(), transmitter );
|
||||
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
|
||||
string line = reader.ReadLine();
|
||||
match = _functionDefineEnd.Match( line );
|
||||
while( !match.Success ) {
|
||||
transmitter.WriteLine( line );
|
||||
line = reader.ReadLine();
|
||||
match = _functionDefineEnd.Match( line );
|
||||
}
|
||||
string endedName = match.Groups[ "FunctionName" ].ToString();
|
||||
if( !string.Equals( endedName, _source.Name ) ) {
|
||||
throw new ExpInvalidTypeDeclareEndingExceptions(
|
||||
_source.Name, endedName );
|
||||
}
|
||||
transmitter.WriteLine( "END_FUNCTION" );
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryReadRule(
|
||||
string firstLine,
|
||||
ExpFileReader reader,
|
||||
out IExpElementSource source )
|
||||
{
|
||||
Match match = _ruleDefineBegin.Match( firstLine );
|
||||
if( match.Success ) {
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||
"END_RULE" );
|
||||
ExpRuleSource _source = new ExpRuleSource(
|
||||
match.Groups[ "RuleName" ].ToString(), transmitter );
|
||||
string target = match.Groups[ "Target" ].ToString();
|
||||
if( !string.IsNullOrEmpty( target ) ) {
|
||||
transmitter.WriteLine( target );
|
||||
}
|
||||
string line = reader.ReadLine();
|
||||
match = _ruleDefineEnd.Match( line );
|
||||
while( !match.Success ) {
|
||||
transmitter.WriteLine( line );
|
||||
line = reader.ReadLine();
|
||||
match = _ruleDefineEnd.Match( line );
|
||||
}
|
||||
string endedName = match.Groups[ "RuleName" ].ToString();
|
||||
if( !string.Equals( endedName, _source.Name ) ) {
|
||||
throw new ExpInvalidTypeDeclareEndingExceptions(
|
||||
_source.Name, endedName );
|
||||
}
|
||||
transmitter.WriteLine( "END_RULE" );
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryReadType(
|
||||
string firstLine,
|
||||
ExpFileReader reader,
|
||||
out IExpElementSource source )
|
||||
{
|
||||
Match match = _typeDefineBegin.Match( firstLine );
|
||||
if( match.Success ) {
|
||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||
"END_ENTITY" );
|
||||
ExpTypeSource _source = new ExpTypeSource(
|
||||
match.Groups[ "TypeName" ].ToString(), transmitter );
|
||||
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
|
||||
string line = reader.ReadLine();
|
||||
match = _typeDefineEnd.Match( line );
|
||||
while( !match.Success ) {
|
||||
transmitter.WriteLine( line );
|
||||
line = reader.ReadLine();
|
||||
match = _typeDefineEnd.Match( line );
|
||||
}
|
||||
string endedName = match.Groups[ "TypeName" ].ToString();
|
||||
if( !string.Equals( endedName, _source.Name ) ) {
|
||||
throw new ExpInvalidTypeDeclareEndingExceptions(
|
||||
_source.Name, endedName );
|
||||
}
|
||||
transmitter.WriteLine( "END_ENTITY" );
|
||||
source = _source;
|
||||
return true;
|
||||
}
|
||||
source = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpToken.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using CommunityToolkit.HighPerformance.Buffers;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
[Flags]
|
||||
public enum ExpTokenFlag : long
|
||||
{
|
||||
None = 0,
|
||||
Name_Element = 1,
|
||||
Name_Param = 2,
|
||||
Name_Block=4,
|
||||
Name_Keyword=8,
|
||||
Name_Any = Name_Block | Name_Element | Name_Keyword | Name_Param,
|
||||
Collection_Set=16,
|
||||
Collection_Bag=32,
|
||||
Collection_Array=64,
|
||||
Collection_List=128,
|
||||
Collection_Any = Collection_Set | Collection_Bag | Collection_Array | Collection_List,
|
||||
Element_Const=256,
|
||||
Element_Entity=512,
|
||||
Element_type=1024,
|
||||
Element_Rule=2048,
|
||||
Element_Function=4096,
|
||||
Element_Any = Element_Entity | Element_Const | Element_Function | Element_Rule | Element_type,
|
||||
BuiltinType_Int=8192,
|
||||
BuiltinType_Float=16384,
|
||||
BuiltinType_String=32768,
|
||||
BuiltinType_Boolean=65536,
|
||||
BuiltinType_Binary=0x2000,
|
||||
BuiltinType_Logic=0x4000,
|
||||
BuiltinType_Any = BuiltinType_Int | BuiltinType_Float | BuiltinType_String | BuiltinType_Boolean | BuiltinType_Binary | BuiltinType_Logic,
|
||||
Branch_If = 0x8000,
|
||||
Branch_Switch = 0x1_0000,
|
||||
Branch_Repeat = 0x2_0000,
|
||||
}
|
||||
|
||||
public abstract class ExpToken : IExpressionToken
|
||||
{
|
||||
|
||||
protected internal ExpToken _previousToken;
|
||||
protected internal ExpTokenFlag _tokenType;
|
||||
protected internal List<ExpToken> _nextLevelTokens = new List<ExpToken>(
|
||||
);
|
||||
protected internal string _name;
|
||||
|
||||
|
||||
protected ExpToken( string name, ExpSchema context )
|
||||
{
|
||||
_name = name;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public virtual bool TryGetNextLevel(out ICollection<IExpressionToken> nextLevel)
|
||||
{
|
||||
nextLevel = (_nextLevelTokens as ICollection<IExpressionToken>)!;
|
||||
return true;
|
||||
}
|
||||
|
||||
public long TokenTypeCode => ( long )_tokenType;
|
||||
|
||||
public string Name => _name;
|
||||
|
||||
public ExpSchema Context
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
protected void AssertSchemaInclude(ExpToken expressionRoot)
|
||||
{
|
||||
if (expressionRoot.Context != Context &&
|
||||
Context.HasSchemaInclude(expressionRoot.Context))
|
||||
{
|
||||
throw new ExpInvalidSchemaIncludeException(Context, expressionRoot.Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user