mirror of
https://github.com/github/semantic.git
synced 2025-01-03 21:16:12 +03:00
Skip all but regular nodes.
This commit is contained in:
parent
86f5e21529
commit
309636dc2c
@ -16,6 +16,7 @@ import Control.Monad.Free.Freer
|
||||
import Data.Functor.Classes
|
||||
import Data.Functor.Foldable
|
||||
import Prologue hiding (Alt)
|
||||
import Text.Parser.TreeSitter.Language
|
||||
import Text.Show hiding (show)
|
||||
|
||||
-- | Assignment from an AST with some set of 'symbol's onto some other value.
|
||||
@ -63,15 +64,15 @@ data Result a = Result a | Error [Text]
|
||||
|
||||
|
||||
-- | Run an assignment of nodes in a grammar onto terms in a syntax, discarding any unparsed nodes.
|
||||
assignAll :: (Eq grammar, Show grammar) => Assignment grammar a -> [AST grammar] -> Result a
|
||||
assignAll :: (Symbol grammar, Eq grammar, Show grammar) => Assignment grammar a -> [AST grammar] -> Result a
|
||||
assignAll assignment nodes = case runAssignment assignment nodes of
|
||||
Result ([], a) -> Result a
|
||||
Result (c:_, _) -> Error ["Expected end of input, but got: " <> show c]
|
||||
Error e -> Error e
|
||||
|
||||
-- | Run an assignment of nodes in a grammar onto terms in a syntax.
|
||||
runAssignment :: (Eq grammar, Show grammar) => Assignment grammar a -> [AST grammar] -> Result ([AST grammar], a)
|
||||
runAssignment = iterFreer (\ assignment yield nodes -> case (assignment, nodes) of
|
||||
runAssignment :: (Symbol grammar, Eq grammar, Show grammar) => Assignment grammar a -> [AST grammar] -> Result ([AST grammar], a)
|
||||
runAssignment = iterFreer (\ assignment yield nodes -> case (assignment, dropWhile ((/= Regular) . symbolType . nodeSymbol . roseValue) 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.
|
||||
(Alt a b, nodes) -> yield a nodes <|> yield b nodes -- FIXME: Rule `Alt` Rule `Alt` Rule is inefficient, should build and match against an IntMap instead.
|
||||
(assignment, node@(Rose Node{..} children) : rest) -> case assignment of
|
||||
|
Loading…
Reference in New Issue
Block a user