1.新增context内置变量2.修复一些问题

This commit is contained in:
2025-10-16 20:15:35 +08:00
parent 97a6e4d76b
commit 52e8e85542
3 changed files with 57 additions and 31 deletions

View File

@@ -42,16 +42,16 @@ namespace Convention.RScript
else if (c == '/' && i + 1 < e)
{
// Skip single-line comment
if (script[i + 1] == '/')
if (line[i + 1] == '/')
{
while (i < script.Length && script[i] != '\n')
while (i < line.Length && line[i] != '\n')
i++;
}
// Skip multi-line comment
else if (script[i + 1] == '*')
else if (line[i + 1] == '*')
{
i += 2;
while (i + 1 < script.Length && !(script[i] == '*' && script[i + 1] == '/'))
while (i + 1 < line.Length && !(line[i] == '*' && line[i + 1] == '/'))
i++;
i++;
}
@@ -63,23 +63,24 @@ namespace Convention.RScript
else if (c == '#')
{
// Skip single-line comment
while (i < script.Length && script[i] != '\n')
while (i < line.Length && line[i] != '\n')
i++;
}
else if (c == '\"')
{
builder.Append(c);
for (i++; i < e; i++)
{
builder.Append(script[i]);
if (script[i] == '\"')
builder.Append(line[i]);
if (line[i] == '\"')
{
break;
}
else if (script[i] == '\\')
else if (line[i] == '\\')
{
i++;
if (i < e)
builder.Append(script[i]);
builder.Append(line[i]);
else
throw new RScriptCompileException("Invalid escape sequence in string literal", lineIndex, i);
}
@@ -90,14 +91,10 @@ namespace Convention.RScript
PushBuilder();
statements.Add(c.ToString());
}
else if (string.Compare("namespace", 0, script, i, "namespace".Length) == 0)
else if (string.Compare("namespace", 0, line, i, "namespace".Length) == 0)
{
builder.Append("namespace");
i += "namespace".Length;
if (i >= e)
throw new RScriptCompileException("Invalid namespace declaration", lineIndex, i);
Regex regex = new(@"^\s*\([a-zA-Z_][a-zA-Z0-9_]*\)");
var match = regex.Match(script, i);
Regex regex = new(@"^\s*namespace\s*\([a-zA-Z_][a-zA-Z0-9_]*\)");
var match = regex.Match(line);
if (match.Success)
{
builder.Append(match.Value);
@@ -129,8 +126,6 @@ namespace Convention.RScript
{
parser = new(new());
context = new(SplitScript(script).ToArray(), import, variables);
foreach (var type in context.Import)
parser.context.Imports.AddType(type);
context.Run(parser);
return context.GetCurrentVariables();
}
@@ -139,8 +134,6 @@ namespace Convention.RScript
{
parser = new(new());
context = new(SplitScript(script).ToArray(), import, variables);
foreach (var type in context.Import)
parser.context.Imports.AddType(type);
return context.RunAsync(parser);
}
}