Skip to content
Stan B edited this page Apr 28, 2014 · 4 revisions

Create a new visitor-derived class

For example

public class TopRowFilterVisitor : Visitor
{
  private int _leftParethesisCount;
  private int _rightParethesisCount;      

  public bool HasParenthesis { get { return _leftParethesisCount == 1 && _rightParethesisCount == 1; }
  public override void ExplicitVisit(TopRowFilter node)
  {
    WasVisited = true;
    SqlFragment = node;
    for (int i = node.FirstTokenIndex; i <= node.LastTokenIndex; i++)
    {
      TSqlParserToken token = node.ScriptTokenStream[i];
      if (token.TokenType == TSqlTokenType.LeftParenthesis) _leftParethesisCount++;
      if (token.TokenType == TSqlTokenType.RightParenthesis) _rightParethesisCount++;
    }        
  }
}

Create a rule class that uses this or any other visitors

Clone this wiki locally