Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Working in comment processing.

  • Loading branch information...
commit 42faafb4f5abb4bf5b026be060b2ae996b4901ee 1 parent 9b48077
Alan Zimmerman authored

Showing 2 changed files with 17 additions and 2 deletions. Show diff stats Hide diff stats

  1. +2 0  TODO.txt
  2. +15 2 src/Language/JavaScript/Pretty/Printer.hs
2  TODO.txt
@@ -33,5 +33,7 @@ manipulation.
33 33
34 34 14. Look at http://jsshaper.org/
35 35
  36 +15. Store number of rows/cols in a comment, to speed output
  37 +
36 38 EOF
37 39
17 src/Language/JavaScript/Pretty/Printer.hs
@@ -6,8 +6,8 @@ module Language.JavaScript.Pretty.Printer (
6 6 import Data.Char
7 7 import Data.List
8 8 import Data.Monoid (Monoid, mappend, mempty, mconcat)
9   --- import Text.Jasmine.Parse
10 9 import Language.JavaScript.Parser
  10 +import Language.JavaScript.Parser.Token
11 11 import qualified Blaze.ByteString.Builder as BB
12 12 import qualified Blaze.ByteString.Builder.Char.Utf8 as BS
13 13 import qualified Data.ByteString.Lazy as LB
@@ -40,6 +40,7 @@ punctuate :: a -> [a] -> [a]
40 40 punctuate p xs = intersperse p xs
41 41
42 42 -- ---------------------------------------------------------------------
  43 +-- Utility (boilerplate) functions
43 44
44 45 bp :: (Int,Int) -> TokenPosn -> ((Int,Int) -> ((Int,Int),BB.Builder)) -> ((Int,Int),BB.Builder)
45 46 bp (r,c) p f = ((r'',c''),bb <> bb')
@@ -47,6 +48,17 @@ bp (r,c) p f = ((r'',c''),bb <> bb')
47 48 ((r',c'),bb) = skipTo (r,c) p
48 49 ((r'',c''),bb') = f (r',c')
49 50
  51 +
  52 +bpc (r,c) p cs f = ((r'',c''),bb <> bb')
  53 + where
  54 + ((r', c'), bb) = foldl' (\((rc,cc),bb) (pc,comment) -> bp (rc,cc) pc (rComment comment)) ((r,c),mempty) cs
  55 + ((r'',c''),bb') = bp (r',c') p f
  56 +
  57 +rComment NoComment (r,c) = ((r,c),mempty)
  58 +rComment (CommentA p s) (r,c) = ((r',c'),text s)
  59 + where
  60 + (r',c') = (r,c) -- TODO: advance as per actual comment
  61 +
50 62 bprJS
51 63 :: (Int, Int) -> TokenPosn -> [JSNode] -> ((Int, Int), BB.Builder)
52 64 bprJS (r,c) p xs = bp (r,c) p (\(r,c) -> rJS (r,c) xs)
@@ -55,6 +67,7 @@ bpText
55 67 :: (Int, Int) -> TokenPosn -> [Char] -> ((Int, Int), BB.Builder)
56 68 bpText (r,c) p s = bp (r,c) p (\(r,c) -> ((r,c + (length s)),text s))
57 69
  70 +bpcText (r,c) p cs s = bpc (r,c) p cs (\(r,c) -> ((r,c + (length s)),text s))
58 71
59 72 -- ---------------------------------------------------------------------
60 73
@@ -83,7 +96,7 @@ rn (r,c) (NS (JSDecimal i) p cs) = bpText (r,c) p i
83 96
84 97 rn (r,c) (NS (JSLiteral l) p cs) = bpText (r,c) p l
85 98
86   -rn (r,c) (NS (JSUnary l) p cs = bpText (r,c) p l
  99 +rn (r,c) (NS (JSUnary l) p cs) = bpText (r,c) p l
87 100
88 101 {-
89 102

0 comments on commit 42faafb

Please sign in to comment.
Something went wrong with that request. Please try again.