Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 3daee38

Browse files
authored
Merge branch 'master' into add-php
2 parents 6863168 + 9d1c024 commit 3daee38

File tree

14 files changed

+191
-157
lines changed

14 files changed

+191
-157
lines changed

semantic.cabal

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ common dependencies
5656
, fused-effects-exceptions ^>= 0.1.1.0
5757
, hashable ^>= 1.2.7.0
5858
, tree-sitter ^>= 0.1.0.0
59-
, machines ^>= 0.6.4
6059
, mtl ^>= 2.2.2
6160
, network ^>= 2.8.0.0
6261
, process ^>= 1.6.3.0
@@ -65,6 +64,7 @@ common dependencies
6564
, safe-exceptions ^>= 0.1.7.0
6665
, semilattices ^>= 0.0.0.3
6766
, shelly >= 1.5 && <2
67+
, streaming ^>= 0.2.2.0
6868
, text ^>= 1.2.3.1
6969
, these >= 0.7 && <1
7070
, unix ^>= 2.7.2.2
@@ -308,7 +308,6 @@ library
308308
, profunctors ^>= 5.3
309309
, reducers ^>= 3.12.3
310310
, semigroupoids ^>= 5.3.2
311-
, servant ^>= 0.15
312311
, split ^>= 0.2.3.3
313312
, stm-chans ^>= 3.0.0.4
314313
, template-haskell ^>= 2.14

src/Data/Language.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ languageForType mediaType = case mediaType of
108108
".rb" -> Ruby
109109
".go" -> Go
110110
".js" -> JavaScript
111+
".mjs" -> JavaScript
111112
".ts" -> TypeScript
112113
".tsx" -> TSX
113114
".jsx" -> JSX
@@ -120,7 +121,7 @@ extensionsForLanguage :: Language -> [String]
120121
extensionsForLanguage language = case language of
121122
Go -> [".go"]
122123
Haskell -> [".hs"]
123-
JavaScript -> [".js"]
124+
JavaScript -> [".js", ".mjs"]
124125
PHP -> [".php", ".phpt"]
125126
Python -> [".py"]
126127
Ruby -> [".rb"]
@@ -134,7 +135,7 @@ languageForFilePath :: FilePath -> Language
134135
languageForFilePath = languageForType . takeExtension
135136

136137
supportedExts :: [String]
137-
supportedExts = [".go", ".py", ".rb", ".js", ".ts", ".php", ".phpt"]
138+
supportedExts = [".go", ".py", ".rb", ".js", ".mjs", ".ts", ".php", ".phpt"]
138139

139140
codeNavLanguages :: [Language]
140141
codeNavLanguages = [Go, Ruby, Python, JavaScript, TypeScript, PHP]

src/Data/Reprinting/Fragment.hs

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ module Data.Reprinting.Fragment
77
, defer
88
) where
99

10-
import Data.Machine
1110
import Data.Text (Text)
11+
import Streaming
12+
import Streaming.Prelude (yield)
1213

1314
import Data.Reprinting.Scope
1415
import Data.Reprinting.Token
@@ -25,13 +26,13 @@ data Fragment
2526
deriving (Eq, Show)
2627

2728
-- | Copy along some original, un-refactored 'Text'.
28-
copy :: Text -> Plan k Fragment ()
29+
copy :: Monad m => Text -> Stream (Of Fragment) m ()
2930
copy = yield . Verbatim
3031

3132
-- | Insert some new 'Text'.
32-
insert :: Element -> [Scope] -> Text -> Plan k Fragment ()
33+
insert :: Monad m => Element -> [Scope] -> Text -> Stream (Of Fragment) m ()
3334
insert el c = yield . New el c
3435

3536
-- | Defer processing an element to a later stage.
36-
defer :: Element -> [Scope] -> Plan k Fragment ()
37+
defer :: Monad m => Element -> [Scope] -> Stream (Of Fragment) m ()
3738
defer el = yield . Defer el

src/Data/Reprinting/Splice.hs

+8-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module Data.Reprinting.Splice
1818

1919
import Prologue hiding (Element)
2020

21-
import Data.Machine
21+
import Streaming
22+
import Streaming.Prelude (yield)
2223

2324
import Data.Reprinting.Fragment
2425

@@ -29,29 +30,29 @@ data Splice
2930
deriving (Eq, Show)
3031

3132
-- | Emit some 'Text' as a 'Splice'.
32-
emit :: Text -> Plan k Splice ()
33+
emit :: Monad m => Text -> Stream (Of Splice) m ()
3334
emit = yield . Emit
3435

3536
-- | Emit the provided 'Text' if the given predicate is true.
36-
emitIf :: Bool -> Text -> Plan k Splice ()
37+
emitIf :: Monad m => Bool -> Text -> Stream (Of Splice) m ()
3738
emitIf p = when p . emit
3839

