daily update on 20250214 by nitload youmu, building syntax analysor, tough!

This commit is contained in:
Nitload
2025-02-14 13:30:17 +08:00
parent c23b640cae
commit ccef0de6f6
68 changed files with 2594 additions and 913 deletions
@@ -36,90 +36,66 @@ using System.Text;
namespace StgSharp.Script.Express
{
[Flags]
public enum ExpTokenFlag : long
{
None = 0,
Name_Element = 1,
Name_Param = 2,
Name_Block = 4,
Name_Keyword = 8,
Name_Any = Name_Block | Name_Element | Name_Keyword | Name_Param,
Collection_Set = 16,
Collection_Bag = 32,
Collection_Array = 64,
Collection_List = 128,
Collection_Any = Collection_Set | Collection_Bag | Collection_Array | Collection_List,
Element_Const = 256,
Element_Entity = 512,
Element_type = 1024,
Element_Rule = 2048,
Element_Function = 4096,
Element_Any = Element_Entity | Element_Const | Element_Function | Element_Rule | Element_type,
BuiltinType_Int = 8192,
BuiltinType_Float = 16384,
BuiltinType_String = 32768,
BuiltinType_Boolean = 65536,
BuiltinType_Binary = 0x2000,
BuiltinType_Logic = 0x4000,
BuiltinType_Any = BuiltinType_Int | BuiltinType_Float | BuiltinType_String | BuiltinType_Boolean | BuiltinType_Binary | BuiltinType_Logic,
Branch_If = 0x8000,
Branch_Switch = 0x1_0000,
Branch_Repeat = 0x2_0000,
}
public ref struct ExpTokenSource
{
public ReadOnlySpan<char> Value;
public readonly int Line;
public readonly int Column;
public ExpTokenSource(ReadOnlySpan<char> chars, int lineNumber, int columnNumber)
{
Value = chars; Line = lineNumber; Column = columnNumber;
}
}
public abstract class ExpToken : IExpressionToken
public abstract class ExpToken : IExpressionToken<ExpToken, IExpElementSource>
{
protected internal ExpToken _previousToken;
protected internal ExpTokenFlag _tokenType;
protected internal List<ExpToken> _nextLevelTokens
= new List<ExpToken>();
protected internal string _name;
protected ExpToken( string name, ExpSchema context )
{
_name = name;
Context = context;
NameSpace = context;
}
public ExpSchema Context
public ExpSchema NameSpace
{
get;
private set;
}
public abstract ExpToken Left
{
get;
}
public abstract ExpToken Next
{
get;
set;
}
public abstract ExpToken Right
{
get;
}
public abstract IExpElementSource EqualityTypeConvert
{
get;
}
public long TokenTypeCode => ( long )_tokenType;
public string Name => _name;
public virtual bool TryGetNextLevel(
out ICollection<IExpressionToken> nextLevel )
public virtual void AppendToken( ExpToken nextToken )
{
nextLevel = ( _nextLevelTokens as ICollection<IExpressionToken> )!;
return true;
Next = nextToken;
}
public ExpTokenEnumerator GetEnumerator()
{
return new ExpTokenEnumerator( this );
}
protected void AssertSchemaInclude( ExpToken expressionRoot )
{
if( expressionRoot.Context != Context && Context.HasSchemaInclude(
expressionRoot.Context ) ) {
if( expressionRoot.NameSpace != NameSpace && NameSpace.HasSchemaInclude(
expressionRoot.NameSpace ) ) {
throw new ExpInvalidSchemaIncludeException(
Context, expressionRoot.Context );
NameSpace, expressionRoot.NameSpace );
}
}