Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement an Obj-C lexer #27

Closed
jneen opened this issue Sep 15, 2012 · 17 comments
Closed

Implement an Obj-C lexer #27

jneen opened this issue Sep 15, 2012 · 17 comments
Labels
lexer-request A request for a lexer to be developed.

Comments

@jneen
Copy link
Member

jneen commented Sep 15, 2012

No description provided.

@nathany
Copy link
Contributor

nathany commented Mar 2, 2013

Pygments is interesting in that it calls objective() on the CLexer to get an ObjectiveCLexer and on the CppLexer to get an ObjectiveCppLexer.

@jneen
Copy link
Member Author

jneen commented Mar 2, 2013

Oh, interesting. Right, because it's built on top of C, and they have to support C and C++. In Rouge, I'd think it'd be easier just to delegate and have a :parent option that defaults to C. Like objc vs objc?parent=c++ or something.

@nathany
Copy link
Contributor

nathany commented Mar 2, 2013

So objc delegates to c and objc++ delegates to c++. But the extra Objective-C functionality is like a mixin into objc & objc++.

I have guest posts on my luanova.org blog that use Objective-C, so I'm hoping to see this one.

@jneen jneen closed this as completed in 0a0cf99 Sep 17, 2013
@jneen
Copy link
Member Author

jneen commented Sep 17, 2013

Released in 0.5.2

lucidbee pushed a commit to BonsaiAI/rouge that referenced this issue Mar 16, 2017
@saagarjha
Copy link
Contributor

Hi, apologies for commenting on a long-closed issue but I was wondering if Rouge ever got Objective-C++ support. If it did, how can I turn it on? If not, is there I anything I can do to help get this added (should I file a lexer request?) I want to put some snippets in Objective-C++ on my blog and would like that to be highlighted too :)

@pyrmont
Copy link
Contributor

pyrmont commented Dec 15, 2019

@saagarjha Rouge has an Objective-C lexer, it was added in version 0.5.2 so will in all likelihood be in the version you're using.

With GitHub-style code blocks that look like ```<some_lang>, you can tell Rouge to use the Objective-C lexer by replacing <some_lang> with objc (or objective_c, obj-c or any of the alternatives here).

Hope that helps!

@saagarjha
Copy link
Contributor

Right, that's what I'm using now. But that one doesn't "get" C++ like an actual Objective-C++ lexer would, so it leaves large blocks of my code unhighlighted.

@pyrmont
Copy link
Contributor

pyrmont commented Dec 15, 2019

Oh sorry—I didn't catch that it was Objective-C++. I'm afraid no, we don't have a lexer for that. You can look at how the Objective-C lexer is implemented if you'd like to try making an Objective-C++ lexer.

@saagarjha
Copy link
Contributor

So I took a look and it looks like there's some sort of "load_lexer" functionality? Could we implement this with an e.g. "_objective_c.rb" that contains all the Objective-C stuff, then an "objective_c.rb" that includes "c.rb" an "_objective_c.rb", while "objective_cpp.rb" includes "cpp.rb" and "_objective_c.rb"?

@jneen
Copy link
Member Author

jneen commented Dec 15, 2019

It's possible - it has a lot of room for bugs though. See sass/scss, which both extend from css, for an example.

@jneen
Copy link
Member Author

jneen commented Dec 15, 2019

I'm actually astounded that such a language exists, and that somebody took the time to write a parser for it to be honest.

@saagarjha
Copy link
Contributor

Hey, once you have one C++ parser, you try to get as much milage out of it as you can ;) I'll take a look at factoring out the Objective-C parts and see how it works out.

@jneen
Copy link
Member Author

jneen commented Dec 15, 2019

Another example worth looking at is TSX, a combination of typescript and JSX, which are both extensions of javascript.

@saagarjha
Copy link
Contributor

saagarjha commented Dec 15, 2019

Hmm, so I'm having some difficulty with subclassing, and I unfortunately don't know Ruby well enough to figure it out. AFAIK Ruby doesn't do multiple inheritance, so what I'm trying to do is have ObjectiveC subclass C, and ObjectiveCpp subclass Cpp, but put all the common parsing stuff in ObjectiveCCommon (which inherits from Lexer). But unlike TSX the common parser has state-related stuff in it that it needs to get from C, so I can't just load it like TSX does. Any ideas on how to approach this? Is there a way to include code from a module without trying to execute it, or inside the correct scope so it can use the surrounding state information?

@jneen
Copy link
Member Author

jneen commented Dec 15, 2019

Yes, since there is no multiple inheritance, you will need to move existing code around in order to implement this. Look into how TypescriptCommon does it, as well as the self.inherited hook that Ruby provides to modules.

@pyrmont
Copy link
Contributor

pyrmont commented Dec 15, 2019

@saagarjha I suggest you move this into a new issue or (better yet) a PR; this isn't really related to the original issue.

@saagarjha
Copy link
Contributor

Thanks for the help; I filed #1378 with a rough attempt at getting this to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lexer-request A request for a lexer to be developed.
Projects
None yet
Development

No branches or pull requests

4 participants