-
Notifications
You must be signed in to change notification settings - Fork 743
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
Restore support for highlighting XML-encoded plists #1026
Conversation
The XML lexer can now read *.plists, and a disambiguation has been added for *.plist files since now both the Plist and XML lexers can handle them. The reason this change was made is that the current Plist lexer handles (and mangles) property lists that are XML-based. Property lists can be encoded as binary, ASCII, or XML, with most files being XML-encoded.
@Footpad If most Plists are XML-encoded, I wonder if it would be preferable to add delegation to the Plist lexer so that it delegates XML leading to the XML lexer. Having the XML be able to handle them directly isn't a bad thing but it seems like needing to know you should use the XML lexer rather than the Plist lexer violates the principle of least surprise. What do you think? |
I’m not sure what is meant by delegation, is there an example or documentation that illustrates it? The approach I took here was based on the other examples for similar file types that are lexed as XML. It might be cleaner to do something else, but I would need guidance on how to do so. |
@Footpad Delegation is a mechanism by which one lexer can 'call' another lexer to perform some of the work. The method is defined in the excerpt below. rouge/lib/rouge/regex_lexer.rb Lines 355 to 376 in 273de5e
You can see some examples in the project. That said, thinking more about it, it's probably not the right approach given that you'd be effectively delegating the entirety of the source. Are Plists ever a mixture of XML and non-XML? Or is it all one or the other? |
Plists are either all XML or all binary. XML is the only format that would need lexing. Apple's documentation describes the binary format as optimized and opaque. |
Wow, can't believe plists have three different formats. Since the format should be all one type in any case, I think this approach is fine. Maybe it would be worth adding some comments in each lexer to make sure in the future someone doesn't come along and say WTF and remove something. |
@dhmoore wrote:
It seems like ASCII-based Plists are a third option (this is the type that Rouge's Plist lexer actually scans). |
Yeah, I agree. I'll make an issue. |
The XML lexer can now read *.plists, and a disambiguation has been added for
*.plist files since now both the Plist and XML lexers can handle them.
The reason this change was made is that the current Plist lexer handles (and
mangles) property lists that are XML-based. Property lists can be encoded as
binary, ASCII, or XML, with most files being XML-encoded.