mirror of
https://github.com/github/semantic.git
synced 2025-01-02 12:23:08 +03:00
Factor slicing the source out of term assignment.
This commit is contained in:
parent
77c80ac970
commit
1c0c7e4bdf
@ -50,7 +50,7 @@ termConstructor
|
||||
termConstructor source (range :. category :. sourceSpan :. Nil) children _ =
|
||||
withDefaultInfo $ case (category, children) of
|
||||
(Error, _) -> S.Error children
|
||||
(_, []) -> S.Leaf (toText $ slice range source)
|
||||
(_, []) -> S.Leaf (toText source)
|
||||
_ -> S.Indexed children
|
||||
where
|
||||
withDefaultInfo syntax =
|
||||
|
@ -9,7 +9,7 @@ import qualified Syntax as S
|
||||
import Term
|
||||
|
||||
termConstructor
|
||||
:: Source Char -- ^ The source that the term occurs within.
|
||||
:: Source Char -- ^ The source of the term.
|
||||
-> Record '[Range, Category, SourceSpan] -- ^ The proposed annotation for the term.
|
||||
-> [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ The child nodes of the term.
|
||||
-> IO [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ All child nodes (included unnamed productions) of the term as 'IO'. Only use this if you need it.
|
||||
@ -17,7 +17,7 @@ termConstructor
|
||||
termConstructor source (range :. category :. sourceSpan :. Nil) children _
|
||||
| category == Error = withDefaultInfo (S.Error children)
|
||||
| otherwise = withDefaultInfo $ case children of
|
||||
[] -> S.Leaf . toText $ slice range source
|
||||
[] -> S.Leaf $ toText source
|
||||
_ -> S.Indexed children
|
||||
where
|
||||
withDefaultInfo syntax = pure $! cofree ((range :. category :. sourceSpan :. Nil) :< syntax)
|
||||
|
@ -11,7 +11,7 @@ import Range (unionRangesFrom)
|
||||
import SourceSpan (unionSourceSpansFrom)
|
||||
|
||||
termConstructor
|
||||
:: Source Char -- ^ The source that the term occurs within.
|
||||
:: Source Char -- ^ The source of the term.
|
||||
-> Record '[Range, Category, SourceSpan] -- ^ The proposed annotation for the term.
|
||||
-> [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ The child nodes of the term.
|
||||
-> IO [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ All child nodes (included unnamed productions) of the term as 'IO'. Only use this if you need it.
|
||||
@ -103,17 +103,17 @@ termConstructor source (range :. category :. sourceSpan :. Nil) children _ = pur
|
||||
let params = withRanges range Params children $ S.Indexed children
|
||||
in withDefaultInfo $ S.Ty params
|
||||
IncrementStatement ->
|
||||
withDefaultInfo $ S.Leaf . toText $ slice range source
|
||||
withDefaultInfo $ S.Leaf $ toText source
|
||||
DecrementStatement ->
|
||||
withDefaultInfo $ S.Leaf . toText $ slice range source
|
||||
withDefaultInfo $ S.Leaf $ toText source
|
||||
QualifiedIdentifier ->
|
||||
withDefaultInfo $ S.Leaf . toText $ slice range source
|
||||
withDefaultInfo $ S.Leaf $ toText source
|
||||
Break -> toBreak children
|
||||
Continue -> toContinue children
|
||||
Pair -> toPair children
|
||||
Method -> toMethod children
|
||||
_ -> withDefaultInfo $ case children of
|
||||
[] -> S.Leaf . toText $ slice range source
|
||||
[] -> S.Leaf $ toText source
|
||||
_ -> S.Indexed children
|
||||
where
|
||||
toMethod = \case
|
||||
|
@ -13,7 +13,7 @@ operators :: [Category]
|
||||
operators = [ Operator, BooleanOperator, MathOperator, RelationalOperator, BitwiseOperator ]
|
||||
|
||||
termConstructor
|
||||
:: Source Char -- ^ The source that the term occurs within.
|
||||
:: Source Char -- ^ The source of the term.
|
||||
-> Record '[Range, Category, SourceSpan] -- ^ The proposed annotation for the term.
|
||||
-> [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ The child nodes of the term.
|
||||
-> IO [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ All child nodes (included unnamed productions) of the term as 'IO'. Only use this if you need it.
|
||||
@ -54,7 +54,7 @@ termConstructor source (range :. category :. sourceSpan :. Nil) children allChil
|
||||
(Case, _ ) -> S.Error children
|
||||
(Object, _) -> S.Object Nothing $ foldMap toTuple children
|
||||
(Pair, _) -> S.Fixed children
|
||||
(Comment, _) -> S.Comment . toText $ slice range source
|
||||
(Comment, _) -> S.Comment $ toText source
|
||||
(If, expr : rest ) -> S.If expr rest
|
||||
(If, _ ) -> S.Error children
|
||||
(While, expr : rest ) -> S.While expr rest
|
||||
@ -98,7 +98,7 @@ termConstructor source (range :. category :. sourceSpan :. Nil) children allChil
|
||||
[ params, body ] -> S.AnonymousFunction (toList (unwrap params)) [body]
|
||||
[ id, params, body ] -> S.Function id (toList (unwrap params)) [body]
|
||||
_ -> S.Error children
|
||||
(_, []) -> S.Leaf . toText $ slice range source
|
||||
(_, []) -> S.Leaf $ toText source
|
||||
_ -> S.Indexed children
|
||||
where
|
||||
withDefaultInfo syntax =
|
||||
|
@ -14,7 +14,7 @@ operators :: [Category]
|
||||
operators = [ Binary, Unary, RangeExpression, ScopeOperator ]
|
||||
|
||||
termConstructor
|
||||
:: Source Char -- ^ The source that the term occurs within.
|
||||
:: Source Char -- ^ The source of the term.
|
||||
-> Record '[Range, Category, SourceSpan] -- ^ The proposed annotation for the term.
|
||||
-> [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ The child nodes of the term.
|
||||
-> IO [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ All child nodes (included unnamed productions) of the term as 'IO'. Only use this if you need it.
|
||||
@ -58,7 +58,7 @@ termConstructor source (range :. category :. sourceSpan :. Nil) children allChil
|
||||
(Class, _ ) -> S.Error children
|
||||
(SingletonClass, identifier : rest ) -> S.Class identifier Nothing rest
|
||||
(SingletonClass, _ ) -> S.Error children
|
||||
(Comment, _ ) -> S.Comment . toText $ slice range source
|
||||
(Comment, _ ) -> S.Comment $ toText source
|
||||
(Ternary, condition : cases) -> S.Ternary condition cases
|
||||
(Ternary, _ ) -> S.Error children
|
||||
(Constant, _ ) -> S.Fixed children
|
||||
@ -117,7 +117,7 @@ termConstructor source (range :. category :. sourceSpan :. Nil) children allChil
|
||||
(While, _ ) -> S.Error children
|
||||
(Yield, _ ) -> S.Yield children
|
||||
_ | category `elem` [ BeginBlock, EndBlock ] -> S.BlockStatement children
|
||||
(_, []) -> S.Leaf . toText $ slice range source
|
||||
(_, []) -> S.Leaf $ toText source
|
||||
_ -> S.Indexed children
|
||||
where
|
||||
withRecord record syntax = cofree (record :< syntax)
|
||||
|
@ -57,7 +57,7 @@ documentToTerm language document SourceBlob{..} = alloca $ \ root -> do
|
||||
-- Without it, we may not evaluate the value until after we’ve exited
|
||||
-- the scope that `node` was allocated within, meaning `alloca` will
|
||||
-- free it & other stack data may overwrite it.
|
||||
range `seq` sourceSpan `seq` assignTerm language source (range :. categoryForLanguageProductionName language (toS name) :. sourceSpan :. Nil) children allChildren
|
||||
range `seq` sourceSpan `seq` assignTerm language (slice range source) (range :. categoryForLanguageProductionName language (toS name) :. sourceSpan :. Nil) children allChildren
|
||||
getChild node n out = ts_node_p_named_child node n out >> toTerm out
|
||||
{-# INLINE getChild #-}
|
||||
getUnnamedChild node n out = ts_node_p_child node n out >> toTerm out
|
||||
|
Loading…
Reference in New Issue
Block a user