Issue #21608 has been updated by Henrik Lindberg.

Status changed from Needs Decision to Closed

I tried this in the future parser:
<pre>
Syntax error at '}' at ./foo.pp:8:75
</pre>

Indicating that the parser does not know what to do at the very final `}`.

It is unfortunately impossible to differentiate between the two cases:
* a function call of function f with a hash as an argument (with an array as a 
key, missing a => and a value), which BTW is illegal since an array is not 
valid hash key
* a resource expression creating an instance of a resource of type F with a 
title being an array, but missing a colon.

This is very difficult to anything about - the parser technology is not smart 
enough to report what would make it happy at that point. It only announce its 
unhappiness when seeing the final `}ยด.

In order to be able to give a better error message the parser would need to be 
able to accept an expression block - i.e.

<pre>
'{' expression '}'
</pre>

This is however not easily introduced because of the ambiguities it creates - 
we would need to relax the grammar substantially and move the complexity 
elsewhere. 
IMO, the distinction between a literal hash and a resource expression is one of 
the harder to solve ambiguities in the language and was one of the difficult 
things to handle when being able to
use literal hashes everywhere a value is allowed.

It may still be solvable, effort is not known.

When giving the same logic to Geppetto and trying it with 3.2 and with future 
langauge versions - it gives a series of errors:

* Not a top level expression (the entire expression
* missing } at [
* extranous input }, expecting EOF
* Unknown function 'f'

If the final comma in the title array is removed, it also gives this problem:
* A resource reference must start with a [(deprecated) name, or] class 
reference. (i.e. this is given because the LHS before the [] is not a name (it 
is an error), it could have been f['foo'].

>From that it is possible to figure out that the expression clearly is highly 
>ambiguous (which we sort of knew already), but it tells us that 'f' is an 
>unknown function - so clearly what follows is not recognized as a resource 
>(body/bodies) expression. I.e. the function 'f' is the last piece it can make 
>sense of. 

This is pretty much the same as what happens in the puppet parser.

To summarize. The ':' is a darned important clue to the parser what is actually 
being expressed, and it is almost impossible to make it suggest a missing ':' 
as being the problem simply because it does not know that is the problem.

IMO, the detailed position information from future parser - or using Geppetto 
which tries more options is as good as it gets without either a very large 
effort (possible not being able to fix it), or changing the language itself.

I am therefore marking this issue as closed. There is no "works as best as it 
can in future version"- status to set.

There may be a greater chance in improving the error message in Geppetto 
(different parser technology), but I still think it is going to be hard because 
of the fundamental problem "is it a hash" or a "resource expression".


----------------------------------------
Bug #21608: Syntax error at '}'; expected '}'
https://projects.puppetlabs.com/issues/21608#change-97776

* Author: Chris Wilson
* Status: Closed
* Priority: Normal
* Assignee: Henrik Lindberg
* Category: language
* Target version: 
* Affected Puppet version: 2.6.18
* Keywords: parser errors
* Branch: 
----------------------------------------
>From the following code:

<pre>
  # 
http://stackoverflow.com/questions/6399922/are-there-iterators-and-loops-in-puppet
  define f {
    file { "/root/.ssh/${title}":
      ensure => present,
      source => 'puppet:///files/ssh_keys/${title}',
      owner   => 'root', group => 'root', mode => '0400',
    }
  }
  f { ["id_beep_down", "id_beep_down.pub", "id_beep_up", "id_beep_up.pub",] }
</pre>

I think it's missing a colon after the last ], but that's not what the error 
message says.

<pre>
[puppet server]$ rpm -q puppet
puppet-2.6.18-3.el6.noarch
</pre>


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to