[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: line/col info of node



Are you asking on how to do this?

class TokenFinder extends DepthFirstAdapter
{
  Token find (Node n)
  {
    token = null;
    n.apply(this);
    return token;
  }

  private Token token;

  public void defaultCase (Node n)
  {
    if ( n instanceof Token && token == null)
        token = (Token)n;
  }
}

Probably this should do what you want. Note - it's not reentrant. And
it can still return null if no token is found.

Regards,
Indrek


On Thursday 22 January 2004 23:58, Anil T Samuel wrote:
> Hi
>
> This message was sent before right after I joining the mailing list;
> since this was my first and also since not finding any response, I am
> not sure whether this got posted. So I am re-posting it.
>
> > A frequent approach is to use a depth first adapter to find the first
> > token under the node and use it's line/column info.
>
> how can i get the first token of a node ? I did see the methods
> getLine/Pos on Token; but didnot know how to get a handle to it from node.
>
> ------First message----
> Hi Etienne
>
> I am working with SableCC tool to build a tool for PHP.
>
> To handle the tokens I am subclassing DepthFirstAdapter and overriding
> the necessary functions.
> Here I also need to get the location information of the node like line
> number and column it is
> appearing. Any way to do this ?
>
> Thanks in advance for your time
> Anthos
> ------First message----