daily update on 20250127 by nitload youmu, schema and element splitter complete, builtin defination building
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Expression
|
||||
{
|
||||
public class ExpConst : ExpElementBase
|
||||
{
|
||||
|
||||
private ExpConstSource _source;
|
||||
private string _name, _target;
|
||||
|
||||
public ExpConst( string name, ExpSchema context ):
|
||||
base( context )
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
public override object? Value => _source;
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Const;
|
||||
|
||||
}
|
||||
|
||||
internal sealed class ExpBuiltinConst : ExpConstSource
|
||||
{
|
||||
|
||||
private readonly float _value;
|
||||
|
||||
public ExpBuiltinConst( string name, float value )
|
||||
: base( name, null ) { }
|
||||
|
||||
public string Name => throw new NotImplementedException();
|
||||
|
||||
public override sealed void Analyse()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpConstSource : IExpElementSource
|
||||
{
|
||||
|
||||
private static Lazy<ReadOnlyDictionary<string, ExpConstSource>> _builtinConst
|
||||
= new(
|
||||
() => ReadOnlyDictionary(
|
||||
new Dictionary<string, ExpConstSource> {
|
||||
{ "PI", new ExpConstSource( "PI", ) },
|
||||
} ) );
|
||||
|
||||
private IScriptSourceProvider _sourceProvider;
|
||||
|
||||
private string _name;
|
||||
|
||||
public ExpConstSource(
|
||||
string name,
|
||||
IScriptSourceProvider sourceProvider )
|
||||
{
|
||||
_name = name;
|
||||
_sourceProvider = sourceProvider;
|
||||
}
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Const;
|
||||
|
||||
public IScriptSourceProvider SourceProvider => _sourceProvider;
|
||||
|
||||
public static ReadOnlyDictionary<string, ExpConstSource> BuiltinConst => _builtinConst.Value;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
}
|
||||
|
||||
public virtual void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Security.Authentication.ExtendedProtection;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Expression
|
||||
{
|
||||
public class ExpEntity : ExpToken
|
||||
{
|
||||
|
||||
public ExpEntity( string name ,ExpSchema context):
|
||||
base(name, context)
|
||||
{
|
||||
}
|
||||
|
||||
public override object? Value => throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
public class ExpEntitySource : IExpElementSource
|
||||
{
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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.Expression
|
||||
{
|
||||
public class ExpFunction : ExpToken
|
||||
{
|
||||
|
||||
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 object? value => this;
|
||||
|
||||
public override object? Value => this;
|
||||
|
||||
public ExpElementType ElementType => ExpElementType.Function;
|
||||
|
||||
public void CallThisFunction( params ExpToken[] parameters ) { }
|
||||
|
||||
}
|
||||
|
||||
public class ExpFunctionSource : IExpElementSource
|
||||
{
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Expression
|
||||
{
|
||||
public class ExpRule : ExpElementBase
|
||||
{
|
||||
|
||||
|
||||
public ExpRule(string name, ExpSchema context) : base(context)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
public object? value => throw new NotImplementedException();
|
||||
|
||||
public override object? Value => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public class ExpRuleSource : IExpElementSource
|
||||
{
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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.Expression
|
||||
{
|
||||
public class ExpType : ExpElementBase
|
||||
{
|
||||
|
||||
|
||||
public override object? Value => throw new NotImplementedException();
|
||||
|
||||
public ExpType(ExpSchema context) : base(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 void Analyse()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Expression
|
||||
{
|
||||
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 ExpInvalidCollectionMemberTypeException : InvalidCastException
|
||||
{
|
||||
|
||||
public ExpInvalidCollectionMemberTypeException(
|
||||
ExpElementBase elementInstance,
|
||||
ExpCollectionBase collection )
|
||||
: base(
|
||||
$"Attempt to add or remove an element of type: {elementInstance.ElementType} from a collection" + $"collects {collection.}" ) { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpElementBase.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.Expression
|
||||
{
|
||||
public enum ExpElementType : int
|
||||
{
|
||||
|
||||
Const,
|
||||
Entity,
|
||||
Type,
|
||||
Function,
|
||||
Section,
|
||||
Expression,
|
||||
Rule
|
||||
|
||||
}
|
||||
|
||||
public abstract class ExpElementBase : ExpToken
|
||||
{
|
||||
protected ExpElementBase(string name, ExpSchema context):
|
||||
base(name, context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ExpElementType ElementType
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface IExpElementSource
|
||||
{
|
||||
|
||||
public ExpElementType ElementType
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
IScriptSourceProvider SourceProvider
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
string Name
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public void Analyse();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Expression
|
||||
{
|
||||
public class ExpExpressionTree : AbstractSyntaxTree<ExpToken> { }
|
||||
}
|
||||
@@ -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.Expression
|
||||
{
|
||||
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,343 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace StgSharp.Script.Expression
|
||||
{
|
||||
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-z_]+)\s?;",
|
||||
RegexOptions.Compiled ),
|
||||
_schemaEnd = new Regex(
|
||||
@"END_SCHEMA;\s*--\s*(?<namespace>[A-Za-z_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_entityDefineBegin = new Regex(
|
||||
@"\s*ENTITY\s*(?<TypeName>[A-Za-z_]+)\s*", RegexOptions.Compiled ),
|
||||
_entityDefineEnd = new Regex(
|
||||
@"\s*END_ENTITY;\s*--\s*(?<TypeName>[A-Za-z_]+)\s*",
|
||||
RegexOptions.Compiled ),
|
||||
_typeDefineBegin = new Regex(
|
||||
@"\s*TYPE\s+(?<TypeName>[A-Za-z_]+)\s*=\s*(?<Remaining>[A-Z]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_typeDefineEnd = new Regex(
|
||||
@"\s*END_TYPE\s*;\s*--\s*(?<TypeName>[a-zA-Z_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_functionDefineBegin = new Regex(
|
||||
@"\s*FUNCTION\s*\s*(?<FunctionName>[a-zA-Z_]+)\s*(?<Remaining>.*)",
|
||||
RegexOptions.Compiled ),
|
||||
_functionDefineEnd = new Regex(
|
||||
@"\s*END_FUNCTION\s*;\s*--\s*(?<FunctionName>[a-zA-Z_]+)",
|
||||
RegexOptions.Compiled ),
|
||||
_ruleDefineBegin = new Regex(
|
||||
@"\s*RULE\s*(?<RuleName>[a-zA-Z_]+)\s*FOR\s*\((?<Target>[a-zA-Z_]*(\s*\)\s*;)?)",
|
||||
RegexOptions.Compiled ),
|
||||
_ruleDefineEnd = new Regex(
|
||||
@"\s*END_RULE\s*;\s*--\s*(?<RuleName>[A-Za-z_]+)",
|
||||
RegexOptions.Compiled );
|
||||
|
||||
private Dictionary<string, IExpElementSource> _sourceCache = new();
|
||||
|
||||
private string name;
|
||||
|
||||
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" );
|
||||
ExpConstSource _source = new ExpConstSource(
|
||||
"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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpSchema
|
||||
{
|
||||
|
||||
private Dictionary<string, ExpConstSource> _constDict = new();
|
||||
private Dictionary<string, ExpEntitySource> _entityDict = new Dictionary<string, ExpEntitySource>(
|
||||
);
|
||||
private Dictionary<string, ExpFunctionSource> _functionDict = new Dictionary<string, ExpFunctionSource>(
|
||||
);
|
||||
private Dictionary<string, ExpRuleSource> _ruleDict = new Dictionary<string, ExpRuleSource>(
|
||||
);
|
||||
private Dictionary<string, ExpTypeSource> _typeDict = new Dictionary<string, ExpTypeSource>(
|
||||
);
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public ExpConstSource SearchConstDeclare( string typeName )
|
||||
{
|
||||
if( _constDict.TryGetValue( typeName,
|
||||
out ExpConstSource? source ) ) {
|
||||
return source;
|
||||
}
|
||||
if( _constDict.TryGetValue( typeName,
|
||||
out ExpConstSource? type ) ) { }
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Expression
|
||||
{
|
||||
[Flags]
|
||||
public enum ExpTokenType : long
|
||||
{
|
||||
|
||||
None = 0,
|
||||
Name_Element = 1,
|
||||
Name_Param = 2,
|
||||
Name_Block,
|
||||
Name_Keyword,
|
||||
Collection_Set,
|
||||
Collection_Bag,
|
||||
Collection_Array,
|
||||
Collection_List,
|
||||
Type_Const,
|
||||
Type_Entity,
|
||||
Type_type,
|
||||
Type_Rule,
|
||||
Type_Function,
|
||||
|
||||
|
||||
}
|
||||
|
||||
public abstract class ExpToken : IExpressionToken
|
||||
{
|
||||
|
||||
protected internal ExpToken _previousToken;
|
||||
protected internal ExpTokenType _tokenType;
|
||||
protected internal List<ExpToken> _nextLevelTokens = new List<ExpToken>(
|
||||
);
|
||||
protected internal string _name;
|
||||
|
||||
protected ExpSchema Context
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
protected ExpToken(string name,ExpSchema context)
|
||||
{
|
||||
_name = name;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public abstract object? Value
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public ICollection<IExpressionToken> NextLevel => ( _nextLevelTokens as ICollection<IExpressionToken> )!;
|
||||
|
||||
public int TokenTypeCode => ( int )_tokenType;
|
||||
|
||||
public string Name => _name;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Expression
|
||||
{
|
||||
public abstract class ExpCollectionBase : IEnumerable<ExpElementBase>
|
||||
{
|
||||
protected internal string _accurateType;
|
||||
protected internal ExpElementType _memberType;
|
||||
|
||||
protected ExpCollectionBase(
|
||||
ExpElementType memberType )
|
||||
{
|
||||
_memberType = memberType;
|
||||
}
|
||||
|
||||
public ExpElementType MemberType
|
||||
{
|
||||
get => _memberType;
|
||||
}
|
||||
|
||||
public abstract int Count { get; }
|
||||
|
||||
public abstract IEnumerator<ExpElementBase> GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class ExpList : ExpCollectionBase
|
||||
{
|
||||
public ExpList(ExpElementType type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private List<ExpElementBase> _collection = new List<ExpElementBase>();
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override IEnumerator<ExpElementBase> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class ExpSet : ExpCollectionBase
|
||||
{
|
||||
|
||||
private HashSet<ExpElementBase> _collection = new();
|
||||
|
||||
public ExpSet( (int,int) range, ExpElementType type )
|
||||
: base( type, range ) { }
|
||||
|
||||
public void Add( ExpElementBase token )
|
||||
{
|
||||
if( token.ElementType != _memberType ) {
|
||||
throw new ExpInvalidCollectionMemberTypeException( token,
|
||||
this );
|
||||
}
|
||||
_collection.Add( token );
|
||||
}
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override sealed IEnumerator<ExpElementBase> GetEnumerator()
|
||||
{
|
||||
return ( ( IEnumerable<ExpElementBase> )_collection ).GetEnumerator(
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpArray : ExpCollectionBase
|
||||
{
|
||||
|
||||
private ExpElementBase[] _collection;
|
||||
|
||||
public ExpArray( (int, int) range, ExpElementType type )
|
||||
: base( type, range ) { }
|
||||
|
||||
public ExpElementBase this[ int index ]
|
||||
{
|
||||
get { return _collection[ index ]; }
|
||||
set
|
||||
{
|
||||
if( value.ElementType != MemberType ) {
|
||||
throw new ExpInvalidCollectionMemberTypeException(
|
||||
value, this );
|
||||
}
|
||||
_collection[ index ] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override int Count => _collection.Length;
|
||||
public override IEnumerator<ExpElementBase> GetEnumerator()
|
||||
{
|
||||
return ( ( IEnumerable<ExpElementBase> )_collection ).GetEnumerator(
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExpBag : ExpCollectionBase
|
||||
{
|
||||
|
||||
private ConcurrentBag<ExpElementBase> _collection = new ConcurrentBag<ExpElementBase>(
|
||||
);
|
||||
|
||||
public ExpBag( ExpElementType type, (int,int) range )
|
||||
: base( type, range ) { }
|
||||
|
||||
public override int Count => _collection.Count;
|
||||
|
||||
public override IEnumerator<ExpElementBase> GetEnumerator()
|
||||
{
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Expression
|
||||
{
|
||||
public abstract class ExpCollectionInstanceBase : ExpToken
|
||||
{
|
||||
|
||||
protected internal (int min, int max) _range;
|
||||
protected internal ExpElementType _memberType;
|
||||
|
||||
public override sealed object? Value => CollectionValue;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user