mirror of
https://github.com/github/semantic.git
synced 2025-01-03 21:16:12 +03:00
Define a location combinator.
This commit is contained in:
parent
25ebe64d83
commit
ec65a199dc
@ -3,6 +3,8 @@ module Data.Syntax.Assignment
|
|||||||
( Assignment
|
( Assignment
|
||||||
, get
|
, get
|
||||||
, state
|
, state
|
||||||
|
, Location
|
||||||
|
, location
|
||||||
, symbol
|
, symbol
|
||||||
, range
|
, range
|
||||||
, sourceSpan
|
, sourceSpan
|
||||||
@ -24,7 +26,7 @@ import Data.Functor.Foldable hiding (Nil)
|
|||||||
import Data.Record
|
import Data.Record
|
||||||
import Data.Text (unpack)
|
import Data.Text (unpack)
|
||||||
import qualified Info
|
import qualified Info
|
||||||
import Prologue hiding (Alt, get, state)
|
import Prologue hiding (Alt, get, Location, state)
|
||||||
import Range (offsetRange)
|
import Range (offsetRange)
|
||||||
import qualified Source (Source(..), drop, slice, sourceText)
|
import qualified Source (Source(..), drop, slice, sourceText)
|
||||||
import Text.Parser.TreeSitter.Language
|
import Text.Parser.TreeSitter.Language
|
||||||
@ -55,6 +57,12 @@ get = Get `Then` return
|
|||||||
state :: Assignment (Node grammar) (AssignmentState grammar)
|
state :: Assignment (Node grammar) (AssignmentState grammar)
|
||||||
state = State `Then` return
|
state = State `Then` return
|
||||||
|
|
||||||
|
-- | Zero-width production of the current location.
|
||||||
|
--
|
||||||
|
-- If assigning at the end of input or at the end of a list of children, the loccation will be returned as an empty Range and SourceSpan at the current offset. Otherwise, it will be the Range and SourceSpan of the current node.
|
||||||
|
location :: Assignment (Node grammar) Location
|
||||||
|
location = rtail <$> get <|> (\ (AssignmentState o p _ _) -> Info.Range o o :. Info.SourceSpan p p :. Nil) <$> state
|
||||||
|
|
||||||
-- | Zero-width match of a node with the given symbol.
|
-- | Zero-width match of a node with the given symbol.
|
||||||
--
|
--
|
||||||
-- Since this is zero-width, care must be taken not to repeat it without chaining on other rules. I.e. 'many (symbol A *> b)' is fine, but 'many (symbol A)' is not.
|
-- Since this is zero-width, care must be taken not to repeat it without chaining on other rules. I.e. 'many (symbol A *> b)' is fine, but 'many (symbol A)' is not.
|
||||||
@ -86,6 +94,8 @@ children forEach = Children forEach `Then` return
|
|||||||
data Rose a = Rose { roseValue :: !a, roseChildren :: ![Rose a] }
|
data Rose a = Rose { roseValue :: !a, roseChildren :: ![Rose a] }
|
||||||
deriving (Eq, Functor, Show)
|
deriving (Eq, Functor, Show)
|
||||||
|
|
||||||
|
-- | A location specified as possibly-empty intervals of bytes and line/column positions.
|
||||||
|
type Location = Record '[Info.Range, Info.SourceSpan]
|
||||||
type Node grammar = Record '[grammar, Info.Range, Info.SourceSpan]
|
type Node grammar = Record '[grammar, Info.Range, Info.SourceSpan]
|
||||||
|
|
||||||
type AST grammar = Rose (Node grammar)
|
type AST grammar = Rose (Node grammar)
|
||||||
|
Loading…
Reference in New Issue
Block a user