尝试新增命名空间的命名, 用于具有名称的块或是函数
This commit is contained in:
@@ -32,11 +32,11 @@ namespace Convention.RScript
|
||||
/// </summary>
|
||||
ExitNamespace,
|
||||
/// <summary>
|
||||
/// 标签, 格式: label(labelname)
|
||||
/// 标签, 格式: label(labelname);
|
||||
/// </summary>
|
||||
Label,
|
||||
/// <summary>
|
||||
/// 跳转到指定标签, 格式: goto(boolean,labelname)
|
||||
/// 跳转到指定标签, 格式: goto(boolean,labelname);
|
||||
/// <para>判断为真时跳转到labelname</para>
|
||||
/// </summary>
|
||||
Goto,
|
||||
@@ -48,6 +48,10 @@ namespace Convention.RScript
|
||||
/// 跳转到上次跳转的位置的后一个位置, 格式: back(boolean);
|
||||
/// </summary>
|
||||
Backpoint,
|
||||
/// <summary>
|
||||
/// 命名空间命名, 格式: namespace(labelname){}
|
||||
/// </summary>
|
||||
NamedSpace,
|
||||
}
|
||||
|
||||
public string content;
|
||||
@@ -66,7 +70,8 @@ namespace Convention.RScript
|
||||
public readonly RScriptVariables Variables;
|
||||
private readonly RScriptSentence[] Sentences;
|
||||
private readonly Dictionary<string, int> Labels;
|
||||
private readonly Dictionary<int, int> Namespace;
|
||||
private readonly Dictionary<int, int> NamespaceLayer;
|
||||
private readonly Dictionary<string, int> NamespaceLabels;
|
||||
|
||||
public List<IRSentenceMatcher> SentenceParser = new()
|
||||
{
|
||||
@@ -86,8 +91,8 @@ namespace Convention.RScript
|
||||
mode = RScriptSentence.Mode.Expression
|
||||
};
|
||||
expression = expression.Trim();
|
||||
expression.TrimEnd(';');
|
||||
SentenceParser.Any(matcher => matcher.Match(expression, ref result));
|
||||
expression = expression.TrimEnd(';');
|
||||
var _ = SentenceParser.Any(matcher => matcher.Match(expression, ref result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -107,14 +112,14 @@ namespace Convention.RScript
|
||||
else if (Sentences[i].mode == RScriptSentence.Mode.ExitNamespace)
|
||||
{
|
||||
if (namespaceLayers.Count == 0)
|
||||
throw new RScriptException("Namespace exit without enter.", i);
|
||||
throw new RScriptRuntimeException("Namespace exit without enter.", i);
|
||||
var enterPointer = namespaceLayers.Pop();
|
||||
namespaceIndicator[enterPointer] = i;
|
||||
}
|
||||
}
|
||||
if (namespaceLayers.Count > 0)
|
||||
{
|
||||
throw new RScriptException("Namespace enter without exit.", namespaceLayers.Peek());
|
||||
throw new RScriptRuntimeException("Namespace enter without exit.", namespaceLayers.Peek());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,8 +129,9 @@ namespace Convention.RScript
|
||||
this.Variables = variables ?? new();
|
||||
this.Sentences = (from item in expressions select ParseToSentence(item)).ToArray();
|
||||
this.Labels = new();
|
||||
this.Namespace = new();
|
||||
BuildUpLabelsAndNamespace(ref this.Labels, ref this.Namespace);
|
||||
this.NamespaceLayer = new();
|
||||
this.NamespaceLabels = new();
|
||||
BuildUpLabelsAndNamespace(ref this.Labels, ref this.NamespaceLayer);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +177,7 @@ namespace Convention.RScript
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RScriptException($"Unsupported variable type '{varTypeName}'.", CurrentRuntimePointer);
|
||||
throw new RScriptRuntimeException($"Unsupported variable type '{varTypeName}'.", CurrentRuntimePointer);
|
||||
}
|
||||
}
|
||||
if (CurrentLocalSpaceVariableNames.Peek().Contains(varName) == false)
|
||||
@@ -182,7 +188,7 @@ namespace Convention.RScript
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RScriptException($"Variable '{varName}' already defined on this namespace.", CurrentRuntimePointer);
|
||||
throw new RScriptRuntimeException($"Variable '{varName}' already defined on this namespace.", CurrentRuntimePointer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +258,7 @@ namespace Convention.RScript
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RScriptException($"Label '{sentence.content}' not found.", CurrentRuntimePointer);
|
||||
throw new RScriptRuntimeException($"Label '{sentence.content}' not found.", CurrentRuntimePointer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,7 +272,7 @@ namespace Convention.RScript
|
||||
{
|
||||
CurrentRuntimePointer = Sentences.Length;
|
||||
}
|
||||
else if (Namespace.TryGetValue(RuntimePointerStack.Peek(), out var exitPointer))
|
||||
else if (NamespaceLayer.TryGetValue(RuntimePointerStack.Peek(), out var exitPointer))
|
||||
{
|
||||
CurrentRuntimePointer = exitPointer;
|
||||
DoExitNamespace(parser);
|
||||
|
Reference in New Issue
Block a user