44 lines
1.8 KiB
C#
44 lines
1.8 KiB
C#
using common;
|
|
using syntax.Parsing.Statements;
|
|
using syntax.Tokenization;
|
|
using syntax.Typing;
|
|
|
|
namespace syntax.Parsing.Definitions;
|
|
|
|
public class FuncParameter(string name, NubType type)
|
|
{
|
|
public string Name { get; } = name;
|
|
public NubType Type { get; } = type;
|
|
|
|
public override string ToString() => $"{Name}: {Type}";
|
|
}
|
|
|
|
public interface IFuncSignature
|
|
{
|
|
public string Name { get; }
|
|
public List<FuncParameter> Parameters { get; }
|
|
public NubType ReturnType { get; }
|
|
|
|
public string ToString() => $"{Name}({string.Join(", ", Parameters.Select(p => p.ToString()))}){": " + ReturnType}";
|
|
}
|
|
|
|
public class LocalFuncDefinitionNode(IReadOnlyList<Token> tokens, Optional<string> documentation, string @namespace, string name, List<FuncParameter> parameters, BlockNode body, NubType returnType, bool exported) : DefinitionNode(tokens, documentation, @namespace), IFuncSignature
|
|
{
|
|
public string Name { get; } = name;
|
|
public List<FuncParameter> Parameters { get; } = parameters;
|
|
public BlockNode Body { get; } = body;
|
|
public NubType ReturnType { get; } = returnType;
|
|
public bool Exported { get; } = exported;
|
|
|
|
public override string ToString() => $"{Name}({string.Join(", ", Parameters.Select(p => p.ToString()))}){": " + ReturnType}";
|
|
}
|
|
|
|
public class ExternFuncDefinitionNode(IReadOnlyList<Token> tokens, Optional<string> documentation, string @namespace, string name, string callName, List<FuncParameter> parameters, NubType returnType) : DefinitionNode(tokens, documentation, @namespace), IFuncSignature
|
|
{
|
|
public string Name { get; } = name;
|
|
public string CallName { get; } = callName;
|
|
public List<FuncParameter> Parameters { get; } = parameters;
|
|
public NubType ReturnType { get; } = returnType;
|
|
|
|
public override string ToString() => $"{Name}({string.Join(", ", Parameters.Select(p => p.ToString()))}){": " + ReturnType}";
|
|
} |