pygments / pygments.rb

💎 Ruby wrapper for Pygments syntax highlighter
MIT License
572 stars 141 forks source link

undefined method 'create' #233

Closed sdarwin closed 2 years ago

sdarwin commented 2 years ago

Hi,

I am working on updating a library from python2 to python3. In the process, it's necessary to upgrade pygments.rb, since earlier versions didn't support python3.

A certain script now gives the error "undefined method 'create'". Examining the pygments.rb source code, it looks like such a method had existed, but has now been removed.

Here is the entire script that uses "create". Should a different method be used instead of that? Thanks.

require 'pygments'

# Need to create/register non-builtin lexers even if they are global plugins.
Pygments::Lexer.create name: 'Jam', aliases: ['jam','bjam','b2'],
    filenames: ['*.jam','Jamfile','Jamroot'], mimetypes: ['text/x-jam']
slonopotamus commented 2 years ago

Lexer::create was documented as being internal.

slonopotamus commented 2 years ago

But. Do you actually need this code? Since #225, pygments.rb automatically picks up lexers registered in Pygments via plugins. Maybe everything will work for you properly if you just remove that code?

sdarwin commented 2 years ago

It's a small world. Pull 225 mentions Issue 187, where literally the same code snippet using Lexer::create appears.

Do you actually need this code? if you just remove that code?

Could be an idea to try. That implies this lexer was already "registered in Pygments via plugins".

However, discussing the issue with the original developer yesterday, he might be redesigning that documentation toolchain so the error is sidestepped entirely. I will close the issue for now and re-open later if still a problem. Thanks.

slonopotamus commented 2 years ago

That implies this lexer was already "registered in Pygments via plugins".

Yeah, but your snipped doesn't actually teach pygments how to parse. It just adds info "pretend as if you know that language". Actual parser/highlighter still has to be somehow registered in Pygments. And if it is registered, pygments.rb will automatically know about its existence.