Daily update on 20250324-100332 by Nitload Youmu. Additional Message : Single line syntax analyzer ok, gonging on unit test of multi line, func call. Then building branch, loop, area syntax analyzer. Some of descriptors not supported.

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-03-24 10:03:32 +08:00
parent 148b0fed4a
commit ffd5825a05
52 changed files with 522 additions and 560 deletions
@@ -41,8 +41,7 @@ namespace StgSharp.Script.Express
internal partial class ExpSchema_Builtin : ExpSchema
{
private static readonly ExpSchema_Builtin _onlyInstance = new ExpSchema_Builtin(
);
private static readonly ExpSchema_Builtin _onlyInstance = new ExpSchema_Builtin();
private ExpSchema_Builtin()
: base()
@@ -60,9 +59,7 @@ namespace StgSharp.Script.Express
return;
}
public override bool TryGetConst(
string name,
out ExpElementInstanceBase c )
public override bool TryGetConst( string name, out ExpElementInstanceBase c )
{
return ConstDict.TryGetValue( name, out c );
}
@@ -73,9 +70,7 @@ namespace StgSharp.Script.Express
return false;
}
public override bool TryGetFunction(
string name,
out ExpFunctionSource f )
public override bool TryGetFunction( string name, out ExpFunctionSource f )
{
return FunctionDict.TryGetValue( name, out f! );
}
@@ -86,9 +81,7 @@ namespace StgSharp.Script.Express
return false;
}
public override bool TryGetSchemaInclude(
string name,
out ExpSchema include )
public override bool TryGetSchemaInclude( string name, out ExpSchema include )
{
include = null!;
return false;
@@ -103,37 +96,33 @@ namespace StgSharp.Script.Express
{
IEnumerable<KeyValuePair<string, ExpTypeSource>> builtinTypeSource = [
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Integer ),
new ExpBuiltinType( KeyWord.Integer, typeof( int ) ) ),
PoolString( Keyword.Integer ),
new ExpBuiltinType( Keyword.Integer, typeof( int ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Real ),
new ExpBuiltinType( KeyWord.Real, typeof( float ) ) ),
PoolString( Keyword.Real ), new ExpBuiltinType( Keyword.Real, typeof( float ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Boolean ),
new ExpBuiltinType( KeyWord.Boolean, typeof( bool ) ) ),
PoolString( Keyword.Boolean ),
new ExpBuiltinType( Keyword.Boolean, typeof( bool ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Logical ),
new ExpBuiltinType( KeyWord.Logical, typeof( ExpLogic ) ) ),
PoolString( Keyword.Logical ),
new ExpBuiltinType( Keyword.Logical, typeof( ExpLogic ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.String ),
new ExpBuiltinType( KeyWord.String, typeof( string ) ) ),
PoolString( Keyword.String ),
new ExpBuiltinType( Keyword.String, typeof( string ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Binary ),
new ExpBuiltinType( KeyWord.Binary, typeof( BitArray ) ) ),
PoolString( Keyword.Binary ),
new ExpBuiltinType( Keyword.Binary, typeof( BitArray ) ) ),
];
TypeDict = new Dictionary<string, ExpTypeSource>(
builtinTypeSource, Multiplexer ).ToFrozenDictionary();
TypeDict = new Dictionary<string, ExpTypeSource>( builtinTypeSource,
Multiplexer ).ToFrozenDictionary();
ConstDict = new Dictionary<string, ExpElementInstanceBase>(
Multiplexer ) {
ConstDict = new Dictionary<string, ExpElementInstanceBase>( Multiplexer ) {
{ PoolString( "PI" ), new ExpRealNumberNode(
new Token( PoolString( "PI" ), -1, -1, TokenFlag.Number ),
MathF.PI ) },
new Token( PoolString( "PI" ), -1, -1, TokenFlag.Number ), MathF.PI ) },
{ PoolString( "E" ), new ExpRealNumberNode(
new Token( PoolString( "E" ), -1, -1, TokenFlag.Number ),
MathF.E ) },
new Token( PoolString( "E" ), -1, -1, TokenFlag.Number ), MathF.E ) },
}.ToFrozenDictionary();
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpressCompile.cs"
// file="ExpCompile.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -88,32 +88,28 @@ namespace StgSharp.Script.Express
InitPrecedence();
_operatorsWithLetter = [
KeyWord.Add,
KeyWord.Sub,
KeyWord.Mul,
KeyWord.Div,
KeyWord.And,
KeyWord.Or,
KeyWord.Xor,
KeyWord.AndOr,
KeyWord.Not,
Keyword.Add,
Keyword.Sub,
Keyword.Mul,
Keyword.Div,
Keyword.And,
Keyword.Or,
Keyword.Xor,
Keyword.AndOr,
Keyword.Not,
];
ExpSchema_Builtin.Only
.TryGetType(
PoolString( KeyWord.Integer ),
out ExpTypeSource? _expInt );
.TryGetType(
PoolString( Keyword.Integer ), out ExpTypeSource? _expInt );
ExpInt = _expInt;
ExpSchema_Builtin.Only
.TryGetType(
PoolString( KeyWord.Real ),
out ExpTypeSource? _expReal );
.TryGetType( PoolString( Keyword.Real ), out ExpTypeSource? _expReal );
ExpReal = _expReal;
ExpSchema_Builtin.Only
.TryGetType(
PoolString( KeyWord.Boolean ),
out ExpTypeSource? _expBool );
.TryGetType(
PoolString( Keyword.Boolean ), out ExpTypeSource? _expBool );
ExpBool = _expBool;
_emptyCache = new StringPool();
@@ -40,20 +40,16 @@ namespace StgSharp.Script.Express
public static partial class ExpressCompile
{
public static bool TryGetOperatorPrecedence(
string operatorName,
out int precedence )
public static bool TryGetOperatorPrecedence( string operatorName, out int precedence )
{
return _operatorPrecedence.TryGetValue(
operatorName, out precedence );
return _operatorPrecedence.TryGetValue( operatorName, out precedence );
}
public static bool TryGetSuperTypeOperatorPrecedence(
string operatorName,
out int precedence )
string operatorName,
out int precedence )
{
return _superTypeOperatorPrecedent.TryGetValue(
operatorName, out precedence );
return _superTypeOperatorPrecedent.TryGetValue( operatorName, out precedence );
}
private static void InitPrecedence()
@@ -86,16 +82,18 @@ namespace StgSharp.Script.Express
new KeyValuePair<string, int>( PoolString( ":<>:" ), 6 ),
new KeyValuePair<string, int>( PoolString( "IN" ), 6 ),
new KeyValuePair<string, int>( PoolString( "LIKE" ), 6 ),
new KeyValuePair<string, int>( PoolString( Keyword.Assignment ), 7 )
];
_operatorPrecedence = new Dictionary<string, int>(
source, _multiplexer ).ToFrozenDictionary();
_operatorPrecedence = new Dictionary<string, int>( source,
_multiplexer ).ToFrozenDictionary();
source = [
new KeyValuePair<string, int>( "ONEOF", 1 ),
new KeyValuePair<string, int>( "AND", 2 ),
new KeyValuePair<string, int>( "ANDOR", 3 ),
];
_superTypeOperatorPrecedent = new Dictionary<string, int>(
source, _multiplexer ).ToFrozenDictionary();
_superTypeOperatorPrecedent = new Dictionary<string, int>( source,
_multiplexer ).ToFrozenDictionary(
);
}
#pragma warning disable CS8618
+15 -49
View File
@@ -46,12 +46,11 @@ namespace StgSharp.Script.Express
{
_keywordSet = new();
FieldInfo[] fields = typeof( KeyWord ).GetFields(
BindingFlags.Public );
FieldInfo[] fields = typeof( Keyword ).GetFields( BindingFlags.Public );
ParallelLoopResult result = Parallel.ForEach(
fields, static( field ) => {
if( field.FieldType == typeof( string ) && field.GetValue(
null ) is string str ) {
if( field.FieldType == typeof( string ) && field.GetValue( null ) is string str )
{
_compileStringCache.GetOrAdd( str );
_keywordSet.Add( str );
}
@@ -59,7 +58,7 @@ namespace StgSharp.Script.Express
while( !result.IsCompleted ) { }
}
public static class KeyWord
public static class Keyword
{
public static HashSet<string> ScopeBlock = new HashSet<string> {
@@ -74,24 +73,15 @@ namespace StgSharp.Script.Express
CommentStart, CommentEnd, ColonEqualColon, ColonNotEqualColon
];
public static HashSet<string> DataTypes
{
get;
} = [
public static HashSet<string> DataTypes { get; } = [
Array, Bag, Binary, Boolean, Enumeration, Integer, List, Logical, Number, Of, Real, Set, String
];
public static HashSet<string> InternalProcess
{
get;
} = [
public static HashSet<string> InternalProcess { get; } = [
Insert, Remove
];
public static HashSet<string> BuiltinFunctions
{
get;
} = [
public static HashSet<string> BuiltinFunctions { get; } = [
Abs, Acos, Asin, Atan, BLength, Cos, Exists, Exp,
Format, HiBound, HiIndex, Length, LoBound, Log,
Log2, Log10, LoIndex, Nvl, Odd, Rolesof, Sin,
@@ -99,62 +89,38 @@ namespace StgSharp.Script.Express
ValueIn, ValueUnique
];
public static HashSet<string> Literals
{
get;
} = [
public static HashSet<string> Literals { get; } = [
QuestionMark, Self, Const, E, Pi, False, True, Unknown
];
public static HashSet<string> Operators
{
get;
} = [
public static HashSet<string> Operators { get; } = [
And, AndOr, Div, In, Like, Mod, Not, Or, Xor,
Add, Sub, Mul, Slash, Equal, NotEqual,
LessThan, GreaterThan, LessThanOrEqual, GreaterThanOrEqual
];
public static HashSet<string> Aliasing
{
get;
} = [
public static HashSet<string> Aliasing { get; } = [
Alias, Renamed
];
public static HashSet<string> ModifiersAttributes
{
get;
} = [
public static HashSet<string> ModifiersAttributes { get; } = [
Abstract, Aggregate, As, BasedOn, By, Escape, Fixed, From, Use, With
];
public static HashSet<string> QueryReference
{
get;
} = [
public static HashSet<string> QueryReference { get; } = [
Query, Reference, Select
];
public static HashSet<string> ConstraintsInheritance
{
get;
} = [
public static HashSet<string> ConstraintsInheritance { get; } = [
Oneof, Optional, Subtype, SubtypeConstraint, Supertype, TotalOver, Unique, Where
];
public static HashSet<string> Declarations
{
get;
} = [
public static HashSet<string> Declarations { get; } = [
Constant, Derive, Entity, Extensible, Fixed, Function, Generic,
GenericEntity, Inverse, Local, Procedure, Rule, Schema, Type, Var
];
public static HashSet<string> FlowControl
{
get;
} = [
public static HashSet<string> FlowControl { get; } = [
Begin, Case, Else, End, For, If, Otherwise, Repeat, Return, Skip, Then, To, Until, While
];