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

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



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

 

Hi,

> 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. 

 

Hmmm. I played around with this last night. For everynode passed in I get a null return from Parser.ignoredTokens.getIn(). I added debugging methods to interact more with the ignoredTokens object. It's full, everything is there, I can get an enumeration just fine BUT when I pass a node in as a key a match is never made.

>
> 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.  

I will try that after I send this off. I placed the code in defaultIn() last night.

> 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.  

Maybe I'm misunderstanding how the ignored tokens are handled. I thought that each Parser has an instance of AnalysisAdapter called ignoredTokens. When the parser encounters a token designated as ignored, it grabs a reference to the next non-ignored token which it uses as a key when storing the ignored token into ignoredTokens. So the node doesn't know if it is preceeded by any ignored tokens but it you can pass it into the getIn() method of the ignoredTokens that is in the parser you used, you can see if there are any.

Well, I'm going to go start from scratch and see if things go better.

 

Thank you,

Gary Montogmery

 

Cheers,
Thomas