Daily update on 20250430-073804 by Nitload Youmu. Additional Message : full function of syntax analyze to STEP file

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-04-30 07:38:04 +08:00
parent a6411e2f25
commit 74c01effe4
52 changed files with 693 additions and 442 deletions
@@ -69,7 +69,7 @@ namespace StgSharp.Script.Express
Dot, Comma, Semicolon, Colon, Percent, Apostrophe,
Backslash, IndexOf, RightBracket, LeftBrace,
RightBrace, Pipe, LeftParen, RightParen, LeftAsterisk,
Assignment, DoublePipe, ExpSymbole, CommentSingleLine,
Assignment, DoublePipe, ExpSymbol, CommentSingleLine,
CommentStart, CommentEnd, InstanceEqual, InstanceNotEqual
];
@@ -342,7 +342,7 @@ namespace StgSharp.Script.Express
public const string LeftAsterisk = "<*";
public const string Assignment = ":=";
public const string DoublePipe = "||";
public const string ExpSymbole = "**";
public const string ExpSymbol = "**";
public const string CommentSingleLine = "--";
public const string CommentStart = "(*";
public const string CommentEnd = "*)";
@@ -54,7 +54,7 @@ namespace StgSharp.Script.Express
public override ExpElementType ElementType => ExpElementType.Function;
public IExpElementSource ReturningType { get; protected set; }
public ExpInstantiableElement ReturningType { get; protected set; }
public override IScriptSourceProvider SourceProvider => _transmitter;
@@ -69,7 +69,8 @@ namespace StgSharp.Script.Express
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
@@ -89,7 +90,7 @@ namespace StgSharp.Script.Express
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
source, left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
@@ -133,7 +134,7 @@ namespace StgSharp.Script.Express
{
if( right is not ExpMetaRefNode metaRef ) {
throw new ExpInvalidTypeException(
"<source of element>", right.EqualityTypeConvert.Name );
source, "<source of element>", right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
@@ -153,7 +154,8 @@ namespace StgSharp.Script.Express
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
@@ -173,7 +175,7 @@ namespace StgSharp.Script.Express
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
source, left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
@@ -189,7 +191,8 @@ namespace StgSharp.Script.Express
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
@@ -205,7 +208,8 @@ namespace StgSharp.Script.Express
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
@@ -221,7 +225,8 @@ namespace StgSharp.Script.Express
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
@@ -241,7 +246,7 @@ namespace StgSharp.Script.Express
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
source, left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
@@ -257,7 +262,8 @@ namespace StgSharp.Script.Express
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
@@ -273,7 +279,8 @@ namespace StgSharp.Script.Express
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( "Number", left.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
@@ -67,7 +67,7 @@ namespace StgSharp.Script.Express
{
if( !indexExpression.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", indexExpression.EqualityTypeConvert.Name );
source, "Number", indexExpression.EqualityTypeConvert.Name );
}
return new ExpCollectionIndexNode( source, instance, indexExpression );
}
@@ -58,7 +58,7 @@ namespace StgSharp.Script.Express
public ExpFunctionSource FunctionCaller => _function;
public override ExpInstantiableElement EqualityTypeConvert => _function.;
public override ExpInstantiableElement EqualityTypeConvert => _function.ReturningType;
public override ExpSyntaxNode Left => Empty;
@@ -78,7 +78,7 @@ namespace StgSharp.Script.Express
1, isLiteral: true );
break;
default:
throw new ExpInvalidTypeException( "Int or Real", "otherwise" );
throw new ExpInvalidTypeException( variable, "Int or Real", "otherwise" );
}
}
_variable = variable;
@@ -58,7 +58,8 @@ namespace StgSharp.Script.Express
public static ExpUnaryOperatorNode UnaryMinus( Token source, ExpSyntaxNode operand )
{
if( !operand.IsNumber ) {
throw new ExpInvalidTypeException( "Number", operand.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException(
source, "Number", operand.EqualityTypeConvert.Name );
}
bool isFloat =
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
@@ -74,7 +75,7 @@ namespace StgSharp.Script.Express
if( ( operand._nodeFlag | ( ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.BuiltinType_Logic ) ) ==
0 ) {
throw new ExpInvalidTypeException(
"Bool or Logic", operand.EqualityTypeConvert.Name );
source, "Bool or Logic", operand.EqualityTypeConvert.Name );
}
return new ExpUnaryOperatorNode( source )
{
@@ -86,7 +87,8 @@ namespace StgSharp.Script.Express
public static ExpUnaryOperatorNode UnaryPlus( Token source, ExpSyntaxNode operand )
{
if( !operand.IsNumber ) {
throw new ExpInvalidTypeException( "Number", operand.EqualityTypeConvert.Name );
throw new ExpInvalidTypeException(
source, "Number", operand.EqualityTypeConvert.Name );
}
bool isFloat =
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
+23 -2
View File
@@ -42,8 +42,23 @@ namespace StgSharp.Script.Express
public class ExpException : Exception
{
private Token _pos;
public ExpException( string message ) : base( message ) { }
public ExpException( Token position, string message )
: base( $"Express compile error at {position.Line}-{position.Column}:\n{message}" )
{
_pos = position;
}
public ExpException( ExpSyntaxNode node, string message )
: base(
$"Express compile error at {node.Source.Line}-{node.Source.Column}:\n{message}" )
{
_pos = node._source;
}
}
public class ExpInvalidCharException : ExpException
@@ -100,11 +115,17 @@ namespace StgSharp.Script.Express
}
public class ExpInvalidTypeException : InvalidCastException
public class ExpInvalidTypeException : ExpException
{
public ExpInvalidTypeException( string required, string provided )
public ExpInvalidTypeException( ExpSyntaxNode node, string required, string provided )
: base(
node,
$"Type {required} is required at position, but a {provided} instance is provided." ) { }
public ExpInvalidTypeException( Token t, string required, string provided )
: base(
t,
$"Type {required} is required at position, but a {provided} instance is provided." ) { }
}
@@ -54,7 +54,7 @@ namespace StgSharp.Script.Express
_cache.StatementsInDepth.Push( statement );
} else
{
ExpInvalidSyntaxException.ThrowNoOperator( rightSeparator );
_cache.StatementsInDepth.Push( ExpSyntaxNode.Empty );
}
} else
{
+8 -17
View File
@@ -114,7 +114,7 @@ namespace StgSharp.Script.Express
do
{
_lineCache = _provider.ReadLine( out _lineNum );
} while (string.IsNullOrEmpty( _lineCache ));
} while (string.IsNullOrEmpty( _lineCache ) && !_provider.IsEmpty);
_current = 0;
}
if( _isReadingMultiLineComment )
@@ -182,7 +182,7 @@ namespace StgSharp.Script.Express
rest = match.Groups[ "rest" ].Index;
_current = rest;
_last = new(
ExpressCompile.PoolString( source[ 1..( end - begin ) ] ), _lineNum,
ExpressCompile.PoolString( source[ 0..( end - begin ) ] ), _lineNum,
begin, TokenFlag.Member );
return _last;
} else
@@ -236,21 +236,12 @@ namespace StgSharp.Script.Express
throw new ExpInvalidCharException( '\"' );
}
case '(':
cNext = source[ 1 ];
if( cNext == '*' )
{
_isReadingMultiLineComment = true;
_current += 2;
goto readLine;
} else
{
begin = _current;
_current++;
_last = new(
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Separator_Left );
return _last;
}
begin = _current;
_current++;
_last = new(
ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin,
TokenFlag.Separator_Left );
return _last;
case ')' or '}':
begin = _current;
_current++;