Properly handle composite tables
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Upsilon.BaseTypes;
|
||||
using Upsilon.Binder.VariableSymbols;
|
||||
using Upsilon.BoundTypes;
|
||||
using Upsilon.StandardLibraries;
|
||||
@@ -61,7 +65,8 @@ namespace UpsilonLanguageServer
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParseMethod(JObject value, IDictionary<string, UserDataBoundProperty> dic, string propertyName, string type, string comment)
|
||||
private static void ParseMethod(JObject value, IDictionary<string, UserDataBoundProperty> dic,
|
||||
string propertyName, string type, string comment)
|
||||
{
|
||||
var returnType = value.GetValue("returns", StringComparison.InvariantCultureIgnoreCase)?.ToString();
|
||||
var parameters = new List<UserDataBoundFunctionParameter>();
|
||||
@@ -120,11 +125,11 @@ namespace UpsilonLanguageServer
|
||||
var boundType = BoundTypeHandler.GetTypeDefinition(stringType);
|
||||
if (boundType != null)
|
||||
{
|
||||
StaticScope.BoundScope.AssignToNearest(new UserDataVariableSymbol(name, boundType){CommentValue = comments});
|
||||
StaticScope.BoundScope.AssignToNearest(new UserDataVariableSymbol(name, boundType, true){CommentValue = comments});
|
||||
}
|
||||
else
|
||||
{
|
||||
StaticScope.BoundScope.AssignToNearest(new UserDataVariableSymbol(name, Type.Unknown){CommentValue = comments});
|
||||
StaticScope.BoundScope.AssignToNearest(new UserDataVariableSymbol(name, Type.Unknown, true){CommentValue = comments});
|
||||
}
|
||||
}
|
||||
else if (type == Type.Function)
|
||||
@@ -166,8 +171,10 @@ namespace UpsilonLanguageServer
|
||||
}
|
||||
}
|
||||
|
||||
private static Type ParseType(string input)
|
||||
private static readonly Regex TableMatcher = new Regex(@"table *\((?'catch'.*)\)", RegexOptions.IgnoreCase);
|
||||
private static TypeContainer ParseType(string input)
|
||||
{
|
||||
input = input.Trim();
|
||||
if (string.Equals(input, "string", StringComparison.InvariantCultureIgnoreCase))
|
||||
return Type.String;
|
||||
if (string.Equals(input, "number", StringComparison.InvariantCultureIgnoreCase))
|
||||
@@ -175,13 +182,23 @@ namespace UpsilonLanguageServer
|
||||
if (string.Equals(input, "bool", StringComparison.InvariantCultureIgnoreCase))
|
||||
return Type.Boolean;
|
||||
if (string.Equals(input, "table", StringComparison.InvariantCultureIgnoreCase))
|
||||
return Type.Table;
|
||||
{
|
||||
}
|
||||
if (string.Equals(input, "function", StringComparison.InvariantCultureIgnoreCase))
|
||||
return Type.Function;
|
||||
if (string.Equals(input, "unknown", StringComparison.InvariantCultureIgnoreCase))
|
||||
return Type.Unknown;
|
||||
|
||||
return Type.UserData;
|
||||
var match = TableMatcher.Match(input);
|
||||
if (match.Success)
|
||||
{
|
||||
var group = match.Groups["catch"].Value;
|
||||
var split = group.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
return new CompositeTypeContainer()
|
||||
{
|
||||
Types = split.Select(ParseType).ToImmutableArray()
|
||||
};
|
||||
}
|
||||
return new TypeContainer(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user