sslang-0.1.0.0
Safe HaskellNone
LanguageHaskell2010

Front.Scanner

Description

Scanner for sslang.

In addition to tokenizing the input text stream, this scanner is responsible for the following:

  • Insert implicit open braces after any block-starting token, if necessary;
  • Insert implicit separators for aligned lines within the same block; and
  • Insert implicit close braces if an implicit block closed, either by a decrease in indentation, or by the closure of a surrounding explicit block.

As such, the scanner's state is enriched with a stack of contexts which it uses to perform basic delimiter matching. It also relies on epsilon transitions to emit implicit tokens.

Synopsis

Documentation

scanTokens :: String -> Pass [Token] Source #

Extract a token stream from an input string.

scanTokenTypes :: String -> Pass [TokenType] Source #

Extract a stream of token types (without span) from an input string.

lexerForHappy :: (Token -> Alex a) -> Alex a Source #

Used to integrate with Happy parser.

newtype Token Source #

Tokens extracted from source text.

Constructors

Token (Span, TokenType) 

Instances

Instances details
Eq Token Source # 
Instance details

Defined in Front.Token

Methods

(==) :: Token -> Token -> Bool #

(/=) :: Token -> Token -> Bool #

Show Token Source # 
Instance details

Defined in Front.Token

Methods

showsPrec :: Int -> Token -> ShowS #

show :: Token -> String #

showList :: [Token] -> ShowS #

Pretty Token Source #

Pretty instance for Token, good for dumping tokens for inspection.

Prints TokenType via both its Pretty and Show instances for clarity.

Instance details

Defined in Front.Token

Methods

pretty :: Token -> Doc ann

prettyList :: [Token] -> Doc ann

data TokenType Source #

The types of tokens that can appear in a sslang source file.

Instances

Instances details
Eq TokenType Source # 
Instance details

Defined in Front.Token

Show TokenType Source # 
Instance details

Defined in Front.Token

Pretty TokenType Source #

Pretty instance for TokenType. Recovers strings from keywords.

Instance details

Defined in Front.Token

Methods

pretty :: TokenType -> Doc ann

prettyList :: [TokenType] -> Doc ann

data Span Source #

The location of a token in the source text.

Constructors

Span 

Fields

Instances

Instances details
Eq Span Source # 
Instance details

Defined in Front.Token

Methods

(==) :: Span -> Span -> Bool #

(/=) :: Span -> Span -> Bool #

Show Span Source # 
Instance details

Defined in Front.Token

Methods

showsPrec :: Int -> Span -> ShowS #

show :: Span -> String #

showList :: [Span] -> ShowS #

Pretty Span Source #

Pretty instance for Span. Reports both line:col and [addr+len].

Instance details

Defined in Front.Token

Methods

pretty :: Span -> Doc ann

prettyList :: [Span] -> Doc ann

syntaxErr :: String -> Alex a Source #

User-facing syntax error.

internalErr :: String -> Alex a Source #

Internal compiler error for unreachable code.

liftErr :: String -> Error Source #

Convert Alex's String-encoded errors to Sslang Error.