コード例 #1
0
        public void GetPositionNodeTest()
        {
            AstRoot ast = RParser.Parse(new TextStream(" x <- a+b"));

            IAstNode scope;
            IAstNode variable;

            ast.GetPositionNode(0, out scope);
            scope.Should().BeAssignableTo <IScope>();

            scope.GetPositionNode(1, out variable);
            variable.Should().BeOfType <Variable>();
        }
コード例 #2
0
ファイル: AstRootExtensions.cs プロジェクト: skrutsick/RTVS
        /// <summary>
        /// Given position over function name retrieves name range and the function call.
        /// </summary>
        public static string GetFunctionName(this AstRoot ast, int position, out FunctionCall functionCall, out Variable functionVariable)
        {
            functionVariable = null;
            functionCall     = null;

            ast.GetPositionNode(position, out var node);
            if (node == null)
            {
                return(null);
            }

            // In abc(de|f(x)) first find inner function, then outer.
            if (node is TokenNode && node.Parent is FunctionCall)
            {
                functionCall = (FunctionCall)node.Parent;
            }
            else
            {
                functionCall = ast.GetNodeOfTypeFromPosition <FunctionCall>(position);
            }
            functionVariable = functionCall?.RightOperand as Variable;
            return(functionVariable?.Name);
        }