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 1QSTix-0002cu-Bn for garchives@archives.gentoo.org; Fri, 03 Jun 2011 12:43:35 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2D2BB1C095; Fri, 3 Jun 2011 12:43:18 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id DEBC41C013 for ; Fri, 3 Jun 2011 12:43:17 +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 632911B402F for ; Fri, 3 Jun 2011 12:43:17 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id BB7BC80506 for ; Fri, 3 Jun 2011 12:43:16 +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: <752ef90a75d20aa62b34bd4efa04db5a75c581cf.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/libbashWalker.g scripts/test_expr.bash scripts/test_expr.bash.result X-VCS-Directories: scripts/ bashast/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 752ef90a75d20aa62b34bd4efa04db5a75c581cf Date: Fri, 3 Jun 2011 12:43:16 +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: 36e25040bcb5df4b33afef347652f6ab commit: 752ef90a75d20aa62b34bd4efa04db5a75c581cf Author: Mu Qiao gentoo org> AuthorDate: Tue May 31 12:02:07 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Wed Jun 1 06:12:50 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D752ef90a Walker: support pattern matching in keyword test --- bashast/libbashWalker.g | 17 +++++++++++++---- scripts/test_expr.bash | 6 ++++++ scripts/test_expr.bash.result | 3 +++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index f53a2be..a55e0b2 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -551,6 +551,9 @@ cond_expr |^(KEYWORD_TEST status=3Dkeyword_condition) { walker->set_status(!statu= s); }; =20 common_condition returns[bool status] +@declarations { + boost::xpressive::sregex pattern; +} // -eq, -ne, -lt, -le, -gt, or -ge for arithmetic. -nt -ot -ef for file= s :^(NAME left_str=3Dstring_expr right_str=3Dstring_expr) { $status =3D internal::test_binary(walker->get_string($NAME), left_str.= libbash_value, right_str.libbash_value); @@ -560,14 +563,20 @@ common_condition returns[bool status] $status =3D internal::test_unary(*reinterpret_cast(op->g= etToken(op)->start), $string_expr.libbash_value); } - // We do not trigger pattern matching for now - |^((EQUALS|MATCH_PATTERN) left_str=3Dstring_expr right_str=3Dstring_exp= r) { + |^(EQUALS left_str=3Dstring_expr right_str=3Dstring_expr) { $status =3D left_str.libbash_value =3D=3D right_str.libbash_value; } - // We do not trigger pattern matching for now - |^((NOT_EQUALS|NOT_MATCH_PATTERN) left_str=3Dstring_expr right_str=3Dst= ring_expr) { + // Greedy is meaningless as we need to match the whole string + |^(MATCH_PATTERN left_str=3Dstring_expr bash_pattern[pattern, false]) { + $status =3D match(left_str.libbash_value, pattern); + } + |^(NOT_EQUALS left_str=3Dstring_expr right_str=3Dstring_expr) { $status =3D left_str.libbash_value !=3D right_str.libbash_value; } + // Greedy is meaningless as we need to match the whole string + |^(NOT_MATCH_PATTERN left_str=3Dstring_expr bash_pattern[pattern, false= ]) { + $status =3D !match(left_str.libbash_value, pattern); + } |^(LESS_THAN left_str=3Dstring_expr right_str=3Dstring_expr) { $status =3D left_str.libbash_value < right_str.libbash_value; } diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash index f89287b..79398dd 100644 --- a/scripts/test_expr.bash +++ b/scripts/test_expr.bash @@ -38,3 +38,9 @@ echo $? # 0 [[ -a "/" ]] && echo "true10" [[ . -ef . ]] && echo "true11" [[ 2 -ge 2 ]] && echo "true12" +[[ "abc def xyz" =3D=3D *"def"* ]] && echo "true13" +[[ "abc def xyz" =3D=3D *"defg"* ]] && echo "wrong" +[[ "abc def xyz" !=3D *"def"* ]] && echo "wrong" +[[ "abc def xyz" !=3D *"defg"* ]] && echo "true14" +shopt -s extglob +[[ "123" =3D=3D *([[:digit:]]) ]] && echo "true15" diff --git a/scripts/test_expr.bash.result b/scripts/test_expr.bash.resul= t index d045597..653200b 100644 --- a/scripts/test_expr.bash.result +++ b/scripts/test_expr.bash.result @@ -19,3 +19,6 @@ true9 true10 true11 true12 +true13 +true14 +true15