void HandleMultipleParameters(ParseNode astNode, CleanupAstNodeStates states) { var typeNode = states[0]; var commaPositions = ComputeCommaPositions(states); var functionBlockNode = typeNode.GetParentFunctionBlockNode() ?? typeNode.GetRootNode(); ExtractArrayParameters(states, commaPositions, typeNode, functionBlockNode); astNode.RemoveFromParent(); _found = true; states.Remap(); }
static void DeclareVariable(ParseNode functionBody, ParseNode typeNameNode, ParseNode variableNameNode) { var nodesToAdd = new List<ParseNode> { typeNameNode.Clone(), TokenKind.Space.BuildTokenFromId(" "), variableNameNode.Clone(), TokenKind.SemiColon.BuildTokenFromId() }; var declarationNode = new ParseNode(RuleKind.DeclareVariable); declarationNode.AddRange(nodesToAdd); functionBody.Insert(1, declarationNode); if (typeNameNode.Parent.Rule == RuleKind.DeclareVariable) { typeNameNode.Parent.Rule = RuleKind.InstructionCode; } typeNameNode.RemoveFromParent(); }
void HandleMultipleParameters(ParseNode astNode, CleanupAstNodeStates states) { var typeNode = states[0]; var commaPositions = new List<int>(); var isInSquares = false; states.EachWithIndex((node, id) => { var isComma = node.Token == TokenKind.Comma; var isOpen = node.Token == TokenKind.OpenSquared; var isClosed = node.Token == TokenKind.CloseSquared; if (isOpen) isInSquares = true; if (isClosed) isInSquares = false; if (isComma && !isInSquares) commaPositions.Add(id); }); commaPositions.Add(states.Count - 1); var functionBlockNode = typeNode.GetParentFunctionBlockNode(); if (functionBlockNode == null) functionBlockNode = typeNode.GetRootNode(); var startPos = 1; foreach (var commaPosition in commaPositions) { ExtractArrayParameter(typeNode, states, startPos, commaPosition - 1, functionBlockNode); startPos = commaPosition + 1; } astNode.RemoveFromParent(); }