/// <summary> /// 分析标签 /// </summary> /// <param name="parser">TemplateParser</param> /// <param name="tc">Token集合</param> /// <returns></returns> public Tag Parse(TemplateParser parser, TokenCollection tc) { if (tc.First.TokenKind == TokenKind.TextData && tc.Count > 2 && (tc[1].TokenKind == TokenKind.LeftParentheses) && tc.Last.TokenKind == TokenKind.RightParentheses) { FunctaionTag tag = new FunctaionTag(); tag.Name = tc.First.Text; Int32 pos = 0, start = 2, end; for (Int32 i = 2; i < tc.Count; i++) { end = i; switch (tc[i].TokenKind) { case TokenKind.Comma: if (pos == 0) { TokenCollection coll = new TokenCollection(); coll.Add(tc, start, end - 1); if (coll.Count > 0) { tag.AddChild(parser.Read(coll)); } start = i + 1; } break; default: if (tc[i].TokenKind == TokenKind.LeftParentheses) { pos++; } else if (tc[i].TokenKind == TokenKind.RightParentheses) { pos--; } if (i == tc.Count - 1) { TokenCollection coll = new TokenCollection(); coll.Add(tc, start, end - 1); if (coll.Count > 0) { tag.AddChild(parser.Read(coll)); } } break; } } return(tag); } return(null); }
/// <summary> /// 分析标签 /// </summary> /// <param name="parser">TemplateParser</param> /// <param name="tc">Token集合</param> /// <returns></returns> public ITag Parse(TemplateParser parser, TokenCollection tc) { if (tc != null && parser != null && tc.First.TokenKind == TokenKind.TextData && tc.Count > 2 && tc[1].TokenKind == TokenKind.LeftParentheses && tc.Last.TokenKind == TokenKind.RightParentheses && tc.Split(0, tc.Count, TokenKind.Operator).Length == 1) { FunctaionTag tag = new FunctaionTag(); tag.Name = tc.First.Text; //tag.Func = (BasisTag)parser.Read(tc[0, 1]); TokenCollection[] tcs = tc.Split(2, tc.Count - 1, TokenKind.Comma); for (int i = 0; i < tcs.Length; i++) { if (tcs[i].Count == 1 && tcs[i][0].TokenKind == TokenKind.Comma) { continue; } tag.AddChild(parser.Read(tcs[i])); } return(tag); } return(null); }