mirror of
https://github.com/Cekis/SWG-ScriptConverter.git
synced 2026-09-27 12:13:37 -04:00
Add code
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System.Linq;
|
||||
using ScriptConverter.Ast;
|
||||
using ScriptConverter.Ast.Declarations;
|
||||
|
||||
namespace ScriptConverter.Parser.Parselets.Declarations
|
||||
{
|
||||
class MethodParselet : IDeclarationParselet
|
||||
{
|
||||
public Declaration Parse(ScriptParser parser, ScriptToken token)
|
||||
{
|
||||
var returnType = parser.ParseType(token);
|
||||
var name = parser.Take(ScriptTokenType.Identifier).Contents;
|
||||
|
||||
if (parser.MatchAndTake(ScriptTokenType.Assign))
|
||||
{
|
||||
var value = parser.ParseExpression();
|
||||
parser.Take(ScriptTokenType.Semicolon);
|
||||
|
||||
return new FieldDeclaration(token, parser.Previous, returnType, name, value, false, false);
|
||||
}
|
||||
|
||||
parser.Take(ScriptTokenType.LeftParen);
|
||||
|
||||
var parameters = parser.ParseSeparatedBy(ScriptTokenType.Comma, (_, first) =>
|
||||
{
|
||||
if (parser.Match(ScriptTokenType.RightParen))
|
||||
return null;
|
||||
|
||||
ScriptType paramType;
|
||||
string paramName;
|
||||
parser.ParseNamedType(out paramType, out paramName);
|
||||
|
||||
return new MethodDeclaration.Parameter(paramType, paramName);
|
||||
}).ToList();
|
||||
|
||||
parser.Take(ScriptTokenType.RightParen);
|
||||
|
||||
var block = parser.ParseBlock(false);
|
||||
|
||||
return new MethodDeclaration(token, parser.Previous, returnType, name, parameters, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user