Skip to content

Commit

Permalink
Restructure some funs and fix split issue
Browse files Browse the repository at this point in the history
  • Loading branch information
isakb committed Aug 25, 2012
1 parent c6826b7 commit a214cec
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions beauty.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,7 @@ _ = require 'underscore'
_.str = require 'underscore.string'


WHITESPACE = ["\n", "\r", "\t", " "]

WORDCHAR = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'

DIGITS = '0123456789'

PUNCT = '''
+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> <<
>>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::
<?= <? ?> <%= <% %>
'''.split(/\s+/)

# Words which always should start on a new line
LINE_STARTERS = '''
continue try throw return var if switch case default for
while break function
'''.split(' ')

debug = (x...) -> console.info.apply(console, x) if process.env.DEBUG

# Pythonic functions etc:
None = "THIS_IS_NONE" # FIXME: replace with undefined later

len = (x) -> x.length

Expand All @@ -51,6 +30,29 @@ String::lstrip = -> @replace(/^\s+/g, '')

String::isdigit = -> /[0-9]/.test(@)


# Contants

WHITESPACE = ["\n", "\r", "\t", " "]

WORDCHAR = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'

DIGITS = '0123456789'

PUNCT = '''
+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> <<
>>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::
<?= <? ?> <%= <% %>
'''.strip().split(/\s+/)

# Words which always should start on a new line
LINE_STARTERS = '''
continue try throw return var if switch case default for
while break function
'''.strip().split(/\s+/)

debug = (x...) -> console.info.apply(console, x) if process.env.DEBUG

$ =
pos: undefined

Expand Down Expand Up @@ -109,7 +111,7 @@ class Beautifier
@last_text = '' # last token text
@last_last_text = '' # pre-last token text

@input = None
@input = undefined
@output = [] # formatted javascript gets built here


Expand Down Expand Up @@ -1129,7 +1131,7 @@ main = () ->

# js_options = default_options()

# file = None
# file = undefined
# outfile = 'stdout'
# if len(args) == 1
# file = args[0]
Expand Down

0 comments on commit a214cec

Please sign in to comment.