rouge-ruby/rouge · error · ClosedState

State :#{state.name} cannot continue after #{rule.inspect},

Error message

State :#{state.name} cannot continue after #{rule.inspect}, which will always match.

What it means

Error "State :#{state.name} cannot continue after #{rule.inspect}, which will always match." thrown in rouge-ruby/rouge.

Source

Thrown at lib/rouge/regex_lexer.rb:284

      # @overload rule(re, token, next_state=nil)
      # @overload rule(re, &callback)
      #
      # @param [Regexp] re
      #   a regular expression for this rule to test.
      # @param [String] tok
      #   the token type to yield if `re` matches.
      # @param [#to_s] next_state
      #   (optional) a state to push onto the stack if `re` matches.
      #   If `next_state` is `:pop!`, the state stack will be popped
      #   instead.
      # @param [Proc] callback
      #   a block that will be evaluated in the context of the lexer
      #   if `re` matches.  This block has access to a number of lexer
      #   methods, including {RegexLexer#push}, {RegexLexer#pop!},
      #   {RegexLexer#token}, and {RegexLexer#delegate}.  The first
      #   argument can be used to access the match groups.
      def rule(re, *args, &callback)
        raise ClosedState.new(self) if @closed

        matches_empty = re =~ ''

        callback ||= Rule.make_action(re, *args)

        rules << Rule.new(@lexer_class, re, callback)

        close! if matches_empty && !context_sensitive?(re)
      end

      def context_sensitive?(re)
        source = re.source
        return true if source =~ /[(][?]<?[!=]/

        # anchors count as lookahead/behind
        return true if source =~ /[$^]/

        false

View on GitHub (pinned to bd7dad7b09)

When it happens

Trigger: Thrown at lib/rouge/regex_lexer.rb:284 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rouge-ruby/rouge@bd7dad7b09 (2026-08-23). Data as JSON: /api/errors/64cbd2e33d39ca21. Report an issue: GitHub.