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 Stan Lexer #1735

Merged
merged 15 commits into from
Jan 7, 2022
Merged

Add Stan Lexer #1735

merged 15 commits into from
Jan 7, 2022

Conversation

jgaeb
Copy link
Contributor

@jgaeb jgaeb commented Sep 5, 2021

This PR adds a lexer for the Stan Bayesian data analysis language, based on the C and R lexers. Stan files do not have an associated mime type, so I've left that attribute as nil—please let me know if it should be a default text type or something like that. (I figured that would lead to it being chosen as a default parser for text files, but maybe that's not right.)

@jgaeb
Copy link
Contributor Author

jgaeb commented Sep 6, 2021

Looks like I didn't take into account functions being called inside other functions. Shouldn't be difficult to resolve (just add another scope for parentheses) but I will be away for a few days and will fix it then.

@spinkney
Copy link

Oh I didn't know this already existed!

@spinkney
Copy link

@jgaeb can you update for 2.28? This fixes #1768

@jgaeb
Copy link
Contributor Author

jgaeb commented Nov 23, 2021

Just added the complex type and complex literals!

@spinkney
Copy link

Does this have the array[ ] syntax and will it lex .stanfunctions files?

@jgaeb
Copy link
Contributor Author

jgaeb commented Nov 23, 2021

Ah, good catch on the array syntax—that's an easy fix. Can you point me to the spec / something describing the structure of .stanfunctions files? I'm having trouble finding any docs. (Although I'm guessing I'm overlooking something obvious!)

@spinkney
Copy link

No worries this is brand new. It should just highlight the same as .stan files but allow the ending to be .stanfunctions.

The doc is at stan-dev/docs#434.

vs-code put it in by just adding .stanfunctions as another extension in the json

@jgaeb
Copy link
Contributor Author

jgaeb commented Nov 23, 2021

Cool, both easy changes—should be taken care of now.

@spinkney
Copy link

spinkney commented Nov 24, 2021

@tancnle I see you've made most of the acceptances. This is ready for review/acceptance

@spinkney
Copy link

Also, we need to make sure that complex numbers are highlighted correctly
vscode shows this:
Screen Shot 2021-11-28 at 9 03 18 AM

issues:

  • complex is not highlighted
  • to_complex is not highlighted
  • get_real is not highlighted
  • and 3i - 40e-3i + 1e10i should each be highlighted as "green", just like regular numbers

@jgaeb
Copy link
Contributor Author

jgaeb commented Nov 28, 2021

@spinkney The lexer should deal with all of those issues. Let me know if anything still looks weird to you.

@spinkney
Copy link

spinkney commented Nov 29, 2021

there's a typo on line 160 for multiply_lower_tri_self_transpose. Will see if there are others

@spinkney
Copy link

also, @jgaeb how did you get/make that list of functions/distributions?

@jgaeb
Copy link
Contributor Author

jgaeb commented Nov 30, 2021

It looks like the multiply_lower_tri_self_transpose was just a typo. (Edit: Ah, I see you found it too.)

I constructed the list manually from the function reference. I thought a little bit if there might be a way to pull it out of the compiler code or something like that, but I'm not sure where the language's standard functions (as opposed to just the functions defined in the stan/math library) are defined, exactly.

@spinkney
Copy link

spinkney commented Dec 1, 2021

It looks like the multiply_lower_tri_self_transpose was just a typo. (Edit: Ah, I see you found it too.)

I constructed the list manually from the function reference. I thought a little bit if there might be a way to pull it out of the compiler code or something like that, but I'm not sure where the language's standard functions (as opposed to just the functions defined in the stan/math library) are defined, exactly.

You can get all the signatures this way:

clone the stan-docs repo then cd into it run the python script with the major and minor version numbers:

python3 extract_function_sigs.py 2 28

then run a bash command to extract only the unique names

cut -d ';' -f1 stan-functions-2_28.txt | uniq -u > stan_functions_list-2_28.txt

@spinkney
Copy link

spinkney commented Dec 9, 2021

@pyrmont @jneen this ready for review

@tancnle tancnle added the needs-review The PR needs to be reviewed label Dec 10, 2021
@tancnle tancnle self-assigned this Dec 10, 2021
Copy link
Collaborator

@tancnle tancnle left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution @jgaeb ❤️ Warm welcome to the Rouge project. stan is an interesting language and it would be great to add this support to Rouge. The PR looks great to me. I have added some minor suggestions for your consideration. Please let me know what you think 🙏🏼

Could you also please add stan to the list of supported languages?

lib/rouge/lexers/stan.rb Outdated Show resolved Hide resolved
lib/rouge/lexers/stan.rb Outdated Show resolved Hide resolved
lib/rouge/lexers/stan.rb Outdated Show resolved Hide resolved
lib/rouge/lexers/stan.rb Outdated Show resolved Hide resolved
lib/rouge/lexers/stan.rb Outdated Show resolved Hide resolved
@tancnle tancnle added author-action The PR has been reviewed but action by the author is needed and removed needs-review The PR needs to be reviewed labels Dec 27, 2021
@tancnle tancnle removed their assignment Dec 27, 2021
@jgaeb
Copy link
Contributor Author

jgaeb commented Dec 31, 2021

@tancnle Thank you very much for the suggestions! I made all of the changes you requested, including to preprocessor directives.

lib/rouge/lexers/stan.rb Outdated Show resolved Hide resolved
lib/rouge/lexers/stan.rb Outdated Show resolved Hide resolved
@tancnle
Copy link
Collaborator

tancnle commented Jan 7, 2022

Thank you for a delightful collaboration on this @jgaeb ❤️ Your work is greatly appreciated 🙏🏼

@tancnle tancnle merged commit e8297f4 into rouge-ruby:master Jan 7, 2022
@tancnle tancnle removed the author-action The PR has been reviewed but action by the author is needed label Jan 7, 2022
@tancnle tancnle mentioned this pull request Jan 17, 2022
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.

3 participants