Safe Haskell | None |
---|---|
Language | Haskell2010 |
BNFC.Backend.TreeSitter.CFtoTreeSitter
Synopsis
- indent :: Doc -> Doc
- cfToTreeSitter :: String -> CF -> Doc
- prExtras :: CF -> Doc
- prWord :: CF -> Doc
- prBuiltinTokenRules :: CF -> Doc
- integerRule :: Doc
- doubleRule :: Doc
- charRule :: Doc
- stringRule :: Doc
- identRule :: Doc
- prRules :: CF -> Doc
- prOtherRules :: Cat -> CF -> Doc
- prUsrTokenRules :: CF -> Doc
- hasInternal :: [Rule] -> Bool
- prOneCat :: [Rule] -> NonTerminal -> Doc
- prOneToken :: (TokenCat, Reg) -> Doc
- defineSymbol :: String -> Doc
- appendComma :: Doc -> Doc
- commaJoin :: Bool -> [Doc] -> Doc
- wrapSeq :: [Doc] -> Doc
- wrapChoice :: [Doc] -> Doc
- wrapOptListFun :: String -> Bool -> [Doc] -> Doc
- wrapFun :: String -> Bool -> Doc -> Doc
- refName :: String -> String
- formatRhs :: SentForm -> [Doc]
- quoted :: String -> Doc
- formatCatName :: Bool -> Cat -> String
Documentation
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.
prBuiltinTokenRules :: CF -> Doc Source #
Print builtin token rules according to their usage
integerRule :: Doc Source #
Predefined builtin token rules
doubleRule :: Doc Source #
Predefined builtin token rules
stringRule :: Doc Source #
Predefined builtin token rules
First print the entrypoint rule, tree-sitter always use the first rule as entrypoint and does not support multi-entrypoint. Then print rest of the rules
prUsrTokenRules :: CF -> Doc Source #
hasInternal :: [Rule] -> Bool Source #
Check if a set of rules contains internal rules
prOneCat :: [Rule] -> NonTerminal -> Doc Source #
Generates one or two tree-sitter rule(s) for one non-terminal from CF. Uses choice function from tree-sitter to combine rules for the non-terminal If the non-terminal has internal rules, an internal version of the non-terminal will be created (prefixed with "_" in tree-sitter), and all internal rules will be sectioned as such.
defineSymbol :: String -> Doc Source #
Start a defined symbol block in tree-sitter grammar
appendComma :: Doc -> Doc Source #
wrapChoice :: [Doc] -> Doc Source #