1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 13:02:37 +03:00

Rename the term constructor for JS.

This commit is contained in:
Rob Rix 2016-09-07 11:57:24 -04:00
parent 0c0a67ba65
commit 9750b252ed
2 changed files with 4 additions and 4 deletions

View File

@ -9,14 +9,14 @@ import SourceSpan
import qualified Syntax as S
import Term
javascriptTermConstructor
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.
javascriptTermConstructor source sourceSpan name range children
termConstructor source sourceSpan name range children
| name == "ERROR" = sourceSpan >>= withDefaultInfo . (`S.Error` children)
| otherwise = withDefaultInfo $ case (name, children) of
("return_statement", _) -> S.Return (listToMaybe children)

View File

@ -6,7 +6,7 @@ import Control.Monad
import Category
import Data.Record
import Language
import Language.JavaScript
import qualified Language.JavaScript as JS
import Parser
import Range
import Source
@ -48,6 +48,6 @@ documentToTerm language document blob = alloca $ \ root -> do
, spanEnd = SourcePos (fromIntegral $! ts_node_p_end_point_row node) (fromIntegral $! ts_node_p_end_point_column node) }
-- Note: The strict application here is semantically important. Without it, we may not evaluate the range until after weve exited the scope that `node` was allocated within, meaning `alloca` will free it & other stack data may overwrite it.
range `seq` javascriptTermConstructor (source blob) (sourceSpan `seq` pure sourceSpan) (toS name) range (filter (\child -> category (extract child) /= Empty) children)
range `seq` JS.termConstructor (source blob) (sourceSpan `seq` pure sourceSpan) (toS name) range (filter (\child -> category (extract child) /= Empty) children)
getChild node n out = ts_node_p_named_child node n out >> toTerm out
{-# INLINE getChild #-}