1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +03:00
semantic/src/Data/AST.hs

36 lines
775 B
Haskell
Raw Normal View History

{-# LANGUAGE DataKinds #-}
module Data.AST
( Node (..)
, nodeSpan
, nodeByteRange
, AST
) where
import Data.Term
2018-05-01 19:51:34 +03:00
import Data.Aeson
2018-06-04 17:59:31 +03:00
import Data.Text (pack)
2018-05-01 19:51:34 +03:00
import Data.JSON.Fields
import Source.Loc
2018-05-01 19:51:34 +03:00
-- | An AST node labelled with symbols and source location.
type AST syntax grammar = Term syntax (Node grammar)
data Node grammar = Node
2018-06-04 17:59:31 +03:00
{ nodeSymbol :: !grammar
, nodeLocation :: {-# UNPACK #-} !Loc
}
2018-06-28 20:20:44 +03:00
deriving (Eq, Ord, Show)
2018-05-01 19:51:34 +03:00
instance Show grammar => ToJSONFields (Node grammar) where
toJSONFields Node{..} =
2018-06-04 17:59:31 +03:00
[ "symbol" .= pack (show nodeSymbol)
, "span" .= locSpan nodeLocation
2018-06-04 17:59:31 +03:00
]
2018-05-01 19:51:34 +03:00
nodeSpan :: Node grammar -> Span
nodeSpan = locSpan . nodeLocation
nodeByteRange :: Node grammar -> Range
nodeByteRange = locByteRange . nodeLocation