NixOS / nix-mode

An Emacs major mode for editing Nix expressions.
GNU Lesser General Public License v2.1
299 stars 76 forks source link

`${` not correctly highlighted in double-quoted strings #6

Closed taktoa closed 8 years ago

taktoa commented 8 years ago

A string of the form

"foo-${bar}"

gets blue highlighting for the initial ${ but otherwise is not correctly highlighted.

Note that that is a double-quoted string ("foo") rather than a double-single-quoted string (''foo''), which has the correct behavior in nix-mode master.

Example screenshot:

taktoa commented 8 years ago

It's also worth noting that the following code is valid and evaluates to "foo bar baz\nquux":

"foo ${
"bar"
} baz
quux"

Perhaps it would be worthwhile for Nix to have an optional dependency on nlohmann/json that adds a --json option to spit out the parsed AST of a given Nix expression, which editors could then use strategically.

taktoa commented 8 years ago

I have verified that this bug occurs upstream as well.

matthewbauer commented 8 years ago

:+1:

I can't quite figure out what's going on here.

Two other cases that are broken but should work are:

x = ''${asdf} '';

and

x = '' ${asdf}'';

The first one is something I broke trying to work out character escaping. The other one was always broken.

taktoa commented 8 years ago

You may be interested in this issue I raised on Nix: https://github.com/NixOS/nix/issues/1102

matthewbauer commented 8 years ago

Eventually I want to write a proper nix parser in elisp similar to how js2-mode works. Most likely I'd try not to use nix-instantiate so we don't have to deal with the external process.

matthewbauer commented 8 years ago

Some notes on this issue:

taktoa commented 8 years ago

Eventually I want to write a proper nix parser in elisp similar to how js2-mode works. Most likely I'd try not to use nix-instantiate so we don't have to deal with the external process.

If we do end up getting a BNFC grammar for Nix, it might be more efficient to just write a new elisp backend for BNFC (if one doesn't already exist).

matthewbauer commented 8 years ago

This is all I've found: https://github.com/robstewart57/bnfc/commit/3bf49b354132a6eb47375c7e83eec30dcb2ddb54