3940
-- | Construct a layout 'Splice'.
40-
layout :: Whitespace -> Plan k Splice ()
41+
layout :: Monad m => Whitespace -> Stream (Of Splice) m ()
4142
layout = yield . Layout
4243

4344
-- | @indent w n@ emits @w@ 'Spaces' @n@ times.
44-
indent :: Int -> Int -> Plan k Splice ()
45+
indent :: Monad m => Int -> Int -> Stream (Of Splice) m ()
4546
indent width times
4647
| times > 0 = replicateM_ times (layout (Indent width Spaces))
4748
| otherwise = pure ()
4849

4950
-- | Construct multiple layouts.
50-
layouts :: [Whitespace] -> Plan k Splice ()
51+
layouts :: Monad m => [Whitespace] -> Stream (Of Splice) m ()
5152
layouts = traverse_ (yield . Layout)
5253

5354
-- | Single space.
54-
space :: Plan k Splice ()
55+
space :: Monad m => Stream (Of Splice) m ()
5556
space = yield (Layout Space)
5657

5758
-- | Indentation, spacing, and other whitespace.

src/Language/JSON/PrettyPrint.hs

+29-23
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,35 @@ module Language.JSON.PrettyPrint
88

99
import Prologue
1010

11-
import Control.Effect
12-
import Control.Effect.Error
13-
import Control.Monad.Trans (lift)
14-
import Data.Machine
11+
import Control.Effect
12+
import Control.Effect.Error
13+
import Streaming
14+
import qualified Streaming.Prelude as Streaming
1515

1616
import Data.Reprinting.Errors
17+
import Data.Reprinting.Scope
1718
import Data.Reprinting.Splice
1819
import Data.Reprinting.Token
19-
import Data.Reprinting.Scope
2020

2121
-- | Default printing pipeline for JSON.
2222
defaultJSONPipeline :: (Member (Error TranslationError) sig, Carrier sig m)
23-
=> ProcessT m Fragment Splice
23+
=> Stream (Of Fragment) m a
24+
-> Stream (Of Splice) m a
2425
defaultJSONPipeline
25-
= printingJSON
26-
~> beautifyingJSON defaultBeautyOpts
26+
= beautifyingJSON defaultBeautyOpts
27+
. printingJSON
2728

2829
-- | Print JSON syntax.
29-
printingJSON :: Monad m => ProcessT m Fragment Fragment
30-
printingJSON = repeatedly (await >>= step) where
30+
printingJSON :: Monad m
31+
=> Stream (Of Fragment) m a
32+
-> Stream (Of Fragment) m a
33+
printingJSON = Streaming.map step where
3134
step s@(Defer el cs) =
32-
let ins = yield . New el cs
35+
let ins = New el cs
3336
in case (el, listToMaybe cs) of
34-
(Truth True, _) -> ins "true"
35-
(Truth False, _) -> ins "false"
36-
(Nullity, _) -> ins "null"
37+
(Truth True, _) -> ins "true"
38+
(Truth False, _) -> ins "false"
39+
(Nullity, _) -> ins "null"
3740

3841
(Open, Just List) -> ins "["
3942
(Close, Just List) -> ins "]"
@@ -44,8 +47,8 @@ printingJSON = repeatedly (await >>= step) where
4447
(Sep, Just Pair) -> ins ":"
4548
(Sep, Just Hash) -> ins ","
4649

47-
_ -> yield s
48-
step x = yield x
50+
_ -> s
51+
step x = x
4952

5053
-- TODO: Fill out and implement configurable options like indentation count,
5154
-- tabs vs. spaces, etc.
@@ -57,23 +60,26 @@ defaultBeautyOpts = JSONBeautyOpts 2 False
5760

5861
-- | Produce JSON with configurable whitespace and layout.
5962
beautifyingJSON :: (Member (Error TranslationError) sig, Carrier sig m)
60-
=> JSONBeautyOpts -> ProcessT m Fragment Splice
61-
beautifyingJSON _ = repeatedly (await >>= step) where
62-
step (Defer el cs) = lift (throwError (NoTranslation el cs))
63+
=> JSONBeautyOpts
64+
-> Stream (Of Fragment) m a
65+
-> Stream (Of Splice) m a
66+
beautifyingJSON _ s = Streaming.for s step where
67+
step (Defer el cs) = effect (throwError (NoTranslation el cs))
6368
step (Verbatim txt) = emit txt
6469
step (New el cs txt) = case (el, cs) of
6570
(Open, Hash:_) -> emit txt *> layout HardWrap *> indent 2 (hashDepth cs)
6671
(Close, Hash:rest) -> layout HardWrap *> indent 2 (hashDepth rest) *> emit txt
6772
(Sep, List:_) -> emit txt *> space
6873
(Sep, Pair:_) -> emit txt *> space
6974
(Sep, Hash:_) -> emit txt *> layout HardWrap *> indent 2 (hashDepth cs)
70-
_ -> emit txt
75+
_ -> emit txt
7176

