Properly handle composite tables

This commit is contained in:
Deukhoofd 2019-01-19 17:27:43 +01:00
parent 513d8069fc
commit 89f3db509d
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
8 changed files with 24 additions and 7 deletions

Binary file not shown.

Binary file not shown.

View File

@ -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);
}
}
}