Skip to content

PROPOSAL: add a fallthrough! method for continuing to check later rules#2210

Open
jneen wants to merge 2 commits intomasterfrom
feature.fallthrough
Open

PROPOSAL: add a fallthrough! method for continuing to check later rules#2210
jneen wants to merge 2 commits intomasterfrom
feature.fallthrough

Conversation

@jneen
Copy link
Member

@jneen jneen commented Feb 11, 2026

Usage:

class MyLexer < Rouge::RegexLexer
  state :root do
    rule %r/\w+\b/ do |m|
      # aborts the current block and continues as if the regex for this rule did not match
      fallthrough! unless SOME_SET.include?(m[0].downcase)
      token Name::Builtin
    end

    rule %r/\w+\b/ do
      # will end up here if the previous rule called #fallthrough!
      # ...
    end
  end
end

@jneen
Copy link
Member Author

jneen commented Feb 11, 2026

The purpose of this is to allow for more easily removing massive regexes as in e.g. the Ruby lexer. This way, runtime code can more simply test set inclusion while maintaining the same semantics as the giant regex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant