mirror of
https://github.com/github/semantic.git
synced 2024-12-23 06:41:45 +03:00
Tidy up the nullability rules.
This commit is contained in:
parent
9b69f3aae8
commit
b8e4cb7471
@ -88,8 +88,10 @@ type AST grammar = Rose (Node grammar)
|
||||
|
||||
-- | Small-step evaluation of an assignment from a grammar onto a syntax.
|
||||
stepAssignment :: Eq grammar => Assignment grammar a -> [AST grammar] -> Maybe ([AST grammar], a)
|
||||
stepAssignment = iterFreer (\ assignment yield nodes -> case nodes of
|
||||
Rose Node{..} children : rest -> case assignment of
|
||||
stepAssignment = iterFreer (\ assignment yield nodes -> case (assignment, 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, Rose Node{..} children : rest) -> case assignment of
|
||||
Rule symbol subRule ->
|
||||
if symbol == nodeSymbol then
|
||||
yield subRule nodes
|
||||
@ -97,13 +99,8 @@ stepAssignment = iterFreer (\ assignment yield nodes -> case nodes of
|
||||
Nothing
|
||||
Content -> yield nodeContent rest
|
||||
Children each -> fmap (first (const rest)) (yield each children)
|
||||
Alt a b -> yield a nodes <|> yield b nodes
|
||||
-- FIXME: Rule `Alt` Rule `Alt` Rule is inefficient, should build and match against an IntMap instead.
|
||||
Fail -> Nothing
|
||||
-- Nullability: some rules, e.g. 'pure a' and 'many a', should match at the end of input.
|
||||
[] -> case assignment of
|
||||
Alt a b -> yield a [] <|> yield b []
|
||||
_ -> Nothing)
|
||||
_ -> Nothing
|
||||
_ -> Nothing)
|
||||
. fmap ((Just .) . flip (,))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user