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

Safe HaskellSafe
LanguageHaskell98

DDC.Core.Lexer.Offside

Description

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

Synopsis

Documentation

data Lexeme n Source #

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

Constructors

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

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

Instances

Eq n => Eq (Lexeme n) Source # 

Methods

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

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

Show n => Show (Lexeme n) Source # 

Methods

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

show :: Lexeme n -> String #

showList :: [Lexeme n] -> ShowS #

applyOffside Source #

Arguments

:: (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'.