{-
    BNF Converter: TreeSitter Grammar Generator
    Copyright (C) 2004  Author:  Markus Forsberg, Michael Pellauer,
                                 Bjorn Bringert

    Description   : This module generates the grammar.js input file for
                    tree-sitter.

    Author        : Kangjing Huang (huangkangjing@gmail.com)
    Created       : 23 Nov, 2023

-}

module BNFC.Backend.TreeSitter where

import BNFC.Backend.Base
import BNFC.Backend.TreeSitter.CFtoTreeSitter (cfToTreeSitter)
import BNFC.CF
import BNFC.Options hiding (Backend)
import BNFC.PrettyPrint

-- | Entry point: create grammar.js file
makeTreeSitter :: SharedOptions -> CF -> Backend
makeTreeSitter :: SharedOptions -> CF -> Backend
makeTreeSitter SharedOptions
opts CF
cf = do
  String -> MakeComment -> String -> Backend
forall c. FileContent c => String -> MakeComment -> c -> Backend
mkfile String
"grammar.js" MakeComment
comment (Doc -> String
render (Doc -> String) -> Doc -> String
forall a b. (a -> b) -> a -> b
$ String -> CF -> Doc
cfToTreeSitter String
name CF
cf)
  where
    name :: String
name = SharedOptions -> String
lang SharedOptions
opts

comment :: String -> String
comment :: MakeComment
comment = (String
"// " String -> MakeComment
forall a. [a] -> [a] -> [a]
++)

-- | TODO: Add Makefile generation for tree-sitter