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

Future parser returns nil when parsing a source that contains no statements

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • PUP 3.6.1
    • PUP 3.7.0
    • Compiler

    Description

      Consider the following example:

      require 'puppet'
      require 'puppet/pops'
       
      parser = Puppet::Pops::Parser::Parser.new
       
      result = parser.parse_string('# This is a comment')
       
      puts "Result: #{result.inspect}"
       
      result = parser.parse_string <<-EOM
      # This is a comment
      $foo = 1
      EOM
       
      puts "Result: #{result.inspect}"
      

      The result is:

      # ruby parser_tst.rp 
      Result: nil
      Result: #<Puppet::Pops::Model::Factory:0x7ffe0c270dc8 @current=Puppet::Pops::Model::AssignmentExpression>
      

      In the first case, a nil is returned because there are no Puppet statements in the input. We should consider returning some Pops::Model object, such as Nop, instead of nil.

      Or, document nil as a valid return type for the future parser.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              chuck Charlie Sharpsteen
              Kurt Wall Kurt Wall
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support