47 lines
2.2 KiB
C#
47 lines
2.2 KiB
C#
using Nub.Lang.Frontend.Lexing;
|
|
using Nub.Lang.Frontend.Parsing.Statements;
|
|
using Nub.Lang.Frontend.Typing;
|
|
|
|
namespace Nub.Lang.Frontend.Parsing.Definitions;
|
|
|
|
public class FuncParameter(string name, NubType type, bool variadic)
|
|
{
|
|
public string Name { get; } = name;
|
|
public NubType Type { get; } = type;
|
|
public bool Variadic { get; } = variadic;
|
|
|
|
public override string ToString() => $"{Name}: {Type}";
|
|
}
|
|
|
|
public interface IFuncSignature
|
|
{
|
|
public string Name { get; }
|
|
public string Namespace { get; }
|
|
public List<FuncParameter> Parameters { get; }
|
|
public Optional<NubType> ReturnType { get; }
|
|
|
|
public string ToString() => $"{Name}({string.Join(", ", Parameters.Select(p => p.ToString()))}){(ReturnType.HasValue ? ": " + ReturnType.Value : "")}";
|
|
}
|
|
|
|
public class LocalFuncDefinitionNode(IReadOnlyList<Token> tokens, Optional<string> documentation, string name, string @namespace, List<FuncParameter> parameters, BlockNode body, Optional<NubType> returnType, bool exported) : DefinitionNode(tokens, documentation), IFuncSignature
|
|
{
|
|
public string Name { get; } = name;
|
|
public string Namespace { get; } = @namespace;
|
|
public List<FuncParameter> Parameters { get; } = parameters;
|
|
public BlockNode Body { get; } = body;
|
|
public Optional<NubType> ReturnType { get; } = returnType;
|
|
public bool Exported { get; } = exported;
|
|
|
|
public override string ToString() => $"{Name}({string.Join(", ", Parameters.Select(p => p.ToString()))}){(ReturnType.HasValue ? ": " + ReturnType.Value : "")}";
|
|
}
|
|
|
|
public class ExternFuncDefinitionNode(IReadOnlyList<Token> tokens, Optional<string> documentation, string name, string @namespace, string callName, List<FuncParameter> parameters, Optional<NubType> returnType) : DefinitionNode(tokens, documentation), IFuncSignature
|
|
{
|
|
public string Name { get; } = name;
|
|
public string Namespace { get; } = @namespace;
|
|
public string CallName { get; } = callName;
|
|
public List<FuncParameter> Parameters { get; } = parameters;
|
|
public Optional<NubType> ReturnType { get; } = returnType;
|
|
|
|
public override string ToString() => $"{Name}({string.Join(", ", Parameters.Select(p => p.ToString()))}){(ReturnType.HasValue ? ": " + ReturnType.Value : "")}";
|
|
} |