Skip to content

Fix NoMethodError in Magik lexer's method_name state - #2328

Merged
jneen merged 1 commit into
rouge-ruby:mainfrom
sebastiaanspeck:patch-1
Aug 28, 2026
Merged

jneen merged 1 commit into
rouge-ruby:mainfrom
sebastiaanspeck:patch-1

Conversation

@sebastiaanspeck

Copy link
Copy Markdown
Contributor

Follow-up to #2318.

state :method_name still called Magik.identifier, a leftover from an earlier revision of that PR that cached regexes as memoized class methods (the style @jneen's review comments on #2318 asked to move away from). That refactor was done for every other regex in the file, but this one call site was missed.

Since RegexLexer evaluates a state's rule arguments eagerly when the state is first loaded, Magik.identifier raises NoMethodError: undefined method 'identifier' for class Rouge::Lexers::Magik as soon as :method_name is entered - i.e. on any input containing _method, not just the new []-method syntax. Verified against a clean checkout of current main (909e8ca):

$ ruby -Ilib -e 'require "rouge"; Rouge::Lexers::Magik.new.lex("_method a.b()\n_endmethod\n").to_a'
NoMethodError: undefined method 'identifier' for class Rouge::Lexers::Magik

This fix replaces the stale class-method reference with the identifier local variable already used everywhere else in the file. It's a one-line change with no other effect: the sample file round-trips through the lexer with no errors, and no other tokenization changes since identifier is the exact same regex Magik.identifier was aliasing.

The regex-caching class methods that comment 2318 review threads
targeted were already removed in favor of local variables; this
call was missed and would raise NoMethodError at lex time.
@jneen
jneen added this pull request to the merge queue Aug 28, 2026
Merged via the queue into rouge-ruby:main with commit 548d5d9 Aug 28, 2026
10 checks passed
@jneen

jneen commented Aug 28, 2026

Copy link
Copy Markdown
Member

I'm a little shocked that the tests didn't catch this. Does the visual spec never trigger this state?

@sebastiaanspeck

sebastiaanspeck commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

I'm a little shocked that the tests didn't catch this. Does the visual spec never trigger this state?

The tests caught it, but it was ignored(?) - https://github.com/rouge-ruby/rouge/actions/runs/32947811182/job/98230454981 and https://github.com/rouge-ruby/rouge/actions/runs/32947811182/job/98230455001

@sebastiaanspeck
sebastiaanspeck deleted the patch-1 branch August 28, 2026 04:34
@jneen

jneen commented Aug 28, 2026

Copy link
Copy Markdown
Member

Hm, the action ran but it never made its way to the PR. Incredible.

UlyssesZh pushed a commit to UlyssesZh/rouge that referenced this pull request Aug 28, 2026
* Add missing _locking keyword to Magik lexer

_locking is a real keyword (used in _protect _locking <expr>) that was
missing from KEYWORDS, so it highlighted as a plain identifier instead
of Keyword. Confirmed against a live Magik session.

Also drops _recursive from the same list to keep this change focused
on the one clear, verifiable gap.

* Integrate rouge-ruby#2328
UlyssesZh pushed a commit to UlyssesZh/rouge that referenced this pull request Aug 28, 2026
* Fix over-greedy character-literal regex in Magik lexer

%[^\s]+ consumed everything up to the next whitespace, so a character
literal immediately followed by punctuation (e.g. %a.foo) was lexed as
one Literal::String::Char token instead of a character literal plus a
separate slot access.

Replaced with %(?:\w+|\W), matching Magik's actual CHARACTER_REGEXP
(used by magik-tools' MagikGrammar and the same pattern the Magik
TextMate grammar documents). Verified against a live Magik session and
tree-sitter-magik that %a.foo parses as two tokens (character literal
"%a", then a call to .foo), and that the existing character-literal
samples (%q, %u000A, %newline, %space, %tab, ...) still lex identically.

* Integrate rouge-ruby#2328
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.

2 participants