elixir-editors / language-elixir

Elixir language support for the Atom editor.
Other
181 stars 40 forks source link

Capture double/single-quoted atoms used as keys in keyword lists or maps #93

Closed ymtszw closed 7 years ago

ymtszw commented 7 years ago

Atoms can be defined using double/single-quotes, with arbitrary unicode (with erlang 20.x onwards; otherwise ascii? or Latin-1? I don't recall) strings. When used as keys in keyword lists or maps, they can also be written in short-hand style.

Interactive Elixir (1.5.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :"foo bar"
:"foo bar"
iex(2)> ["foo bar": :baz]
["foo bar": :baz]

This PR introduces highlight support for latter; double/single-quoted atoms used as keys where colons are suffixed to strings.

Edit: Initially I proposed and introduced an idea to match all letters inside quotes, then warn for unescaped quotes inside. Though it turned out it won't work well when there are multiple valid matches within a single line. So I scrapped that in 3ed4064

Current behavior (with One Dark theme): 2017-08-09 15 49 47

With this PR: 2017-08-14 17 53 54

As shown in the above, the introduced patterns will not match when there are nested single/double-quotes inside, even if they are properly escaped. This is caused by the difficulty to capture such patterns, since starting letter of these patterns are identical to ordinary strings (thus we cannot use begin-end section).

As a reference, in case of normal double/single-quoted atoms: 2017-08-09 15 50 32


As a note, I have found atoms are referred to as 'symbols' in the file (residue from Ruby package?). Could use renaming, though I kept using 'symbols' in my hunks for consistency.

keathley commented 7 years ago

Thanks @ymtszw. This looks great. I appreciate all the work :tada:.

You're probably right about the name "symbol" and its probably a hold over from the base ruby version. We should probably change that name at some point just to avoid extra confusion.