On Sun, 2008-11-02 at 21:56 -0600, Luke Kanies wrote:
> On Oct 31, 2008, at 5:40 PM, Brice Figureau wrote:
> > grammar.ra
> > index 23c2934..d01ab61 100644
> > --- a/lib/puppet/parser/grammar.ra
> > +++ b/lib/puppet/parser/grammar.ra
> > @@ -77,26 +77,28 @@ fstatement:   NAME LPAREN funcvalues RPAREN {
> >     result = ast AST::Function,
> >         :name => val[0],
> >         :arguments => args,
> > -        :ftype => :statement
> > +        :ftype => :statement,
> > +        :doc => @lexer.getcomment
> > }
> 
> Wouldn't it be easier to have the 'ast' method add the 'doc' attribute?

That was my first implementation, but it doesn't work. In fact you want
the documenation to be attached to the statement AST node (ie the
resource, the class, the define...). If you let the doc to be attached
on each AST creation, you end up with a class comment attached to the
AST node of the name of the class and not the class itself :-(

That's why I had to move the comment association to the specific
upper-level nodes. I think I could have done it only in the statement:
grammar rule but it would have need some logic code to scan the current
_values stack to find the real proper node. I think the solution I chose
is simpler and more clear this way.
The only drawback is that whenever you have to add a statement to the
language you need to provide the documentation association.

> If you're not adding docs to every ast class, then you could have a  
> boolean on the AST classes that should add docs.

I'm not sure I understand what you mean. Can you elaborate on this,
please?

> > +    # returns the content of the currently accumulated content cache
> > +    def commentpop
> > +        return @commentstack.pop
> > +    end
> > +
> > +    def getcomment
> > +        comment = @commentstack.pop
> > +        @commentstack.push('')
> > +        return comment
> > +    end
> 
> Why add the empty string?

Because it means we are starting a new documentation section so that
accumulate has just to peek the last pushed string and concat the
current doc with it.

This is for this case of doc:

# comment 1
statement1

# comment 2
statement2

On statement1, the parser calls getcomment to fetch comment1, then
resets the current accumulated comment so that statement2 sees only
comment2. 

Hope that helps,
-- 
Brice Figureau <[EMAIL PROTECTED]>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to