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

Functional Languages: ML/OCaml/Haskell #619

Closed
edalorzo opened this issue Oct 28, 2014 · 5 comments
Closed

Functional Languages: ML/OCaml/Haskell #619

edalorzo opened this issue Oct 28, 2014 · 5 comments

Comments

@edalorzo
Copy link
Contributor

I have identified a few interesting problems while working with the syntax highlight of SML.

First, there is no support for SML itself. It defaults to OCaml but the keywords are not exactly the same although the syntax is. I guess, it is just a matter of taking the OCaml definition and use it for SML just with a different set of keywords.

That being said, the parser misinterprets the use of ' (prime) in variables.

fun sum_list xs =
   case xs of
      [] => 0
     | x::xs' => x + sum_list xs'

In this case the parser interprets everything from the first ' to the second one as a string. This happens in both Ocaml and Haskell.

I tried to fix it myself, but my understanding of how languages are defined is limited and even after reading the documentation and comparing with other language definitions I did not manage to make it work for me, so I decided to report the issue and with luck you guys may fix it in the future.

@isagalaev
Copy link
Member

Incidentally, the apostrophe thing was fixed recently along with other things in #608. Here's how that snippet is rendered with the current master code:

ocaml

This is going to be in the next release.

As for SML, if it's that simple could you take on doing this? We have developer docs over at http://highlightjs.readthedocs.org/.

@edalorzo
Copy link
Contributor Author

Awesome, thanks @isagalaev

Yeah, I think I can fix the SML thing, I will simply change the OCaml definition to use the right SML keywords. I will see about making a merge request in the coming hours.

@edalorzo
Copy link
Contributor Author

@isagalaev

I could confirm that your case case works, but this one doesn't

fun append_my_list(xs, ys) =
    case xs of
        Empty => ys
      | Cons(x, xs') => Cons(x, append_my_list(xs',ys))

It again misinterprets the apostrophe here.

Changing the relevance in (ocaml lang) to

{ /* don't color identifiers, but safely catch all identifiers with '*/
 begin: '[a-z_]\\w*\'[\\w\']*',
 relevance: 5
},

It solved the problem for me. No sure yet how relevance affects parsing, though.

@isagalaev
Copy link
Member

If you fixed it by changing the relevance then the problem was that it was highlighted as a different language. I'll look into it and see if I can find a more robust solution. Thanks for the test case!

@isagalaev
Copy link
Member

I fixed language detection so this Ocaml snippet is now recognized and highlighted correctly. If you find any other problem, please feel free to open a new issue. It's great to get feedback based on real-world testing :-).

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

No branches or pull requests

2 participants