Skip to content

Commit

Permalink
Add shebang support (#121)
Browse files Browse the repository at this point in the history
Fixes #120
  • Loading branch information
natefaubion authored Feb 28, 2024
1 parent d6e21ec commit 474a2ec
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ in upstream
}

with language-cst-parser =
(upstream.language-cst-parser with version = "v0.13.0")
(upstream.language-cst-parser with version = "v0.14.0")
6 changes: 4 additions & 2 deletions src/Tidy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ instance formatErrorRecoveredError :: FormatError RecoveredError where
goComments :: forall a b. Int -> { line :: Boolean, doc :: Dodo.Doc b } -> Comment a -> { line :: Boolean, doc :: Dodo.Doc b }
goComments ind acc = case _ of
Comment str
| SCU.take 2 str == "--" ->
| leading <- SCU.take 2 str
, leading == "--" || leading == "#!" ->
{ line: false, doc: acc.doc <> Dodo.text str }
| otherwise ->
{ line: false, doc: acc.doc <> Dodo.lines (Dodo.text <$> splitLines str) }
Expand All @@ -145,7 +146,8 @@ formatComment
-> FormatDoc a
formatComment lineComment blockComment com next = case com of
Comment str
| SCU.take 2 str == "--" ->
| leading <- SCU.take 2 str
, leading == "--" || leading == "#!" ->
lineComment str next
| otherwise ->
blockComment str next
Expand Down
4 changes: 4 additions & 0 deletions test/snapshots/Shebang.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! shebang 1
#! shebang 2
-- comment
module Foo.Bar where
4 changes: 4 additions & 0 deletions test/snapshots/Shebang.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! shebang 1
#! shebang 2
-- comment
module Foo.Bar where

0 comments on commit 474a2ec

Please sign in to comment.