1
1
mirror of https://github.com/github/semantic.git synced 2024-11-25 02:58:36 +03:00

🔥 branchNode/leafNode/toTerm.

This commit is contained in:
Rob Rix 2019-10-30 14:30:52 -04:00
parent 4941cb8dc8
commit 890d05dfd7
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -62,9 +62,6 @@ module Assigning.Assignment
( Assignment
, L.Loc(..)
-- Combinators
, branchNode
, leafNode
, toTerm
, Alternative(..)
, MonadError(..)
, MonadFail(..)
@ -109,21 +106,6 @@ import Source.Span as Span
import Text.Parser.Combinators as Parsers hiding (choice)
import TreeSitter.Language
-- | Match a branch node, matching its children with the supplied 'Assignment' & returning the result.
branchNode :: Enum grammar => grammar -> Assignment ast grammar a -> Assignment ast grammar a
branchNode sym child = symbol sym *> children child
-- | Match a leaf node, returning the corresponding 'Text'.
leafNode :: Enum grammar => grammar -> Assignment ast grammar Text
leafNode sym = symbol sym *> source
-- | Wrap an 'Assignment' producing @syntax@ up into an 'Assignment' producing 'Term's.
toTerm :: Element syntax syntaxes
=> Assignment ast grammar (syntax (Term (Sum syntaxes) L.Loc))
-> Assignment ast grammar (Term (Sum syntaxes) L.Loc)
toTerm syntax = termIn <$> location <*> (inject <$> syntax)
-- | Assignment from an AST with some set of 'symbol's onto some other value.
--
-- This is essentially a parser.