ddc-core- Disciplined Disciple Compiler core language and type checker.

Safe HaskellSafe



Apply the offside rule to a token stream to add braces.



data Lexeme n Source #

Holds a real token or start symbol which is used to apply the offside rule.


LexemeToken (Located (Token n)) 
LexemeStartLine Int 
LexemeStartBlock Int

Signal that we're starting a block in this column.


Eq n => Eq (Lexeme n) Source # 


(==) :: Lexeme n -> Lexeme n -> Bool #

(/=) :: Lexeme n -> Lexeme n -> Bool #

Show n => Show (Lexeme n) Source # 


showsPrec :: Int -> Lexeme n -> ShowS #

show :: Lexeme n -> String #

showList :: [Lexeme n] -> ShowS #

applyOffside Source #


:: (Eq n, Show n) 
=> [Paren]

What parenthesis we're inside.

-> [Context]

Current layout context.

-> [Lexeme n]

Input lexemes.

-> [Located (Token n)] 

Apply the offside rule to this token stream.

It should have been processed with addStarts first to add the LexemeStartLine/LexemeStartLine tokens.

Unlike the definition in the Haskell 98 report, we explicitly track which parenthesis we're inside. We use these to partly implement the layout rule that says we much check for entire parse errors to perform the offside rule.

addStarts :: (Eq n, Show n) => [Located (Token n)] -> [Lexeme n] Source #

Add block and line start tokens to this stream.

This is identical to the definition in the Haskell98 report, except that we also use multi-token starting strings like imports foreign 'type'.