Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-1576

New Parser does not handle hyphenated barewords

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 3.5.0
    • Component/s: DSL, Server
    • Labels:
      None
    • Template:
    • Story Points:
      1
    • Sprint:
      Week 2014-2-26 to 2014-3-5

      Description

      The current parser/evaluator handles hyphenated bare words such as hi-there. The new parser and evaluator chokes on these, and tries to interpret them as numeric expressions of subtraction.

      Works on current parser:

      [16:08:41][Ruby(ruby-1.9.3-p448)][Git(pr/2320)] andy:puppet
      > be puppet apply -e 'notify { hi-there: }'
      Notice: Compiled catalog for aparker.corp.puppetlabs.net in environment production in 0.02 seconds
      Notice: hi-there
      Notice: /Stage[main]/Main/Notify[hi-there]/message: defined 'message' as 'hi-there'
      Notice: Finished catalog run in 0.03 seconds
      

      New evaluator shows that it is checking that the left and right operands of the - operator are numeric:

      [16:08:05][Ruby(ruby-1.9.3-p448)][Git(pr/2320)] andy:puppet
      > be puppet apply -e 'notify { hi-there: }' --parser future
      Error: Evaluation Error: The value 'hi' cannot be converted to Numeric. at line 1:10 on node aparker.corp.puppetlabs.net
      Error: Evaluation Error: The value 'hi' cannot be converted to Numeric. at line 1:10 on node aparker.corp.puppetlabs.net
      

      The current evaluator is passed it as a numeric expression as well.

      [16:08:13][Ruby(ruby-1.9.3-p448)][Git(pr/2320)] andy:puppet
      > be puppet apply -e 'notify { hi-there: }' --parser future --evaluator current
      Error: left operand of - is not a number at line 1 on node aparker.corp.puppetlabs.net
      Wrapped exception:
      left operand of - is not a number
      Error: left operand of - is not a number at line 1 on node aparker.corp.puppetlabs.net
      

      It appears that the new parser is tokenizing the hyphenated bare word as something like IDENTIFIER, SUBTRACT, IDENTIFIER where the old parser is seeing it as simply IDENTIFIER.

        Attachments

          Issue Links

            Activity

            Hide
            henrik.lindberg Henrik Lindberg added a comment -

            Hyphenated bare-words potentially opens up a can of worms. There are a couple of options:

            • add hyphen back (should not start or end with a hyphen though), and then either:
              • validate if a NAME token contains it, when the NAME token is used as a NAME - this requires more CPU cycles as it again has to check with a regexp + overhead of validating each and every name - now it does not have to do this because it trusts the lexer
              • return it as an unquoted STRING token (that way it can never be mistaken for a NAME) - it is always as if it was quoted in source.

            I like the last approach best

            Show
            henrik.lindberg Henrik Lindberg added a comment - Hyphenated bare-words potentially opens up a can of worms. There are a couple of options: add hyphen back (should not start or end with a hyphen though), and then either: validate if a NAME token contains it, when the NAME token is used as a NAME - this requires more CPU cycles as it again has to check with a regexp + overhead of validating each and every name - now it does not have to do this because it trusts the lexer return it as an unquoted STRING token (that way it can never be mistaken for a NAME) - it is always as if it was quoted in source. I like the last approach best
            Hide
            henrik.lindberg Henrik Lindberg added a comment -

            I have a gut feeling that there are corner cases around numeric, or numeric look alike bare words and hyphens / 'minus' mismatch.
            How strongly is it desired to be able to use hyphenated bare-words? How common are they?

            Show
            henrik.lindberg Henrik Lindberg added a comment - I have a gut feeling that there are corner cases around numeric, or numeric look alike bare words and hyphens / 'minus' mismatch. How strongly is it desired to be able to use hyphenated bare-words? How common are they?
            Hide
            andy Andrew Parker added a comment -

            Merged into master in 048f88

            Show
            andy Andrew Parker added a comment - Merged into master in 048f88
            Hide
            kylo Kylo Ginsberg added a comment -

            Verified with the example above.

            Show
            kylo Kylo Ginsberg added a comment - Verified with the example above.

              People

              • Assignee:
                Unassigned
                Reporter:
                andy Andrew Parker
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support