Exemplo n.º 1
0
		internal static STNode ParseInterCompareExp(Cell cell, string input)
		{
			ExcelFormulaLexer lexer = new ExcelFormulaLexer(
				cell.Worksheet == null ? null : cell.Worksheet.workbook, cell, input);

			STNodeType type = STNodeType.NONE;

			if (lexer.IsToken("=") || lexer.IsToken("=="))
				type = STNodeType.EQUALS;
			else if (lexer.IsToken("<>") || lexer.IsToken("!="))
				type = STNodeType.NOT_EQUALS;
			else if (lexer.IsToken(">"))
				type = STNodeType.GREAT_THAN;
			else if (lexer.IsToken("<"))
				type = STNodeType.LESS_THAN;
			else if (lexer.IsToken(">="))
				type = STNodeType.GREAT_EQUALS;
			else if (lexer.IsToken("<="))
				type = STNodeType.LESS_EQUALS;

			if (type != STNodeType.NONE)
			{
				lexer.NextToken();

				var right = ReadExpr(lexer);
				if (right != null)
				{
					return CreateNode(lexer, type, 0, lexer.CommittedLength, new List<STNode> { null, right });
				}
			}

			STNode node = ReadConnect(lexer);

			return new STNode(STNodeType.EQUALS, 0, input.Length, new List<STNode> { null,
				(node != null && node.Type != STNodeType.IDENTIFIER) ? node : 
				new STStringNode(input, 0, input.Length) });
		}
Exemplo n.º 2
0
        private static STNode CreateNode(ExcelFormulaLexer lexer, STNodeType type, int start, int len, List <STNode> nodes)
        {
            switch (type)
            {
            case STNodeType.NUMBER:
                string text = lexer.Input.Substring(start, len);
                return(double.TryParse(text, out var v) ? new STNumberNode(v, start, len) : null);

            case STNodeType.IDENTIFIER:
                return(new STIdentifierNode(lexer.Cell == null ? null : lexer.Cell.Worksheet, lexer.Input.Substring(start, len), start, len));

            case STNodeType.STRING:
                return(new STStringNode(lexer.Input, start, len));

            case STNodeType.RANGE:
                return(new STRangeNode(null, new RangePosition(lexer.Input.Substring(start, len)), start, len));

            case STNodeType.CELL:
                return(new STCellNode(null, new CellPosition(lexer.Input.Substring(start, len)), type, start, len));

            default:
                return(new STNode(type, start, len, nodes));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Construct STNode by specified arguments
 /// </summary>
 /// <param name="type">Type of node</param>
 /// <param name="start">Start index from an input string</param>
 /// <param name="len">Length of value in an input string</param>
 public STNode(STNodeType type, int start, int len)
     : this(type, start, len, null)
 {
 }
Exemplo n.º 4
0
 private static STNode CreateNode(ExcelFormulaLexer lexer, STNodeType type)
 {
     return(new STNode(type, lexer.CurrentToken.Index, lexer.CurrentToken.Length, null));
 }
Exemplo n.º 5
0
 private static STNode CommitRunAndCreateNode(ExcelFormulaLexer lexer, STNodeType type,
                                              int start, int len, List <STNode> nodes)
 {
     lexer.NextToken();
     return(CreateNode(lexer, type, start, len, nodes));
 }
Exemplo n.º 6
0
 private static bool CommitMatchNode(ExcelFormulaLexer lexer, string groupName, STNodeType type, out STNode node)
 {
     if (lexer.IsMatch(groupName))
     {
         var g = lexer.CurrentToken.Groups[groupName];
         node = CommitRunAndCreateNode(lexer, type, g.Index, g.Length, null);
         return(true);
     }
     else
     {
         node = null;
         return(false);
     }
 }
Exemplo n.º 7
0
 public STCellNode(Worksheet worksheet, CellPosition pos, STNodeType type, int start, int len)
     : base(type, start, len)
 {
     this.Worksheet = worksheet;
     this.Position  = pos;
 }