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 1Q8ReT-0004qY-QE for garchives@archives.gentoo.org; Sat, 09 Apr 2011 06:28:10 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id F1D061C00D; Sat, 9 Apr 2011 06:27:37 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id A06651C00D for ; Sat, 9 Apr 2011 06:27:37 +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 2328B1B404B for ; Sat, 9 Apr 2011 06:27:37 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 5AD5480076 for ; Sat, 9 Apr 2011 06:27:36 +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: <167e235cabb2528bc53e9d975053018c6b53fc04.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/bashast.g bashast/gunit/arith_main.gunit bashast/gunit/compound.gunit bashast/gunit/cond_main.gunit bashast/gunit/continued_lines.gunit bashast/gunit/fname.gunit bashast/gunit/list.gunit bashast/gunit/simp_command.gunit X-VCS-Directories: bashast/ bashast/gunit/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 167e235cabb2528bc53e9d975053018c6b53fc04 Date: Sat, 9 Apr 2011 06:27:36 +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: 9f007a09977445da3ee57c8b13786bbe commit: 167e235cabb2528bc53e9d975053018c6b53fc04 Author: Petteri R=C3=A4ty petteriraty eu> AuthorDate: Fri Apr 8 18:00:17 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Sat Apr 9 06:13:53 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D167e235c Improve support for arithmetic expressions Things like double negation $((!!a)) were not supported. Fixing this resulted in bubbled changes elsewhere. The main change is that we have less specialized tokens so that we don't end up with special tokens in wrong contexts. --- bashast/bashast.g | 44 +++++++++++++++++++----------= ------ bashast/gunit/arith_main.gunit | 22 +++++++++-------- bashast/gunit/compound.gunit | 6 ++-- bashast/gunit/cond_main.gunit | 8 +++--- bashast/gunit/continued_lines.gunit | 2 +- bashast/gunit/fname.gunit | 6 ++-- bashast/gunit/list.gunit | 2 +- bashast/gunit/simp_command.gunit | 2 +- 8 files changed, 49 insertions(+), 43 deletions(-) diff --git a/bashast/bashast.g b/bashast/bashast.g index 2b4e713..bf07b7f 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -98,7 +98,7 @@ pipeline | BLANK!* time? (BANG BLANK!+)? command^ (BLANK!* PIPE^ BLANK!* command= )*; time : TIME^ BLANK!+ time_posix?; time_posix - : '-p' BLANK!+; + : TIME_POSIX BLANK!+; //The structure of a command in bash command : EXPORT^ var_def+ @@ -286,7 +286,7 @@ cond_primary keyword_cond_binary : cond_part BLANK!* binary_str_op_keyword^ BLANK!? cond_part; keyword_cond_unary - : UOP^ BLANK!+ cond_part; + : uop^ BLANK!+ cond_part; builtin_cond_primary : LPAREN! BLANK!* builtin_cond BLANK!* RPAREN! | builtin_cond_binary @@ -295,7 +295,7 @@ builtin_cond_primary builtin_cond_binary : cond_part BLANK!* binary_string_op_builtin^ BLANK!? cond_part; builtin_cond_unary - : UOP^ BLANK!+ cond_part; + : uop^ BLANK!+ cond_part; keyword_cond : (negate_primary|cond_primary) (BLANK!* (LOGICOR^|LOGICAND^) BLANK!* k= eyword_cond)?; builtin_cond @@ -305,20 +305,22 @@ negate_primary negate_builtin_primary : BANG BLANK+ builtin_cond_primary -> ^(NEGATION builtin_cond_primary); binary_str_op_keyword - : BOP + : bop | EQUALS EQUALS -> OP["=3D=3D"] | EQUALS | BANG EQUALS -> OP["!=3D"] | LESS_THAN | GREATER_THAN; binary_string_op_builtin - : BOP + : bop | EQUALS | BANG EQUALS -> OP["!=3D"] | ESC_LT | ESC_GT; +bop : MINUS! NAME^; unary_cond - : UOP^ BLANK! cond_part; + : uop^ BLANK! cond_part; +uop : MINUS! LETTER; //Allowable parts of conditions cond_part: brace_expansion | var_ref @@ -363,7 +365,11 @@ ns_str_part //Parts of strings, no slashes, no reserved words ns_str_part_no_res : num - | name|OTHER|EQUALS|PCT|PCTPCT|MINUS|DOT|DOTDOT|COLON|BOP|UOP|TEST_EXPR= |'_'|TILDE|INC|DEC|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_= ASSIGN|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|OR_ASSIGN|ESC_CH= AR|CARET; + | name + |OTHER|EQUALS|PCT|PCTPCT|MINUS|DOT|DOTDOT|COLON|TEST_EXPR|'_' + |TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN + |TIME_POSIX|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN + |OR_ASSIGN|ESC_CHAR|CARET; //strings with no slashes, used in certain variable expansions ns_str : ns_str_part* -> ^(STRING ns_str_part*); //Generic strings/filenames. @@ -452,20 +458,19 @@ primary : num | name -> ^(VAR_REF name) | LPAREN! (arithmetics) RPAREN!; post_inc_dec - : name BLANK?INC -> ^(POST_INCR name) - | name BLANK?DEC -> ^(POST_DECR name); + : primary BLANK? PLUS PLUS -> ^(POST_INCR primary) + | primary BLANK? MINUS MINUS -> ^(POST_DECR primary); pre_inc_dec - : INC BLANK?name -> ^(PRE_INCR name) - | DEC BLANK?name -> ^(PRE_DECR name); + : PLUS PLUS BLANK? primary -> ^(PRE_INCR primary) + | MINUS MINUS BLANK? primary -> ^(PRE_DECR primary); unary : post_inc_dec | pre_inc_dec | primary - | PLUS primary -> ^(PLUS_SIGN primary) - | MINUS primary -> ^(MINUS_SIGN primary); -negation - : (BANG^BLANK!?|TILDE^BLANK!?)?unary; + | PLUS unary -> ^(PLUS_SIGN unary) + | MINUS unary -> ^(MINUS_SIGN unary) + | (TILDE|BANG)^ unary; exponential - : negation (BLANK!* EXP^ BLANK!* negation)* ; + : unary (BLANK!* EXP^ BLANK!* unary)* ; times_division_modulus : exponential (BLANK!* (TIMES^|SLASH^|PCT^) BLANK!* exponential)*; addsub : times_division_modulus (BLANK!* (PLUS^|MINUS^)BLANK!* times_div= ision_modulus)*; @@ -540,8 +545,6 @@ TIMES : '*'; EQUALS : '=3D'; MINUS : '-'; PLUS : '+'; -INC : '++'; -DEC : '--'; EXP : '**'; AMP : '&'; LEQ : '<=3D'; @@ -600,8 +603,6 @@ TEST_EXPR : 'test'; LOGICAND : '&&'; LOGICOR : '||'; -BOP : MINUS LETTER LETTER; -UOP : MINUS LETTER; //Some builtins EXPORT : 'export'; //Tokens for strings @@ -613,6 +614,9 @@ ESC_LPAREN : '\\' LPAREN; ESC_LT : '\\''<'; ESC_GT : '\\''>'; +//For pipeline +TIME_POSIX + : '-p'; //Handle ANSI C escaped characters: escaped octal, escaped hex, escaped = ctrl+ chars, then all others ESC_CHAR: '\\' (('0'..'7')('0'..'7')('0'..'7')?|'x'('0'..'9'|'a'..'f'|'A= '..'F')('0'..'9'|'a'..'f'|'A'..'F')?|'c'.|.); NAME : (LETTER|'_')(ALPHANUM|'_')+; diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gu= nit index be91c42..9010822 100644 --- a/bashast/gunit/arith_main.gunit +++ b/bashast/gunit/arith_main.gunit @@ -25,24 +25,26 @@ primary: "3" -> "3" =20 post_inc_dec: -"b--" -> (POST_DECR b) -"i++" -> (POST_INCR i) +"b--" -> (POST_DECR (VAR_REF b)) +"i++" -> (POST_INCR (VAR_REF i)) =20 pre_inc_dec: -"++i" -> (PRE_INCR i) -"--b" -> (PRE_DECR b) +"++i" -> (PRE_INCR (VAR_REF i)) +"--b" -> (PRE_DECR (VAR_REF b)) =20 unary: "6" -> "6" "+9" -> (PLUS_SIGN 9) "-15" -> (MINUS_SIGN 15) -"++ z" -> (PRE_INCR z) -"f--" -> (POST_DECR f) - -negation: -"8" -> "8" +"++ z" -> (PRE_INCR (VAR_REF z)) +"f--" -> (POST_DECR (VAR_REF f)) "~8" -> (~ 8) "!8" -> (! 8) +"!!8" -> (! (! 8)) +"--8" -> (PRE_DECR 8) +"+++${a}" -> (PLUS_SIGN (PRE_INCR (VAR_REF a))) +"++++${a}" -> (PLUS_SIGN (PLUS_SIGN (PRE_INCR (VAR_REF a)))) +"+-++${a}" -> (PLUS_SIGN (MINUS_SIGN (PRE_INCR (VAR_REF a)))) =20 exponential: "8" -> "8" @@ -120,5 +122,5 @@ arithmetics: =20 start: "echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_= EXPRESSION (+ 3 2))))) -"echo $((++i))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPR= ESSION (PRE_INCR i))))) +"echo $((++i))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPR= ESSION (PRE_INCR (VAR_REF i)))))) "echo \"The solution is: $(( 3+2 ))\""-> (LIST (COMMAND (STRING echo) (S= TRING (DOUBLE_QUOTED_STRING The solution is : (ARITHMETIC_EXPRESSIO= N (+ 3 2)))))) diff --git a/bashast/gunit/compound.gunit b/bashast/gunit/compound.gunit index 2e0c795..b8e8ef6 100644 --- a/bashast/gunit/compound.gunit +++ b/bashast/gunit/compound.gunit @@ -19,12 +19,12 @@ gunit bashast; =20 cond_comparison: -"[[ -a this/is.afile ]]" -> (COMPOUND_COND (KEYWORD_TEST (-a (STRING thi= s / is . afile)))) +"[[ -a this/is.afile ]]" -> (COMPOUND_COND (KEYWORD_TEST (a (STRING this= / is . afile)))) "[[ -a this/is.afile]]" FAIL "[[-a this/is.afile ]]" FAIL "[[ --a this/is.afile ]]" -> (COMPOUND_COND (KEYWORD_TEST (-a (STRING this / = is . afile)))) -"test ! -a this/is.afile" -> (COMPOUND_COND (BUILTIN_TEST (NEGATION (-a = (STRING this / is . afile))))) +-a this/is.afile ]]" -> (COMPOUND_COND (KEYWORD_TEST (a (STRING this / i= s . afile)))) +"test ! -a this/is.afile" -> (COMPOUND_COND (BUILTIN_TEST (NEGATION (a (= STRING this / is . afile))))) "[[ asdf > qwert ]]" -> (COMPOUND_COND (KEYWORD_TEST (> (STRING asdf) (S= TRING qwert)))) "[ asdf \> qwert ]" -> (COMPOUND_COND (BUILTIN_TEST (\> (STRING asdf) (S= TRING qwert)))) =20 diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.guni= t index 91eb883..b40322d 100644 --- a/bashast/gunit/cond_main.gunit +++ b/bashast/gunit/cond_main.gunit @@ -19,9 +19,9 @@ gunit bashast; =20 cond_expr: -"[[ -a this/is.afile ]]" -> (KEYWORD_TEST (-a (STRING this / is . afile)= )) -"[ -n \"yar53\" ]" -> (BUILTIN_TEST (-n (STRING (DOUBLE_QUOTED_STRING ya= r53)))) -"test 5 -eq 6" -> (BUILTIN_TEST (-eq 5 6)) -"[[ \"asdf\" !=3D \"boo\" && -a filename ]]" -> (KEYWORD_TEST (&& (!=3D = (STRING (DOUBLE_QUOTED_STRING asdf)) (STRING (DOUBLE_QUOTED_STRING boo)))= (-a (STRING filename)))) +"[[ -a this/is.afile ]]" -> (KEYWORD_TEST (a (STRING this / is . afile))= ) +"[ -n \"yar53\" ]" -> (BUILTIN_TEST (n (STRING (DOUBLE_QUOTED_STRING yar= 53)))) +"test 5 -eq 6" -> (BUILTIN_TEST (eq 5 6)) +"[[ \"asdf\" !=3D \"boo\" && -a filename ]]" -> (KEYWORD_TEST (&& (!=3D = (STRING (DOUBLE_QUOTED_STRING asdf)) (STRING (DOUBLE_QUOTED_STRING boo)))= (a (STRING filename)))) "[[ true ]]" -> (KEYWORD_TEST (STRING true)) "[[ true && (false || three) ]]" -> (KEYWORD_TEST (&& (STRING true) (|| = (STRING false) (STRING three)))) diff --git a/bashast/gunit/continued_lines.gunit b/bashast/gunit/continue= d_lines.gunit index debbe1f..96f6ee4 100644 --- a/bashast/gunit/continued_lines.gunit +++ b/bashast/gunit/continued_lines.gunit @@ -26,4 +26,4 @@ o Hello\ =20 "sed -i \ -e 's/three/\ - four/'" -> (LIST (COMMAND (STRING sed) (STRING -i) (STRING -e) (STRING= (SINGLE_QUOTED_STRING s / three / four /)))) + four/'" -> (LIST (COMMAND (STRING sed) (STRING - i) (STRING - e) (STRI= NG (SINGLE_QUOTED_STRING s / three / four /)))) diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit index 4596f23..0272c37 100644 --- a/bashast/gunit/fname.gunit +++ b/bashast/gunit/fname.gunit @@ -49,9 +49,9 @@ fname: "tab\\ttab" -> "(STRING tab \\\t tab)" "abc[def]" -> (STRING abc (MATCH_PATTERN def)) "a[]" -> (STRING a [ ]) -"ab[d-h]" -> (STRING ab (MATCH_PATTERN d -h)) -"ab[!d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d -h)) -"ab[^d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d -h)) +"ab[d-h]" -> (STRING ab (MATCH_PATTERN d - h)) +"ab[!d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d - h)) +"ab[^d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d - h)) "ab[]c]" -> (STRING ab (MATCH_PATTERN ] c)) "ab[:alpha:]" -> (STRING ab (MATCH_PATTERN : alpha :)) "ab[=3Dc=3D]" -> (STRING ab (MATCH_PATTERN =3D c =3D)) diff --git a/bashast/gunit/list.gunit b/bashast/gunit/list.gunit index 04b3243..f21f014 100644 --- a/bashast/gunit/list.gunit +++ b/bashast/gunit/list.gunit @@ -22,7 +22,7 @@ list: "make" -> (LIST (COMMAND (STRING make))) "make && make modules_install;" -> (LIST (&& (COMMAND (STRING make)) (CO= MMAND (STRING make) (STRING modules_install)))) "make && make modules_install &" -> (LIST (&& (COMMAND (STRING make)) (C= OMMAND (STRING make) (STRING modules_install)))) -"cd /usr/bin; ls -al |grep more&& cp ./less ./more" -> (LIST (COMMAND (S= TRING cd) (STRING / usr / bin)) (&& (| (COMMAND (STRING ls) (STRING -al))= (COMMAND (STRING grep) (STRING more))) (COMMAND (STRING cp) (STRING . / = less) (STRING . / more)))) +"cd /usr/bin; ls -al |grep more&& cp ./less ./more" -> (LIST (COMMAND (S= TRING cd) (STRING / usr / bin)) (&& (| (COMMAND (STRING ls) (STRING - al)= ) (COMMAND (STRING grep) (STRING more))) (COMMAND (STRING cp) (STRING . /= less) (STRING . / more)))) "mkdir test cd test cp ../asdf.tar.gz . diff --git a/bashast/gunit/simp_command.gunit b/bashast/gunit/simp_comman= d.gunit index 6f2c2a8..cd847a8 100644 --- a/bashast/gunit/simp_command.gunit +++ b/bashast/gunit/simp_command.gunit @@ -24,7 +24,7 @@ simple_command: "asdf=3D5 cat out.log > result" -> (COMMAND (STRING cat) (STRING out . l= og) (=3D asdf 5) (REDIR > (STRING result))) "cat results.log > asdf 2> /dev/null" -> (COMMAND (STRING cat) (STRING r= esults . log) (REDIR > (STRING asdf)) (REDIR 2 > (STRING / dev / null))) "i=3D3 g=3D4 h=3D18 grep asdf" -> (COMMAND (STRING grep) (STRING asdf) (= =3D i 3) (=3D g 4) (=3D h 18)) -"./configure --prefix=3D/usr/local" -> (COMMAND (STRING . / configure) (= STRING -- prefix =3D / usr / local)) +"./configure --prefix=3D/usr/local" -> (COMMAND (STRING . / configure) (= STRING - -p refix =3D / usr / local)) "[[while" -> (COMMAND (STRING [ [ while)) "./foob=C3=A4r" -> (COMMAND (STRING . / foob =C3=A4 r)) "cat ~/Documents/todo.txt" -> (COMMAND (STRING cat) (STRING ~ / Document= s / todo . txt))