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

hnix permits indented strings as attribute names #666

Open
sjakobi opened this issue Jun 27, 2020 · 1 comment
Open

hnix permits indented strings as attribute names #666

sjakobi opened this issue Jun 27, 2020 · 1 comment

Comments

@sjakobi
Copy link
Member

sjakobi commented Jun 27, 2020

nix-repl> { ''x'' = 0; }.x 
error: syntax error, unexpected IND_STRING_OPEN, at (string):1:3
hnix> { ''x'' = 0; }.x
0

Is this a bug?

@sjakobi
Copy link
Member Author

sjakobi commented Jun 27, 2020

This is the relevant type:

hnix/src/Nix/Expr/Types.hs

Lines 268 to 271 in 704323e

data NKeyName r
= DynamicKey !(Antiquoted (NString r) r)
| StaticKey !VarName
deriving (Eq, Ord, Generic, Typeable, Data, Show, Read, NFData, Hashable)

And here's some parser output:

> parseNixText "{ ''x'' = 0; }"
Success (Fix (NSet NNonRecursive [NamedVar (DynamicKey (Plain (Indented 0 [Plain "x"])) :| []) (Fix (NConstant (NInt 0))) (SourcePos {sourceName = "<string>", sourceLine = Pos 1, sourceColumn = Pos 3})]))

I think the problem is that by using (NString r) for the string type in DynamicKey's Antiquoted field, we also allow Indented strings.

I wonder whether a solution would be to split NString:

newtype DoubleQuoted r = DoubleQuoted [Antiquoted Text r]
data Indented r = Indented Int [Antiquoted Text r]
data NString r = DoubleQuoted' (DoubleQuoted r) | Indented' (Indented r)

Then we could define DynamicKey like this:

 data NKeyName r 
   = DynamicKey !(Antiquoted (DoubleQuoted r) r) 
   | StaticKey !VarName 

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

No branches or pull requests

1 participant