Skip to content

Commit 474a2ec

Browse files
authored
Add shebang support (#121)
Fixes #120
1 parent d6e21ec commit 474a2ec

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

packages.dhall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ in upstream
3939
}
4040

4141
with language-cst-parser =
42-
(upstream.language-cst-parser with version = "v0.13.0")
42+
(upstream.language-cst-parser with version = "v0.14.0")

src/Tidy.purs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ instance formatErrorRecoveredError :: FormatError RecoveredError where
120120
goComments :: forall a b. Int -> { line :: Boolean, doc :: Dodo.Doc b } -> Comment a -> { line :: Boolean, doc :: Dodo.Doc b }
121121
goComments ind acc = case _ of
122122
Comment str
123-
| SCU.take 2 str == "--" ->
123+
| leading <- SCU.take 2 str
124+
, leading == "--" || leading == "#!" ->
124125
{ line: false, doc: acc.doc <> Dodo.text str }
125126
| otherwise ->
126127
{ line: false, doc: acc.doc <> Dodo.lines (Dodo.text <$> splitLines str) }
@@ -145,7 +146,8 @@ formatComment
145146
-> FormatDoc a
146147
formatComment lineComment blockComment com next = case com of
147148
Comment str
148-
| SCU.take 2 str == "--" ->
149+
| leading <- SCU.take 2 str
150+
, leading == "--" || leading == "#!" ->
149151
lineComment str next
150152
| otherwise ->
151153
blockComment str next

test/snapshots/Shebang.output

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! shebang 1
2+
#! shebang 2
3+
-- comment
4+
module Foo.Bar where

test/snapshots/Shebang.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! shebang 1
2+
#! shebang 2
3+
-- comment
4+
module Foo.Bar where

0 commit comments

Comments
 (0)