Last active
June 6, 2016 14:00
-
-
Save Fresheyeball/94e25fcefc517a74382e55283eec9093 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Debug.Pretty exposing (..) | |
import String | |
import Native.Pretty | |
type alias Model = | |
( Int, List Char ) | |
n : Char | |
n = | |
Native.Pretty.n | |
t : Char | |
t = | |
Native.Pretty.t | |
tab : Int -> List Char | |
tab depth = | |
[ n ] ++ List.repeat depth t | |
type alias Parse = | |
{ depth : Int | |
, isTup : Bool | |
, isList : Bool | |
, res : List Char | |
} | |
init : Parse | |
init = | |
{ depth = 1 | |
, isTup = False | |
, isList = False | |
, res = [] | |
} | |
newlineOnOpen : Char -> Parse -> Parse | |
newlineOnOpen char ({ depth, isTup, isList, res } as parse) = | |
let | |
charAdded = | |
{ parse | res = res ++ [ char ] } | |
in | |
case char of | |
'{' -> | |
{ parse | |
| depth = depth + 1 | |
, res = res ++ tab (depth + 1) ++ [ char ] | |
} | |
'}' -> | |
{ parse | |
| depth = depth - 1 | |
, res = res ++ tab depth ++ [ char ] | |
} | |
',' -> | |
let | |
tabs = if isTup || isList | |
then [] | |
else tab depth | |
in | |
{ parse | |
| res = | |
res ++ tabs ++ [ char ] | |
} | |
'(' -> | |
{ charAdded | isTup = True } | |
')' -> | |
{ charAdded | isTup = False } | |
'[' -> | |
{ charAdded | isList = True } | |
']' -> | |
{ charAdded | isList = False } | |
_ -> | |
charAdded | |
pretty : String -> String | |
pretty = | |
String.toList | |
>> List.foldl newlineOnOpen init | |
>> .res | |
>> String.fromList | |
log : String -> a -> a | |
log s a = | |
toString a | |
|> pretty | |
|> Native.Pretty.log s | |
|> always a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global F2*/ | |
/*eslint camelcase: 0*/ | |
/*eslint no-unused-vars: 0*/ | |
/* | |
* Direct `String` access to `console.log`. | |
* Needed because `Debug.log` doesn't pretty print. | |
*/ | |
var _capillary$customer$Native_Pretty = (function () { | |
function log (tag, value) { | |
var msg = tag + ': ' + value | |
console.log(msg) | |
return value | |
} | |
return { | |
log: F2(log), | |
// expose newline and tabs special chars | |
n: '\n', | |
t: '\t' | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment