Track whether braces were present in T_DollarBraced

References of the form $var and ${var} both map to the same structure in
the AST, which prevents any later analysis functions from distinguishing
them.  In preparation for adding checks that need this info, add a Bool
to T_DollarBraced that tracks whether the braces were seen at parsing
time and update all references so that this change is a no-op.
This commit is contained in:
Benjamin Gordon 2019-04-29 14:26:39 -06:00 committed by Benjamin Gordon
parent 0358090b3c
commit aa3b709b5d
7 changed files with 33 additions and 34 deletions

View file

@ -1634,7 +1634,7 @@ readDollarBraced = called "parameter expansion" $ do
word <- readDollarBracedWord
char '}'
id <- endSpan start
return $ T_DollarBraced id word
return $ T_DollarBraced id True word
prop_readDollarExpansion1= isOk readDollarExpansion "$(echo foo; ls\n)"
prop_readDollarExpansion2= isOk readDollarExpansion "$( )"
@ -1661,7 +1661,7 @@ readDollarVariable = do
let singleCharred p = do
value <- wrapString ((:[]) <$> p)
id <- endSpan start
return $ (T_DollarBraced id value)
return $ (T_DollarBraced id False value)
let positional = do
value <- singleCharred digit
@ -1674,7 +1674,7 @@ readDollarVariable = do
let regular = do
value <- wrapString readVariableName
id <- endSpan start
return (T_DollarBraced id value) `attempting` do
return (T_DollarBraced id False value) `attempting` do
lookAhead $ char '['
parseNoteAt pos ErrorC 1087 "Use braces when expanding arrays, e.g. ${array[idx]} (or ${var}[.. to quiet)."