1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 12:51:52 +03:00

Define a Label assignment.

This commit is contained in:
Rob Rix 2017-08-06 11:58:04 -04:00
parent 3d9760d5d8
commit b911f93a58

View File

@ -136,6 +136,7 @@ data AssignmentF ast grammar a where
Alt :: HasCallStack => NonEmpty a -> AssignmentF ast grammar a
Throw :: HasCallStack => Maybe (Error grammar) -> AssignmentF ast grammar a
Catch :: HasCallStack => Assignment ast grammar a -> (Error grammar -> Assignment ast grammar a) -> AssignmentF ast grammar a
Label :: HasCallStack => Assignment ast grammar a -> String -> AssignmentF ast grammar a
-- | Zero-width production of the current location.
--
@ -308,6 +309,7 @@ runAssignment toNode source = (\ assignment state -> go assignment state >>= req
Project{} -> Left (makeError node, state)
Children{} -> Left (makeError node, state)
Source -> Left (makeError node, state)
Label child _ -> go child state >>= uncurry yield
state@State{..} = if not (null expectedSymbols) && all ((== Regular) . symbolType) expectedSymbols then dropAnonymous initialState else initialState
expectedSymbols = firstSet (assignment `Then` return)
@ -402,3 +404,4 @@ instance (Ix grammar, Show grammar) => Show1 (AssignmentF ast grammar) where
Alt as -> showsUnaryWith (const sl) "Alt" d (toList as)
Throw e -> showsUnaryWith showsPrec "Throw" d e
Catch during handler -> showsBinaryWith (liftShowsPrec sp sl) (const (const (showChar '_'))) "Catch" d during handler
Label child string -> showsBinaryWith (liftShowsPrec sp sl) showsPrec "Label" d child string