On 27/10/08 16:59, Luke Kanies wrote:
> On Oct 25, 2008, at 8:48 AM, Brice Figureau wrote:
>> I choose to push the comments on the stack on each LBRACE and pop on
>> each RBRACE. I also fetch a reset the current stack level on each
>> statement reduction. This way I can attach comment precisely to the
>> puppet statement they belong to.
>
> Seems reasonable. I did something similar when I had some code that
> needed to know whether it was in a define or not, and I think it's a
> pretty common pattern. It's clumsy, but then, LALR parses always are,
> it seems.
Except my proposed solution doesn't work all the time.
This (simple) example fails:
# comment
node test {
include klass
}
When we read the comment we push "comment" on the comment stack.
When the parser calls the lexer to read the { we push a new stack level.
When the parser calls the lexer to read the } we pop the stack.
Then the parser noticing the }, will reduce the include function, with
will fetch the current comment level as it documenation. Unfortunately
we already popped it, so the function include will get the #comment
comment as documenation instead of an empty level.
Really, the only real fix is to push/pop on token shifting.
Unfortunately, this isn't possible with Racc at this time, except by
playing games (ie enable debug, override the methods that prints when a
shift happens to push or pop our comment stack...arghhh...)
The only other alternative I can think of is to change the grammar to
understand comments and deal with them directly in the parser instead of
in the lexer (which has no knowledge of the language).
If someone has a better idea, please speak up.
Otherwise, I'll start with the comment-enhanced parser grammar :-(
--
Brice Figureau
Days of Wonder
http://www.daysofwonder.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---