// Try to fold a negated constant int32. We have to do this so that parsing int32.MinValue will work public override Node ExitNegateExpression(Production node) { IList childValues = GetChildValues(node); // Get last child var childElement = (BaseExpressionElement)childValues[childValues.Count - 1]; // Is it an signed integer constant? if (ReferenceEquals(childElement.GetType(), typeof(Int32LiteralElement)) & childValues.Count == 2) { ((Int32LiteralElement)childElement).Negate(); // Add it directly instead of the negate element since it will already be negated node.AddValue(childElement); } else if (ReferenceEquals(childElement.GetType(), typeof(Int64LiteralElement)) & childValues.Count == 2) { ((Int64LiteralElement)childElement).Negate(); // Add it directly instead of the negate element since it will already be negated node.AddValue(childElement); } else { // No so just add a regular negate AddUnaryOp(node, typeof(NegateElement)); } return(node); }
public override Node ExitNegateExpression(Production node) { IList childValues = this.GetChildValues(node); var childElement = (ExpressionElement)childValues[childValues.Count - 1]; var flag = (childElement.GetType() == typeof(Int32LiteralElement)) & (childValues.Count == 2); if (flag) { ((Int32LiteralElement)childElement).Negate(); node.AddValue(childElement); } else { var flag2 = (childElement.GetType() == typeof(Int64LiteralElement)) & (childValues.Count == 2); if (flag2) { ((Int64LiteralElement)childElement).Negate(); node.AddValue(childElement); } else { this.AddUnaryOp(node, typeof(NegateElement)); } } return(node); }
public override Node ExitCastTypeExpression(Production node) { var childValues = this.GetChildValues(node); var parts = childValues.Map(Conversions.ToString).ToList(); //try //{ // IEnumerator enumerator = childValues.GetEnumerator(); // while (enumerator.MoveNext()) // { // string part = Conversions.ToString(enumerator.Current); // parts.Add(part); // } //} //finally //{ // IEnumerator enumerator; // if (enumerator is IDisposable) // { // (enumerator as IDisposable).Dispose(); // } //} var isArray = false; var flag = Operators.CompareString(parts[parts.Count - 1], "[]", false) == 0; if (flag) { isArray = true; parts.RemoveAt(parts.Count - 1); } node.AddValue(parts.ToArray()); node.AddValue(isArray); return(node); }
public override Node ExitArith(Production node) { if (node.Count > 1) { node.AddValue(new Func((string)node[1].Values[0], (Expression)node[0].Values[0], (Expression)node[2].Values[0])); } else { node.AddValue(node[0].Values[0]); } return(node); }
public override Node ExitCons(Production node) { if (node.Count > 1) { node.AddValue(new Func(":", (Expression)node[0].Values[0], (Expression)node[node.Count - 1].Values[0])); } else { node.AddValue(node[0].Values[0]); } return(node); }
private void AddUnaryOp(Production node, Type elementType) { IList childValues = GetChildValues(node); if (childValues.Count == 2) { var element = (UnaryElement)Activator.CreateInstance(elementType, childValues[1]); node.AddValue(element); } else { node.AddValue(childValues[0]); } }
public override Node ExitEqualOrExpr(Production node) { var isExpression = (ExpConstants)node[1].Id == ExpConstants.NEWLINE; if (isExpression) { node.AddValue(node[0].Values[0]); } else { node.AddValue(new Func("=", (Expression)node[0].Values[0], (Expression)node[2].Values[0])); } return(node); }
private void AddUnaryOp(Production node, Type elementType) { IList childValues = this.GetChildValues(node); if (childValues.Count == 2) { UnaryElement element = (UnaryElement)Activator.CreateInstance(elementType); element.SetChild((ExpressionElement)childValues[1]); node.AddValue(element); } else { node.AddValue(childValues[0]); } }
public override Node ExitInExpression(Production node) { IList childValues = GetChildValues(node); if (childValues.Count == 1) { AddFirstChildValue(node); return(node); } var operand = (BaseExpressionElement)childValues[0]; childValues.RemoveAt(0); var second = childValues[0]; InElement op; if (second is IList list) { op = new InElement(operand, list); } else { var invocationListElement = new InvocationListElement(childValues, context); op = new InElement(operand, invocationListElement); } node.AddValue(op); return(node); }
public override Node ExitGridReferenceExpression(Production node) { var cr = new CharacterRange(); string sheetName = null; Node refNode = node.GetChildAt(node.GetChildCount() - 1); var creator = (ReferenceCreator)refNode.GetValue(0); cr.First = refNode.StartColumn - 1; cr.Length = refNode.EndColumn - refNode.StartColumn + 1; if (node.GetChildCount() == 2) { var sheetToken = (Token)node.GetChildAt(0); sheetName = sheetToken.Image.Substring(0, sheetToken.Image.Length - 1); cr.First = sheetToken.StartColumn - 1; cr.Length = refNode.EndColumn - sheetToken.StartColumn + 1; } Reference @ref = creator.CreateReference(); var info = new ReferenceParseInfo { Target = @ref, Location = cr, Properties = creator.CreateProperties(node.GetChildCount() == 1), ParseProperties = new ReferenceParseProperties { SheetName = sheetName } }; _referenceInfos.Add(info); node.AddValue(@ref); return(node); }
public override Node ExitBoolean(Production node) { var b = (bool)node.GetChildAt(0).Values[0]; node.AddValue(new BooleanOperand(b)); return(node); }
public override Node ExitInExpression(Production node) { var childValues = this.GetChildValues(node); var flag = childValues.Count == 1; Node exitInExpression; if (flag) { this.AddFirstChildValue(node); exitInExpression = node; } else { var operand = (ExpressionElement)childValues[0]; childValues.RemoveAt(0); var second = RuntimeHelpers.GetObjectValue(childValues[0]); var flag2 = second is IList; InElement op; if (flag2) { op = new InElement(operand, (IList)second); } else { var il = new InvocationListElement(childValues, this.myServices); op = new InElement(operand, il); } node.AddValue(op); exitInExpression = node; } return(exitInExpression); }
public override Node ExitInListTargetExpression(Production node) { IList childValues = GetChildValues(node); node.AddValue(childValues); return(node); }
public override Node ExitInExpression(Production node) { IList childValues = this.GetChildValues(node); if (childValues.Count == 1) { this.AddFirstChildValue(node); return(node); } ExpressionElement operand = (ExpressionElement)childValues[0]; childValues.RemoveAt(0); object second = childValues[0]; InElement op = default(InElement); if ((second) is IList) { op = new InElement(operand, (IList)second); } else { InvocationListElement il = new InvocationListElement(childValues, _myServices); op = new InElement(operand, il); } node.AddValue(op); return(node); }
private void AddUnaryOp(Production node, Type elementType) { IList childValues = this.GetChildValues(node); var flag = childValues.Count == 2; if (flag) { var element = (UnaryElement)Activator.CreateInstance(elementType); element.SetChild((ExpressionElement)childValues[1]); node.AddValue(element); } else { node.AddValue(RuntimeHelpers.GetObjectValue(childValues[0])); } }
public override Node ExitMemberExpression(Production node) { IList childValues = GetChildValues(node); var first = childValues[0]; if (childValues.Count == 1 && !(first is MemberElement)) { node.AddValue(first); } else { var invocationListElement = new InvocationListElement(childValues, context); node.AddValue(invocationListElement); } return(node); }
public override Node ExitMemberExpression(Production node) { var childValues = this.GetChildValues(node); var first = RuntimeHelpers.GetObjectValue(childValues[0]); var flag = childValues.Count == 1 && !(first is MemberElement); if (flag) { node.AddValue(RuntimeHelpers.GetObjectValue(first)); } else { var list = new InvocationListElement(childValues, this.myServices); node.AddValue(list); } return(node); }
public override Node ExitPrimitive(Production node) { IList values = GetChildValues(node); var oe = new ContainerElement(values[0]); node.AddValue(oe); return(node); }
public override Node ExitPercentExpression(Production node) { IList values = GetChildValues(node); var first = (ParseTreeElement)values[0]; if (values.Count > 1) { var pe = new PercentOperator(values.Count - 1); node.AddValue(new UnaryOperatorElement(pe, first)); } else { node.AddValue(first); } return(node); }
public override Node ExitIfExpression(Production node) { IList childValues = GetChildValues(node); var op = new ConditionalElement((BaseExpressionElement)childValues[0], (BaseExpressionElement)childValues[1], (BaseExpressionElement)childValues[2]); node.AddValue(op); return(node); }
public override Node ExitMemberExpression(Production node) { IList childValues = this.GetChildValues(node); object first = childValues[0]; if (childValues.Count == 1 && !(first is MemberElement)) { node.AddValue(first); } else { InvocationListElement list = new InvocationListElement(childValues, _myServices); node.AddValue(list); } return(node); }
public override Node ExitFieldPropertyExpression(Production node) { var name = (string)node.GetChildAt(0).GetValue(0); var elem = new IdentifierElement(name); node.AddValue(elem); return(node); }
public override Node ExitFunctionCall(Production node) { var fe = new FunctionCallElement(); fe.AcceptValues(GetChildValues(node)); node.AddValue(fe); return(node); }
public override Node ExitFieldPropertyExpression(Production node) { //string name = ((Token)node.GetChildAt(0))?.Image; var name = node.GetChildAt(0).GetValue(0).ToString(); var elem = new IdentifierElement(name); node.AddValue(elem); return(node); }
private void AddBinaryOp(Production node, Type elementType) { IList childValues = GetChildValues(node); if (childValues.Count > 1) { var expressionElement = BinaryExpressionElement.CreateElement(childValues, elementType); node.AddValue(expressionElement); } else if (childValues.Count == 1) { node.AddValue(childValues[0]); } else { Debug.Assert(false, "wrong number of children"); } }
public override Node ExitIndexExpression(Production node) { IList childValues = GetChildValues(node); var args = new ArgumentList(childValues); var e = new IndexerElement(args); node.AddValue(e); return(node); }
public override Node ExitCastExpression(Production node) { IList childValues = GetChildValues(node); var destTypeParts = (string[])childValues[1]; var isArray = (bool)childValues[2]; var op = new CastElement((BaseExpressionElement)childValues[0], destTypeParts, isArray, context); node.AddValue(op); return(node); }
public override Node ExitUnaryExpression(Production node) { IList values = GetChildValues(node); var last = (ParseTreeElement)values[values.Count - 1]; int negCount = values.Cast <object>().Count(op => ReferenceEquals(op.GetType(), typeof(BinarySubOperator))); if ((negCount & 1) != 0) { var ne = new UnaryNegateOperator(); node.AddValue(new UnaryOperatorElement(ne, last)); } else { node.AddValue(last); } return(node); }
public override Node ExitCastExpression(Production node) { IList childValues = this.GetChildValues(node); string[] destTypeParts = (string[])childValues[1]; bool isArray = (bool)childValues[2]; CastElement op = new CastElement((ExpressionElement)childValues[0], destTypeParts, isArray, _myServices); node.AddValue(op); return(node); }
public override Node ExitFunctionCallExpression(Production node) { var childValues = GetChildValues(node); var name = (string)childValues[0]; childValues.RemoveAt(0); var args = new ArgumentList(childValues); var funcCall = new FunctionCallElement(name, args); node.AddValue(funcCall); return(node); }