2019-07-03 09:44:53 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using Godot;
|
|
|
|
using Godot.Collections;
|
|
|
|
|
|
|
|
namespace GodotTools.Internals
|
|
|
|
{
|
|
|
|
public static class ScriptClassParser
|
|
|
|
{
|
|
|
|
public class ClassDecl
|
|
|
|
{
|
|
|
|
public string Name { get; }
|
|
|
|
public string Namespace { get; }
|
|
|
|
public bool Nested { get; }
|
2020-06-22 01:31:48 +02:00
|
|
|
public long BaseCount { get; }
|
2019-07-03 09:44:53 +02:00
|
|
|
|
2020-07-20 15:48:12 +02:00
|
|
|
public string SearchName => Nested ?
|
|
|
|
Name.Substring(Name.LastIndexOf(".", StringComparison.Ordinal) + 1) :
|
|
|
|
Name;
|
|
|
|
|
2020-06-22 01:31:48 +02:00
|
|
|
public ClassDecl(string name, string @namespace, bool nested, long baseCount)
|
2019-07-03 09:44:53 +02:00
|
|
|
{
|
|
|
|
Name = name;
|
|
|
|
Namespace = @namespace;
|
|
|
|
Nested = nested;
|
|
|
|
BaseCount = baseCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
2020-01-20 19:08:08 +01:00
|
|
|
private static extern Error internal_ParseFile(string filePath, Array<Dictionary> classes, out string errorStr);
|
2019-07-03 09:44:53 +02:00
|
|
|
|
2020-01-21 20:07:26 +01:00
|
|
|
public static Error ParseFile(string filePath, out IEnumerable<ClassDecl> classes, out string errorStr)
|
2019-07-03 09:44:53 +02:00
|
|
|
{
|
|
|
|
var classesArray = new Array<Dictionary>();
|
2020-01-21 20:07:26 +01:00
|
|
|
var error = internal_ParseFile(filePath, classesArray, out errorStr);
|
2019-07-03 09:44:53 +02:00
|
|
|
if (error != Error.Ok)
|
2020-01-21 20:07:26 +01:00
|
|
|
{
|
|
|
|
classes = null;
|
|
|
|
return error;
|
|
|
|
}
|
2019-07-03 09:44:53 +02:00
|
|
|
|
|
|
|
var classesList = new List<ClassDecl>();
|
|
|
|
|
|
|
|
foreach (var classDeclDict in classesArray)
|
|
|
|
{
|
|
|
|
classesList.Add(new ClassDecl(
|
2019-12-11 14:46:28 +01:00
|
|
|
(string)classDeclDict["name"],
|
|
|
|
(string)classDeclDict["namespace"],
|
|
|
|
(bool)classDeclDict["nested"],
|
2020-06-22 01:31:48 +02:00
|
|
|
(long)classDeclDict["base_count"]
|
2019-07-03 09:44:53 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
classes = classesList;
|
2020-01-21 20:07:26 +01:00
|
|
|
|
|
|
|
return Error.Ok;
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|