mirror of
https://github.com/github/semantic.git
synced 2024-12-23 14:54:16 +03:00
Return a slice of the source.
This commit is contained in:
parent
fdde8b0255
commit
94452afacc
@ -23,7 +23,8 @@ import Data.Record
|
|||||||
import Data.Text (unpack)
|
import Data.Text (unpack)
|
||||||
import qualified Info
|
import qualified Info
|
||||||
import Prologue hiding (Alt, get)
|
import Prologue hiding (Alt, get)
|
||||||
import Source (Source())
|
import Range (offsetRange)
|
||||||
|
import Source (Source(), slice, sourceText)
|
||||||
import Text.Parser.TreeSitter.Language
|
import Text.Parser.TreeSitter.Language
|
||||||
import Text.Show hiding (show)
|
import Text.Show hiding (show)
|
||||||
|
|
||||||
@ -102,9 +103,9 @@ runAssignment :: (Symbol grammar, Eq grammar, Show grammar) => Assignment (Node
|
|||||||
runAssignment = iterFreer (\ assignment yield offset source nodes -> case (assignment, dropAnonymous nodes) of
|
runAssignment = iterFreer (\ assignment yield offset source nodes -> case (assignment, dropAnonymous nodes) of
|
||||||
-- Nullability: some rules, e.g. 'pure a' and 'many a', should match at the end of input. Either side of an alternation may be nullable, ergo Alt can match at the end of input.
|
-- Nullability: some rules, e.g. 'pure a' and 'many a', should match at the end of input. Either side of an alternation may be nullable, ergo Alt can match at the end of input.
|
||||||
(Alt a b, nodes) -> yield a offset source nodes <|> yield b offset source nodes -- FIXME: Symbol `Alt` Symbol `Alt` Symbol is inefficient, should build and match against an IntMap instead.
|
(Alt a b, nodes) -> yield a offset source nodes <|> yield b offset source nodes -- FIXME: Symbol `Alt` Symbol `Alt` Symbol is inefficient, should build and match against an IntMap instead.
|
||||||
(assignment, subtree@(Rose node children) : rest) -> case assignment of
|
(assignment, subtree@(Rose node@(_ :. range :. _) children) : rest) -> case assignment of
|
||||||
Get -> yield node offset source nodes
|
Get -> yield node offset source nodes
|
||||||
Source -> yield "" offset source rest
|
Source -> yield (sourceText (slice (offsetRange range offset) source)) offset source rest
|
||||||
Children childAssignment -> do
|
Children childAssignment -> do
|
||||||
c <- assignAllFrom childAssignment offset source children
|
c <- assignAllFrom childAssignment offset source children
|
||||||
yield c offset source rest
|
yield c offset source rest
|
||||||
|
Loading…
Reference in New Issue
Block a user