From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QK3iU-0003v0-Lm for garchives@archives.gentoo.org; Wed, 11 May 2011 07:20:19 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CDDC81C0D0; Wed, 11 May 2011 07:19:36 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 841541C0D0 for ; Wed, 11 May 2011 07:19:36 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 357731B40BA for ; Wed, 11 May 2011 07:19:36 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 9CEA880062 for ; Wed, 11 May 2011 07:19:35 +0000 (UTC) From: "Petteri Räty" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Petteri Räty" Message-ID: <63ee3c1c1242562685bf78b58a662204bf5e6c42.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/libbashWalker.g scripts/compound_command.bash scripts/compound_command.bash.result X-VCS-Directories: scripts/ bashast/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 63ee3c1c1242562685bf78b58a662204bf5e6c42 Date: Wed, 11 May 2011 07:19:35 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 16d837dbe47e349ac85cab230645416a commit: 63ee3c1c1242562685bf78b58a662204bf5e6c42 Author: Mu Qiao gentoo org> AuthorDate: Mon May 9 10:38:10 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Wed May 11 06:46:28 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D63ee3c1c Walker: support ranged pattern Patterns like [a-z] and [!0-9] are supported. --- bashast/libbashWalker.g | 36 ++++++++++++++++++++++++++++= +---- scripts/compound_command.bash | 25 +++++++++++++++++++++++ scripts/compound_command.bash.result | 5 +++- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 38cd459..c3ef8ac 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -209,6 +209,7 @@ bash_pattern[boost::xpressive::sregex& pattern] using namespace boost::xpressive; bool do_append =3D false; bool negation; + std::string pattern_str; } :^(STRING ( (DOUBLE_QUOTED_STRING) =3D> @@ -222,13 +223,38 @@ bash_pattern[boost::xpressive::sregex& pattern] append($pattern, _, do_append); } |(MATCH_ANY_EXCEPT|MATCH_PATTERN) =3D> - ^((MATCH_ANY_EXCEPT { negation =3D true; } | MATCH_PATTERN { negation = =3D false;}) s=3Dstring_part) { - if(s.libbash_value.empty()) + ^((MATCH_ANY_EXCEPT { negation =3D true; } | MATCH_PATTERN { negation = =3D false; }) + (s=3Dstring_part { pattern_str +=3D s.libbash_value; })+) { + if(pattern_str.empty()) return; =20 - auto char_set =3D set =3D as_xpr(s.libbash_value[0]); - for(auto iter =3D s.libbash_value.begin() + 1; iter !=3D s.libbash_va= lue.end(); ++iter) - char_set =3D (char_set | *iter); + // deal with the first character specially + int index =3D 0; + auto char_set =3D set =3D as_xpr(pattern_str[0]); + if( index + 1 < pattern_str.size() && pattern_str[index + 1] =3D=3D '= -') + { + char_set =3D set[range(pattern_str[index], pattern_str[index + 2])]; + index +=3D 3; + } + else + { + ++index; + } + + // handle all characters in the pattern + while(index < pattern_str.size()) + { + if( index + 1 < pattern_str.size() && pattern_str[index + 1] =3D=3D = '-') + { + char_set |=3D range(pattern_str[index], pattern_str[index + 2]); + index +=3D 3; + } + else + { + char_set |=3D pattern_str[index]; + ++index; + } + } =20 if(negation) append($pattern, ~char_set, do_append); diff --git a/scripts/compound_command.bash b/scripts/compound_command.bas= h index 3a3c5d8..a75898f 100644 --- a/scripts/compound_command.bash +++ b/scripts/compound_command.bash @@ -135,4 +135,29 @@ case $target in echo yep ;; esac +case $target in + [d-z]) + echo "Shouldn't print this" + ;; + [a-c]) + echo yep + ;; +esac +case $target in + [!a-c]) + echo "Shouldn't print this" + ;; + [!d-z]) + echo yep + ;; +esac +target=3Dbar +case $target in + a[a-cx-z]r) + echo "Shouldn't print this" + ;; + b[!d-fx-z]r) + echo yep + ;; +esac echo "case end" diff --git a/scripts/compound_command.bash.result b/scripts/compound_comm= and.bash.result index 1ee0f91..255c8eb 100644 --- a/scripts/compound_command.bash.result +++ b/scripts/compound_command.bash.result @@ -28,10 +28,13 @@ default yep yep yep +yep +yep +yep case end a=3D1 b=3D2 file=3D foo bar=20 foo=3Dghi i=3D4 -target=3Da +target=3Dbar