public List <ColumnExpressionMsx> ColExprList = new List <ColumnExpressionMsx>(); // list of parsed column expressions in axis expression /// <summary> /// Parse an axis expression /// </summary> /// <param name="axisExpr"></param> /// <returns></returns> public static AxisExpressionMsx Parse(string axisExpr) { AxisExpressionMsx ax = new AxisExpressionMsx(); ax.Expression = axisExpr; List <string> colExprs = Split(axisExpr); foreach (string colExpr in colExprs) { ax.ColExprList.Add(ColumnExpressionMsx.Parse(colExpr)); } return(ax); }
public static ColumnExpressionMsx Parse(string expr) { Lex lex = new Lex(); lex.SetDelimiters(" , ; ( ) [ ]"); lex.OpenString(expr); StringBuilder sb = new StringBuilder(); PositionedToken lastTok = null, leftBracket = null; ColumnExpressionMsx colExpr = new ColumnExpressionMsx(); List <PositionedToken> tokens = new List <PositionedToken>(); // list of tokens seen int parenDepth = 0; while (true) { PositionedToken pTok = lex.GetPositionedToken(); if (pTok == null) { break; } tokens.Add(pTok); if (lastTok != null) { // include same white space between tokens int wsBeg = lastTok.Position + lastTok.Text.Length; sb.Append(expr.Substring(wsBeg, pTok.Position - wsBeg)); } string tok = pTok.Text; if (pTok.Text == "(") { parenDepth++; } else if (pTok.Text == ")") { parenDepth--; } else if (tok == "[") { leftBracket = pTok; } else if (tok == "]") { if (leftBracket != null) { int p = leftBracket.Position + 1; int l = pTok.Position - p; string colName = expr.Substring(p, l); colExpr.ColumnNames.Add(colName); leftBracket = null; } } } return(colExpr); }