BNFC-2.9.6.2: A compiler front-end generator.
Safe HaskellSafe-Inferred
LanguageHaskell2010

BNFC.Backend.TreeSitter.CFtoTreeSitter

Synopsis

Documentation

indent :: Doc -> Doc Source #

Indent one level of 2 spaces

cfToTreeSitter :: String -> Cat -> CF -> Doc Source #

Create content of grammar.js file

prExtras :: [Reg] -> Doc Source #

Print rules for comments

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.

prRules :: CF -> Doc Source #

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).

prTokenRules :: CF -> [(Reg, TokenCat)] -> Doc Source #

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 #

commaJoin :: Bool -> [Doc] -> Doc Source #

wrapSeq :: [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

wrapFun :: String -> Bool -> Doc -> Doc Source #

refName :: String -> String Source #

Helper for referring to non-terminal names in tree-sitter

formatRhs :: [OptSentForm] -> Doc Source #

Format right hand side into list of strings

formatCatName :: Bool -> Cat -> String Source #

Format string for cat name, prefix "_" if the name is for internal rules