daily update on 20240203 by nitload youmu, ExpComment Comment Splitter ok, case code(* comment[comment*)code--comment and comment*)code--comment not added, may use span optimize all programme

This commit is contained in:
Nitload
2025-02-03 23:27:54 +08:00
parent 4ee675669f
commit 4e5a1b0dfb
48 changed files with 1247 additions and 662 deletions
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script
{
public static class CodeLineHelper
{
public static string SliceAndTrim(this string line, int startIndex, int length)
{
if (line == null) throw new ArgumentNullException(nameof(line));
if (startIndex < 0 || startIndex >= line.Length)
throw new ArgumentOutOfRangeException(nameof(startIndex));
if (length < 0 || startIndex + length > line.Length)
throw new ArgumentOutOfRangeException(nameof(length));
ReadOnlySpan<char> sourceSpan = line.AsSpan();
ReadOnlySpan<char> subSpan = sourceSpan.Slice(startIndex, length);
int start = 0;
while (start < subSpan.Length && char.IsWhiteSpace(subSpan[start]))
{
start++;
}
int end = subSpan.Length - 1;
while (end >= start && char.IsWhiteSpace(subSpan[end]))
{
end--;
}
if (start > end)
{
return string.Empty;
}
int finalLength = end - start + 1;
return new string(subSpan.Slice(start, finalLength));
}
public static string SliceAndTrim(this string line, int startIndex)
{
if (line == null) throw new ArgumentNullException(nameof(line));
if (startIndex < 0 || startIndex >= line.Length)
throw new ArgumentOutOfRangeException(nameof(startIndex));
ReadOnlySpan<char> sourceSpan = line.AsSpan();
ReadOnlySpan<char> subSpan = sourceSpan.Slice(startIndex);
int start = 0;
while (start < subSpan.Length && char.IsWhiteSpace(subSpan[start]))
{
start++;
}
int end = subSpan.Length - 1;
while (end >= start && char.IsWhiteSpace(subSpan[end]))
{
end--;
}
if (start > end)
{
return string.Empty;
}
int finalLength = end - start + 1;
return new string(subSpan.Slice(start, finalLength));
}
}
}
@@ -0,0 +1,42 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpBuiltinConstant.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;
namespace StgSharp.Script.Express
{
public class ExpBuiltinConstant<T> : ExpLiteralToken<T>
{
internal ExpBuiltinConstant( string name, T value )
: base( name, null!, value )
{
}
}
}
@@ -0,0 +1,54 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BuiltinType.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public sealed class ExpBuiltinType : ExpTypeSource
{
private Type _marshalType;
internal ExpBuiltinType( string name, Type origin )
: base( name, null! )
{
_marshalType = origin;
}
public override void Analyse()
{
return;
}
}
}
@@ -39,14 +39,11 @@ namespace StgSharp.Script.Express
public class ExpConstantCollectionSource : IExpImmutableElement
{
private IScriptSourceProvider _sourceProvider;
private string _name;
private Dictionary<string, ExpElementInstanceBase> _constants;
public ExpConstantCollectionSource(
string name,
IScriptSourceProvider sourceProvider )
{
_name = name;
_sourceProvider = sourceProvider;
_constants = new Dictionary<string, ExpElementInstanceBase>(
ExpCompile.Multiplexer);
@@ -61,11 +58,11 @@ namespace StgSharp.Script.Express
public IScriptSourceProvider SourceProvider => _sourceProvider;
public static Dictionary<string, ExpConstantCollectionSource> BuiltinConst => ExpCompile.BuiltinConst;
public static Dictionary<string, ExpElementInstanceBase> BuiltinConst => ExpCompile.BuiltinConst;
public string Name
{
get => _name;
get => ExpCompile.KeyWord.Constant;
}
public virtual void Analyse()
@@ -75,7 +72,24 @@ namespace StgSharp.Script.Express
public ExpToken MakeReference(params object[] options)
{
throw new NotImplementedException();
if (options.Length == 0 || options[0] is not string str)
{
return null!;
}
if (_constants.Count == 0)
{
return null!;
}
if (_constants.TryGetValue(str, out var token))
{
return token;
}
return null!;
}
public bool TryGetConstant(string name, out ExpElementInstanceBase instance)
{
return _constants.TryGetValue(name, out instance);
}
}
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpInit.cs"
// file="ExpCompile.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -41,13 +41,25 @@ namespace StgSharp.Script.Express
{
public static partial class ExpCompile
{
private static ConcurrentStringHashMultiplexer _multiplexer;
private static Dictionary<string, ExpConstantCollectionSource> _builtinConst;
private static Dictionary<string, ExpElementInstanceBase> _builtinConst;
private static Dictionary<string, ExpTypeSource> _builtinType;
private static StringPool _compileStringCache;
public static Dictionary<string, ExpConstantCollectionSource> BuiltinConst => _builtinConst;
public static Dictionary<string, ExpElementInstanceBase> BuiltinConst => _builtinConst;
internal static ConcurrentStringHashMultiplexer Multiplexer
{
get
{
if( _multiplexer == null ) {
throw new ExpCompileNotInitializedException();
}
return _multiplexer;
}
}
public static string AddOrGetString( string str )
{
@@ -59,63 +71,65 @@ namespace StgSharp.Script.Express
_compileStringCache.Reset();
}
public static bool TryGetBuiltinType(string typename, out ExpTypeSource typeSource)
public static void SkipComment(IScriptSourceProvider source)
{
return _builtinType.TryGetValue( typename, out typeSource );
}
public static bool TryGetBuiltinConst(string constName, out ExpConstantCollectionSource source)
{
return _builtinConst.TryGetValue(constName, out source);
}
internal static ConcurrentStringHashMultiplexer Multiplexer
{
get
{
if (_multiplexer == null)
{
throw new ExpCompileNotInitializedException();
}
return _multiplexer;
}
}
public static void InitCompile()
{
_compileStringCache = new StringPool();
_multiplexer = new ConcurrentStringHashMultiplexer();
_builtinConst = new Dictionary<string, ExpConstantCollectionSource>(_multiplexer){
{ AddOrGetString( "PI" ), new ExpBuiltinConst<float>(
_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 ) ) } };
_builtinConst = new Dictionary<string, ExpElementInstanceBase>(
_multiplexer ) {
{ AddOrGetString( "PI" ), new ExpBuiltinConstant<float>(
AddOrGetString( "PI" ), MathF.PI ) },
{ AddOrGetString( "E" ), new ExpBuiltinConst<float>(
{ AddOrGetString( "E" ), new ExpBuiltinConstant<float>(
AddOrGetString( "E" ), MathF.E ) },
};
//TODO keep on here
_builtinType = new Dictionary<string, ExpTypeSource>(_multiplexer){
{ AddOrGetString( KeyWord.Int ), new ExpBuiltinType(
AddOrGetString( KeyWord.Int ), typeof( int ) ) },
{ AddOrGetString( KeyWord.Real ), new ExpBuiltinType(
AddOrGetString( KeyWord.Real ), typeof( float ) ) },
{ AddOrGetString( KeyWord.Bool ), new ExpBuiltinType(
AddOrGetString( KeyWord.Bool ), typeof( bool ) ) },
{ AddOrGetString( KeyWord.Binary ), new ExpBuiltinType(
AddOrGetString( KeyWord.Binary ), typeof( bool ) ) },
{ AddOrGetString( KeyWord.String ), new ExpBuiltinType(
AddOrGetString( KeyWord.String ), typeof( string ) ) },
{ AddOrGetString(KeyWord.Logic),new ExpBuiltinType(
AddOrGetString(KeyWord.Logic), typeof(Logic)) }
};
}
public static bool TryGetBuiltinConst(
string constName,
out ExpElementInstanceBase source )
{
return _builtinConst.TryGetValue( constName, out source );
}
public static bool TryGetBuiltinType(
string typename,
out ExpTypeSource typeSource )
{
return _builtinType.TryGetValue( typename, out typeSource );
}
public static class KeyWord
{
public const string Int = "INTAGER",
Real = "REAL",
Bool = "BOOLEAN",
String = "STRING",
Logic = "LOGIC",
Binary = "BINARY";
Binary = "BINARY",
Constant = "CONSTANT";
}
}
}
@@ -28,6 +28,8 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using CommunityToolkit.HighPerformance.Helpers;
using StgSharp.Collections;
using System;
@@ -84,22 +86,20 @@ namespace StgSharp.Script.Express
return _schemaInclude.ContainsKey( schema.Name );
}
public bool TryGetConst(string name, out ExpElementInstanceBase constInstance)
public bool TryGetConstant(string name, out ExpElementInstanceBase constInstance)
{
if (ExpCompile.BuiltinConst.TryGetValue(name, out constInstance))
{
}
}
public ExpToken SearchConstDeclare( string typeName )
{
ExpToken constant;
foreach (var item in ExpCompile.BuiltinConst.Values)
{
return true;
}
throw new KeyNotFoundException();
foreach (var item in _constDict.Values)
{
if (item.TryGetConstant(name, out constInstance))
{
return true;
}
}
return false;
}
}
}
@@ -95,7 +95,7 @@ namespace StgSharp.Script.Express
public ExpSchemaSource() { }
public void ReadSchema( ExpFileReader reader )
public void ReadSchema( ExpFileSource reader )
{
string line = reader.ReadLine();
while( !_schemaBegin.IsMatch( line ) ) {
@@ -122,7 +122,7 @@ namespace StgSharp.Script.Express
public static bool TryReadSchema(
string firstLine,
ExpFileReader reader,
ExpFileSource reader,
out ExpSchemaSource source )
{
if( !_schemaBegin.IsMatch( firstLine ) ) {
@@ -163,15 +163,15 @@ namespace StgSharp.Script.Express
private bool TryReadConst(
string firstLine,
ExpFileReader reader,
ExpFileSource reader,
out IExpElementSource source )
{
Match match = _constDefineBegin.Match( firstLine );
if( match.Success ) {
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_CONSTANT" );
"END_CONSTANT",reader.Location );
ExpConstantCollectionSource _source = new ExpConstantCollectionSource(
"Constant", transmitter );
transmitter );
string line = reader.ReadLine();
while( !_constDefineEnd.IsMatch( line ) ) {
transmitter.WriteLine( line );
@@ -187,13 +187,13 @@ namespace StgSharp.Script.Express
private bool TryReadEntity(
string firstLine,
ExpFileReader reader,
ExpFileSource reader,
out IExpElementSource source )
{
Match match = _entityDefineBegin.Match( firstLine );
if( match.Success ) {
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_ENTITY" );
"END_ENTITY", reader.Location);
ExpEntitySource _source = new ExpEntitySource(
match.Groups[ "TypeName" ].ToString(), transmitter );
string line = reader.ReadLine();
@@ -218,13 +218,13 @@ namespace StgSharp.Script.Express
private bool TryReadFunction(
string firstLine,
ExpFileReader reader,
ExpFileSource reader,
out IExpElementSource source )
{
Match match = _functionDefineBegin.Match( firstLine );
if( match.Success ) {
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_FUNCTION" );
"END_FUNCTION", reader.Location);
ExpFunctionSource _source = new ExpFunctionSource(
match.Groups[ "FunctionName" ].ToString(), transmitter );
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
@@ -250,13 +250,13 @@ namespace StgSharp.Script.Express
private bool TryReadRule(
string firstLine,
ExpFileReader reader,
ExpFileSource reader,
out IExpElementSource source )
{
Match match = _ruleDefineBegin.Match( firstLine );
if( match.Success ) {
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_RULE" );
"END_RULE", reader.Location);
ExpRuleSource _source = new ExpRuleSource(
match.Groups[ "RuleName" ].ToString(), transmitter );
string target = match.Groups[ "Target" ].ToString();
@@ -285,13 +285,13 @@ namespace StgSharp.Script.Express
private bool TryReadType(
string firstLine,
ExpFileReader reader,
ExpFileSource reader,
out IExpElementSource source )
{
Match match = _typeDefineBegin.Match( firstLine );
if( match.Success ) {
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_ENTITY" );
"END_ENTITY", reader.Location);
ExpTypeSource _source = new ExpTypeSource(
match.Groups[ "TypeName" ].ToString(), transmitter );
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
@@ -0,0 +1,113 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpReader.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Text;
using System.Threading;
namespace StgSharp.Script.Express
{
public class ExpFileSource : 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 ExpFileSource( 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;
public bool IsEmpty => _memoryReader.EndOfStream;
// ~ExpFileSource()
// {
// 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,143 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSourceReader.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.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
namespace StgSharp.Script.Express
{
public class ExpSourceReader
{
private static Regex
_commentSplitter = new Regex(
@"(?<code>\S*)\s*--.*", RegexOptions.Compiled ),
_multiLineCommentBegin = new Regex(
@"(?<code>\S*)\s*\(\*.*", RegexOptions.Compiled ),
_multiLineCommentEnd = new Regex(
@".*\*\)\s*(?<code>\S*)", RegexOptions.Compiled );
private bool _isReadingMultiLineComment;
private IScriptSourceProvider _provider;
public ExpSourceReader( IScriptSourceProvider provider )
{
_provider = provider;
}
public string ReadLine()
{
return _provider.ReadLine();
}
public string ReadNoCommentLine()
{
string line = string.Empty;
while( TryReadNoCommentLine( ref line ) ) { }
return line;
}
//Returns true when no usable string returns
private bool TryReadNoCommentLine( ref string line )
{
int index;
string str = _provider.ReadLine();
if( string.IsNullOrEmpty( str ) ) {
return true;
}
if( _isReadingMultiLineComment ) {
index = str.LastIndexOf( @"*)" ) + 2; //calc by beginning of code
if( index == 1 || index >= str.Length ) {
return true;
}
line = str.SliceAndTrim( index );
_isReadingMultiLineComment = false;
return string.IsNullOrEmpty(line);
}
index = str.IndexOf( @"--" );
if( index != -1 ) {
line = str.SliceAndTrim( 0, index );
return string.IsNullOrEmpty(str);
}
index = str.IndexOf(@"(*");
if (index > 0) {
if (TrySliceMultiLineCommentInSingleLine(ref str, index))
{
line = str;
return string.IsNullOrEmpty(str);
}
line = str.SliceAndTrim(0,index);
_isReadingMultiLineComment = true;
return string.IsNullOrEmpty(str);
}
line = str;
return string.IsNullOrEmpty(str);
}
//returns true when a usable string returns
private unsafe bool TrySliceMultiLineCommentInSingleLine(ref string source, int commentBegin)
{
string origin = source;
int index = origin.IndexOf("*)",commentBegin);
if (index == -1)
{
return false;
}
index += 2;
int begin = commentBegin - 1;
ReadOnlySpan<char> sourceSpan = origin.AsSpan();
while (begin >= 0 && char.IsWhiteSpace(sourceSpan[begin]))
{
begin--;
}
while (index < origin.Length && char.IsWhiteSpace(sourceSpan[index]))
{
index++;
}
if (begin == 0 && index == origin.Length - 1)
{
source = string.Empty;
return true;
}
fixed (char* cPtr = sourceSpan)
{
int secLength = origin.Length - index;
Span<char> o = new Span<char>(cPtr, origin.Length);
Span<char> s = o.Slice(0, begin + 1 + secLength);
Span<char> sec = o.Slice(index), dest = o.Slice(begin+1, secLength);
sec.CopyTo(dest);
source = new string(s);
}
return true;
}
}
}
@@ -42,6 +42,8 @@ namespace StgSharp.Script
get;
}
bool IsEmpty { get; }
string ReadLine();
}
@@ -33,23 +33,26 @@ using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace StgSharp.Script
{
public class ScriptSourceTransmitter : IScriptSourceProvider
{
private bool _isWriting = true;
private ConcurrentQueue<string> cache = new ConcurrentQueue<string>();
private int _location;
private readonly string _completeMark;
public ScriptSourceTransmitter( string endMark )
public ScriptSourceTransmitter( string endMark, int location )
{
_completeMark = endMark;
_location = location;
}
public int Location => throw new NotImplementedException();
public int Location => _location;
public bool IsEmpty => cache.IsEmpty;
public string ReadLine()
{
@@ -69,5 +72,6 @@ namespace StgSharp.Script
cache.Enqueue( line );
}
}
}
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e687473132786f419a48170313782d6779890c3d")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4ee675669ffd20ba891984a7dcdc6e382d12143f")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/e687473132786f419a48170313782d6779890c3d/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/4ee675669ffd20ba891984a7dcdc6e382d12143f/*"}}