PrismJS / prism

Lightweight, robust, elegant syntax highlighting.
https://prismjs.com
MIT License
12.32k stars 1.29k forks source link

[language-support] Add support for `ObjectPascal` #1426

Closed pakLebah closed 6 years ago

pakLebah commented 6 years ago

I know PrismJS already supports Pascal language. However, modern Pascal language –that's being used by Delphi, Free Pascal, Oxygene, etc– tend to call itself as Object Pascal, instead of just simple Pascal. Because the latter is mostly known as and associated to the old school Wirth's Pascal of the 70's.

So, I propose either PrismJS renames its Pascal language into ObjectPascal, or create a duplicate of Pascal language and name it as ObjectPascal.

Why the name is important? Because I'm using VS Code to write Object Pascal programs with OmniPascal extension. I'm also using Bracket Pair Colorizer extension. The problem is… OmniPascal extension only supports ObjectPascal language, while Bracket Pair extension only support Pascal language. Bracket Pair extension is using PrismJS as its language definition tool, so I have to ask PrismJS if I want Bracket Pair extension to support a new language.

Yes, I know it's a bit complicated relationship that I have to live on if I want to write Object Pascal programs using those extensions. Hopefully you'll understand.

Thank you. 😊

Golmote commented 6 years ago

Hi! Thanks for reporting.

If we were to add ObjectPascal to Prism, it would be added as an alias to the pascal component, along with TurboPascal and FreePascal. But I'm not even sure Bracket Pair Colorizer can use aliases at the moment, seeing it already has custom language name associations: https://github.com/CoenraadS/BracketPair/blob/master/src/documentDecorationManager.ts#L129

It appears that @CoenraadS already had to deal with language name mappings for its extension in the past (https://github.com/CoenraadS/BracketPair/issues/99, https://github.com/CoenraadS/BracketPair/issues/128, https://github.com/CoenraadS/BracketPair/issues/131...). Maybe this issue should be fixed the same way here. Thoughts, @CoenraadS?

CoenraadS commented 6 years ago

Is there a better way? I would like to be able to pass an alias to the loadLanguages function and have it choose the correct parameters, so I don't have to do so myself. This code was actually from before loadLanguages was available, so maybe it can already handle aliases, but I didn't check very hard.

pakLebah commented 6 years ago

@Golmote: The language are Pascal (the classic one) and ObjectPascal (the modern one). Delphi, TurboPascal (who is still using TP anyway?), FreePascal, and Oxygene are the names of compilers that implement Pascal language in various dialects. Along with those popular Pascal compilers, there are many other Pascal compilers out there with its own dialect e.g. NewPascal, SmartPascal, Turbo51, PascalABC, etc. but even those are still using either Pascal or ObjectPascal language, despite their dialects are not completely compatible. So, PrismJS should only support Pascal and ObjectPascal, not the compiler names.

Golmote commented 6 years ago

@CoenraadS I think loadLanguages can't work with aliases at the moment. But it definitely could, so I just created #1427. Yet, I don't know if Prism would add all the aliases you defined in your getPrismLanguageID function (like scad or apex which seem to be actual languages, even if they might look like existing ones, or javascriptreact and typescriptreact which are really weird names for JSX and TSX IMO).

@pakLebah You seem to know your stuff, so i'll trust you on this ^^. We could then add only objectpascal as an alias to the pascal component.

pakLebah commented 6 years ago

@Golmote: Thank you. I've been a professional Pascal programmer for more than fifteen years, mostly with Delphi and Free Pascal. Well… it was before I retired a few years ago. Now I'm doing programming just for fun and hobby So, yes… I know this Pascal stuffs well enough. 😊

CoenraadS commented 6 years ago

@Golmote Great! I was just talking about the PrismJS aliases also, not vscode specific ones or languages hacks I did just because existing languages are good enough to get the bracket information.

mAAdhaTTah commented 6 years ago

@Golmote You've added ObjectPascal as an alias for Pascal. Is there any other action item here?

Golmote commented 6 years ago

@mAAdhaTTah Yes, we need to make loadLanguages() work with aliases.

mAAdhaTTah commented 6 years ago

@Golmote Can we close this one in favor of #1427?

Golmote commented 6 years ago

We can.

shaunroselt commented 5 years ago

Maybe add an alias for 'Delphi' also?

RunDevelopment commented 5 years ago

@shaunroselt As @pakLebah pointed out: Delphi is merely the name of a compiler for a Pascal/ObjectPascal dialect and therefore shouldn't be classified as its own language.