From 70cfb185044685240c28ccd3a2071951c3f6e06f Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 14 Jun 2012 11:16:01 -0700 Subject: [PATCH] 1836 - bugfix in paren-insertion http://arclanguage.org/item?id=16414 --- 002parenthesize.cc | 17 ++++++----------- 002parenthesize.test.cc | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/002parenthesize.cc b/002parenthesize.cc index e080fed8..9759e7e0 100644 --- a/002parenthesize.cc +++ b/002parenthesize.cc @@ -57,18 +57,13 @@ list nextLine(CodeStream& c) { return (*q == "("); } - Token nthTokenInLine(list line, long n) { - list::iterator p = line.begin(); - for (long i = 0; i < n; ++i) - ++p; - return *p; - } - bool alreadyGrouped(list line) { - Token firstToken = nthTokenInLine(line, 1); - Token secondToken = nthTokenInLine(line, 2); // line must have 2 tokens - return firstToken == "(" - || (isQuoteOrUnquote(firstToken) && secondToken == "("); + for (list::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 parenStack) { diff --git a/002parenthesize.test.cc b/002parenthesize.test.cc index 65f40dec..18d881b9 100644 --- a/002parenthesize.test.cc +++ b/002parenthesize.test.cc @@ -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 tokens = nextExpr(c); + list::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 tokens = nextExpr(c);