Created
June 10, 2014 10:40
-
-
Save fpinzn/11a4dc53dabf3be7a173 to your computer and use it in GitHub Desktop.
This file contains 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
{head, group-by, lines, take-while} = require 'prelude-ls' | |
fs = require 'fs' | |
#aliases | |
CL = console.log | |
#returns the lines in the N level of indentation | |
# Usage: indentificator file [level] | |
# If no level is provided all levels will be printed | |
# TODO: receive char-value (tab-space equivalency)as an arg of the program | |
char-value = {'\t': 1, ' ': 0.5} | |
file = process.argv[2] | |
level = process.argv[3] | |
# INPUT transformation | |
indentation-grouper= (a)-> | |
char0 = head a | |
char0-count = take-while (in ['\t',' ']), a .length | |
char0-count * char-value[char0] | |
#PROCESS | |
fs.readFile "./#{file}", 'utf8', (err, data)-> | |
groups = group-by indentation-grouper, lines data | |
#Remove the group of the lines that don't have indentation | |
delete groups[NaN] | |
CL if level? then groups[level] else groups |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment