language-lua 0.4.1 → 0.4.2
raw patch · 2 files changed
+22/−17 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- language-lua.cabal +6/−1
- src/Language/Lua/PrettyPrinter.hs +16/−16
language-lua.cabal view
@@ -2,6 +2,11 @@ Description: Lua 5.2 lexer, parser and pretty-printer. Documentation: (<https://osa1.github.com/language-lua>) . Changelog:+ \0.4.2:+ .+ - More tweaks in pretty printer.+ - Started using 2 spaces for indentation(instead of 4 as before).+ . \0.4.1: . - Some tweaks in pretty-printer.@@ -29,7 +34,7 @@ \0.2.0: . - Syntax tree is annotated. All parsers(`parseText`, `parseFile`) annotate resulting tree with source positions.-Version: 0.4.1+Version: 0.4.2 Synopsis: Lua parser and pretty-printer Homepage: http://github.com/osa1/language-lua Bug-reports: http://github.com/osa1/language-lua/issues
src/Language/Lua/PrettyPrinter.hs view
@@ -80,7 +80,7 @@ pprint (Paren e) = parens (pprint e) instance LPretty [TableField] where- pprint fields = braces (align (fillSep (punctuate (comma <> space) (map pprint fields))))+ pprint fields = braces (align (fillSep (punctuate comma (map pprint fields)))) instance LPretty TableField where pprint (ExpField e1 e2) = brackets (pprint e1) <+> equals <+> pprint e2@@ -95,7 +95,7 @@ where ret' = case ret of Nothing -> empty Just [fun@EFunDef{}] -> text "return" <+> pprint fun- Just e -> nest 4 (text "return" </> intercalate comma (map (align . pprint) e))+ Just e -> nest 2 (text "return" </> intercalate comma (map (align . pprint) e)) instance LPretty FunName where pprint (FunName name s methods) = cat (punctuate dot (map pprint $ name:s)) <> method'@@ -108,7 +108,7 @@ pprintFunction :: Maybe Doc -> FunBody -> Doc pprintFunction funname (FunBody args vararg block) =- group (nest 4 (header <$> body) <$> end)+ group (nest 2 (header <$> body) <$> end) where header = case funname of Nothing -> text "function" <+> args'@@ -137,37 +137,37 @@ pprint (Label name) = text "::" <> pprint name <> text "::" pprint Break = text "break" pprint (Goto name) = text "goto" <+> pprint name- pprint (Do block) = group (nest 4 (text "do" <$> pprint block) <$> text "end")+ pprint (Do block) = group (nest 2 (text "do" <$> pprint block) <$> text "end") pprint (While guard e)- = text "while" <+> pprint guard <+> text "do"- <$> indent 4 (pprint e)+ = nest 2 (text "while" <+> pprint guard <+> text "do" <$> pprint e) <$> text "end" pprint (Repeat block guard)- = (text "repeat" <$> indent 4 (pprint block))- </> nest 4 (text "until" </> pprint guard)+ = nest 2 (text "repeat" <$> pprint block)+ </> nest 2 (text "until" </> pprint guard) pprint (If cases elsePart) = group (printIf cases elsePart) where printIf ((guard, block) : xs) e =- nest 4 (text "if" <+> pprint guard <+> text "then" <$> pprint block) <$> printIf' xs e+ nest 2 (text "if" <+> pprint guard <+> text "then" <$> pprint block) <$> printIf' xs e printIf' [] Nothing = text "end"- printIf' [] (Just b) = nest 4 (text "else" <$> pprint b) <$> text "end"+ printIf' [] (Just b) = nest 2 (text "else" <$> pprint b) <$> text "end" printIf' ((guard, block) : xs) e =- nest 4 (text "elseif" <+> pprint guard <+> text "then" <$> pprint block) <$> printIf' xs e+ nest 2 (text "elseif" <+> pprint guard <+> text "then" <$> pprint block) <$> printIf' xs e pprint (ForRange name e1 e2 e3 block)- = text "for" <+> pprint name <> equals <> pprint e1 <> comma <> pprint e2 <> e3' <+> text "do"- <$> indent 4 (pprint block)+ = nest 2 (text "for" <+> pprint name <> equals <> pprint e1+ <> comma <> pprint e2 <> e3' <+> text "do"+ <$> pprint block) <$> text "end" where e3' = case e3 of Nothing -> empty Just e -> comma <> pprint e pprint (ForIn names exps block)- = text "for" <+> intercalate comma (map pprint names)- <+> text "in" <+> intercalate comma (map pprint exps) <+> text "do"- <$> indent 4 (pprint block)+ = nest 2 (text "for" <+> intercalate comma (map pprint names) <+> text "in"+ <+> intercalate comma (map pprint exps) <+> text "do"+ <$> pprint block) <$> text "end" pprint (FunAssign name body) = pprintFunction (Just (pprint name)) body