Skip to content

Layout: patching of columns leads to misalignment #345

@andreasabel

Description

@andreasabel

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:

, "-- | 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"

, "-- | 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"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions