# File lib/puppet/parser/lexer.rb, line 397
397:     def scan
398:         #Puppet.debug("entering scan")
399:         raise Puppet::LexError.new("Invalid or empty string") unless @scanner
400: 
401:         # Skip any initial whitespace.
402:         skip()
403: 
404:         until @scanner.eos? do
405:             yielded = false
406:             matched_token, value = find_token
407: 
408:             # error out if we didn't match anything at all
409:             if matched_token.nil?
410:                 nword = nil
411:                 # Try to pull a 'word' out of the remaining string.
412:                 if @scanner.rest =~ /^(\S+)/
413:                     nword = $1
414:                 elsif @scanner.rest =~ /^(\s+)/
415:                     nword = $1
416:                 else
417:                     nword = @scanner.rest
418:                 end
419:                 raise "Could not match '%s'" % nword
420:             end
421: 
422:             newline = matched_token.name == :RETURN
423: 
424:             # this matches a blank line; eat the previously accumulated comments
425:             getcomment if lexing_context[:start_of_line] and newline
426:             lexing_context[:start_of_line] = newline
427: 
428:             final_token, token_value = munge_token(matched_token, value)
429: 
430:             unless final_token
431:                 skip()
432:                 next
433:             end
434: 
435:             lexing_context[:after]         = final_token.name unless newline
436: 
437:             value = token_value[:value]
438: 
439:             if match = @@pairs[value] and final_token.name != :DQUOTE and final_token.name != :SQUOTE
440:                 @expected << match
441:             elsif exp = @expected[-1] and exp == value and final_token.name != :DQUOTE and final_token.name != :SQUOTE
442:                 @expected.pop
443:             end
444: 
445:             if final_token.name == :LBRACE
446:                 commentpush
447:             end
448: 
449:             yield [final_token.name, token_value]
450: 
451:             if @previous_token
452:                 namestack(value) if @previous_token.name == :CLASS
453: 
454:                 if @previous_token.name == :DEFINE
455:                     if indefine?
456:                         msg = "Cannot nest definition %s inside %s" % [value, @indefine]
457:                         self.indefine = false
458:                         raise Puppet::ParseError, msg
459:                     end
460: 
461:                     @indefine = value
462:                 end
463:             end
464:             @previous_token = final_token
465:             skip()
466:         end
467:         @scanner = nil
468: 
469:         # This indicates that we're done parsing.
470:         yield [false,false]
471:     end