Skip to content

Commit

Permalink
fix pattern printing
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Jan 22, 2023
1 parent f67b851 commit 4827ddd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion juvix-mode/juvix-mode.el
Expand Up @@ -69,7 +69,7 @@
)
(with-temp-buffer
(let ((
cmd-str (concat "juvix " (if juvix-disable-embedded-stdlib "--no-stdlib " "") "dev scope "
cmd-str (concat "juvix " (if juvix-disable-embedded-stdlib "--no-stdlib " "") "dev scope --with-comments "
buff-name)
))
(if (zerop (call-process-shell-command
Expand Down
8 changes: 7 additions & 1 deletion src/Juvix/Compiler/Concrete/Print/Base.hs
Expand Up @@ -254,13 +254,19 @@ instance PrettyPrint (FunctionClause 'Scoped) where
let clauseFun' = ppCode _clauseOwnerFunction
clausePatterns' = case nonEmpty _clausePatterns of
Nothing -> Nothing
Just ne -> Just (hsep (ppCode <$> ne))
Just ne -> Just (hsep (ppPatternAtom <$> ne))
clauseBody' = ppCode _clauseBody
clauseFun'
<+?> clausePatterns'
<+> noLoc P.kwAssign
<+> nest clauseBody'

ppPatternAtom :: forall r. (Members '[Reader Options, ExactPrint] r) => PatternArg -> Sem r ()
ppPatternAtom pat =
case pat ^. patternArgPattern of
PatternVariable s | s ^. S.nameVerbatim == "=" -> parens (ppAtom pat)
_ -> ppAtom pat

instance PrettyPrint (InductiveParameter 'Scoped) where
ppCode InductiveParameter {..} = do
let name' = region (P.annDef _inductiveParameterName) (ppCode _inductiveParameterName)
Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Concrete/Translation/FromSource.hs
Expand Up @@ -253,7 +253,7 @@ builtinStatement = do

compileBlock :: forall r. Members '[InfoTableBuilder, JudocStash, NameIdGen] r => ParsecS r (Compile 'Parsed)
compileBlock = do
kw kwCompile
_compileKw <- kw kwCompile
_compileName <- symbol
_compileBackendItems <- backends
return Compile {..}
Expand Down
3 changes: 3 additions & 0 deletions src/Juvix/Data/Comment.hs
Expand Up @@ -60,6 +60,9 @@ mkComments cs = Comments {..}
let _fileCommentsSorted = sortOn (^. commentInterval) (toList filecomments)
]

emptyComments :: Comments
emptyComments = Comments mempty

emptyFileComments :: Path Abs File -> FileComments
emptyFileComments _fileCommentsFile =
FileComments
Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Data/Keyword.hs
Expand Up @@ -29,7 +29,7 @@ makeLenses ''Keyword
makeLenses ''KeywordRef

instance Eq KeywordRef where
a == b = (a ^. keywordRefKeyword, a ^. keywordRefUnicode) == (b ^. keywordRefKeyword, b ^. keywordRefUnicode)
a == b = a ^. keywordRefKeyword == b ^. keywordRefKeyword

instance Ord KeywordRef where
compare a b = compare (a ^. keywordRefKeyword, a ^. keywordRefUnicode) (b ^. keywordRefKeyword, b ^. keywordRefUnicode)
Expand Down
7 changes: 4 additions & 3 deletions test/Scope/Positive.hs
Expand Up @@ -13,6 +13,7 @@ import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.Scoping qualified
import Juvix.Compiler.Concrete.Translation.FromSource qualified as Parser
import Juvix.Compiler.Pipeline
import Juvix.Compiler.Pipeline.Setup
import Juvix.Data.Comment
import Juvix.Prelude.Aeson
import Juvix.Prelude.Pretty

Expand All @@ -30,8 +31,8 @@ root = relToProject $(mkRelDir "tests/positive")
renderCode2 :: M.PrettyCode c => c -> Text
renderCode2 = prettyText . M.ppOutDefault

renderCode :: P.PrettyPrint c => c -> Text
renderCode = prettyText . P.ppOutDefault
renderCode :: (HasLoc c, P.PrettyPrint c) => c -> Text
renderCode = prettyText . P.ppOutDefault emptyComments

type Pipe =
'[ PathResolver,
Expand Down Expand Up @@ -95,7 +96,7 @@ testDescr PosTest {..} =
<> yamlFiles

let scopedPretty = renderCode s2
parsedPretty = renderCode p2
parsedPretty = renderCode2 p2
onlyMainFile :: Text -> HashMap (Path Abs File) Text
onlyMainFile t = HashMap.fromList $ (file', t) : yamlFiles

Expand Down
2 changes: 1 addition & 1 deletion tests/positive/Imports/A.juvix
Expand Up @@ -7,7 +7,7 @@ module A;
end ;
infix 2 +;
axiom + : Type → Type → Type;
end ;
end;
import M;
f : M.N.T;
f (_ M.N.t _) := Type M.+ Type;
Expand Down

0 comments on commit 4827ddd

Please sign in to comment.