本文整理汇总了C#中NPOI.SS.Formula.ParseNode类的典型用法代码示例。如果您正苦于以下问题:C# ParseNode类的具体用法?C# ParseNode怎么用?C# ParseNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParseNode类属于NPOI.SS.Formula命名空间,在下文中一共展示了ParseNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseNode
public ParseNode(Ptg token, ParseNode[] children)
{
_token = token;
_children = children;
_isIf = IsIf(token);
int tokenCount = 1;
for (int i = 0; i < children.Length; i++)
{
tokenCount += children[i].TokenCount;
}
if (_isIf)
{
// there will be 2 or 3 extra tAttr Tokens according To whether the false param is present
tokenCount += children.Length;
}
_tokenCount = tokenCount;
}
示例2: TransformFormula
/**
* Traverses the supplied formula parse tree, calling <tt>Ptg.SetClass()</tt> for each non-base
* Token To Set its operand class.
*/
public void TransformFormula(ParseNode rootNode)
{
byte rootNodeOperandClass;
switch (_formulaType)
{
case FormulaType.CELL:
rootNodeOperandClass = Ptg.CLASS_VALUE;
break;
case FormulaType.DATAVALIDATION_LIST:
rootNodeOperandClass = Ptg.CLASS_REF;
break;
default:
throw new Exception("Incomplete code - formula type ("
+ _formulaType + ") not supported yet");
}
TransformNode(rootNode, rootNodeOperandClass, false);
}
示例3: TransformFormula
/**
* Traverses the supplied formula parse tree, calling <c>Ptg.SetClass()</c> for each non-base
* Token To Set its operand class.
*/
public void TransformFormula(ParseNode rootNode)
{
byte rootNodeOperandClass;
switch (_formulaType)
{
case FormulaType.Cell:
rootNodeOperandClass = Ptg.CLASS_VALUE;
break;
case FormulaType.Array:
rootNodeOperandClass = Ptg.CLASS_ARRAY;
break;
case FormulaType.NamedRange:
case FormulaType.DataValidationList:
rootNodeOperandClass = Ptg.CLASS_REF;
break;
default:
throw new Exception("Incomplete code - formula type ("
+ _formulaType + ") not supported yet");
}
TransformNode(rootNode, rootNodeOperandClass, false);
}
示例4: ParseRangeExpression
private ParseNode ParseRangeExpression()
{
ParseNode result = ParseRangeable();
bool hasRange = false;
while (look == ':')
{
int pos = pointer;
GetChar();
ParseNode nextPart = ParseRangeable();
// Note - no range simplification here. An expr like "A1:B2:C3:D4:E5" should be
// grouped into area ref pairs like: "(A1:B2):(C3:D4):E5"
// Furthermore, Excel doesn't seem to simplify
// expressions like "Sheet1!A1:Sheet1:B2" into "Sheet1!A1:B2"
CheckValidRangeOperand("LHS", pos, result);
CheckValidRangeOperand("RHS", pos, nextPart);
ParseNode[] children = { result, nextPart, };
result = new ParseNode(RangePtg.instance, children);
hasRange = true;
}
if (hasRange)
{
return AugmentWithMemPtg(result);
}
return result;
}
示例5: UnionExpression
private ParseNode UnionExpression()
{
ParseNode result = ComparisonExpression();
bool hasUnions = false;
while (true)
{
SkipWhite();
switch (look)
{
case ',':
GetChar();
hasUnions = true;
ParseNode other = ComparisonExpression();
result = new ParseNode(UnionPtg.instance, result, other);
continue;
}
if (hasUnions)
{
return AugmentWithMemPtg(result);
}
return result;
}
}
示例6: AdditiveExpression
/** Parse and Translate an Expression */
private ParseNode AdditiveExpression()
{
ParseNode result = Term();
while (true)
{
SkipWhite();
Ptg operator1;
switch (look)
{
case '+':
Match('+');
operator1 = AddPtg.instance;
break;
case '-':
Match('-');
operator1 = SubtractPtg.instance;
break;
default:
return result; // finished with Additive expression
}
ParseNode other = Term();
result = new ParseNode(operator1, result, other);
}
}
示例7: TransformFunctionNode
private void TransformFunctionNode(AbstractFunctionPtg afp, ParseNode[] children,
byte desiredOperandClass, bool callerForceArrayFlag)
{
bool localForceArrayFlag;
byte defaultReturnOperandClass = afp.DefaultOperandClass;
if (callerForceArrayFlag)
{
switch (defaultReturnOperandClass)
{
case Ptg.CLASS_REF:
if (desiredOperandClass == Ptg.CLASS_REF)
{
afp.PtgClass = (Ptg.CLASS_REF);
}
else
{
afp.PtgClass = (Ptg.CLASS_ARRAY);
}
localForceArrayFlag = false;
break;
case Ptg.CLASS_ARRAY:
afp.PtgClass = (Ptg.CLASS_ARRAY);
localForceArrayFlag = false;
break;
case Ptg.CLASS_VALUE:
afp.PtgClass = (Ptg.CLASS_ARRAY);
localForceArrayFlag = true;
break;
default:
throw new InvalidOperationException("Unexpected operand class ("
+ defaultReturnOperandClass + ")");
}
}
else
{
if (defaultReturnOperandClass == desiredOperandClass)
{
localForceArrayFlag = false;
// an alternative would have been To for non-base Ptgs To Set their operand class
// from their default, but this would require the call in many subclasses because
// the default OC is not known until the end of the constructor
afp.PtgClass = (defaultReturnOperandClass);
}
else
{
switch (desiredOperandClass)
{
case Ptg.CLASS_VALUE:
// always OK To Set functions To return 'value'
afp.PtgClass = (Ptg.CLASS_VALUE);
localForceArrayFlag = false;
break;
case Ptg.CLASS_ARRAY:
switch (defaultReturnOperandClass)
{
case Ptg.CLASS_REF:
afp.PtgClass = (Ptg.CLASS_REF);
// afp.SetClass(Ptg.CLASS_ARRAY);
break;
case Ptg.CLASS_VALUE:
afp.PtgClass = (Ptg.CLASS_ARRAY);
break;
default:
throw new InvalidOperationException("Unexpected operand class ("
+ defaultReturnOperandClass + ")");
}
localForceArrayFlag = (defaultReturnOperandClass == Ptg.CLASS_VALUE);
break;
case Ptg.CLASS_REF:
switch (defaultReturnOperandClass)
{
case Ptg.CLASS_ARRAY:
afp.PtgClass=(Ptg.CLASS_ARRAY);
break;
case Ptg.CLASS_VALUE:
afp.PtgClass=(Ptg.CLASS_VALUE);
break;
default:
throw new InvalidOperationException("Unexpected operand class ("
+ defaultReturnOperandClass + ")");
}
localForceArrayFlag = false;
break;
default:
throw new InvalidOperationException("Unexpected operand class ("
+ desiredOperandClass + ")");
}
}
}
for (int i = 0; i < children.Length; i++)
{
ParseNode child = children[i];
byte paramOperandClass = afp.GetParameterClass(i);
TransformNode(child, paramOperandClass, localForceArrayFlag);
}
}
示例8: CheckValidRangeOperand
/**
* @param currentParsePosition used to format a potential error message
*/
private void CheckValidRangeOperand(String sideName, int currentParsePosition, ParseNode pn)
{
if (!IsValidRangeOperand(pn))
{
throw new FormulaParseException("The " + sideName
+ " of the range operator ':' at position "
+ currentParsePosition + " is not a proper reference.");
}
}
示例9: PercentFactor
private ParseNode PercentFactor()
{
ParseNode result = ParseSimpleFactor();
while (true)
{
SkipWhite();
if (look != '%')
{
return result;
}
Match('%');
result = new ParseNode(PercentPtg.instance, result);
}
}
示例10: PowerFactor
/** Parse and Translate a Math Factor */
private ParseNode PowerFactor()
{
ParseNode result = PercentFactor();
while (true)
{
SkipWhite();
if (look != '^')
{
return result;
}
Match('^');
ParseNode other = PercentFactor();
result = new ParseNode(PowerPtg.instance, result, other);
}
}
示例11: GetFunction
/**
* Generates the variable Function ptg for the formula.
*
* For IF Formulas, Additional PTGs are Added To the Tokens
* @param name a {@link NamePtg} or {@link NameXPtg} or <code>null</code>
* @return Ptg a null is returned if we're in an IF formula, it needs extreme manipulation and is handled in this Function
*/
private ParseNode GetFunction(String name, Ptg namePtg, ParseNode[] args)
{
FunctionMetadata fm = FunctionMetadataRegistry.GetFunctionByName(name.ToUpper());
int numArgs = args.Length;
if (fm == null)
{
if (namePtg == null)
{
throw new InvalidOperationException("NamePtg must be supplied for external Functions");
}
// must be external Function
ParseNode[] allArgs = new ParseNode[numArgs + 1];
allArgs[0] = new ParseNode(namePtg);
System.Array.Copy(args, 0, allArgs, 1, numArgs);
return new ParseNode(FuncVarPtg.Create(name, (byte)(numArgs + 1)), allArgs);
}
if (namePtg != null)
{
throw new InvalidOperationException("NamePtg no applicable To internal Functions");
}
bool IsVarArgs = !fm.HasFixedArgsLength;
int funcIx = fm.Index;
if (funcIx == FunctionMetadataRegistry.FUNCTION_INDEX_SUM && args.Length == 1) {
// Excel encodes the sum of a single argument as tAttrSum
// POI does the same for consistency, but this is not critical
return new ParseNode(AttrPtg.GetSumSingle(), args);
// The code below would encode tFuncVar(SUM) which seems to do no harm
}
ValidateNumArgs(args.Length, fm);
AbstractFunctionPtg retval;
if (IsVarArgs)
{
retval = FuncVarPtg.Create(name, (byte)numArgs);
}
else
{
retval = FuncPtg.Create(funcIx);
}
return new ParseNode(retval, args);
}
示例12: ToTokenArray
/**
* Collects the array of <c>Ptg</c> Tokens for the specified tree.
*/
public static Ptg[] ToTokenArray(ParseNode rootNode)
{
TokenCollector temp = new TokenCollector(rootNode.TokenCount);
rootNode.CollectPtgs(temp);
return temp.GetResult();
}
示例13: GetFunction
/**
* Generates the variable Function ptg for the formula.
*
* For IF Formulas, Additional PTGs are Added To the Tokens
* @param name a {@link NamePtg} or {@link NameXPtg} or <c>null</c>
* @param numArgs
* @return Ptg a null is returned if we're in an IF formula, it needs extreme manipulation and is handled in this Function
*/
private ParseNode GetFunction(String name, Ptg namePtg, ParseNode[] args)
{
FunctionMetadata fm = FunctionMetadataRegistry.GetFunctionByName(name.ToUpper());
int numArgs = args.Length;
if (fm == null)
{
if (namePtg == null)
{
throw new InvalidOperationException("NamePtg must be supplied for external Functions");
}
// must be external Function
ParseNode[] allArgs = new ParseNode[numArgs + 1];
allArgs[0] = new ParseNode(namePtg);
System.Array.Copy(args, 0, allArgs, 1, numArgs);
return new ParseNode(new FuncVarPtg(name, (byte)(numArgs + 1)), allArgs);
}
if (namePtg != null)
{
throw new InvalidOperationException("NamePtg no applicable To internal Functions");
}
bool IsVarArgs = !fm.HasFixedArgsLength;
int funcIx = fm.Index;
ValidateNumArgs(args.Length, fm);
AbstractFunctionPtg retval;
if (IsVarArgs)
{
retval = new FuncVarPtg(name, (byte)numArgs);
}
else
{
retval = new FuncPtg(funcIx);
}
return new ParseNode(retval, args);
}
示例14: AugmentWithMemPtg
private static ParseNode AugmentWithMemPtg(ParseNode root)
{
Ptg memPtg;
if (NeedsMemFunc(root))
{
memPtg = new MemFuncPtg(root.EncodedSize);
}
else
{
memPtg = new MemAreaPtg(root.EncodedSize);
}
return new ParseNode(memPtg, root);
}
示例15: NeedsMemFunc
/**
* From OOO doc: "Whenever one operand of the reference subexpression is a function,
* a defined name, a 3D reference, or an external reference (and no error occurs),
* a tMemFunc token is used"
*
*/
private static bool NeedsMemFunc(ParseNode root)
{
Ptg token = root.GetToken();
if (token is AbstractFunctionPtg)
{
return true;
}
if (token is IExternSheetReferenceToken)
{ // 3D refs
return true;
}
if (token is NamePtg || token is NameXPtg)
{ // 3D refs
return true;
}
if (token is OperationPtg || token is ParenthesisPtg)
{
// expect RangePtg, but perhaps also UnionPtg, IntersectionPtg etc
foreach (ParseNode child in root.GetChildren())
{
if (NeedsMemFunc(child))
{
return true;
}
}
return false;
}
if (token is OperandPtg)
{
return false;
}
if (token is OperationPtg)
{
return true;
}
return false;
}