-
Notifications
You must be signed in to change notification settings - Fork 6
Couple of improvements and fixes #2
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
Conversation
princemaple
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @azizk , thanks for the PR. I think you misunderstood how \w works.
Other than that, I asked a few questions.
Looking forward to your reply and future improvements.
|
|
||
| variables: | ||
| module_name: '\b[A-Z]\w*\b' | ||
| module_name: '\b[A-Z][a-zA-Z0-9_]*\b' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\w is exactly that
iex(3)> "0" =~ ~r/\w/
trueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite, because it also matches Unicode characters like "á". The compiler rejects those and only allows ASCII characters in module names. "\w" is a nice shorthand but it does more than ASCII letters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Elixir.sublime-syntax
Outdated
| - match: '{{module_name}}' | ||
| scope: entity.name.protocol.elixir | ||
| - match: '^\s*(def|defmacro)\s+([a-zA-Z_]\w*(?:!|\?)?)(?:(\()|\s*)' | ||
| - match: '^\s*(def|defmacro)\s+(\w+(?:!|\?)?)(?:(\()|\s*)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
identifiers cannot start with numbers. see my previous comment, \w can match a number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's true. So it's a mistake. This should do:
| - match: '^\s*(def|defmacro)\s+(\w+(?:!|\?)?)(?:(\()|\s*)' | |
| - match: '^\s*(def|defmacro)\s+([_[:alpha:]]\w*(?:!|\?)?)(?:(\()|\s*)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested, functions can actually start with unicode (or be entirely a unicode name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does [:alpha:] cover unicode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it does 👍
Elixir.sublime-syntax
Outdated
| 3: punctuation.definition.parameters.elixir | ||
| push: function_body | ||
| - match: '^\s*(defp|defmacrop)\s+([a-zA-Z_]\w*(?:!|\?)?)(?:(\()|\s*)' | ||
| - match: '^\s*(defp|defmacrop)\s+(\w+(?:!|\?)?)(?:(\()|\s*)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - match: '^\s*(defp|defmacrop)\s+(\w+(?:!|\?)?)(?:(\()|\s*)' | |
| - match: '^\s*(defp|defmacrop)\s+([_[:alpha:]]\w*(?:!|\?)?)(?:(\()|\s*)' |
| pop: true | ||
| - include: main | ||
| - match: \b(is_atom|is_binary|is_bitstring|is_boolean|is_float|is_function|is_integer|is_list|is_map|is_nil|is_number|is_pid|is_port|is_record|is_reference|is_tuple|is_exception|abs|bit_size|byte_size|div|elem|hd|length|map_size|node|rem|round|tl|trunc|tuple_size)\b | ||
| - match: \b(is_(?:atom|binary|bitstring|boolean|float|function|integer|list|map|nil|number|pid|port|record|reference|tuple|exception)|abs|bit_size|byte_size|div|elem|hd|length|map_size|node|rem|round|tl|trunc|tuple_size)\b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| comment: as above, just doesn't need a 'end' and does a logic operation | ||
| scope: keyword.operator.elixir | ||
| - match: '{{module_name}}' | ||
| - match: '{{module_name}}(?!:)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when would you do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you have a map or list containing keys starting with a capital letter: [A: 0, B: 1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems rare, but OK :)
Elixir.sublime-syntax
Outdated
| - include: interpolated_elixir | ||
| - include: escaped_char | ||
| - match: '(?<!:)(:)(?>[a-zA-Z_][\w@]*(?>[?!]|=(?![>=]))?|\<\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\-|\|>|=>|=~|=|/|\\\\|\*\*?|\.\.?\.?|>=?|<=?|&&?&?|\+\+?|\-\-?|\|\|?\|?|\!|@|\%?\{\}|%|\[\]|\^(\^\^)?)' | ||
| - match: '(?<!:)(:)(?>[_[:alpha:]][\w@]*(?>[?!]|=(?![>=]))?|\<\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\-|\|>|=>|=~|=|/|\\\\|\*\*?|\.\.?\.?|>=?|<=?|&&?&?|\+\+?|\-\-?|\|\|?\|?|\!|@|\%?\{\}|%|\[\]|\^(\^\^)?)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allows Unicode atoms like :á or even :_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guess that answers my question above :)
What do you mean exactly? I'm not quite sure what PythonImproved does that you are referring to specifically. Some examples might help. FYI I have no intention messing with tmLanguage in my lifetime 😆 . |
|
Hey @azizk , looks like you did not tick the allow maintainer to modify your code checkbox. You will have to commit the suggestions yourself. They look good 👍 . |
|
Thanks for the review! I added my suggestions. Of course, I don't want any tmLanguage XML craziness either. The PythonImproved package uses YAML. It looks very extensive, complete and well thought out. I don't know Sublime's syntax file format fully yet, but one main difference to Elixir.sublime-syntax is that PythonImproved mainly uses beginCaptures and endCaptures which may enable Sublime to actually parse the text into a proper syntax tree for more accurate and contextful highlighting, which is better than just having some semi-tree structure with flat areas where regexes match blindly more or less. It's fine in the beginning but it can definitely be improved. |
|
Oh, but I think I did tick the box to allow changes by you. Don't know why it's not working. I'll take a look again tomorrow. Until then! |
Thank you very much!
Looks like it's just a yaml version of tm language. They probably got sick of XML and decided to write yaml first and compile to tmLanguage. |
Yeah, let's do so! :) I added one commit to fix the issue of matching numbers in function names like |
|
Thanks @azizk ! Merged. |
Hi!
I'm using Elixir every moment at work and would love to see improvements to the syntax highlighting definition. That's why I'm contributing these changes.
I hope to add a syntax test file soon in order to ensure a better quality and to avoid possible regressions when we modify the regular expressions.
Besides, what do you think about adopting the style of other syntax definition files like the one for Python in the PythonImproved package? Maybe that's the path we should take to make ours better and more ideal?