mirror of
https://github.com/github/semantic.git
synced 2024-11-27 12:57:49 +03:00
Stub in a term constructor for C.
This commit is contained in:
parent
fe7b83663a
commit
cccd9e9cc6
@ -30,6 +30,7 @@ library
|
||||
, Info
|
||||
, Interpreter
|
||||
, Language
|
||||
, Language.C
|
||||
, Language.JavaScript
|
||||
, Parser
|
||||
, Patch
|
||||
|
28
src/Language/C.hs
Normal file
28
src/Language/C.hs
Normal file
@ -0,0 +1,28 @@
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
module Language.C where
|
||||
|
||||
import Data.Record
|
||||
import Info
|
||||
import Prologue
|
||||
import Source
|
||||
import SourceSpan
|
||||
import qualified Syntax as S
|
||||
import Term
|
||||
|
||||
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 Text (Record '[Range, Category])] -- ^ The child nodes of the term.
|
||||
-> IO (Term Text (Record '[Range, Category])) -- ^ The resulting term, in IO.
|
||||
termConstructor source sourceSpan name range children
|
||||
| name == "ERROR" = sourceSpan >>= withDefaultInfo . (`S.Error` children)
|
||||
| otherwise = withDefaultInfo $ case (name, children) of
|
||||
(_, []) -> S.Leaf . toText $ slice range source
|
||||
_ -> S.Indexed children
|
||||
where withDefaultInfo syntax = pure $! cofree ((range .: categoryForCProductionName name .: RNil) :< syntax)
|
||||
|
||||
categoryForCProductionName :: Text -> Category
|
||||
categoryForCProductionName name = case name of
|
||||
_ -> Other name
|
Loading…
Reference in New Issue
Block a user