-
Notifications
You must be signed in to change notification settings - Fork 170
Closed
Labels
Milestone
Description
The layout mechanism adjust columns of subsequent tokens on the same line when inserting braces and semicolons. This leads to misalignment and subsequent parse errors.
E.g. this parses in haskell but is rejected by the grammar of #344:
f = g + h where g = 3; h = i where i = j
j = 2
Suggested fix: just remove the incrGlobal
mechanism, simplifying addToken
:
bnfc/source/src/BNFC/Backend/Haskell/CFtoLayout.hs
Lines 206 to 212 in 71ebcee
, "-- | Insert a new symbol token at the begninning of a list of tokens." | |
, "addToken :: Position -- ^ Position of the new token." | |
, " -> String -- ^ Symbol in the new token." | |
, " -> [Token] -- ^ The rest of the tokens. These will have their" | |
, " -- positions updated to make room for the new token." | |
, " -> [Token]" | |
, "addToken p s ts = sToken p s : map (incrGlobal p (length s)) ts" |
bnfc/source/src/BNFC/Backend/Haskell/CFtoLayout.hs
Lines 225 to 235 in 71ebcee
, "-- | Add to the global and column positions of a token." | |
, "-- The column position is only changed if the token is on" | |
, "-- the same line as the given position." | |
, "incrGlobal :: Position -- ^ If the token is on the same line" | |
, " -- as this position, update the column position." | |
, " -> Int -- ^ Number of characters to add to the position." | |
, " -> Token -> Token" | |
, "incrGlobal (Pn _ l0 _) i (PT (Pn g l c) t) =" | |
, " if l /= l0 then PT (Pn (g + i) l c) t" | |
, " else PT (Pn (g + i) l (c + i)) t" | |
, "incrGlobal _ _ p = error $ \"cannot add token at \" ++ show p" |