BNFC
Safe HaskellNone
LanguageHaskell2010

BNFC.Backend.TreeSitter.CFtoTreeSitter

Synopsis

Documentation

indent :: Doc -> Doc Source #

Indent one level of 2 spaces

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

Create content of grammar.js file

prExtras :: CF -> Doc Source #

Print rules for comments

prWord :: 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.

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

charRule :: Doc Source #

Predefined builtin token rules

stringRule :: Doc Source #

Predefined builtin token rules

identRule :: Doc Source #

Predefined builtin token rules

prRules :: CF -> Doc Source #

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

prOtherRules :: Cat -> CF -> Doc Source #

Print all other rules except the entrypoint

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.

prOneToken :: (TokenCat, Reg) -> Doc Source #

Generate one tree-sitter rule for one defined token

defineSymbol :: String -> Doc Source #

Start a defined symbol block in tree-sitter grammar

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

refName :: String -> String Source #

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

formatRhs :: SentForm -> [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