private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { PostfixIncDec postfixIncDec = new PostfixIncDec(); int startIndex = parentInfo.CurrentIndex; int length; // find operand MoveInfo operandInfo = new MoveInfo(parentInfo); IElement operand = operandInfo.FindNextBlack(SearchDirection.RightToLeft); if (operand != null && operand is ExpressionOperand) { startIndex = operandInfo.CurrentIndex; } else { throw new SyntaxException("Could not find PostfixIncDec operand", parentInfo.GetErrorInfo()); } // build length = (parentInfo.CurrentIndex + 1) - startIndex; postfixIncDec.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length)); parentInfo.MoveToIndex(startIndex); parentInfo.Replace(length, postfixIncDec); }
public override IElement CreateCopy() { PostfixIncDec e = new PostfixIncDec(); e.AddChildren(this.CopyChildren()); return(e); }
public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo, ref bool isNextOperand, ref bool isNextNeeded, out bool isSingleOperand, bool isExpStatement, bool isArrayContentDefEnabled, bool isArrayDefEnabled) { isSingleOperand = false; IElement cur = parentInfo.Current; if (isNextOperand) // operand { // all unary operators -> without + and - // ex. !var if (!isExpStatement && UnaryOperator.Check(parentInfo, parsingInfo, scriptInfo)) { isNextOperand = true; isNextNeeded = true; return(true); } // real operand // ex. VarName, FuncCall, etc. if (ExpressionOperand.Check(parentInfo, parsingInfo, scriptInfo, ref isSingleOperand, isArrayContentDefEnabled, isArrayDefEnabled)) { isNextOperand = false; isNextNeeded = false; return(true); } else { if (isNextNeeded) { throw new SyntaxException("Could not find operand", parentInfo.GetErrorInfo()); } return(false); } } else // operator { if (isExpStatement && PostfixIncDec.Check(parentInfo, parsingInfo, scriptInfo)) { isSingleOperand = ExpressionOperand.IsSingle(parentInfo, parsingInfo); isNextOperand = false; isNextNeeded = false; return(true); } if (!isExpStatement && BinaryOperator.Check(parentInfo, parsingInfo, scriptInfo)) { isNextOperand = true; isNextNeeded = true; return(true); } if (isExpStatement && Assign.Check(parentInfo, parsingInfo, scriptInfo)) // = Expression { isSingleOperand = ExpressionOperand.IsSingle(parentInfo, parsingInfo); isNextNeeded = false; isNextOperand = false; return(true); } // self thread f() if (FuncCallModifier.Check(parentInfo, parsingInfo, scriptInfo)) // thread { isSingleOperand = ExpressionOperand.IsSingle(parentInfo, parsingInfo); isNextNeeded = true; isNextOperand = false; return(true); } // self f() // self thread f() // NOT f() !! if (DelegateCall.Check(parentInfo, parsingInfo, scriptInfo) || // // [[delegate]](funcArgs) | [[d]]().member* | [[d]]()[]* FuncCall.Check(parentInfo, parsingInfo, scriptInfo)) // f() | path::f() | f().member* | f()[i]* { isSingleOperand = ExpressionOperand.IsSingle(parentInfo, parsingInfo); isNextOperand = false; isNextNeeded = false; return(true); } if (isNextNeeded) { throw new SyntaxException("unknown operator '" + parentInfo.Current.ToString() + "'", parentInfo.GetErrorInfo()); } else { return(false); } } }