| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
BNFC.Backend.TreeSitter.CFtoTreeSitter
Synopsis
- indent :: Doc -> Doc
- cfToTreeSitter :: String -> Cat -> CF -> Doc
- prExtras :: [Reg] -> Doc
- prWord :: Cat -> CF -> Doc
- prRules :: CF -> Doc
- prTokenRules :: CF -> [(Reg, TokenCat)] -> Doc
- prOneToken :: (Reg, TokenCat) -> Doc
- prOneCat :: KnownEmpty -> Bool -> NonTerminal -> [Rule] -> Doc
- defineSymbol :: String -> Doc
- appendComma :: Doc -> Doc
- commaJoin :: Bool -> [Doc] -> Doc
- wrapSeq :: [Doc] -> Doc
- wrapChoice :: [Doc] -> Doc
- wrapOptional :: Doc -> Doc
- wrapOptional' :: Doc -> Doc
- wrapOptListFun :: String -> Bool -> [Doc] -> Doc
- wrapFun :: String -> Bool -> Doc -> Doc
- refName :: String -> String
- formatRhs :: [OptSentForm] -> Doc
- formatSent :: OptSentForm -> Doc
- formatCatName :: Bool -> Cat -> String
Documentation
cfToTreeSitter :: String -> Cat -> CF -> Doc Source #
Create content of grammar.js file
prWord :: Cat -> CF -> Doc Source #
Print word section, this section is needed for tree-sitter to do keyword extraction before any parsing/lexing, see https://tree-sitter.github.io/tree-sitter/creating-parsers#keyword-extraction TODO: currently, we just add every user defined token as well as the predefined Ident token to this list to be safe. Ideally, we should enumerate all defined tokens against all occurrences of keywords. Any tokens patterns that could accept a keyword will go into this list. This will require integration of a regex engine.
Prints the rules in the grammar with the entry point first.
Since Treesitter requires a unique entry point, this will build a "virtual" entry point which dispatches to each of the declared BNFC entry points via a choice list. Additionally, the virtual entry point can be marked optional (and is the only rule which can be).
prOneToken :: (Reg, TokenCat) -> Doc Source #
Generate one tree-sitter rule for one terminal token.
prOneCat :: KnownEmpty -> Bool -> NonTerminal -> [Rule] -> Doc Source #
Generates one tree-sitter rule for one non-terminal from CF.
defineSymbol :: String -> Doc Source #
Start a defined symbol block in tree-sitter grammar
appendComma :: Doc -> Doc Source #
wrapChoice :: [Doc] -> Doc Source #
wrapOptional :: Doc -> Doc Source #
wrapOptional' :: Doc -> Doc Source #
wrapOptListFun :: String -> Bool -> [Doc] -> Doc Source #
Wrap list using tree-sitter fun if the list contains multiple items Returns the only item without wrapping otherwise
formatRhs :: [OptSentForm] -> Doc Source #
Format right hand side into list of strings
formatSent :: OptSentForm -> Doc Source #
formatCatName :: Bool -> Cat -> String Source #
Format string for cat name, prefix "_" if the name is for internal rules