private static IEnumerable <DocumentElement> Execute(CompilerState state, SyntaxNode element) { var obj = state.Execute(element); var elements = new List <DocumentElement>(); if (obj != null) { var flattened = obj.Flatten(); return(flattened.Select(e => e.Value).OfType <DocumentElement>()); } else { return(Array.Empty <DocumentElement>()); } }
/// <summary> /// <para>Pads the given arguments so that they fit the specified parameter infos.</para> /// <para>Also transforms <c>params</c> variable length arrays into CLR Arrays.</para> /// </summary> /// <param name="command"></param> /// <param name="state"></param> /// <param name="args"></param> /// <param name="parameters"></param> /// <returns></returns> /// <exception cref="CompilerException"/> public static object[] PadArguments(string command, Element element, CompilerState state, Argument[] args, ParameterInfo[] parameters) { // Guard for when the command does not require any arguments if (parameters.Length == 0) { if (args.Length != 0) { throw new CompilerException(element, $"Command {command} does not expect any arguments. Received: {args.Length}"); } return(Array.Empty <object>()); } var objects = new List <object>(parameters.Length); CountParameters(parameters, out var hasState, out int required, out int optional); if (args.Length < required || args.Length > required + optional && !IsParams(parameters[^ 1]))
public static CompilerResult Compile(Context context, IEnumerable <Element> elements) { var state = new CompilerState(context); state.Issues.CollectionChanged += (_, e) => IssuesChanged(context.Logger, e); foreach (var element in elements) { Execute(state, element); } state.Document.Elements.AddRange(state.Blocks.Current.Objects.Select(e => e.Value).OfType <DocumentElement>()); ResolveCallbacks(state.Document.Elements); var result = new CompilerResult(state.Document, state.Issues); return(result); }
public static CompilerResult Compile(Context context, IEnumerable <SyntaxNode> elements) { var state = new CompilerState(context); state.Issues.CollectionChanged += (_, e) => IssuesChanged(context.Logger, e); foreach (var element in elements) { if (state.Continue) { state.Document.Elements.AddRange(Execute(state, element)); } } ResolveCallbacks(state.Document.Elements); var result = new CompilerResult(state.Document, state.Issues); return(result); }
/// <summary> /// /// </summary> /// <param name="origin"></param> /// <param name="compilerState"></param> /// <exception cref="ArgumentNullException"/> public ObjectCreator(ObjectSyntax origin, CompilerState compilerState) : base(origin) { CompilerState = compilerState ?? throw new ArgumentNullException(nameof(compilerState)); }
public ObjectArray(ArraySyntax origin, CompilerState compilerState, Argument[] objects) : base(origin) { CompilerState = compilerState ?? throw new ArgumentNullException(nameof(compilerState)); array = objects ?? throw new ArgumentNullException(nameof(objects)); }