daily update on 20240206 by nitload youmu, token parser change to use regex generator

This commit is contained in:
Nitload
2025-02-06 07:45:06 +08:00
parent 4e5a1b0dfb
commit 7d0470d50b
104 changed files with 2752 additions and 3134 deletions
@@ -104,6 +104,15 @@ namespace StgSharp.Script.Express
};
}
public static void DeinitCompile()
{
_compileStringCache.Reset();
_compileStringCache = null;
_multiplexer.Dispose();
_multiplexer = null;
}
public static bool TryGetBuiltinConst(
string constName,
out ExpElementInstanceBase source )
@@ -41,17 +41,15 @@ using System.Text.RegularExpressions;
namespace StgSharp.Script.Express
{
public class ExpSchemaSource
public partial class ExpSchemaSource
{
[GeneratedRegex(@"\s*END_CONSTANT;")]
private static partial Regex GetConstDefineEnd();
private static Regex
_constDefineBegin = new Regex(
@"\s*CONSTANT", RegexOptions.Compiled ),
_constDefineEnd = new Regex(
@"\s*END_CONSTANT;", RegexOptions.Compiled ),
_schemaBegin = new Regex(
@"\s*SCHEMA\s*(?<namespace>[A-Za-z0-9_]+)\s?;",
RegexOptions.Compiled ),
_constDefineBegin = GetConstDefineBegin(),
_constDefineEnd = GetConstDefineEnd(),
_schemaBegin = GetSchemaBegin(),
_schemaEnd = new Regex(
@"END_SCHEMA;\s*--\s*(?<namespace>[A-Za-z0-9_]+)",
RegexOptions.Compiled ),
@@ -315,6 +313,11 @@ namespace StgSharp.Script.Express
return false;
}
[GeneratedRegex(@"\s*CONSTANT")]
private static partial Regex GetConstDefineBegin();
[GeneratedRegex(@"\s*SCHEMA\s*(?<namespace>[A-Za-z0-9_]+)\s?;")]
private static partial Regex GetSchemaBegin();
}
}
@@ -28,37 +28,77 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using CommunityToolkit.HighPerformance;
using StgSharp.Intrinsic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
namespace StgSharp.Script.Express
{
public class ExpSourceReader
public partial 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 const int SingleComment = 0x2D2D, // --
MultiLineBegin = 0x282A, // (*
MultiLineEnd = 0x2A29; // *)
private Regex _nextWordTokenPattern = GetNextWordTokenPattern(),
_;
private bool _isReadingMultiLineComment;
private int _index;
private IScriptSourceProvider _provider;
private string _lineCache;
public ExpSourceReader( IScriptSourceProvider provider )
{
_provider = provider;
}
public string ReadLine()
[GeneratedRegex(@"(?<token>[a-zA-Z][a-zA-Z0-9_]*)(?<end>\s|\W)(?<rest>.*)")]
internal static partial Regex GetNextWordTokenPattern();
/// <summary>
/// <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>
/// </summary>
/// <returns></returns>
public unsafe ReadOnlySpan<char> ReadLine()
{
return _provider.ReadLine();
while( string.IsNullOrEmpty( _lineCache ) || _index >=
_lineCache.Length || _isReadingMultiLineComment ) {
_lineCache = _provider.ReadLine();
if( _isReadingMultiLineComment ) {
int index;
fixed( char* cPtr = _lineCache.AsSpan() ) {
index = UnsafeCompute.IndexOfCharPair(
cPtr, MultiLineEnd, _lineCache.Length );
}
if( index != -1 ) {
_lineCache = string.Empty;
continue;
}
}
}
return _lineCache.AsSpan().Slice( _index );
}
public unsafe ReadOnlySpan<char> ReadToken( out string operand )
{
int tokenBegin,tokenEnd,mark;
readLine:
}
/*
public string ReadNoCommentLine()
{
string line = string.Empty;
@@ -69,33 +109,33 @@ namespace StgSharp.Script.Express
//Returns true when no usable string returns
private bool TryReadNoCommentLine( ref string line )
{
int index;
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 ) {
_index = str.LastIndexOf( @"*)" ) + 2; //calc by beginning of code
if( _index == 1 || _index >= str.Length ) {
return true;
}
line = str.SliceAndTrim( index );
line = str.SliceAndTrim( _index );
_isReadingMultiLineComment = false;
return string.IsNullOrEmpty(line);
}
index = str.IndexOf( @"--" );
if( index != -1 ) {
line = str.SliceAndTrim( 0, index );
_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))
_index = str.IndexOf(@"(*");
if (_index > 0) {
if (TrySliceMultiLineCommentInSingleLine(ref str, _index))
{
line = str;
return string.IsNullOrEmpty(str);
}
line = str.SliceAndTrim(0,index);
line = str.SliceAndTrim(0,_index);
_isReadingMultiLineComment = true;
return string.IsNullOrEmpty(str);
}
@@ -107,37 +147,38 @@ namespace StgSharp.Script.Express
private unsafe bool TrySliceMultiLineCommentInSingleLine(ref string source, int commentBegin)
{
string origin = source;
int index = origin.IndexOf("*)",commentBegin);
if (index == -1)
int _index = origin.IndexOf("*)",commentBegin);
if (_index == -1)
{
return false;
}
index += 2;
_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]))
while (_index < origin.Length && char.IsWhiteSpace(sourceSpan[_index]))
{
index++;
_index++;
}
if (begin == 0 && index == origin.Length - 1)
if (begin == 0 && _index == origin.Length - 1)
{
source = string.Empty;
return true;
}
fixed (char* cPtr = sourceSpan)
{
int secLength = origin.Length - index;
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);
Span<char> sec = o.Slice(_index), dest = o.Slice(begin+1, secLength);
sec.CopyTo(dest);
source = new string(s);
}
return true;
}
/**/
}
}
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
@@ -13,11 +13,16 @@
"packagesPath": "C:\\Users\\Youmu\\.nuget\\packages\\",
"outputPath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\StgSharp.Common\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Youmu\\AppData\\Roaming\\NuGet\\NuGet.Config"
"C:\\Users\\Youmu\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netstandard2.1"
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
@@ -26,8 +31,8 @@
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
@@ -43,8 +48,8 @@
}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"Microsoft.CSharp": {
"target": "Package",
@@ -67,11 +72,11 @@
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"NETStandard.Library": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400/PortableRuntimeIdentifierGraph.json"
}
}
},
@@ -84,11 +89,16 @@
"packagesPath": "C:\\Users\\Youmu\\.nuget\\packages\\",
"outputPath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\StgSharp.Script\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Youmu\\AppData\\Roaming\\NuGet\\NuGet.Config"
"C:\\Users\\Youmu\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netstandard2.1"
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
@@ -97,8 +107,8 @@
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {
"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\StgSharp.Common\\StgSharp.Common.csproj": {
"projectPath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\StgSharp.Common\\StgSharp.Common.csproj"
@@ -118,8 +128,8 @@
}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"CommunityToolkit.HighPerformance": {
"target": "Package",
@@ -138,11 +148,11 @@
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"NETStandard.Library": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400/PortableRuntimeIdentifierGraph.json"
}
}
}
@@ -1,19 +1,16 @@
{
"version": 3,
"targets": {
".NETStandard,Version=v2.1": {
"net8.0": {
"CommunityToolkit.HighPerformance/8.4.0": {
"type": "package",
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "6.1.0"
},
"compile": {
"lib/netstandard2.1/CommunityToolkit.HighPerformance.dll": {
"lib/net8.0/CommunityToolkit.HighPerformance.dll": {
"related": ".pdb;.xml"
}
},
"runtime": {
"lib/netstandard2.1/CommunityToolkit.HighPerformance.dll": {
"lib/net8.0/CommunityToolkit.HighPerformance.dll": {
"related": ".pdb;.xml"
}
}
@@ -21,32 +18,27 @@
"Microsoft.CSharp/4.7.0": {
"type": "package",
"compile": {
"ref/netstandard2.0/Microsoft.CSharp.dll": {
"related": ".xml"
}
"ref/netcoreapp2.0/_._": {}
},
"runtime": {
"lib/netstandard2.0/Microsoft.CSharp.dll": {
"related": ".xml"
}
"lib/netcoreapp2.0/_._": {}
}
},
"System.Runtime.CompilerServices.Unsafe/6.1.0": {
"type": "package",
"compile": {
"lib/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll": {
"related": ".xml"
}
"lib/net7.0/_._": {}
},
"runtime": {
"lib/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll": {
"related": ".xml"
}
"lib/net7.0/_._": {}
},
"build": {
"buildTransitive/net6.0/_._": {}
}
},
"StgSharp.Common/1.0.0": {
"type": "project",
"framework": ".NETStandard,Version=v2.1",
"framework": ".NETCoreApp,Version=v8.0",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Runtime.CompilerServices.Unsafe": "6.1.0"
@@ -185,13 +177,14 @@
}
},
"projectFileDependencyGroups": {
".NETStandard,Version=v2.1": [
"net8.0": [
"CommunityToolkit.HighPerformance >= 8.4.0",
"StgSharp.Common >= 1.0.0"
]
},
"packageFolders": {
"C:\\Users\\Youmu\\.nuget\\packages\\": {}
"C:\\Users\\Youmu\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
},
"project": {
"version": "1.0.0",
@@ -202,11 +195,16 @@
"packagesPath": "C:\\Users\\Youmu\\.nuget\\packages\\",
"outputPath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\StgSharp.Script\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Youmu\\AppData\\Roaming\\NuGet\\NuGet.Config"
"C:\\Users\\Youmu\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netstandard2.1"
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
@@ -215,8 +213,8 @@
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {
"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\StgSharp.Common\\StgSharp.Common.csproj": {
"projectPath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\StgSharp.Common\\StgSharp.Common.csproj"
@@ -236,8 +234,8 @@
}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"CommunityToolkit.HighPerformance": {
"target": "Package",
@@ -256,11 +254,11 @@
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"NETStandard.Library": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400/PortableRuntimeIdentifierGraph.json"
}
}
}
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
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+4e5a1b0dfb69dd073410d254e2bab596629c4536")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -1,15 +0,0 @@
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\bin\x64\Debug\netstandard2.1\StgSharp.Script.deps.json
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\bin\x64\Debug\netstandard2.1\StgSharp.Script.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\bin\x64\Debug\netstandard2.1\StgSharp.Script.pdb
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\bin\x64\Debug\netstandard2.1\StgSharp.Common.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\bin\x64\Debug\netstandard2.1\StgSharp.Common.pdb
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\bin\x64\Debug\netstandard2.1\StgSharp.Common.xml
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\obj\x64\Debug\netstandard2.1\StgSharp.Script.csproj.AssemblyReference.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\obj\x64\Debug\netstandard2.1\StgSharp.Script.GeneratedMSBuildEditorConfig.editorconfig
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\obj\x64\Debug\netstandard2.1\StgSharp.Script.AssemblyInfoInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\obj\x64\Debug\netstandard2.1\StgSharp.Script.AssemblyInfo.cs
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\obj\x64\Debug\netstandard2.1\StgSharp.Script.csproj.CoreCompileInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\obj\x64\Debug\netstandard2.1\StgSharp.Script.sourcelink.json
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\obj\x64\Debug\netstandard2.1\StgSharp.D39FE6B0.Up2Date
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\obj\x64\Debug\netstandard2.1\StgSharp.Script.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\obj\x64\Debug\netstandard2.1\StgSharp.Script.pdb