Skip to content

Commit

Permalink
fix crlf bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hsk committed Jul 26, 2015
1 parent 4adf4f2 commit 88250ed
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions beautifier/beauty.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def __repr__(self):
NestM = Nest("NestM", -1)


reg2 = re.compile(r'(^.*\n.*$)')
whiteSpace = re.compile(r'(^\s*$)')
reg2 = re.compile(r'\n')
whiteSpace = re.compile(r'^(\s|\s*\(\*)')
reg1 = re.compile(r'\n')


Expand All @@ -178,7 +178,7 @@ def cnv(e):
i = 0
while(i < len(e)):
s = [e[i]]
if isinstance(s[0], basestring) and reg2.search(s[0]) is not None:
if isinstance(s[0], basestring) and reg2.search(s[0]) is not None and whiteSpace.search(s[0]) is not None:
s = []
while(i < len(e)):
s2 = e[i]
Expand All @@ -200,11 +200,11 @@ def cnv(e):
else:
m = reg2.search(s)
if m is not None:
s = reg1.sub("\n"+(" " * nest), m.group(0))
s = reg1.sub("\n"+(" " * nest), s)
e3.append(s)
return "".join(e3)

keywords = reg(r"^(let|in|if|else|then|rec|begin|end|match|try|with|type|open|struct|module|and|while|do|done)\b")
keywords = reg(r"^(let|in|if|else|then|rec|begin|end|match|try|with|function|fun|type|open|struct|module|and|while|do|done)\b")

semi = notp(";;") >> p(";")

Expand All @@ -213,9 +213,9 @@ def cnv(e):

id = orp(
notp(keywords) >> reg(r"^[_a-zA-Z0-9]+"),
reg(r'^[+\-*\/.<>:@=^]+') ^ (lambda i: i if re.search(r'^(=|->)$', i[1]) is None else None),
reg(r'^[+\-*/.<>:@=^|~?]+') ^ (lambda i: i if re.search(r'^(=|->|\|)$', i[1]) is None else None),
reg(r'^[,!]'),
reg(r'^("(\\.|[^"])*")')
reg(r'^("(\\.|[^"])*"|\'(\\.|[^\'])*\')')
)

sexp = orp(
Expand All @@ -230,10 +230,11 @@ def cnv(e):

exp1 = orp(
p("let", opt("rec"), app, "=", -p[exps], "in", exp),
p("if", -exps, "then", -exps, "else", exp),
p("if", -exps, "then", -p(lambda i: exp3(i)), orp(semi, p("else", exp))),
p("match", -exps, "with", opt("|"), -exps, rep["|", -exps]),
p("try", -exps, "with", opt("|"), -exps, rep["|", -exps]),
p("function", opt("|"), -exps, rep("|", -exps)),
p("fun", opt("|"), -exps, rep("|", -exps)),
p("while", -exps, "do", -exps, "done"),
app
)
Expand Down Expand Up @@ -261,7 +262,7 @@ def cnv(e):
p("module", -p[app], "=", struct)
)

regparse = re.compile(r"^[\s]+", re.M)
regparse = re.compile(r"^[ \t]+", re.M)


def parse(s):
Expand Down

0 comments on commit 88250ed

Please sign in to comment.