1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Dedicated datatype for symbols

This commit is contained in:
Timothy Clem 2018-08-24 14:00:59 -07:00
parent c124a306a3
commit c8d6cab47f
3 changed files with 5 additions and 4 deletions

View File

@ -26,6 +26,7 @@ data Element
| Truth Bool -- ^ A boolean value.
| Nullity -- ^ @null@ or @nil@ or some other zero value.
| TSep -- ^ Some sort of delimiter, interpreted in some 'Context'.
| TSym -- ^ Some sort of symbol, interpreted in some 'Context'.
| TOpen -- ^ The beginning of some 'Context', such as an @[@ or @{@.
| TClose -- ^ The opposite of 'TOpen'.
deriving (Eq, Show)

View File

@ -128,7 +128,7 @@ instance Evaluatable Plus where
go (Plus a b) = liftNumeric2 add a b where add = liftReal (+)
instance Tokenize Plus where
tokenize Plus{..} = within' (TInfixL Add 6) $ lhs *> yield TSep <* rhs
tokenize Plus{..} = within' (TInfixL Add 6) $ lhs *> yield TSym <* rhs
data Minus a = Minus { lhs :: a, rhs :: a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1)
@ -153,7 +153,7 @@ instance Evaluatable Times where
go (Times a b) = liftNumeric2 mul a b where mul = liftReal (*)
instance Tokenize Times where
tokenize Times{..} = within' (TInfixL Mult 7) $ lhs *> yield TSep <* rhs
tokenize Times{..} = within' (TInfixL Mult 7) $ lhs *> yield TSym <* rhs
data DividedBy a = DividedBy { lhs :: a, rhs :: a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1)

View File

@ -33,8 +33,8 @@ step (Defer el cs) = case (el, cs) of
(TClose, TParams:_) -> pure $ emit ")"
(TOpen, TInfixL _ p:xs) -> emitIf (p < prec xs) "("
(TSep, TInfixL Add _:_) -> pure $ space <> emit "+" <> space
(TSep, TInfixL Mult _:_) -> pure $ space <> emit "*" <> space
(TSym, TInfixL Add _:_) -> pure $ space <> emit "+" <> space
(TSym, TInfixL Mult _:_) -> pure $ space <> emit "*" <> space
(TClose, TInfixL _ p:xs) -> emitIf (p < prec xs) ")"
(TOpen, [Imperative]) -> pure mempty