Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
1836 - bugfix in paren-insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
akkartik committed Jun 14, 2012
1 parent 9df452d commit 70cfb18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
17 changes: 6 additions & 11 deletions 002parenthesize.cc
Expand Up @@ -57,18 +57,13 @@ list<Token> nextLine(CodeStream& c) {
return (*q == "(");
}

Token nthTokenInLine(list<Token> line, long n) {
list<Token>::iterator p = line.begin();
for (long i = 0; i < n; ++i)
++p;
return *p;
}

bool alreadyGrouped(list<Token> line) {
Token firstToken = nthTokenInLine(line, 1);
Token secondToken = nthTokenInLine(line, 2); // line must have 2 tokens
return firstToken == "("
|| (isQuoteOrUnquote(firstToken) && secondToken == "(");
for (list<Token>::iterator p = line.begin(); p != line.end(); ++p) {
if (p->isIndent()) continue;
if (isQuoteOrUnquote(*p)) continue;
return *p == "(";
}
return true;
}

bool continuationLine(long currLineIndent, stack<long> parenStack) {
Expand Down
15 changes: 15 additions & 0 deletions 002parenthesize.test.cc
Expand Up @@ -211,6 +211,21 @@ void test_parenthesize_passes_through_quoted_groups2() {
check(c.fd.eof());
}

void test_parenthesize_passes_through_quoted_groups3() {
CodeStream c(stream(",,(a b c)"));
list<Token> tokens = nextExpr(c);
list<Token>::iterator p = tokens.begin();
checkEq(*p, ","); ++p;
checkEq(*p, ","); ++p;
checkEq(*p, "("); ++p;
checkEq(*p, "a"); ++p;
checkEq(*p, "b"); ++p;
checkEq(*p, "c"); ++p;
checkEq(*p, ")"); ++p;
check(p == tokens.end());
check(c.fd.eof());
}

void test_parenthesize_groups_words_on_single_indented_line() {
CodeStream c(stream(" a b c\n 34"));
list<Token> tokens = nextExpr(c);
Expand Down

0 comments on commit 70cfb18

Please sign in to comment.