daily update on 20250210 by nitload youmu

This commit is contained in:
Nitload
2025-02-10 12:48:02 +08:00
parent ae94c265ae
commit c23b640cae
70 changed files with 2135 additions and 805 deletions
@@ -34,9 +34,9 @@ namespace StgSharp.Script.Express
{
public class ExpBuiltinConstant<T> : ExpLiteralToken<T>
{
internal ExpBuiltinConstant( string name, T value )
: base( name, null!, value )
{
}
: base( name, null!, value ) { }
}
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BuiltinType.cs"
// file="ExpBuiltinType.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -39,26 +39,30 @@ namespace StgSharp.Script.Express
{
public abstract class ExpCollectionBase : IExpElementSource, IEnumerable<ExpElementInstanceBase>
{
protected internal string _accurateType;
protected ExpCollectionBase(
string accurateType )
protected ExpCollectionBase( string accurateType )
{
_accurateType = accurateType;
}
public ExpElementType ElementType => ExpElementType.Collection;
public abstract int Count
{
get;
}
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 abstract string Name
{
get;
}
public void Analyse()
{
@@ -72,6 +76,8 @@ namespace StgSharp.Script.Express
return GetEnumerator();
}
IScriptSourceProvider IExpElementSource.SourceProvider => null!;
}
public class ExpArray : ExpCollectionBase
@@ -79,8 +85,7 @@ namespace StgSharp.Script.Express
private ExpElementInstanceBase[] _collection;
public ExpArray( string accurateType )
: base( accurateType ) { }
public ExpArray( string accurateType ) : base( accurateType ) { }
public ExpElementInstanceBase this[ int index ]
{
@@ -97,12 +102,12 @@ namespace StgSharp.Script.Express
public override int Count => _collection.Length;
public override string Name => ExpCompile.AddOrGetString("ARRAY");
public override string Name => ExpCompile.AddOrGetString( "ARRAY" );
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
{
return ( ( IEnumerable<ExpElementInstanceBase> )_collection )
.GetEnumerator( );
.GetEnumerator();
}
}
@@ -113,12 +118,11 @@ namespace StgSharp.Script.Express
private ConcurrentBag<ExpElementInstanceBase> _collection = new ConcurrentBag<ExpElementInstanceBase>(
);
public ExpBag( string accurateType )
: base( accurateType ) { }
public ExpBag( string accurateType ) : base( accurateType ) { }
public override int Count => _collection.Count;
public override string Name => ExpCompile.AddOrGetString("BAG");
public override string Name => ExpCompile.AddOrGetString( "BAG" );
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
{
@@ -126,23 +130,24 @@ namespace StgSharp.Script.Express
}
}
public sealed class ExpList : ExpCollectionBase
{
public ExpList(string accurateType ):base(accurateType)
{
}
private List<ExpElementInstanceBase> _collection = new List<ExpElementInstanceBase>();
private List<ExpElementInstanceBase> _collection = new List<ExpElementInstanceBase>(
);
public ExpList( string accurateType ) : base( accurateType ) { }
public override int Count => _collection.Count;
public override string Name => ExpCompile.AddOrGetString("LIST");
public override string Name => ExpCompile.AddOrGetString( "LIST" );
public override IEnumerator<ExpElementInstanceBase> GetEnumerator()
{
return _collection.GetEnumerator();
}
}
public class ExpSet : ExpCollectionBase
@@ -150,8 +155,11 @@ namespace StgSharp.Script.Express
private HashSet<ExpElementInstanceBase> _collection = new();
public ExpSet( string accurateType )
: base( accurateType ) { }
public ExpSet( string accurateType ) : base( accurateType ) { }
public override int Count => _collection.Count;
public override string Name => ExpCompile.AddOrGetString( "SET" );
public void Add( ExpElementInstanceBase token )
{
@@ -162,16 +170,12 @@ namespace StgSharp.Script.Express
_collection.Add( token );
}
public override int Count => _collection.Count;
public override string Name => ExpCompile.AddOrGetString("SET");
public override sealed IEnumerator<ExpElementInstanceBase> GetEnumerator()
public override sealed IEnumerator<ExpElementInstanceBase> GetEnumerator(
)
{
return ( ( IEnumerable<ExpElementInstanceBase> )_collection )
.GetEnumerator( );
.GetEnumerator();
}
}
}
@@ -38,28 +38,24 @@ namespace StgSharp.Script.Express
{
public class ExpConstantCollectionSource : IExpImmutableElement
{
private IScriptSourceProvider _sourceProvider;
private Dictionary<string, ExpElementInstanceBase> _constants;
private IScriptSourceProvider _sourceProvider;
public ExpConstantCollectionSource(
IScriptSourceProvider sourceProvider )
{
_sourceProvider = sourceProvider;
_constants = new Dictionary<string, ExpElementInstanceBase>(
ExpCompile.Multiplexer);
ExpCompile.Multiplexer );
}
internal void AddConstant(string name, ExpElementInstanceBase value)
{
_constants.Add(name, value);
}
public static Dictionary<string, ExpElementInstanceBase> BuiltinConst => ExpCompile.BuiltinConst;
public ExpElementType ElementType => ExpElementType.Const;
public IScriptSourceProvider SourceProvider => _sourceProvider;
public static Dictionary<string, ExpElementInstanceBase> BuiltinConst => ExpCompile.BuiltinConst;
public string Name
{
get => ExpCompile.KeyWord.Constant;
@@ -70,26 +66,32 @@ namespace StgSharp.Script.Express
throw new NotImplementedException();
}
public ExpToken MakeReference(params object[] options)
public ExpToken MakeReference( params object[] options )
{
if (options.Length == 0 || options[0] is not string str)
{
if( options.Length == 0 || options[ 0 ] is not string str ) {
return null!;
}
if (_constants.Count == 0)
{
if( _constants.Count == 0 ) {
return null!;
}
if (_constants.TryGetValue(str, out var token))
{
if( _constants.TryGetValue( str,
out ExpElementInstanceBase? token ) ) {
return token;
}
return null!;
}
public bool TryGetConstant(string name, out ExpElementInstanceBase instance)
public bool TryGetConstant(
string name,
out ExpElementInstanceBase instance )
{
return _constants.TryGetValue(name, out instance);
return _constants.TryGetValue( name, out instance );
}
internal void AddConstant( string name, ExpElementInstanceBase value )
{
_constants.Add( name, value );
}
}
}
@@ -37,10 +37,8 @@ namespace StgSharp.Script.Express
public class ExpEntity : ExpToken
{
public ExpEntity( string name ,ExpSchema context):
base(name, context)
{
}
public ExpEntity( string name, ExpSchema context )
: base( name, context ) { }
}
@@ -72,5 +70,6 @@ namespace StgSharp.Script.Express
{
throw new NotImplementedException();
}
}
}
@@ -36,13 +36,14 @@ 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 ExpFunction( string name, ExpSchema context )
: base( name, context ) { }
public ExpElementType ElementType => ExpElementType.Function;
@@ -75,9 +76,10 @@ namespace StgSharp.Script.Express
throw new NotImplementedException();
}
public ExpToken MakeReference(params object[] options)
public ExpToken MakeReference( params object[] options )
{
throw new NotImplementedException();
}
}
}
@@ -37,15 +37,16 @@ namespace StgSharp.Script.Express
{
public class ExpRule : ExpElementInstanceBase
{
private ExpRuleSource _source;
public ExpRule(string name, ExpSchema context) : base(name,context)
{
}
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
@@ -71,9 +72,10 @@ namespace StgSharp.Script.Express
throw new NotImplementedException();
}
public ExpToken MakeReference(params object[] options)
public ExpToken MakeReference( params object[] options )
{
throw new NotImplementedException();
}
}
}
@@ -37,14 +37,12 @@ namespace StgSharp.Script.Express
{
public class ExpType : ExpElementInstanceBase
{
public ExpType( string name, ExpSchema context )
: base( name, context ) { }
public override string TypeName => throw new NotImplementedException();
public ExpType(string name, ExpSchema context) : base(name, context)
{
}
}
public class ExpTypeSource : IExpElementSource
@@ -46,30 +46,28 @@ namespace StgSharp.Script.Express
public class ExpInvalidCharException : Exception
{
public ExpInvalidCharException(char c) :
base($"An unknown char {c} occurred.")
{
}
public ExpInvalidCharException( char c )
: base( $"An unknown char {c} occurred." ) { }
}
public class ExpInvalidTokenException : Exception
{
public ExpInvalidTokenException(int index) :
base($"Cannot read a token from line at {index}")
{
}
public ExpInvalidTokenException( int index )
: base( $"Cannot read a token from line at {index}" ) { }
}
public class ExpInvalidTypeDeclareEndingExceptions : Exception
{
public ExpInvalidTypeDeclareEndingExceptions(
string declaredName,
string endedName )
: base(
$"The datatype is declared with name {declaredName} " +
$"but ended with {endedName}" ) { }
$"The datatype is declared with name {declaredName} " + $"but ended with {endedName}" ) { }
}
@@ -0,0 +1,80 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpIfToken.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Script.Express;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public sealed class ExpIfToken : ExpToken
{
private ExpToken _rule;
private List<ExpToken> _falseOp;
private List<ExpToken> _trueOp;
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 AddFalseOperation( ExpToken expressionRoot )
{
AssertSchemaInclude( expressionRoot );
_falseOp.Add( expressionRoot );
}
public void AddTrueOperation( ExpToken expressionRoot )
{
AssertSchemaInclude( expressionRoot );
_trueOp.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 ExpLogic 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 override string TypeName => _type.Name;
public T value => _value;
public override bool TryGetNextLevel(
out ICollection<IExpressionToken> nextLevel )
{
nextLevel = null!;
return false;
}
}
}
@@ -0,0 +1,98 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 ExpElementInstanceBase _variable, _begin, _end, _increment;
private List<ExpToken> _token = new List<ExpToken>();
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,111 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSwitchToken.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 ExpSwitchToken : ExpToken
{
private Dictionary<ExpToken, List<ExpToken>> _cases;
private ExpToken _target;
private List<ExpToken> _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( (ExpToken label, IEnumerable<ExpToken> op) 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 List<ExpToken> this[ ExpToken index ]
{
get
{
if( _cases.TryGetValue( index, out List<ExpToken>? ret ) ) {
return ret;
}
return _default;
}
}
/// <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 List<ExpToken>? op ) ) {
op.Add( expressionRoot );
} else {
throw new ExpCaseNotFoundException( this, label );
}
}
public void AddOperationToDefault( ExpToken expressionRoot )
{
if( expressionRoot != null ) {
_default.Add( expressionRoot );
}
}
public bool ContainsCase( ExpToken token )
{
return _cases.ContainsKey( token );
}
}
}
@@ -0,0 +1,127 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 ref struct ExpTokenSource
{
public ReadOnlySpan<char> Value;
public readonly int Line;
public readonly int Column;
public ExpTokenSource(ReadOnlySpan<char> chars, int lineNumber, int columnNumber)
{
Value = chars; Line = lineNumber; Column = columnNumber;
}
}
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 ExpSchema Context
{
get;
private set;
}
public long TokenTypeCode => ( long )_tokenType;
public string Name => _name;
public virtual bool TryGetNextLevel(
out ICollection<IExpressionToken> nextLevel )
{
nextLevel = ( _nextLevelTokens as ICollection<IExpressionToken> )!;
return true;
}
protected void AssertSchemaInclude( ExpToken expressionRoot )
{
if( expressionRoot.Context != Context && Context.HasSchemaInclude(
expressionRoot.Context ) ) {
throw new ExpInvalidSchemaIncludeException(
Context, expressionRoot.Context );
}
}
}
}
@@ -41,13 +41,12 @@ namespace StgSharp.Script.Express
{
public static partial class ExpCompile
{
private static ConcurrentStringHashMultiplexer _multiplexer;
private static Dictionary<string, ExpElementInstanceBase> _builtinConst;
private static Dictionary<string, ExpTypeSource> _builtinType;
private static StringPool _compileStringCache;
public static Dictionary<string, ExpElementInstanceBase> BuiltinConst => _builtinConst;
internal static ConcurrentStringHashMultiplexer Multiplexer
@@ -71,9 +70,13 @@ namespace StgSharp.Script.Express
_compileStringCache.Reset();
}
public static void SkipComment(IScriptSourceProvider source)
public static void DeinitCompile()
{
_compileStringCache.Reset();
_compileStringCache = null;
_multiplexer.Dispose();
_multiplexer = null;
}
public static void InitCompile()
@@ -83,17 +86,27 @@ namespace StgSharp.Script.Express
_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 ) ) } };
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( ExpLogic ) ) }
};
_builtinConst = new Dictionary<string, ExpElementInstanceBase>(
_multiplexer ) {
@@ -104,14 +117,7 @@ namespace StgSharp.Script.Express
};
}
public static void DeinitCompile()
{
_compileStringCache.Reset();
_compileStringCache = null;
_multiplexer.Dispose();
_multiplexer = null;
}
public static void SkipComment( IScriptSourceProvider source ) { }
public static bool TryGetBuiltinConst(
string constName,
@@ -100,7 +100,8 @@ namespace StgSharp.Script.Express
public interface IExpImmutableElement : IExpElementSource
{
public abstract ExpToken MakeReference(params object[] options);
public abstract ExpToken MakeReference( params object[] options );
}
}
@@ -34,11 +34,14 @@ using System.Text;
namespace StgSharp.Script.Express
{
public class ExpExpressionTree : AbstractSyntaxTree<ExpToken>
public class ExpExpressionTree : AbstractSyntaxTree<ExpToken>
{
public ExpToken RootToken { get; private set; }
public ExpToken RootToken
{
get;
private set;
}
}
}
@@ -1,13 +1,73 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpLogic.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public enum Logic
public enum ExpLogic
{
Unknown = 0,
False = 1,
True = 2,
}
public static class LogicConverter
{
public static bool? AsNullableBool(this ExpLogic l)
{
switch (l)
{
case ExpLogic.Unknown:
return null;
case ExpLogic.False:
return false;
case ExpLogic.True:
return true;
default:
throw new ArgumentException();
}
}
public static ExpLogic AsNullableInt(this bool? b)
{
return b switch
{
null => ExpLogic.Unknown,
true => ExpLogic.True,
false => ExpLogic.False,
};
}
}
}
@@ -40,6 +40,7 @@ namespace StgSharp.Script.Express
{
public class ExpSchema
{
private readonly ConcurrentStringHashMultiplexer _multiplexer = ExpCompile.Multiplexer;
private Dictionary<string, ExpConstantCollectionSource> _constDict;
private Dictionary<string, ExpEntitySource> _entityDict;
@@ -50,12 +51,18 @@ namespace StgSharp.Script.Express
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);
_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
@@ -66,8 +73,8 @@ namespace StgSharp.Script.Express
public ExpTypeSource GetExpType( string typeName )
{
if( ExpCompile.TryGetBuiltinType(
typeName, out ExpTypeSource? ret ) ) {
if( ExpCompile.TryGetBuiltinType( typeName,
out ExpTypeSource? ret ) ) {
return ret;
}
if( _typeDict.TryGetValue( typeName, out ret ) ) {
@@ -86,20 +93,21 @@ namespace StgSharp.Script.Express
return _schemaInclude.ContainsKey( schema.Name );
}
public bool TryGetConstant(string name, out ExpElementInstanceBase constInstance)
public bool TryGetConstant(
string name,
out ExpElementInstanceBase constInstance )
{
if (ExpCompile.BuiltinConst.TryGetValue(name, out constInstance))
{
if( ExpCompile.BuiltinConst.TryGetValue( name,
out constInstance ) ) {
return true;
}
foreach (var item in _constDict.Values)
{
if (item.TryGetConstant(name, out constInstance))
{
foreach( ExpConstantCollectionSource item in _constDict.Values ) {
if( item.TryGetConstant( name, out constInstance ) ) {
return true;
}
}
return false;
}
}
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSchema.cs"
// file="ExpSchemaSource.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -43,39 +43,6 @@ namespace StgSharp.Script.Express
{
public partial class ExpSchemaSource
{
[GeneratedRegex(@"\s*END_CONSTANT;")]
private static partial Regex GetConstDefineEnd();
private static Regex
_constDefineBegin = GetConstDefineBegin(),
_constDefineEnd = GetConstDefineEnd(),
_schemaBegin = GetSchemaBegin(),
_schemaEnd = new Regex(
@"END_SCHEMA;\s*--\s*(?<namespace>[A-Za-z0-9_]+)",
RegexOptions.Compiled ),
_entityDefineBegin = new Regex(
@"\s*ENTITY\s*(?<TypeName>[A-Za-z0-9_]+)\s*", RegexOptions.Compiled ),
_entityDefineEnd = new Regex(
@"\s*END_ENTITY;\s*--\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
RegexOptions.Compiled ),
_typeDefineBegin = new Regex(
@"\s*TYPE\s+(?<TypeName>[A-Za-z0-9_]+)\s*=\s*(?<Remaining>[A-Z]+)",
RegexOptions.Compiled ),
_typeDefineEnd = new Regex(
@"\s*END_TYPE\s*;\s*--\s*(?<TypeName>[a-zA-Z0-9_]+)",
RegexOptions.Compiled ),
_functionDefineBegin = new Regex(
@"\s*FUNCTION\s*\s*(?<FunctionName>[a-zA-Z0-9_]+)\s*(?<Remaining>.*)",
RegexOptions.Compiled ),
_functionDefineEnd = new Regex(
@"\s*END_FUNCTION\s*;\s*--\s*(?<FunctionName>[a-zA-Z0-9_]+)",
RegexOptions.Compiled ),
_ruleDefineBegin = new Regex(
@"\s*RULE\s*(?<RuleName>[a-zA-Z0-9_]+)\s*FOR\s*\((?<Target>[a-zA-Z0-9_]*(\s*\)\s*;)?)",
RegexOptions.Compiled ),
_ruleDefineEnd = new Regex(
@"\s*END_RULE\s*;\s*--\s*(?<RuleName>[A-Za-z0-9_]+)",
RegexOptions.Compiled );
private Dictionary<string, IExpElementSource> _sourceCache = new();
@@ -83,16 +50,14 @@ namespace StgSharp.Script.Express
private string name;
public string Name
public ExpSchemaSource() { }
public string Name
{
get => _compileResult.Name;
internal set => _compileResult.Name = value;
}
public ExpSchemaSource() { }
public void ReadSchema( ExpFileSource reader )
{
string line = reader.ReadLine();
@@ -159,6 +124,15 @@ namespace StgSharp.Script.Express
return true;
}
[GeneratedRegex( @"\s*CONSTANT" )]
private static partial Regex GetConstDefineBegin();
[GeneratedRegex( @"\s*END_CONSTANT;" )]
private static partial Regex GetConstDefineEnd();
[GeneratedRegex( @"\s*SCHEMA\s*(?<namespace>[A-Za-z0-9_]+)\s?;" )]
private static partial Regex GetSchemaBegin();
private bool TryReadConst(
string firstLine,
ExpFileSource reader,
@@ -167,7 +141,7 @@ namespace StgSharp.Script.Express
Match match = _constDefineBegin.Match( firstLine );
if( match.Success ) {
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_CONSTANT",reader.Location );
"END_CONSTANT", reader.Location );
ExpConstantCollectionSource _source = new ExpConstantCollectionSource(
transmitter );
string line = reader.ReadLine();
@@ -191,7 +165,7 @@ namespace StgSharp.Script.Express
Match match = _entityDefineBegin.Match( firstLine );
if( match.Success ) {
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_ENTITY", reader.Location);
"END_ENTITY", reader.Location );
ExpEntitySource _source = new ExpEntitySource(
match.Groups[ "TypeName" ].ToString(), transmitter );
string line = reader.ReadLine();
@@ -222,7 +196,7 @@ namespace StgSharp.Script.Express
Match match = _functionDefineBegin.Match( firstLine );
if( match.Success ) {
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_FUNCTION", reader.Location);
"END_FUNCTION", reader.Location );
ExpFunctionSource _source = new ExpFunctionSource(
match.Groups[ "FunctionName" ].ToString(), transmitter );
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
@@ -254,7 +228,7 @@ namespace StgSharp.Script.Express
Match match = _ruleDefineBegin.Match( firstLine );
if( match.Success ) {
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_RULE", reader.Location);
"END_RULE", reader.Location );
ExpRuleSource _source = new ExpRuleSource(
match.Groups[ "RuleName" ].ToString(), transmitter );
string target = match.Groups[ "Target" ].ToString();
@@ -289,7 +263,7 @@ namespace StgSharp.Script.Express
Match match = _typeDefineBegin.Match( firstLine );
if( match.Success ) {
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_ENTITY", reader.Location);
"END_ENTITY", reader.Location );
ExpTypeSource _source = new ExpTypeSource(
match.Groups[ "TypeName" ].ToString(), transmitter );
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
@@ -313,11 +287,37 @@ namespace StgSharp.Script.Express
return false;
}
[GeneratedRegex(@"\s*CONSTANT")]
private static partial Regex GetConstDefineBegin();
private static Regex
_constDefineBegin = GetConstDefineBegin(),
_constDefineEnd = GetConstDefineEnd(),
_schemaBegin = GetSchemaBegin(),
_schemaEnd = new Regex(
@"END_SCHEMA;\s*--\s*(?<namespace>[A-Za-z0-9_]+)",
RegexOptions.Compiled ),
_entityDefineBegin = new Regex(
@"\s*ENTITY\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
RegexOptions.Compiled ),
_entityDefineEnd = new Regex(
@"\s*END_ENTITY;\s*--\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
RegexOptions.Compiled ),
_typeDefineBegin = new Regex(
@"\s*TYPE\s+(?<TypeName>[A-Za-z0-9_]+)\s*=\s*(?<Remaining>[A-Z]+)",
RegexOptions.Compiled ),
_typeDefineEnd = new Regex(
@"\s*END_TYPE\s*;\s*--\s*(?<TypeName>[a-zA-Z0-9_]+)",
RegexOptions.Compiled ),
_functionDefineBegin = new Regex(
@"\s*FUNCTION\s*\s*(?<FunctionName>[a-zA-Z0-9_]+)\s*(?<Remaining>.*)",
RegexOptions.Compiled ),
_functionDefineEnd = new Regex(
@"\s*END_FUNCTION\s*;\s*--\s*(?<FunctionName>[a-zA-Z0-9_]+)",
RegexOptions.Compiled ),
_ruleDefineBegin = new Regex(
@"\s*RULE\s*(?<RuleName>[a-zA-Z0-9_]+)\s*FOR\s*\((?<Target>[a-zA-Z0-9_]*(\s*\)\s*;)?)",
RegexOptions.Compiled ),
_ruleDefineEnd = new Regex(
@"\s*END_RULE\s*;\s*--\s*(?<RuleName>[A-Za-z0-9_]+)",
RegexOptions.Compiled );
[GeneratedRegex(@"\s*SCHEMA\s*(?<namespace>[A-Za-z0-9_]+)\s?;")]
private static partial Regex GetSchemaBegin();
}
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpReader.cs"
// file="ExpSource.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -64,10 +64,10 @@ namespace StgSharp.Script.Express
_memoryReader = new StreamReader( _expMemoryMappedStream );
}
public int Location => _location;
public bool IsEmpty => _memoryReader.EndOfStream;
public int Location => _location;
// ~ExpFileSource()
// {
// Dispose(disposing: false);
@@ -79,10 +79,14 @@ namespace StgSharp.Script.Express
GC.SuppressFinalize( this );
}
public void EndWriting()
{
}
public string ReadLine()
{
readLineSemaphore.Wait();
string line = _memoryReader.ReadLine();
string line = _memoryReader.ReadLine()!;
_location++;
readLineSemaphore.Release();
return line;
@@ -96,6 +100,11 @@ namespace StgSharp.Script.Express
readLineSemaphore.Release();
}
public IScriptSourceProvider Slice(int location, int count)
{
throw new NotImplementedException();
}
protected virtual void Dispose( bool disposing )
{
if( !disposedValue ) {
@@ -63,50 +63,50 @@ namespace StgSharp.Script.Express
_isReadingMultiLineComment = false;
}
public int LineNumber
{
get => _provider.Location;
}
public bool IsEmpty
{
get => (( string.IsNullOrEmpty( _lineCache ) ||
_current >= _lineCache.Length )) && _provider.IsEmpty;
get => ( ( string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length ) ) && _provider.IsEmpty;
}
/// <summary>
/// <para>Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// <para> Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// begins with part of multi-line comment will automatically remove the comment part, but
/// beginning with a full multi-line comment will not causing removing.</para> <para> (*Just
/// Like The Comment Here*) Will Not Be Removed </para>
/// beginning with a full multi-line comment will not causing removing. </para> <para>(*Just
/// Like The Comment Here*) Will Not Be Removed</para>
/// </summary>
/// <returns></returns>
public unsafe ReadOnlySpan<char> ReadLine()
{
bool lineOver = string.IsNullOrEmpty(_lineCache) || _current >=
_lineCache.Length;
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length;
while( lineOver || _isReadingMultiLineComment ) {
if (lineOver)
{
do
{
if( lineOver ) {
do {
_lineCache = _provider.ReadLine();
} while (string.IsNullOrEmpty(_lineCache));
} while (string.IsNullOrEmpty( _lineCache ));
_current = 0;
}
if( _isReadingMultiLineComment ) {
int index;
fixed( char* cPtr = _lineCache.AsSpan(_current) ) {
fixed( char* cPtr = _lineCache.AsSpan( _current ) ) {
index = UnsafeCompute.IndexOfCharPair(
cPtr, MultiLineEnd, _lineCache.Length );
}
if (index == -1)
{
if( index == -1 ) {
_lineCache = string.Empty;
}
else
{
} else {
_isReadingMultiLineComment = false;
_current += index + 2;
}
}
lineOver = string.IsNullOrEmpty(_lineCache) || _current >=
_lineCache.Length;
lineOver = string.IsNullOrEmpty( _lineCache ) || _current >=
_lineCache.Length;
}
return _lineCache.AsSpan().Slice( _current );
}
@@ -118,99 +118,96 @@ namespace StgSharp.Script.Express
ReadOnlySpan<char> source = ReadLine();
char c = source[ 0 ];
if (char.IsLetter(c)) {
if( char.IsLetter( c ) ) {
Match match = _nextWordTokenPattern.Match(
_lineCache, _current);
if (match.Success) {
begin = match.Groups[Token].Index;
end = match.Groups[End].Index;
rest = match.Groups[Rest].Index;
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return source.Slice(0, end - begin);
return source.Slice( 0, end - begin );
} else {
throw new ExpInvalidTokenException(_current);
throw new ExpInvalidTokenException( _current );
}
} else if (char.IsPunctuation(c) || char.IsSymbol(c)) {
switch (c) {
} else if( char.IsPunctuation( c ) || char.IsSymbol( c ) ) {
switch( c ) {
case '"':
Match match = _nextStringLiteralPattern.Match(
_lineCache, _current);
if (match.Success) {
begin = match.Groups["token"].Index;
end = match.Groups["end"].Index;
rest = match.Groups["rest"].Index;
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ "token" ].Index;
end = match.Groups[ "end" ].Index;
rest = match.Groups[ "rest" ].Index;
_current = rest;
return source[..(end - begin)];
return source[ ..( end - begin ) ];
} else {
throw new ExpInvalidCharException('\"');
throw new ExpInvalidCharException( '\"' );
}
case '(':
char cNext = source[1];
if (cNext == '*') {
char cNext = source[ 1 ];
if( cNext == '*' ) {
_isReadingMultiLineComment = true;
_current += 2;
goto readLine;
} else {
return source[..1];
return source[ ..1 ];
}
case '-':
// 1. -number
// 2. -- comment
// 3. - number type param
cNext = source[1];
if (char.IsNumber(cNext)) {
cNext = source[ 1 ];
if( char.IsNumber( cNext ) ) {
match = _nextNumberLiteralPattern.Match(
_lineCache, _current);
if (match.Success) {
begin = match.Groups[Token].Index;
end = match.Groups[End].Index;
rest = match.Groups[Rest].Index;
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return source[..(end - begin)];
return source[ ..( end - begin ) ];
} else {
throw new ExpInvalidTokenException(_current);
throw new ExpInvalidTokenException( _current );
}
} else if (cNext == '-') {
} else if( cNext == '-' ) {
_lineCache = string.Empty;
_current = 0;
goto readLine;
} else {
_current++;
return source[..1];
return source[ ..1 ];
}
case ')' or '[' or ']' or '{' or '}' or
case ')' or '[' or ']' or '{' or '}' or ':' or ';' or
'+' or '/' or '\\' or '*' or '.' or ',':
_current++;
return source[..1];
return source[ ..1 ];
default:
throw new ExpInvalidCharException(c);
throw new ExpInvalidCharException( c );
}
} else if (char.IsNumber(c)) {
} else if( char.IsNumber( c ) ) {
Match match = _nextNumberLiteralPattern.Match(
_lineCache, _current);
if (match.Success) {
begin = match.Groups[Token].Index;
end = match.Groups[End].Index;
rest = match.Groups[Rest].Index;
_lineCache, _current );
if( match.Success ) {
begin = match.Groups[ Token ].Index;
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return source[..(end - begin)];
return source[ ..( end - begin ) ];
} else {
throw new ExpInvalidTokenException(_current);
throw new ExpInvalidTokenException( _current );
}
} else if (char.IsWhiteSpace(c)) {
Match match = _skipBlankPattern.Match(_lineCache, _current);
if (match.Success)
{
rest = match.Groups[Rest].Index;
} else if( char.IsWhiteSpace( c ) ) {
Match match = _skipBlankPattern.Match( _lineCache, _current );
if( match.Success ) {
rest = match.Groups[ Rest ].Index;
_current = rest;
goto readLine;
} else {
throw new ExpInvalidTokenException( _current );
}
else
{
throw new ExpInvalidTokenException(_current);
}
}else {
} else {
throw new ExpInvalidCharException( c );
}
}
@@ -0,0 +1,28 @@
using StgSharp.Script.Express;
using StgSharp.Threading;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpTokenGenerator
{
private ExpExpressionTree _context;
private IScriptSourceProvider _provider;
private List<ExpToken> _contextLevelList;
public ExpTokenGenerator(IScriptSourceProvider sourceProvider)
{
_provider = sourceProvider;
}
public void AnalyseLine()
{
}
}
}