mirror of https://github.com/Xpl0itR/protodec.git
wip
This commit is contained in:
parent
1c1e14c58f
commit
41db9569dc
|
@ -35,7 +35,8 @@ public sealed class LuaSourceLoader
|
|||
|
||||
return LuaSyntaxTree.ParseText(
|
||||
SourceText.From(fileStream),
|
||||
null, // TODO: maybe expose the options parameter
|
||||
null, // TODO: maybe expose this as a parameter
|
||||
Path.GetFileName(filePath));
|
||||
//TODO: consider checking lua source validity via SyntaxTree.GetDiagnostics()
|
||||
}
|
||||
}
|
|
@ -23,8 +23,11 @@ public sealed class Protobuf
|
|||
public string? AssemblyName { get; init; }
|
||||
public string? Namespace { get; init; }
|
||||
|
||||
public string FileName =>
|
||||
_fileName ??= $"{string.Join('_', TopLevels.Select(static topLevel => topLevel.Name))}.proto";
|
||||
public string FileName
|
||||
{
|
||||
get => _fileName ??= $"{string.Join('_', TopLevels.Select(static topLevel => topLevel.Name))}.proto";
|
||||
set => _fileName = value;
|
||||
}
|
||||
|
||||
public HashSet<string> Imports =>
|
||||
_imports ??= [];
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
using System;
|
||||
using CommunityToolkit.Diagnostics;
|
||||
using Loretta.CodeAnalysis;
|
||||
using Loretta.CodeAnalysis.Lua.Syntax;
|
||||
|
||||
namespace LibProtodec;
|
||||
|
||||
|
@ -13,6 +14,67 @@ partial class ProtodecContext
|
|||
{
|
||||
public void ParseLuaSyntaxTree(SyntaxTree ast)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CompilationUnitSyntax root = (CompilationUnitSyntax)ast.GetRoot();
|
||||
SyntaxList<StatementSyntax> statements = root.Statements.Statements;
|
||||
|
||||
LocalVariableDeclarationStatementSyntax pbTableDeclaration =
|
||||
(LocalVariableDeclarationStatementSyntax)statements[0];
|
||||
|
||||
string pbTableName = pbTableDeclaration.Names[0].Name;
|
||||
Guard.IsTrue(
|
||||
pbTableName.EndsWith("_pbTable"));
|
||||
|
||||
bool importedProtobufLib = false;
|
||||
string? returns = null;
|
||||
|
||||
foreach (StatementSyntax statement in statements)
|
||||
{
|
||||
switch (statement)
|
||||
{
|
||||
case LocalVariableDeclarationStatementSyntax
|
||||
{
|
||||
Names: [{ Name: { } varName }],
|
||||
EqualsValues.Values: [FunctionCallExpressionSyntax { Expression: IdentifierNameSyntax { Name: "require" } } call]
|
||||
}:
|
||||
switch (call.Argument)
|
||||
{
|
||||
case StringFunctionArgumentSyntax { Expression.Token.ValueText: "protobuf/protobuf" }:
|
||||
importedProtobufLib = true;
|
||||
break;
|
||||
case ExpressionListFunctionArgumentSyntax { Expressions: [LiteralExpressionSyntax { Token.ValueText: {} import }] }:
|
||||
// TODO: handle imported protos
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ExpressionStatementSyntax
|
||||
{
|
||||
Expression: FunctionCallExpressionSyntax
|
||||
{
|
||||
Expression: IdentifierNameSyntax { Name: "module" },
|
||||
Argument: ExpressionListFunctionArgumentSyntax
|
||||
{
|
||||
Expressions: [LiteralExpressionSyntax literal]
|
||||
}
|
||||
}
|
||||
}:
|
||||
string moduleName = literal.Token.ValueText;
|
||||
break;
|
||||
case AssignmentStatementSyntax
|
||||
{
|
||||
Variables: [MemberAccessExpressionSyntax varExpr],
|
||||
EqualsValues.Values: [{} valueExpr]
|
||||
}:
|
||||
// TODO: build protos
|
||||
break;
|
||||
case ReturnStatementSyntax { Expressions: [IdentifierNameSyntax identifier] }:
|
||||
returns = identifier.Name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!importedProtobufLib || returns != pbTableName)
|
||||
{
|
||||
ThrowHelper.ThrowInvalidDataException();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue