daily update on 20240203 by nitload youmu, ExpComment[D[D[D[D[D[D[D [C[C[C[C[C[C[D[D[D[D[D[DComment Splitter ok, case code(* comment[D[D[D[D[D[D[D[D[D[D[C[C[[C[Dcomment*)code--comment and comment*)code--comment not added, may use span optimize all programme
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -60,12 +60,59 @@ namespace STgSharpTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestMethod()
|
public void TestSource()
|
||||||
{
|
{
|
||||||
ExpFileReader reader = new ExpFileReader(testExpPath);
|
ScriptSourceTransmitter st = new ScriptSourceTransmitter("end", 0);
|
||||||
ExpSchemaSource schemaSource = new ExpSchemaSource();
|
for (int i = 0; i < 10; i++)
|
||||||
schemaSource.ReadSchema(reader);
|
{
|
||||||
|
st.WriteLine($"Code{i} {new string(' ', i + 1)}-- Comment{i}");
|
||||||
|
}
|
||||||
|
st.WriteLine("Code (* comment");
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
st.WriteLine($"comment-code");
|
||||||
|
}
|
||||||
|
st.WriteLine($"comment *) code");
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
st.WriteLine($" Code{i} (* (* Comment *) *) Code{i}");
|
||||||
|
}
|
||||||
|
st.WriteLine("end");
|
||||||
|
|
||||||
|
ExpSourceReader reader = new ExpSourceReader(st);
|
||||||
|
while (!st.IsEmpty)
|
||||||
|
{
|
||||||
|
Console.WriteLine(reader.ReadLine());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestMethod()
|
||||||
|
{
|
||||||
|
ScriptSourceTransmitter st = new ScriptSourceTransmitter("end", 0);
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
st.WriteLine($"Code{i} {new string(' ',i+1)}-- Comment{i}");
|
||||||
}
|
}
|
||||||
|
st.WriteLine("Code (* comment");
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
st.WriteLine($"comment-code");
|
||||||
|
}
|
||||||
|
st.WriteLine($"comment *) code");
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
st.WriteLine($" Code{i} (* (* Comment *) *) Code{i}");
|
||||||
|
}
|
||||||
|
st.WriteLine("end");
|
||||||
|
|
||||||
|
ExpSourceReader reader = new ExpSourceReader(st);
|
||||||
|
while (!st.IsEmpty)
|
||||||
|
{
|
||||||
|
Console.WriteLine(reader.ReadNoCommentLine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpTest")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpTest")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e687473132786f419a48170313782d6779890c3d")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4ee675669ffd20ba891984a7dcdc6e382d12143f")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpTest")]
|
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpTest")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpTest")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpTest")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/e687473132786f419a48170313782d6779890c3d/*"}}
|
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/4ee675669ffd20ba891984a7dcdc6e382d12143f/*"}}
|
||||||
@@ -69,7 +69,7 @@ namespace StgSharp.Collections
|
|||||||
public class ConcurrentStringHashMultiplexer : IEqualityComparer<string>, IStringHashMultiplexer
|
public class ConcurrentStringHashMultiplexer : IEqualityComparer<string>, IStringHashMultiplexer
|
||||||
{
|
{
|
||||||
private readonly ThreadLocal<StringHashMultiplexer> multiplexers =
|
private readonly ThreadLocal<StringHashMultiplexer> multiplexers =
|
||||||
new ();
|
new (()=>new StringHashMultiplexer());
|
||||||
|
|
||||||
public int RemainedMultiplexCount
|
public int RemainedMultiplexCount
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Common")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Common")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e687473132786f419a48170313782d6779890c3d")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4ee675669ffd20ba891984a7dcdc6e382d12143f")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")]
|
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/e687473132786f419a48170313782d6779890c3d/*"}}
|
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/4ee675669ffd20ba891984a7dcdc6e382d12143f/*"}}
|
||||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e687473132786f419a48170313782d6779890c3d")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4ee675669ffd20ba891984a7dcdc6e382d12143f")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Model")]
|
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Model")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/e687473132786f419a48170313782d6779890c3d/*"}}
|
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/4ee675669ffd20ba891984a7dcdc6e382d12143f/*"}}
|
||||||
@@ -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
|
public class ExpConstantCollectionSource : IExpImmutableElement
|
||||||
{
|
{
|
||||||
private IScriptSourceProvider _sourceProvider;
|
private IScriptSourceProvider _sourceProvider;
|
||||||
private string _name;
|
|
||||||
private Dictionary<string, ExpElementInstanceBase> _constants;
|
private Dictionary<string, ExpElementInstanceBase> _constants;
|
||||||
|
|
||||||
public ExpConstantCollectionSource(
|
public ExpConstantCollectionSource(
|
||||||
string name,
|
|
||||||
IScriptSourceProvider sourceProvider )
|
IScriptSourceProvider sourceProvider )
|
||||||
{
|
{
|
||||||
_name = name;
|
|
||||||
_sourceProvider = sourceProvider;
|
_sourceProvider = sourceProvider;
|
||||||
_constants = new Dictionary<string, ExpElementInstanceBase>(
|
_constants = new Dictionary<string, ExpElementInstanceBase>(
|
||||||
ExpCompile.Multiplexer);
|
ExpCompile.Multiplexer);
|
||||||
@@ -61,11 +58,11 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public IScriptSourceProvider SourceProvider => _sourceProvider;
|
public IScriptSourceProvider SourceProvider => _sourceProvider;
|
||||||
|
|
||||||
public static Dictionary<string, ExpConstantCollectionSource> BuiltinConst => ExpCompile.BuiltinConst;
|
public static Dictionary<string, ExpElementInstanceBase> BuiltinConst => ExpCompile.BuiltinConst;
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get => _name;
|
get => ExpCompile.KeyWord.Constant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Analyse()
|
public virtual void Analyse()
|
||||||
@@ -75,7 +72,24 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public ExpToken MakeReference(params object[] options)
|
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
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
@@ -41,13 +41,25 @@ namespace StgSharp.Script.Express
|
|||||||
{
|
{
|
||||||
public static partial class ExpCompile
|
public static partial class ExpCompile
|
||||||
{
|
{
|
||||||
|
|
||||||
private static ConcurrentStringHashMultiplexer _multiplexer;
|
private static ConcurrentStringHashMultiplexer _multiplexer;
|
||||||
private static Dictionary<string, ExpConstantCollectionSource> _builtinConst;
|
private static Dictionary<string, ExpElementInstanceBase> _builtinConst;
|
||||||
private static Dictionary<string, ExpTypeSource> _builtinType;
|
private static Dictionary<string, ExpTypeSource> _builtinType;
|
||||||
private static StringPool _compileStringCache;
|
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 )
|
public static string AddOrGetString( string str )
|
||||||
{
|
{
|
||||||
@@ -59,63 +71,65 @@ namespace StgSharp.Script.Express
|
|||||||
_compileStringCache.Reset();
|
_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()
|
public static void InitCompile()
|
||||||
{
|
{
|
||||||
_compileStringCache = new StringPool();
|
_compileStringCache = new StringPool();
|
||||||
_multiplexer = new ConcurrentStringHashMultiplexer();
|
_multiplexer = new ConcurrentStringHashMultiplexer();
|
||||||
_builtinConst = new Dictionary<string, ExpConstantCollectionSource>(_multiplexer){
|
|
||||||
{ AddOrGetString( "PI" ), new ExpBuiltinConst<float>(
|
_builtinType = new Dictionary<string, ExpTypeSource>( _multiplexer ) {
|
||||||
AddOrGetString( "PI" ), MathF.PI ) },
|
|
||||||
{ AddOrGetString( "E" ), new ExpBuiltinConst<float>(
|
|
||||||
AddOrGetString( "E" ), MathF.E ) },
|
|
||||||
};
|
|
||||||
//TODO keep on here
|
|
||||||
_builtinType = new Dictionary<string, ExpTypeSource>(_multiplexer){
|
|
||||||
{ AddOrGetString( KeyWord.Int ), new ExpBuiltinType(
|
{ AddOrGetString( KeyWord.Int ), new ExpBuiltinType(
|
||||||
AddOrGetString( KeyWord.Int ), typeof( int ) ) },
|
AddOrGetString( KeyWord.Int ),typeof( int ) ) },
|
||||||
{ AddOrGetString( KeyWord.Real ), new ExpBuiltinType(
|
{ AddOrGetString( KeyWord.Real ), new ExpBuiltinType(
|
||||||
AddOrGetString( KeyWord.Real ), typeof( float ) ) },
|
AddOrGetString( KeyWord.Real ), typeof( float ) ) },
|
||||||
{ AddOrGetString( KeyWord.Bool ), new ExpBuiltinType(
|
{ AddOrGetString(KeyWord.Bool ), new ExpBuiltinType(
|
||||||
AddOrGetString( KeyWord.Bool ), typeof( bool ) ) },
|
AddOrGetString(KeyWord.Bool ), typeof( bool ) ) },
|
||||||
{ AddOrGetString( KeyWord.Binary ), new ExpBuiltinType(
|
{ AddOrGetString(KeyWord.Binary ), new ExpBuiltinType(
|
||||||
AddOrGetString( KeyWord.Binary ), typeof( bool ) ) },
|
AddOrGetString(KeyWord.Binary ),typeof( bool ) ) },
|
||||||
{ AddOrGetString( KeyWord.String ), new ExpBuiltinType(
|
{ AddOrGetString(KeyWord.String ), new ExpBuiltinType(
|
||||||
AddOrGetString( KeyWord.String ), typeof( string ) ) },
|
AddOrGetString(KeyWord.String ),typeof( string ) ) },
|
||||||
{ AddOrGetString(KeyWord.Logic),new ExpBuiltinType(
|
{ AddOrGetString(KeyWord.Logic ), new ExpBuiltinType(
|
||||||
AddOrGetString(KeyWord.Logic), typeof(Logic)) }
|
AddOrGetString(KeyWord.Logic ), typeof( Logic ) ) } };
|
||||||
|
|
||||||
|
_builtinConst = new Dictionary<string, ExpElementInstanceBase>(
|
||||||
|
_multiplexer ) {
|
||||||
|
{ AddOrGetString( "PI" ), new ExpBuiltinConstant<float>(
|
||||||
|
AddOrGetString( "PI" ), MathF.PI ) },
|
||||||
|
{ AddOrGetString( "E" ), new ExpBuiltinConstant<float>(
|
||||||
|
AddOrGetString( "E" ), MathF.E ) },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 static class KeyWord
|
||||||
{
|
{
|
||||||
|
|
||||||
public const string Int = "INTAGER",
|
public const string Int = "INTAGER",
|
||||||
Real = "REAL",
|
Real = "REAL",
|
||||||
Bool = "BOOLEAN",
|
Bool = "BOOLEAN",
|
||||||
String = "STRING",
|
String = "STRING",
|
||||||
Logic = "LOGIC",
|
Logic = "LOGIC",
|
||||||
Binary = "BINARY";
|
Binary = "BINARY",
|
||||||
|
Constant = "CONSTANT";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
using CommunityToolkit.HighPerformance.Helpers;
|
||||||
|
|
||||||
using StgSharp.Collections;
|
using StgSharp.Collections;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@@ -84,22 +86,20 @@ namespace StgSharp.Script.Express
|
|||||||
return _schemaInclude.ContainsKey( schema.Name );
|
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))
|
if (ExpCompile.BuiltinConst.TryGetValue(name, out constInstance))
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
foreach (var item in _constDict.Values)
|
||||||
|
|
||||||
public ExpToken SearchConstDeclare( string typeName )
|
|
||||||
{
|
{
|
||||||
ExpToken constant;
|
if (item.TryGetConstant(name, out constInstance))
|
||||||
foreach (var item in ExpCompile.BuiltinConst.Values)
|
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
throw new KeyNotFoundException();
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public ExpSchemaSource() { }
|
public ExpSchemaSource() { }
|
||||||
|
|
||||||
public void ReadSchema( ExpFileReader reader )
|
public void ReadSchema( ExpFileSource reader )
|
||||||
{
|
{
|
||||||
string line = reader.ReadLine();
|
string line = reader.ReadLine();
|
||||||
while( !_schemaBegin.IsMatch( line ) ) {
|
while( !_schemaBegin.IsMatch( line ) ) {
|
||||||
@@ -122,7 +122,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public static bool TryReadSchema(
|
public static bool TryReadSchema(
|
||||||
string firstLine,
|
string firstLine,
|
||||||
ExpFileReader reader,
|
ExpFileSource reader,
|
||||||
out ExpSchemaSource source )
|
out ExpSchemaSource source )
|
||||||
{
|
{
|
||||||
if( !_schemaBegin.IsMatch( firstLine ) ) {
|
if( !_schemaBegin.IsMatch( firstLine ) ) {
|
||||||
@@ -163,15 +163,15 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private bool TryReadConst(
|
private bool TryReadConst(
|
||||||
string firstLine,
|
string firstLine,
|
||||||
ExpFileReader reader,
|
ExpFileSource reader,
|
||||||
out IExpElementSource source )
|
out IExpElementSource source )
|
||||||
{
|
{
|
||||||
Match match = _constDefineBegin.Match( firstLine );
|
Match match = _constDefineBegin.Match( firstLine );
|
||||||
if( match.Success ) {
|
if( match.Success ) {
|
||||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||||
"END_CONSTANT" );
|
"END_CONSTANT",reader.Location );
|
||||||
ExpConstantCollectionSource _source = new ExpConstantCollectionSource(
|
ExpConstantCollectionSource _source = new ExpConstantCollectionSource(
|
||||||
"Constant", transmitter );
|
transmitter );
|
||||||
string line = reader.ReadLine();
|
string line = reader.ReadLine();
|
||||||
while( !_constDefineEnd.IsMatch( line ) ) {
|
while( !_constDefineEnd.IsMatch( line ) ) {
|
||||||
transmitter.WriteLine( line );
|
transmitter.WriteLine( line );
|
||||||
@@ -187,13 +187,13 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private bool TryReadEntity(
|
private bool TryReadEntity(
|
||||||
string firstLine,
|
string firstLine,
|
||||||
ExpFileReader reader,
|
ExpFileSource reader,
|
||||||
out IExpElementSource source )
|
out IExpElementSource source )
|
||||||
{
|
{
|
||||||
Match match = _entityDefineBegin.Match( firstLine );
|
Match match = _entityDefineBegin.Match( firstLine );
|
||||||
if( match.Success ) {
|
if( match.Success ) {
|
||||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||||
"END_ENTITY" );
|
"END_ENTITY", reader.Location);
|
||||||
ExpEntitySource _source = new ExpEntitySource(
|
ExpEntitySource _source = new ExpEntitySource(
|
||||||
match.Groups[ "TypeName" ].ToString(), transmitter );
|
match.Groups[ "TypeName" ].ToString(), transmitter );
|
||||||
string line = reader.ReadLine();
|
string line = reader.ReadLine();
|
||||||
@@ -218,13 +218,13 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private bool TryReadFunction(
|
private bool TryReadFunction(
|
||||||
string firstLine,
|
string firstLine,
|
||||||
ExpFileReader reader,
|
ExpFileSource reader,
|
||||||
out IExpElementSource source )
|
out IExpElementSource source )
|
||||||
{
|
{
|
||||||
Match match = _functionDefineBegin.Match( firstLine );
|
Match match = _functionDefineBegin.Match( firstLine );
|
||||||
if( match.Success ) {
|
if( match.Success ) {
|
||||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||||
"END_FUNCTION" );
|
"END_FUNCTION", reader.Location);
|
||||||
ExpFunctionSource _source = new ExpFunctionSource(
|
ExpFunctionSource _source = new ExpFunctionSource(
|
||||||
match.Groups[ "FunctionName" ].ToString(), transmitter );
|
match.Groups[ "FunctionName" ].ToString(), transmitter );
|
||||||
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
|
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
|
||||||
@@ -250,13 +250,13 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private bool TryReadRule(
|
private bool TryReadRule(
|
||||||
string firstLine,
|
string firstLine,
|
||||||
ExpFileReader reader,
|
ExpFileSource reader,
|
||||||
out IExpElementSource source )
|
out IExpElementSource source )
|
||||||
{
|
{
|
||||||
Match match = _ruleDefineBegin.Match( firstLine );
|
Match match = _ruleDefineBegin.Match( firstLine );
|
||||||
if( match.Success ) {
|
if( match.Success ) {
|
||||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||||
"END_RULE" );
|
"END_RULE", reader.Location);
|
||||||
ExpRuleSource _source = new ExpRuleSource(
|
ExpRuleSource _source = new ExpRuleSource(
|
||||||
match.Groups[ "RuleName" ].ToString(), transmitter );
|
match.Groups[ "RuleName" ].ToString(), transmitter );
|
||||||
string target = match.Groups[ "Target" ].ToString();
|
string target = match.Groups[ "Target" ].ToString();
|
||||||
@@ -285,13 +285,13 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private bool TryReadType(
|
private bool TryReadType(
|
||||||
string firstLine,
|
string firstLine,
|
||||||
ExpFileReader reader,
|
ExpFileSource reader,
|
||||||
out IExpElementSource source )
|
out IExpElementSource source )
|
||||||
{
|
{
|
||||||
Match match = _typeDefineBegin.Match( firstLine );
|
Match match = _typeDefineBegin.Match( firstLine );
|
||||||
if( match.Success ) {
|
if( match.Success ) {
|
||||||
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
|
||||||
"END_ENTITY" );
|
"END_ENTITY", reader.Location);
|
||||||
ExpTypeSource _source = new ExpTypeSource(
|
ExpTypeSource _source = new ExpTypeSource(
|
||||||
match.Groups[ "TypeName" ].ToString(), transmitter );
|
match.Groups[ "TypeName" ].ToString(), transmitter );
|
||||||
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
|
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;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsEmpty { get; }
|
||||||
|
|
||||||
string ReadLine();
|
string ReadLine();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,23 +33,26 @@ using System.Collections;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace StgSharp.Script
|
namespace StgSharp.Script
|
||||||
{
|
{
|
||||||
public class ScriptSourceTransmitter : IScriptSourceProvider
|
public class ScriptSourceTransmitter : IScriptSourceProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
private bool _isWriting = true;
|
private bool _isWriting = true;
|
||||||
private ConcurrentQueue<string> cache = new ConcurrentQueue<string>();
|
private ConcurrentQueue<string> cache = new ConcurrentQueue<string>();
|
||||||
private int _location;
|
private int _location;
|
||||||
private readonly string _completeMark;
|
private readonly string _completeMark;
|
||||||
|
|
||||||
public ScriptSourceTransmitter( string endMark )
|
public ScriptSourceTransmitter( string endMark, int location )
|
||||||
{
|
{
|
||||||
_completeMark = endMark;
|
_completeMark = endMark;
|
||||||
|
_location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Location => throw new NotImplementedException();
|
public int Location => _location;
|
||||||
|
|
||||||
|
public bool IsEmpty => cache.IsEmpty;
|
||||||
|
|
||||||
public string ReadLine()
|
public string ReadLine()
|
||||||
{
|
{
|
||||||
@@ -69,5 +72,6 @@ namespace StgSharp.Script
|
|||||||
cache.Enqueue( line );
|
cache.Enqueue( line );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e687473132786f419a48170313782d6779890c3d")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4ee675669ffd20ba891984a7dcdc6e382d12143f")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/e687473132786f419a48170313782d6779890c3d/*"}}
|
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/4ee675669ffd20ba891984a7dcdc6e382d12143f/*"}}
|
||||||
@@ -37,6 +37,7 @@ using StgSharp.Graphics;
|
|||||||
using StgSharp.Math;
|
using StgSharp.Math;
|
||||||
using StgSharp.MVVM;
|
using StgSharp.MVVM;
|
||||||
using StgSharp.MVVM.ViewModel;
|
using StgSharp.MVVM.ViewModel;
|
||||||
|
using StgSharp.Script.Express;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -50,6 +51,8 @@ namespace StgSharp
|
|||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
|
||||||
|
|
||||||
internal static unsafe void Main( string[] args )
|
internal static unsafe void Main( string[] args )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -59,6 +62,12 @@ namespace StgSharp
|
|||||||
StgSharp.InitGL( 4, 6 );
|
StgSharp.InitGL( 4, 6 );
|
||||||
StgSharp.GlobalSetting.VSyncActivated = false;
|
StgSharp.GlobalSetting.VSyncActivated = false;
|
||||||
|
|
||||||
|
|
||||||
|
ExpCompile.InitCompile();
|
||||||
|
ExpFileSource reader = new ExpFileSource(testExpPath);
|
||||||
|
ExpSchemaSource schemaSource = new ExpSchemaSource();
|
||||||
|
schemaSource.ReadSchema(reader);
|
||||||
|
|
||||||
ViewPort vp = new ViewPort(800,600,"Hello StgSharp!",IntPtr.Zero);
|
ViewPort vp = new ViewPort(800,600,"Hello StgSharp!",IntPtr.Zero);
|
||||||
//throw new NotImplementedException();
|
//throw new NotImplementedException();
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e687473132786f419a48170313782d6779890c3d")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4ee675669ffd20ba891984a7dcdc6e382d12143f")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
|
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/e687473132786f419a48170313782d6779890c3d/*"}}
|
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/4ee675669ffd20ba891984a7dcdc6e382d12143f/*"}}
|
||||||
Reference in New Issue
Block a user