7277
-- | Produce whitespace minimal JSON.
7378
minimizingJSON :: (Member (Error TranslationError) sig, Carrier sig m)
74-
=> ProcessT m Fragment Splice
75-
minimizingJSON = repeatedly (await >>= step) where
76-
step (Defer el cs) = lift (throwError (NoTranslation el cs))
79+
=> Stream (Of Fragment) m a
80+
-> Stream (Of Splice) m a
81+
minimizingJSON s = Streaming.for s step where
82+
step (Defer el cs) = effect (throwError (NoTranslation el cs))
7783
step (Verbatim txt) = emit txt
7884
step (New _ _ txt) = emit txt
7985

src/Language/Python/PrettyPrint.hs

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module Language.Python.PrettyPrint ( printingPython ) where
44

55
import Control.Effect
66
import Control.Effect.Error
7-
import Control.Monad.Trans (lift)
8-
import Data.Machine
7+
import Streaming
8+
import qualified Streaming.Prelude as Streaming
99

1010
import Data.Reprinting.Errors
1111
import Data.Reprinting.Splice
@@ -14,10 +14,12 @@ import Data.Reprinting.Scope
1414
import Data.Reprinting.Operator
1515

1616
-- | Print Python syntax.
17-
printingPython :: (Member (Error TranslationError) sig, Carrier sig m) => ProcessT m Fragment Splice
18-
printingPython = repeatedly (await >>= step)
17+
printingPython :: (Member (Error TranslationError) sig, Carrier sig m)
18+
=> Stream (Of Fragment) m a
19+
-> Stream (Of Splice) m a
20+
printingPython s = Streaming.for s step
1921

20-
step :: (Member (Error TranslationError) sig, Carrier sig m) => Fragment -> PlanT k Splice m ()
22+
step :: (Member (Error TranslationError) sig, Carrier sig m) => Fragment -> Stream (Of Splice) m ()
2123
step (Verbatim txt) = emit txt
2224
step (New _ _ txt) = emit txt
2325
step (Defer el cs) = case (el, cs) of
@@ -63,7 +65,7 @@ step (Defer el cs) = case (el, cs) of
6365
(Sep, Imperative:xs) -> layout HardWrap *> indent 4 (imperativeDepth xs)
6466
(Close, Imperative:_) -> pure ()
6567

66-
_ -> lift (throwError (NoTranslation el cs))
68+
_ -> effect (throwError (NoTranslation el cs))
6769

6870
where
6971
endContext times = layout HardWrap *> indent 4 (pred times)

src/Language/Ruby/PrettyPrint.hs

+12-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module Language.Ruby.PrettyPrint ( printingRuby ) where
55
import Control.Effect
66
import Control.Effect.Error
77
import Control.Monad.Trans (lift)
8-
import Data.Machine
8+
import Streaming
9+
import qualified Streaming.Prelude as Streaming
910

1011
import Data.Reprinting.Scope
1112
import Data.Reprinting.Errors
@@ -14,10 +15,14 @@ import Data.Reprinting.Splice
1415
import Data.Reprinting.Token as Token
1516

1617
-- | Print Ruby syntax.
17-
printingRuby :: (Member (Error TranslationError) sig, Carrier sig m) => ProcessT m Fragment Splice
18-
printingRuby = repeatedly (await >>= step)
19-
20-
step :: (Member (Error TranslationError) sig, Carrier sig m) => Fragment -> PlanT k Splice m ()
18+
printingRuby :: (Member (Error TranslationError) sig, Carrier sig m)
19+
=> Stream (Of Fragment) m a
20+
-> Stream (Of Splice) m a
21+
printingRuby s = Streaming.for s step
22+
23+
step :: (Member (Error TranslationError) sig, Carrier sig m)
24+
=> Fragment
25+
-> Stream (Of Splice) m ()
2126
step (Verbatim txt) = emit txt
2227
step (New _ _ txt) = emit txt
2328
step (Defer el cs) = case (el, cs) of
@@ -47,9 +52,9 @@ step (Defer el cs) = case (el, cs) of
4752
(Close, [Imperative]) -> layout HardWrap
4853
(Close, Imperative:xs) -> indent 2 (pred (imperativeDepth xs))
4954

50-
(Sep, Call:_) -> emit "."
55+
(Sep, Call:_) -> emit "."
5156

52-
_ -> lift (throwError (NoTranslation el cs))
57+
_ -> effect (throwError (NoTranslation el cs))
5358

5459
where
5560
endContext times = layout HardWrap *> indent 2 (pred times)

0 commit comments

Comments
 (0)