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

enh(elixir) Improves and fixes many issues with Elixir grammar #3212

Merged
merged 11 commits into from Jun 5, 2021
Merged

enh(elixir) Improves and fixes many issues with Elixir grammar #3212

merged 11 commits into from Jun 5, 2021

Conversation

angelikatyborska
Copy link
Contributor

@angelikatyborska angelikatyborska commented May 30, 2021

Closes #3210
Closes #3211

Changes

  • If defmacro is a function definition, defmacrop should be too
  • If defrecord is a class definition, defstruct should be too

Checklist

  • Remove incorrect keywords
  • Add missing keywords
  • Define literals (nil, true, false)
  • Fix highlighting 0 as a number
  • Added markup tests
  • Updated the changelog at CHANGES.md

const DEFSTRUCT = {
className: 'class',
beginKeywords: 'defstruct'
// ends immediately
Copy link
Member

Choose a reason for hiding this comment

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

class is deprecated now. More likely you'd want this to be a newer multi-match rule and then use title.class for the name of the struct... See wren.js for examples. I can also do this myself after though... I already had a few commits patching the other declarations to the newer standard but decided they didn't fit in our regex fix PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... since the struct's name is not part of the defstruct call but it's defined by the module name in which defstruct is called, I think I just need to make defstruct a keyword instead?

Copy link
Member

@joshgoebel joshgoebel Jun 5, 2021

Choose a reason for hiding this comment

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

iex> defmodule User do
...>   defstruct name: "John", age: 27
...> end

Ah, yes, just a keyword then for defstruct... defmodule though would probably be a multi-matcher.

@@ -1,4 +1,8 @@
a = """test"""
b = '''test'''
Copy link
Member

Choose a reason for hiding this comment

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

I see how these are better examples (that you added), but if the previous were valid we should also leave them to serve as additional regression tests... one can still use a multi-line string for a single line - that is valid grammar, yes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is valid grammar, yes?

No, those were syntax errors in Elixir. The only allowed characters after the opening '''/""" is optional whitespace, and then a newline is required.

My assumption is that it's not a big deal if the syntax highlighting colors something that doesn't compile so I didn't feel the need to change the regexes for multiline strings, but the test examples should be valid Elixir code, right?

Copy link
Member

Choose a reason for hiding this comment

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

No, those were syntax errors in Elixir.

Whoa. I stand corrected. ;-)

My assumption is that it's not a big deal if the syntax highlighting colors something that doesn't compile

Right, it's not our job to detect invalid code.

but the test examples should be valid Elixir code, right?

For the most part, yes. In this particular case this indeed makes sense. I just see people "swap" test cases often when they should be adding new cases instead, [not removing old ones]. Thought this was perhaps yet another case of that. :)

@joshgoebel
Copy link
Member

Perhaps we could add aliases for Elixir extensions also.

Comment on lines +8 to +9
- enh(elixir) updated list of keywords (#3212) [Angelika Tyborska][]
- fix(elixir) fixed number detection when numbers start with a zero (#3212) [Angelika Tyborska][]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm assuming the id should be the PR id, not the issue id?

Copy link
Member

Choose a reason for hiding this comment

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

Yep

@angelikatyborska angelikatyborska marked this pull request as ready for review June 5, 2021 07:33
@joshgoebel joshgoebel changed the title Elixir maintenance enh(elixir) Improves and fixes many issues with Elixir grammar Jun 5, 2021
@joshgoebel joshgoebel merged commit 4bd703a into highlightjs:main Jun 5, 2021
@joshgoebel
Copy link
Member

@angelikatyborska Thanks so much!

@angelikatyborska angelikatyborska deleted the elixir-maintenance branch June 5, 2021 08:32
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.

(Elixir) Zero isn't highlighted as a number (chore/fix) Elixir keywords need some serious help
2 participants