public string GetFunctionAtPoint(int column, int line, out int argumentIndex) { // Translate global line index to local index. line = line - lineOffsetIntoContent; argumentIndex = -1; // No argument. if (null == topMostFunctionPart) { return(null); } FunctionCallPart intersection = topMostFunctionPart.GetIntersectionPart(column, line); if (null == intersection) { return(null); } FunctionCallPart parentPart = intersection.ParentPart as FunctionCallPart; if (null != parentPart) { argumentIndex = parentPart.GetArgumentIndex(intersection); return(parentPart.Identifier); } System.Diagnostics.Debug.Assert(intersection == topMostFunctionPart); if (intersection == topMostFunctionPart) { argumentIndex = 0; return(topMostFunctionPart.Identifier); } return(null); }
public FunctionCallPart GetIntersectionPart(System.Drawing.Point point) { if (null != argumentParts) { foreach (FunctionCallPart part in argumentParts) { FunctionCallPart intersection = part.GetIntersectionPart(point); if (null != intersection) { return(intersection); } } } // If there was no child argument parts, or none of them is intersecting // with the input point, then test the parent (this) function call part. if (point.Y < startPoint.Y || (point.Y > endPoint.Y)) { return(null); // The point lies outside of the range. } if (point.Y == startPoint.Y && (point.X < startPoint.X)) { return(null); // On the first line, but outside of range. } if (point.Y == endPoint.Y && (point.X > endPoint.X)) { return(null); // On the last line, but outside of range. } return(this); }
public int GetArgumentIndex(FunctionCallPart argumentPart) { if (null == argumentParts) { return(-1); } return(argumentParts.IndexOf(argumentPart)); }
public void AddArgumentPart(FunctionCallPart argumentPart) { if (null == argumentParts) { argumentParts = new List <FunctionCallPart>(); } argumentPart.ParentPart = this; argumentParts.Add(argumentPart); UpdateStartPointInternal(argumentPart.StartPoint); UpdateEndPointInternal(argumentPart.EndPoint); }
private FunctionCallContext(List <string> content, System.Drawing.Point startPoint, System.Drawing.Point endPoint) { lineOffsetIntoContent = startPoint.Y; StringBuilder contentBuilder = new StringBuilder(); for (int index = startPoint.Y; index <= endPoint.Y; ++index) { string line = content[index]; if (index == startPoint.Y) { // We're looking at the first line to copy, replace // everything before the start point with blank space. if (startPoint.X > 0) { contentBuilder.Append(new string(' ', startPoint.X)); } contentBuilder.Append(line.Substring(startPoint.X)); continue; } // We have come into region of another statement if (line.IndexOf('=') != -1) { break; // Get outta here! } contentBuilder.Append(line); } string intermediate = contentBuilder.ToString(); intermediate = PatchContent(intermediate); MemoryStream inputStream = new MemoryStream( Encoding.Default.GetBytes(intermediate)); FunctionCallParser.Scanner scanner = new FunctionCallParser.Scanner(inputStream); FunctionCallParser.Parser parser = new FunctionCallParser.Parser(scanner); parser.Parse(); topMostFunctionPart = parser.RootFunctionCallPart; }
public void AddDefaultArgument(System.Drawing.Point start, System.Drawing.Point end) { // This "default argument" is not the same as a term used in regular // context. It is an argument for function call that does not specify // any argument. This is inserted so that when queried, the argument // index at the cursor location returns "0" instead of "-1" (which // means there's no argument found in cursor location). AutoComplete // tooltip should always highlight the first argument even before the // first argument is typed in. This should only be done when there is // no argument specified yet (as user types). // System.Diagnostics.Debug.Assert(this.HasArgument == false); FunctionCallPart defaultArgument = new FunctionCallPart(); defaultArgument.SetStartPoint(start); defaultArgument.SetEndPoint(end); this.AddArgumentPart(defaultArgument); }
private FunctionCallContext(List<string> content, System.Drawing.Point startPoint, System.Drawing.Point endPoint) { lineOffsetIntoContent = startPoint.Y; StringBuilder contentBuilder = new StringBuilder(); for (int index = startPoint.Y; index <= endPoint.Y; ++index) { string line = content[index]; if (index == startPoint.Y) { // We're looking at the first line to copy, replace // everything before the start point with blank space. if (startPoint.X > 0) contentBuilder.Append(new string(' ', startPoint.X)); contentBuilder.Append(line.Substring(startPoint.X)); continue; } // We have come into region of another statement if (line.IndexOf('=') != -1) break; // Get outta here! contentBuilder.Append(line); } string intermediate = contentBuilder.ToString(); intermediate = PatchContent(intermediate); MemoryStream inputStream = new MemoryStream( Encoding.Default.GetBytes(intermediate)); FunctionCallParser.Scanner scanner = new FunctionCallParser.Scanner(inputStream); FunctionCallParser.Parser parser = new FunctionCallParser.Parser(scanner); parser.Parse(); topMostFunctionPart = parser.RootFunctionCallPart; }
void CommonFunctionCall(FunctionCallPart part) { CommonIdentifier(part); while (la.kind == 9) { CommonArguments(part); } }
void CommonArrayExpression(FunctionCallPart part) { Expect(53); part.SetStartPoint(t, false); if (StartOf(4)) { FunctionCallPart elementPart = new FunctionCallPart(); CommonExpression(elementPart); part.AddArgumentPart(elementPart); while (la.kind == 54) { Get(); elementPart = new FunctionCallPart(); CommonExpression(elementPart); part.AddArgumentPart(elementPart); } } Expect(55); part.SetEndPoint(t, true); }
void CommonComparisonExpression(FunctionCallPart part) { CommonRangeExpression(part); while (StartOf(2)) { CommonComparisonOperator(part); CommonRangeExpression(part); } }
void CommonNameReference(FunctionCallPart part) { if (la.kind == 1) { CommonFunctionCall(part); } else if (la.kind == 53) { CommonArrayExpression(part); } else SynErr(63); if (la.kind == 7) { Get(); part.AppendIdentifier(t); part.SetEndPoint(t, false); if (StartOf(4)) { CommonExpression(part); part.SetEndPoint(t, false); } Expect(8); part.AppendIdentifier(t); part.SetEndPoint(t, false); while (la.kind == 7) { Get(); part.AppendIdentifier(t); part.SetEndPoint(t, false); if (StartOf(4)) { CommonExpression(part); part.SetEndPoint(t, false); } Expect(8); part.AppendIdentifier(t); part.SetEndPoint(t, false); } } }
void FunctionCallParser() { rootFunctionCallPart = new FunctionCallPart(); CommonExpression(rootFunctionCallPart); }
void CommonMathOperator(FunctionCallPart part) { if (la.kind == 45) { Get(); } else if (la.kind == 12) { Get(); } else if (la.kind == 46) { Get(); } else if (la.kind == 47) { Get(); } else if (la.kind == 48) { Get(); } else SynErr(61); }
void CommonLogicalExpression(FunctionCallPart part) { CommonComparisonExpression(part); while (la.kind == 49 || la.kind == 50) { CommonLogicalOperator(part); CommonComparisonExpression(part); } }
void CommonArithmeticExpression(FunctionCallPart part) { CommonTerm(part); while (StartOf(3)) { CommonMathOperator(part); CommonTerm(part); } }
void CommonTerm(FunctionCallPart part) { switch (la.kind) { case 40: { Get(); break; } case 41: { Get(); break; } case 42: { Get(); break; } case 5: { CommonCharacter(part); break; } case 4: { CommonString(part); break; } case 1: case 2: case 3: case 12: case 53: { CommonNegativeExpression(part); break; } case 11: { Get(); CommonTerm(part); break; } default: SynErr(60); break; } }
void CommonComparisonOperator(FunctionCallPart part) { switch (la.kind) { case 15: { Get(); break; } case 17: { Get(); break; } case 14: { Get(); break; } case 16: { Get(); break; } case 18: { Get(); break; } case 19: { Get(); break; } default: SynErr(59); break; } }
void CommonRangeExpression(FunctionCallPart part) { CommonArithmeticExpression(part); if (la.kind == 21) { Get(); CommonArithmeticExpression(part); if (la.kind == 21) { Get(); if (la.kind == 43 || la.kind == 44) { if (la.kind == 43) { Get(); } else { Get(); } } CommonArithmeticExpression(part); } } }
void CommonLogicalOperator(FunctionCallPart part) { if (la.kind == 49) { Get(); } else if (la.kind == 50) { Get(); } else SynErr(58); }
void CommonIdentifier(FunctionCallPart part) { Expect(1); part.Identifier = t.val; }
public void AddArgumentPart(FunctionCallPart argumentPart) { if (null == argumentParts) argumentParts = new List<FunctionCallPart>(); argumentPart.ParentPart = this; argumentParts.Add(argumentPart); UpdateStartPointInternal(argumentPart.StartPoint); UpdateEndPointInternal(argumentPart.EndPoint); }
void CommonArguments(FunctionCallPart part) { Expect(9); part.SetStartPoint(t, false); part.SetEndPoint(la, true); System.Drawing.Point openBracket = PointFromToken(t, false); if (StartOf(4)) { FunctionCallPart parentCallPart = part; part = new FunctionCallPart(); part.SetStartPoint(t, false); CommonExpression(part); part.SetEndPoint(t, false); parentCallPart.AddArgumentPart(part); part = parentCallPart; while (WeakSeparator(54,4,5) ) { parentCallPart = part; part = new FunctionCallPart(); part.SetStartPoint(t, false); CommonExpression(part); part.SetEndPoint(la, true); parentCallPart.AddArgumentPart(part); part = parentCallPart; } } if (part.HasArgument == false) { // See "AddDefaultArgument" for details. System.Drawing.Point closeBracket = PointFromToken(la, true); part.AddDefaultArgument(openBracket, closeBracket); } Expect(10); part.SetEndPoint(t, true); }
void CommonString(FunctionCallPart part) { Expect(4); }
void CommonExpression(FunctionCallPart part) { if (StartOf(1)) { CommonLogicalExpression(part); } else if (la.kind == 51) { CommonTernaryOperation(part); } else SynErr(57); }
void CommonNegativeExpression(FunctionCallPart part) { if (la.kind == 12) { Get(); part.AppendIdentifier(t); } if (la.kind == 2 || la.kind == 3) { if (la.kind == 2) { Get(); } else { Get(); } part.AppendIdentifier(t); } else if (la.kind == 1 || la.kind == 53) { CommonIdentifierList(part); } else SynErr(62); }
public int GetArgumentIndex(FunctionCallPart argumentPart) { if (null == argumentParts) return -1; return argumentParts.IndexOf(argumentPart); }
void CommonIdentifierList(FunctionCallPart part) { string partName = string.Empty; CommonNameReference(part); partName = part.Identifier; while (la.kind == 6) { Get(); CommonNameReference(part); string newPartName = part.Identifier; part.Identifier = partName + "." + newPartName; partName = part.Identifier; } }
void CommonCharacter(FunctionCallPart part) { Expect(5); }
void CommonTernaryOperation(FunctionCallPart part) { Expect(51); CommonExpression(part); Expect(52); CommonExpression(part); }