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

Support for Mathematica and Wolfram Language #854

Merged
merged 10 commits into from
Aug 7, 2018

Conversation

halirutan
Copy link
Contributor

@halirutan halirutan commented Jan 2, 2018

Provides Mathematica/Wolfram Language support for rouge. This fixes #827

img

  • Provides highlighting of standard built-in symbols that are extracted from
    an online list of functions provided by Wolfram.
  • Support for the various number formats that Mathematica supports. Handling of context symbols
  • Support for named characters like [Alpha]
  • Support for messages
  • Support for slots and association slots of pure functions
  • Support for In[1]:= and Out[1]= markers
  • Support for nested comments and comment markup

Important notice: What you see here are the first Ruby lines of code I ever wrote. I know the language for exactly 2 hours. Please be patient with me.

It would be very nice if someone could look over the code and help me to bring it in a form that can be merged. I tested the lexer locally with the help of rackup and various test-cases some of which I have included in the comments. I couldn't identify any serious slowness even when processing a Mathematica package of about 500 lines.

Additionally, it would be very helpful if someone could point out the best way to use this locally for my Jekyll installation as highlighter so that I can test it more.

I'm not sure what I should do about the filename extension clashes. It has always been a pain that Matlab, Objective-C and Mathematica use *.m as default extension.

* Provides highlighting of standard built-in symbols that are extracted from
an online list of functions provided by Wolfram.
* Support for the various number formats that Mathematica supports. Handling of context symbols
* Support for named characters like \[Alpha]
* Support for messages
* Support for slots and association slots of pure functions
* Support for In[1]:= and Out[1]= markers
* Support for nested comments and comment markup
@DirtyF
Copy link

DirtyF commented Jan 2, 2018

Additionally, it would be very helpful if someone could point out the best way to use this locally for my Jekyll installation as highlighter so that I can test it more.

you can tell bundler to use a specific version of Rouge in your Gemfile:

gem "rouge", git: "https://github.com/halirutan/rouge", branch: "feat_Mathematica"

@halirutan
Copy link
Contributor Author

@dblessing Would you mind reviewing this PR? There is one issue and it's the reason why Travis fails: Mathematica shares the same file extension with Matlab and Objective-C

Rouge::Guesser::Ambiguous: Ambiguous guess: can't decide between ["matlab", "objective_c", "mathematica"]

@miparnisari
Copy link
Contributor

@halirutan you need something like this:

lib\rouge\guessers\disambiguation.rb

      disambiguate '*.m' do
        next ObjectiveC if matches?(/@(end|implementation|protocol|property)\b/)
        next ObjectiveC if contains?('@"')

        next Mathematica if contains?('(*')

        next Matlab if matches?(/^\s*?%/)
      end

And then in the spec:

it 'guesses by filename' do
        assert_guess :filename => 'foo.wl'
        assert_guess :filename => 'foo.m', :source => '(* :Title: Collatz Visualization *)'
      end

@halirutan
Copy link
Contributor Author

@miparnisari Thank you very much. For the ambiguities, I used "(*" and ":=". I quickly checked the syntax of Matlab and Objective C and I think they do not have the := operator while in Mathematica, this is a very common one (far more common than including a comment).

@halirutan
Copy link
Contributor Author

halirutan commented Aug 4, 2018

@miparnisari Is there a particular reason, why this PR is not considered to be merged? Honestly, it is a bit frustrating that this PR is open for 7 months. I chose to implement this specifically for rogue, because it appeared to be a highly active community and as far as I could tell, rogue is very well suited for Jekyll.

If the reason for the silence is that no one here knows the Wolfram Language and cannot judge the quality, then maybe this brings some weight in: I'm also the developer for the Mathematica highlighter that is used for over 6 years on StackExchange and the Wolfram's internal forum. In addition, I'm the maintainer of the Mathematica Plugin for IntelliJ that also exists for about 6 years.

If there are any issues with the implementation here, you can assign the issue to me and I will take care of it. I'm not sure what else to say to finally get the attention of someone with push rights to the repository.

@dblessing
Copy link
Collaborator

dblessing commented Aug 4, 2018 via email

@halirutan
Copy link
Contributor Author

@dblessing First of all, thank you very much. Secondly, I definitely did not want to blame @miparnisari. I dearly appreciated that she helped me in the first place and I only tried to ping someone who might have a clue what's going on.

I really wonder why there are no more volunteers that would like to act as a maintainer as well for such a widely used and highly popular project. It seems your work-load is through the roof. Please take your time. I'm happy as long as I know it is on someone's list and not forgotten.

Copy link
Collaborator

@dblessing dblessing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really great. Thanks for your work @halirutan. I looked over this in detail and couldn't find anything I really thought needed changed.

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

Successfully merging this pull request may close these issues.

Add support for Mathematica / Wolfram Language
4 participants