From c4182ae85cb7955e65324d4ad250202e0417c785 Mon Sep 17 00:00:00 2001 From: joshvera Date: Mon, 17 Oct 2016 15:50:25 -0400 Subject: [PATCH] Stub out Go termConstructor --- src/Language/Go.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Language/Go.hs b/src/Language/Go.hs index 11bf1017d..c1800e64c 100644 --- a/src/Language/Go.hs +++ b/src/Language/Go.hs @@ -3,6 +3,26 @@ module Language.Go where import Prologue import Info +import Source +import Term +import qualified Syntax as S +import Data.Record + +termConstructor + :: Source Char -- ^ The source that the term occurs within. + -> IO SourceSpan -- ^ The span that the term occupies. This is passed in 'IO' to guarantee some access constraints & encourage its use only when needed (improving performance). + -> Text -- ^ The name of the production for this node. + -> Range -- ^ The character range that the term occupies. + -> [Term (S.Syntax Text) (Record '[Range, Category, SourceSpan])] -- ^ The child nodes of the term. + -> IO (Term (S.Syntax Text) (Record '[Range, Category, SourceSpan])) -- ^ The resulting term, in IO. +termConstructor source sourceSpan name range children = withDefaultInfo $ + case (name, children) of + ("return_statement", _) -> S.Return (listToMaybe children) + (_, []) -> S.Leaf . toText $ slice range source + where + withDefaultInfo syntax = do + sourceSpan' <- sourceSpan + pure $! cofree ((range .: categoryForGoName name .: sourceSpan' .: RNil) :< syntax) categoryForGoName :: Text -> Category categoryForGoName = \case