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

Add support for the Racket lisp #1513

Closed
Eugleo opened this issue Aug 1, 2018 · 5 comments · Fixed by #2315
Closed

Add support for the Racket lisp #1513

Eugleo opened this issue Aug 1, 2018 · 5 comments · Fixed by #2315

Comments

@Eugleo
Copy link

Eugleo commented Aug 1, 2018

Racket is basically like Scheme when it comes to syntax highlighting, it only has some minor differences. I have made a complete Racket grammar (link), but I think just copying the Scheme one and adding support for racket language will be cleaner and function just as well.

If you want me I can open a PR, just need to decide if we want the complex grammar or rather the simple one.

EDIT: Updated the link to point to the renamed repo.

@mAAdhaTTah
Copy link
Member

I think the simplest implementation is just another alias for the current lisp language.

Otherwise, simpler is generally going to better if it's "good enough". We're not a parser, so perfection isn't the goal. Would def be interested in a PR if you want to give it a shot.

@jcubic
Copy link
Contributor

jcubic commented Mar 24, 2020

Isn't racket just scheme with brackets in some places? it should work the same as for scheme syntax. If there is something missing in scheme I would add that to that language and use scheme for racket. Or if aliases are possible use racket as aliast for scheme.

@Eugleo
Copy link
Author

Eugleo commented Apr 8, 2020

Well, mostly it is. There are some minor differences, for example the aforementioned braces and brackets, or syntax identifiers, such as #'.

Now that you've reminded me of this old issue, I think duplicating the scheme file and making some changes to it (i.e. creating a whole new language, not just aliasing to the old one) would be the best course of action. Or is there some downside to it that I'm missing? I'd rather not break (=ammend) the scheme syntax highlighting.

@RunDevelopment
Copy link
Member

Hmmm if it's really just brackets and very minor differences, couldn't we just write a little something with go through all scheme patterns and replaces all ( and ) characters with their racket equivalents?

Like this:

The following requires that if a character class in scheme contains both "(" and ")", they have to be at the beginning of the character class. E.g. [^()\s] but not [\s()]

Prism.languages.racket = Prism.languages.extend('scheme', {});
Prism.languages.DFS(Prism.languages.racket, function (key, value) {
    if (Prism.util.type(value) === "RegExp") {
        var source = value.source;
        // replace lone "(" and ")" characters with a character class "[({[]" and "[)}\]]"
        source = source.replace(/((?:^|[^\\])(?:\\{2})*)\\\(/g, "$1[({\\[]");
        source = source.replace(/((?:^|[^\\])(?:\\{2})*)\\\)/g, "$1[)}\\]]");
        // replace "()" in character classes with "(){}[\]"
        source = source.replace(/((?:^|[^\\])(?:\\{2})*\[\^?)\(\)/g, "$1(){}[\\]");
        this[key] = RegExp(source, value.flags);
    }
});

Prism.languages.insertBefore('racket', 'some-token', {
    // some tokens
});

Not tested in any way but I'm optimistic ;)

@jcubic
Copy link
Contributor

jcubic commented Apr 13, 2020

I want to add something to the discussion.

Consider this pretty good book about Scheme The Scheme Programming Language 4ed by R. Kent Dybvig (https://www.scheme.com/tspl4/further.html#./further:h1)

It have mixed parenthesis and brackets I think that scheme should have those to be the same when there is /[()]/ there should be /[[\]]/, I'm in a process of adding this to my Scheme in JavaScript.

It would be nice if Scheme syntax just behave the same if everywere are brackets instead of parenthesis, at Scheme FAQ there is written that R5RS spec say that brackets are reserved characters but don't say what they should do and that some scheme use that character.

http://community.schemewiki.org/?scheme-faq-language#H-yoyi82

So basically if Prism should work with any Scheme implementation it should use brackets as well as parenthesis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants