happy-arbitrary
Safe HaskellNone
LanguageHaskell2010

Language.Happy.Linker

Description

Links the tokens of a Happy grammar to the rules of an Alex lexer that make them, and renders generated tokens as source text.

Synopsis

Documentation

data LinkConfig Source #

How to find the token class in Happy and Alex code.

Constructors

LinkConfig 

Fields

defaultLinkConfig :: LinkConfig Source #

Patterns like { L _ IdVar _ } and actions like { mkL IdVar }.

type Lexer = Text -> Maybe [Text] Source #

The language's lexer: the classes of the tokens in a text, named as the LinkConfig names them, or Nothing if it can't lex the text.

type StartCode = Text Source #

An Alex start code, like 0 or comment.

data TokenGen Source #

How to make the text of one token.

Constructors

TokenGen 

Fields

generateChecked :: LinkConfig -> AlexFile -> Lexer -> Text -> Node (Lexeme Text) -> Gen Text Source #

Generates source code that the lexer agrees with. A tree is drawn again if one of its tokens can't be rendered, up to 100 times.

generateSource :: LinkConfig -> AlexFile -> Text -> Node (Lexeme Text) -> Gen (Either Text Text) Source #

Generates source code without checking what the lexer makes of it.

makeConfig :: LinkConfig -> AlexFile -> Config TokenGen Source #

Makes tokens from the grammar's %token patterns, with text from the lexer's rules. A token needs a rule in the current start code, or a chain of rules that only switch start code to get to one.

renderChecked :: Lexer -> [TokenGen] -> Gen (Either Text Text) Source #

Joins the tokens' text so that the lexer finds exactly these tokens again. A token's text and the space before it are drawn again until the lexer agrees. After 20 tries we give up and say which token failed.

renderUnchecked :: [TokenGen] -> Gen (Either Text Text) Source #

Joins the tokens' text with spaces, without checking what a lexer makes of it.