Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

More harvesting commonality.

  • Loading branch information...
commit 9b48077303663f2c831e6ad3e2a43588e09139dc 1 parent 3b4f442
Alan Zimmerman authored February 28, 2012

Showing 1 changed file with 19 additions and 8 deletions. Show diff stats Hide diff stats

  1. 27  src/Language/JavaScript/Pretty/Printer.hs
27  src/Language/JavaScript/Pretty/Printer.hs
@@ -47,6 +47,15 @@ bp (r,c) p f = ((r'',c''),bb <> bb')
47 47
     ((r',c'),bb) = skipTo (r,c) p
48 48
     ((r'',c''),bb') = f (r',c')
49 49
 
  50
+bprJS
  51
+  :: (Int, Int) -> TokenPosn -> [JSNode] -> ((Int, Int), BB.Builder)
  52
+bprJS (r,c) p xs = bp (r,c) p (\(r,c) -> rJS (r,c) xs)
  53
+
  54
+bpText
  55
+  :: (Int, Int) -> TokenPosn -> [Char] -> ((Int, Int), BB.Builder)
  56
+bpText (r,c) p s = bp (r,c) p (\(r,c) -> ((r,c + (length s)),text s))
  57
+
  58
+
50 59
 -- ---------------------------------------------------------------------
51 60
 
52 61
 renderJS :: JSNode -> BB.Builder
@@ -61,16 +70,20 @@ rn (r,c) (NS (JSEmpty l) p cs) = do
61 70
   (r',c') <- skipTo (r,c) p
62 71
   return (rn (r',c') l)
63 72
 -}
64  
-rn (r,c) (NS (JSSourceElementsTop xs) p cs) = bp (r,c) p (\(r,c) -> rJS (r,c) xs)
65  
-rn (r,c) (NS (JSSourceElements    xs) p cs) = bp (r,c) p (\(r,c) -> rJS (r,c) xs)
  73
+rn (r,c) (NS (JSSourceElementsTop xs) p cs) = bprJS (r,c) p xs
  74
+rn (r,c) (NS (JSSourceElements    xs) p cs) = bprJS (r,c) p xs
  75
+
  76
+rn (r,c) (NS (JSExpression xs) p cs)        = bprJS (r,c) p xs
  77
+
  78
+rn (r,c) (NS (JSIdentifier s) p cs)         = bpText (r,c) p s
66 79
 
67  
-rn (r,c) (NS (JSExpression xs) p cs)        = bp (r,c) p (\(r,c) -> rJS (r,c) xs)
  80
+rn (r,c) (NS (JSOperator s) p cs)           = bpText (r,c) p s
68 81
 
69  
-rn (r,c) (NS (JSIdentifier s) p cs)         = bp (r,c) p (\(r,c) -> ((r,c + (length s)),text s))
  82
+rn (r,c) (NS (JSDecimal i) p cs)            = bpText (r,c) p i
70 83
 
71  
-rn (r,c) (NS (JSOperator s) p cs)           = bp (r,c) p (\(r,c) -> ((r,c + (length s)),text s))
  84
+rn (r,c) (NS (JSLiteral l) p cs)            = bpText (r,c) p l
72 85
 
73  
-rn (r,c) (NS (JSDecimal i) p cs)            = bp (r,c) p (\(r,c) -> ((r,c + (length i)),text i))
  86
+rn (r,c) (NS (JSUnary l) p cs               = bpText (r,c) p l
74 87
 
75 88
 {-
76 89
 
@@ -91,9 +104,7 @@ rn (JSIfElse c t e)        = (text "if") <> (text "(") <> (renderJS c) <> (text
91 104
                                    <> (text "else") <> (spaceOrBlock e)
92 105
 rn (JSMemberDot xs y)        = (rJS xs) <> (text ".") <> (renderJS y)
93 106
 rn (JSMemberSquare xs x)   = (rJS xs) <> (text "[") <> (renderJS x) <> (text "]")
94  
-rn (JSLiteral l)           = (text l)
95 107
 rn (JSStringLiteral s l)   = empty <> (char s) <> (text l) <> (char s)
96  
-rn (JSUnary l  )           = text l
97 108
 rn (JSArrayLiteral xs)     = (text "[") <> (rJS xs) <> (text "]")
98 109
 
99 110
 rn (JSBreak [] [])            = (text "break")

0 notes on commit 9b48077

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