private void RenderExpression(NSprakExpression expression) { switch (expression) { case NSprakBlock block: RenderHeader(block.Header); break; case Command command: char[] characters = command.Keyword.ToCharArray(); characters[0] = char.ToUpper(characters[0]); RenderKeyword(new string(characters)); break; case Indexer _: RenderKeyword("Array Index"); break; case FunctionCall functionCall: RenderKeyword("Call "); RenderName(functionCall.Name); break; case LiteralArrayGet _: RenderComment("(Array literal)"); break; case LiteralGet literal: switch (literal.Value) { case SprakBoolean boolean: RenderBoolean(boolean.Value); break; case SprakNumber number: RenderNumber(number.Value); break; case SprakString text: RenderString(text.Value); break; } break; case OperatorCall op: RenderKeyword("Op "); RenderOperator(op.OperatorText); break; case Return _: RenderKeyword(Keywords.Return); break; case VariableAssignment varAssign: RenderKeyword(varAssign.IsDeclaration?"Declare ":"Assign "); RenderName(varAssign.Name); break; case VariableReference varRef: RenderKeyword("Ref "); RenderName(varRef.Name); break; default: RenderComment("Unrecognized type "); RenderComment($"(Name: {expression.GetType().Name})"); break; } }
private void AddChildren(NSprakExpression parent) { AddDebugParameter("Trace", parent.GetTraceString()); if (parent.TypeHint != SprakType.Unit) { AddDebugParameter("Type Hint", parent.TypeHint); } if (!(parent is NSprakBlock mainBlock && mainBlock.Header is MainHeader)) { AddDebugParameter("Parent Hint", new BlockReferenceElement(parent.ParentBlockHint)); } if (parent.OperatorsHint != null) { List <OpDebugInfo> ops = parent.OperatorsHint.ToList(); if (parent is NSprakBlock block) { ops.AddRange(block.Header.OperatorsHint); } AddDebugParameter("Operators", ops); } AddDebugParameter("Tokens", parent.GetTokens().ToList()); switch (parent) { case Command _: break; case LiteralGet _: break; case NSprakBlock block: AddHeaderParameters(block.Header); if (block.ScopeHint?.VariableDeclarations == null || block.ScopeHint.VariableDeclarations.Count > 0) { AddDebugParameter("Variable Declarations Hint", block.ScopeHint.VariableDeclarations); } foreach (NSprakExpression statement in block.Statements) { AddParameter(null, statement); } if (block.EndStatement != null) { AddParameter(null, block.EndStatement); } break; case FunctionCall functionCall: AddFunctionHintParameters(functionCall.UserFunctionHint, functionCall.BuiltInFunctionHint, null); AddParameter("Arguments", functionCall.Arguments); break; case LiteralArrayGet array: AddParameter("Elements", array.Elements); break; case Indexer indexer: AddParameter("Source", indexer.SourceExpression); AddParameter("Index", indexer.IndexExpression); break; case OperatorCall op: AddFunctionHintParameters(null, op.BuiltInFunctionHint, null); if (op.LeftInput != null) { AddParameter("Left", op.LeftInput); } if (op.RightInput != null) { AddParameter("Right", op.RightInput); } break; case Return ret: if (ret.HasValue) { AddParameter("Value", ret.Value); } break; case VariableAssignment varAssign: AddFunctionHintParameters(null, varAssign.BuiltInFunctionHint, varAssign.OpHint); if (varAssign.OpHint != null) { AddParameter("OpHint", varAssign.OpHint); } if (varAssign.IsDeclaration) { AddParameter("Declared Type", varAssign.DeclarationType); } AddParameter("Name", varAssign.Name); if (varAssign.Indices.Count > 0) { AddParameter("Indices", varAssign.Indices.Select(x => x.Index).ToList()); } AddParameter("Operator", varAssign.Operator); AddParameter("Value", varAssign.Value); break; case VariableReference varRef: AddParameter("Name", varRef.Name); break; default: ErrorParameter($"Unrecognized type: {parent.GetType().Name}"); break; } }