1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 01:47:01 +03:00

s/prettyPrint/tokenize

This commit is contained in:
Timothy Clem 2018-08-20 10:38:03 -07:00
parent a473a346c9
commit 80ee53ed9d
3 changed files with 13 additions and 13 deletions

View File

@ -209,7 +209,7 @@ instance Show1 Error where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Error
instance Tokenize Error where
prettyPrint = ignore
tokenize = ignore
instance Named String where
nameOf _ = "string"

View File

@ -34,7 +34,7 @@ instance Evaluatable Boolean where
eval (Boolean x) = rvalBox (boolean x)
instance Tokenize Boolean where
prettyPrint = yield . Truth . booleanContent
tokenize = yield . Truth . booleanContent
-- Numeric
@ -65,7 +65,7 @@ instance Evaluatable Data.Syntax.Literal.Float where
rvalBox =<< (float <$> either (const (throwEvalError (FloatFormatError s))) pure (parseScientific s))
instance Tokenize Data.Syntax.Literal.Float where
prettyPrint = yield . Fragment . floatContent
tokenize = yield . Fragment . floatContent
-- Rational literals e.g. `2/3r`
newtype Rational a = Rational { value :: Text }
@ -139,7 +139,7 @@ instance Evaluatable TextElement where
eval (TextElement x) = rvalBox (string x)
instance Tokenize TextElement where
prettyPrint = yield . Fragment . textElementContent
tokenize = yield . Fragment . textElementContent
-- | A sequence of textual contents within a string literal.
newtype EscapeSequence a = EscapeSequence { value :: Text }
@ -162,7 +162,7 @@ instance Show1 Null where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Null where eval _ = rvalBox null
instance Tokenize Null where
prettyPrint _ = yield Nullity
tokenize _ = yield Nullity
newtype Symbol a = Symbol { symbolElements :: [a] }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1)
@ -210,7 +210,7 @@ instance Evaluatable Array where
eval (Array a) = rvalBox =<< array =<< traverse subtermAddress a
instance Tokenize Array where
prettyPrint t = within List $
tokenize t = within List $
let withCommas = intersperse (yield Separator) (toList t)
in yield Open *> sequenceA_ withCommas *> yield Close
@ -225,7 +225,7 @@ instance Evaluatable Hash where
eval t = rvalBox =<< (hash <$> traverse (subtermValue >=> asPair) (hashElements t))
instance Tokenize Hash where
prettyPrint t = within Associative $
tokenize t = within Associative $
let withCommas = intersperse (yield Separator) (toList t)
in yield Open *> sequenceA_ withCommas *> yield Close
@ -241,7 +241,7 @@ instance Evaluatable KeyValue where
rvalBox =<< (kvPair <$> key <*> value)
instance Tokenize KeyValue where
prettyPrint (KeyValue k v) = within Pair $
tokenize (KeyValue k v) = within Pair $
k *> yield Separator *> v
newtype Tuple a = Tuple { tupleContents :: [a] }

View File

@ -66,15 +66,15 @@ ignore = const (pure ())
-- pretty print the value of the supplied constructor in its AST context.
class (Show1 constr, Traversable constr) => Tokenize constr where
-- | Should emit control and data tokens.
prettyPrint :: FAlgebra constr (Tokenizer ())
tokenize :: FAlgebra constr (Tokenizer ())
-- | Sums of reprintable terms are reprintable.
instance (Apply Show1 fs, Apply Functor fs, Apply Foldable fs, Apply Traversable fs, Apply Tokenize fs) => Tokenize (Sum fs) where
prettyPrint = apply @Tokenize prettyPrint
tokenize = apply @Tokenize tokenize
-- | Annotated terms are reprintable and operate in a context derived from the annotation.
instance (HasField fields History, Show (Record fields), Tokenize a) => Tokenize (TermF a (Record fields)) where
prettyPrint t = withHistory t (prettyPrint (termFOut t))
tokenize t = withHistory t (tokenize (termFOut t))
-- | The top-level function. Pass in a 'Source' and a 'Term' and
-- you'll get out a 'Seq' of 'Token's for later processing.
@ -138,7 +138,7 @@ descend t = do
let into s = withHistory (subterm s) (subtermRef s)
case (hist, strat) of
(Unmodified _, _) -> traverse_ into t
(Refactored _, PrettyPrinting) -> prettyPrint (fmap into t)
(Refactored _, PrettyPrinting) -> tokenize (fmap into t)
(Refactored r, Reprinting) -> do
crs <- gets _cursor
src <- asks _source
@ -146,5 +146,5 @@ descend t = do
log ("slicing: " <> show delimiter)
chunk (slice delimiter src)
modify (set cursor (start r))
prettyPrint (fmap (withStrategy PrettyPrinting . into) t)
tokenize (fmap (withStrategy PrettyPrinting . into) t)
modify (set cursor (end r))