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

AW: [FWD: [H-e-l-p] with accessing ignoredTokens]

Title: AW: [FWD: [H-e-l-p] with accessing ignoredTokens]


> When outputting modified source to a new file, I'f like to
> preserve the
> original formating the
> original source had. This was addressed in post:
> http://www.sable.mcgill.ca/listarchives/sablecc-list/msg00402.html
> with the code snipet:
> ++++++++++++++++++++++++++++++++++
> LinkedList list = (LinkedList) Parser.ignoredTokens.getIn(classnode);
> for(Iterator i = list.iterator(); i.hasNext(); )
> {
>   System.out.println(i.next());
> }
> ++++++++++++++++++++++++++++++++++  

we use nearly the same source.

      LinkedList list = (LinkedList) oParser.ignoredTokens.getIn(node);

      if( list != null )
         Iterator i = list.iterator();

         for(; i.hasNext(); )

It's only reformated for better understanding and the null case.

> About this I have a few questions:
> 1) Location - Where would be the best place for this code snipet?

We place it in the defaultCase statement. Because we use it in a pretty printer
it should work for you as well.

> 2) How is a static reference to a non-static variable supposed to work
> here:
> Parser.ignoredTokens.getIn(classnode)?
> Doesn't each instance of Parser have it's own ignoredTokens?

Well I guess you tell the parser by the node paramter what you want.
Doesn't matter much if the Parser is static then. Because each node
knows what ignored tokens were placed before it.