On 2014-16-04 23:41, Joshua Hoblitt wrote:
On 04/16/2014 01:05 PM, Andy Parker wrote:
On Tue, Apr 15, 2014 at 11:15 AM, Joshua Hoblitt <[email protected]> wrote:

* Is it possible to escape the endtag so that it can appear inside the
heredoc string?


I don't believe so. In fact I don't know of any heredoc system that allows
that, since you can just select a different end marker.

Nor do I; nor am I requesting this feature. :)  I would be nice for this
to be mentioned in the eventual docs.

yes. good point. (The very purpose of using heredoc is to avoid escapes, and it misses to point this out :-)

The only solid use case that occurs to me is being able to put complete
code examples into a heredoc.  I imagine supporting such a feature would
require the parser to backtrack from the endtag to look for an escape
sequence, which may not be worth the cost.

As Andy said, the idea is to pick something that does not exist in the
text as the end tag, allowing it to be escaped creates a horrible mess, since you can use a multi word string, it can be pretty much anything.

* I feel it's a bit confusing for an operator to have a function call
like syntax.  I'm sure it's already been discussed at length but why
wasn't the shell/perl5/ruby << heredoc operator reused?


Actually, there wasn't much discussion. Henrik will have to explain the
choice. I always assumed it had to do with parsing, possibly since << is
used to introduce the collection query (a complete guess).

That was my thought to but it looks like the DSL has a left shift
operator I was ignorant of:

https://github.com/puppetlabs/puppet/blob/master/lib/puppet/parser/lexer.rb#L168

The total extent of knowledge about racc is that it exists.  Is there a
goal / technical reason to try to keep the grammar as context free as
possible?


The decision was based on several things:

* << is already left shift, although <<- would be unique (but then mean trim if we were to use Ruby semantics. (There is no clash with <|, or <||)
* there are issues with the Ruby syntax (see the ARM - things you cannot do)
* I wanted to be able to control the escapes individually, and therefore needed something that marks the end lexically. (now the closing parenthesis in @(END) ). * Same reason for the syntax checking support, yet another parameter that is hard to handle if there is no end. * All of the work is done in the lexer and it needs to be context free. The lexer delivers tokens based on source code that is "out of band".

To me it is not so strange to think about @(END) as a function call to the special function @() - a function that sucks up the source until the first argument (the end tag), and then hides it from the grammar, and then producing that text as the result of the "call".

Ruby newbies struggle with the Heredoc syntax in Ruby afaict, and the various languages that has heredoc all do it slightly differently, so there was no clear winning syntax to adopt (at least that was my conclusion).

- henrik


--
You received this message because you are subscribed to the Google Groups "Puppet 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/lin0sa%24kv2%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to