mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-02-03 17:20:45 +03:00
Parse from source (it's more reliable)
This commit is contained in:
parent
6719c6d0a4
commit
d7a546d913
49
Generator/CodeParser/CodeParser.Class.cs
Normal file
49
Generator/CodeParser/CodeParser.Class.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace Generator
|
||||||
|
{
|
||||||
|
partial class CodeParser
|
||||||
|
{
|
||||||
|
public class Class
|
||||||
|
{
|
||||||
|
public string Name;
|
||||||
|
|
||||||
|
public class Function
|
||||||
|
{
|
||||||
|
public string Name;
|
||||||
|
public Dictionary<string, string> Arguments = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
public string ReturnType;
|
||||||
|
public string CallResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Function> Functions = new List<Function>();
|
||||||
|
|
||||||
|
internal Function AddFunction( string funcName, string returnType, string args )
|
||||||
|
{
|
||||||
|
var f = new Function
|
||||||
|
{
|
||||||
|
Name = funcName,
|
||||||
|
ReturnType = returnType
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach ( var arg in args.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
|
||||||
|
{
|
||||||
|
var m = Regex.Match( arg.Trim(), @"(.+?[ |\*])?([a-zA-Z0-9_]+?)( = (.+?))?$" );
|
||||||
|
|
||||||
|
var t = m.Groups[1].Value.Trim();
|
||||||
|
var n = m.Groups[2].Value.Trim();
|
||||||
|
|
||||||
|
f.Arguments.Add( n, t );
|
||||||
|
}
|
||||||
|
|
||||||
|
Functions.Add( f );
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Generator
|
namespace Generator
|
||||||
{
|
{
|
||||||
class CodeParser
|
public partial class CodeParser
|
||||||
{
|
{
|
||||||
public string Content;
|
public string Content;
|
||||||
|
|
||||||
|
81
Generator/CodeParser/ParseClasses.cs
Normal file
81
Generator/CodeParser/ParseClasses.cs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Generator
|
||||||
|
{
|
||||||
|
partial class CodeParser
|
||||||
|
{
|
||||||
|
public List<Class> Classes = new List<Class>();
|
||||||
|
|
||||||
|
public void ParseClasses()
|
||||||
|
{
|
||||||
|
var source = RemoveAnnotations( Content );
|
||||||
|
|
||||||
|
{
|
||||||
|
var r = new Regex( @"class ([a-zA-Z]+)[\r|\n]+{[\r|\n]((?s).*?)};" );
|
||||||
|
var ma = r.Matches( source );
|
||||||
|
|
||||||
|
foreach ( Match m in ma )
|
||||||
|
{
|
||||||
|
ProcessClass( m.Groups[0].Value.Trim(), m.Groups[1].Value.Trim(), m.Groups[2].Value.Trim() );
|
||||||
|
//def.CallbackIds.Add( m.Groups[1].Value.Substring( 3 ).Replace( "Callbacks", "" ), int.Parse( m.Groups[2].Value ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine( "OKay" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ProcessClass( string fulldef, string classname, string inner )
|
||||||
|
{
|
||||||
|
Console.WriteLine( $"Class: {classname} " );
|
||||||
|
|
||||||
|
var lines = inner.Split( new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries );
|
||||||
|
|
||||||
|
var func = new Regex( @"virtual (.+[ |\*])([a-zA-Z]+?)\((.+?)?\) = 0 ?;" );
|
||||||
|
|
||||||
|
var c = new Class();
|
||||||
|
c.Name = classname;
|
||||||
|
|
||||||
|
foreach ( var line in lines )
|
||||||
|
{
|
||||||
|
if ( line.Trim().Length < 4 ) continue;
|
||||||
|
if ( line.Trim().StartsWith( "public:" ) ) continue;
|
||||||
|
if ( line.Trim().StartsWith( "//" ) ) continue;
|
||||||
|
|
||||||
|
var f = func.Match( line );
|
||||||
|
if ( f.Success )
|
||||||
|
{
|
||||||
|
var returnType = f.Groups[1].Value.Trim();
|
||||||
|
var funcName = f.Groups[2].Value.Trim();
|
||||||
|
var args = f.Groups[3].Value.Trim();
|
||||||
|
// Console.WriteLine( $"Function: {funcName} returns {returnType} with args {args}" );
|
||||||
|
|
||||||
|
if ( funcName.Contains( ' ' ) || funcName.Contains( '*' ) )
|
||||||
|
throw new System.Exception( "Parsing Error!" );
|
||||||
|
|
||||||
|
c.AddFunction( funcName, returnType, args );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine( $"Unknown Line: {line}" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Classes.Add( c );
|
||||||
|
}
|
||||||
|
|
||||||
|
public string RemoveAnnotations( string str )
|
||||||
|
{
|
||||||
|
str = Regex.Replace( str, @"STEAM_OUT_ARRAY_CALL\((.+?)\)", "" );
|
||||||
|
str = Regex.Replace( str, @"STEAM_PRIVATE_API\((.+)\)", "$1" );
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user