public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
Date: Sat,  9 Apr 2011 06:27:36 +0000 (UTC)	[thread overview]
Message-ID: <167e235cabb2528bc53e9d975053018c6b53fc04.betelgeuse@gentoo> (raw)

commit:     167e235cabb2528bc53e9d975053018c6b53fc04
Author:     Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr  8 18:00:17 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Apr  9 06:13:53 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=167e235c

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!* keyword_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["=="]
 	|	EQUALS
 	|	BANG EQUALS -> OP["!="]
 	|	LESS_THAN
 	|	GREATER_THAN;
 binary_string_op_builtin
-	:	BOP
+	:	bop
 	|	EQUALS
 	|	BANG EQUALS -> OP["!="]
 	|	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_CHAR|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_division_modulus)*;
@@ -540,8 +545,6 @@ TIMES	:	'*';
 EQUALS	:	'=';
 MINUS	:	'-';
 PLUS	:	'+';
-INC	:	'++';
-DEC	:	'--';
 EXP	:	'**';
 AMP	:	'&';
 LEQ	:	'<=';
@@ -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.gunit
index be91c42..9010822 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -25,24 +25,26 @@ primary:
 "3" -> "3"
 
 post_inc_dec:
-"b--" -> (POST_DECR b)
-"i++" -> (POST_INCR i)
+"b--" -> (POST_DECR (VAR_REF b))
+"i++" -> (POST_INCR (VAR_REF i))
 
 pre_inc_dec:
-"++i" -> (PRE_INCR i)
-"--b" -> (PRE_DECR b)
+"++i" -> (PRE_INCR (VAR_REF i))
+"--b" -> (PRE_DECR (VAR_REF b))
 
 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))))
 
 exponential:
 "8" -> "8"
@@ -120,5 +122,5 @@ arithmetics:
 
 start:
 "echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (+ 3 2)))))
-"echo $((++i))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (PRE_INCR i)))))
+"echo $((++i))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (PRE_INCR (VAR_REF i))))))
 "echo \"The solution is: $(( 3+2 ))\""-> (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING The   solution   is :   (ARITHMETIC_EXPRESSION (+ 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;
 
 cond_comparison:
-"[[ -a this/is.afile ]]" -> (COMPOUND_COND (KEYWORD_TEST (-a (STRING this / 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 / is . afile))))
+"test ! -a this/is.afile" -> (COMPOUND_COND (BUILTIN_TEST (NEGATION (a (STRING this / is . afile)))))
 "[[ asdf > qwert ]]" -> (COMPOUND_COND (KEYWORD_TEST (> (STRING asdf) (STRING qwert))))
 "[ asdf \> qwert ]" -> (COMPOUND_COND (BUILTIN_TEST (\> (STRING asdf) (STRING qwert))))
 

diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index 91eb883..b40322d 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -19,9 +19,9 @@
 gunit bashast;
 
 cond_expr:
-"[[ -a this/is.afile ]]" -> (KEYWORD_TEST (-a (STRING this / is . afile)))
-"[ -n \"yar53\" ]" -> (BUILTIN_TEST (-n (STRING (DOUBLE_QUOTED_STRING yar53))))
-"test 5 -eq 6" -> (BUILTIN_TEST (-eq 5 6))
-"[[ \"asdf\" != \"boo\" && -a filename ]]" -> (KEYWORD_TEST (&& (!= (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 yar53))))
+"test 5 -eq 6" -> (BUILTIN_TEST (eq 5 6))
+"[[ \"asdf\" != \"boo\" && -a filename ]]" -> (KEYWORD_TEST (&& (!= (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/continued_lines.gunit
index debbe1f..96f6ee4 100644
--- a/bashast/gunit/continued_lines.gunit
+++ b/bashast/gunit/continued_lines.gunit
@@ -26,4 +26,4 @@ o Hello\
 
 "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) (STRING (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[=c=]" -> (STRING ab (MATCH_PATTERN = c =))

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)) (COMMAND (STRING make) (STRING modules_install))))
 "make && make modules_install &" -> (LIST (&& (COMMAND (STRING make)) (COMMAND (STRING make) (STRING modules_install))))
-"cd /usr/bin; ls -al |grep more&& cp ./less ./more" -> (LIST (COMMAND (STRING 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 (STRING 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_command.gunit
index 6f2c2a8..cd847a8 100644
--- a/bashast/gunit/simp_command.gunit
+++ b/bashast/gunit/simp_command.gunit
@@ -24,7 +24,7 @@ simple_command:
 "asdf=5 cat out.log > result" -> (COMMAND (STRING cat) (STRING out . log) (= asdf 5) (REDIR > (STRING result)))
 "cat results.log > asdf 2> /dev/null" -> (COMMAND (STRING cat) (STRING results . log) (REDIR > (STRING asdf)) (REDIR 2 > (STRING / dev / null)))
 "i=3 g=4 h=18 grep asdf" -> (COMMAND (STRING grep) (STRING asdf) (= i 3) (= g 4) (= h 18))
-"./configure --prefix=/usr/local" -> (COMMAND (STRING . / configure) (STRING -- prefix = / usr / local))
+"./configure --prefix=/usr/local" -> (COMMAND (STRING . / configure) (STRING - -p refix = / usr / local))
 "[[while" -> (COMMAND (STRING [ [ while))
 "./foobär" -> (COMMAND (STRING . / foob ä r))
 "cat ~/Documents/todo.txt" -> (COMMAND (STRING cat) (STRING ~ / Documents / todo . txt))



             reply	other threads:[~2011-04-09  6:28 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-09  6:27 Petteri Räty [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-08-19 14:35 [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/ Petteri Räty
2012-06-03  9:08 Petteri Räty
2012-06-03  9:08 Petteri Räty
2012-06-03  9:08 Petteri Räty
2012-06-03  9:08 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-07-20 13:08 Petteri Räty
2011-07-08 14:12 Petteri Räty
2011-06-21 13:26 Petteri Räty
2011-06-21 13:20 Petteri Räty
2011-06-21 13:20 Petteri Räty
2011-06-19 19:15 Petteri Räty
2011-06-15 21:18 Petteri Räty
2011-06-14  8:28 Petteri Räty
2011-06-14  8:28 Petteri Räty
2011-06-11  8:24 Petteri Räty
2011-06-11  8:24 Petteri Räty
2011-06-09 13:41 Petteri Räty
2011-06-09 13:41 Petteri Räty
2011-06-09  8:15 Petteri Räty
2011-06-01 12:03 Petteri Räty
2011-06-01 12:03 Petteri Räty
2011-06-01 12:03 Petteri Räty
2011-06-01 12:03 Petteri Räty
2011-06-01 12:03 Petteri Räty
2011-05-23 14:34 Petteri Räty
2011-05-22 21:00 Petteri Räty
2011-05-11  7:19 Petteri Räty
2011-05-11  7:19 Petteri Räty
2011-05-11  7:19 Petteri Räty
2011-05-07 12:25 Petteri Räty
2011-04-27 15:11 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-14  4:50 Petteri Räty
2011-04-14  4:50 Petteri Räty
2011-04-14  4:50 Petteri Räty
2011-04-12  7:19 Petteri Räty
2011-04-12  7:19 Petteri Räty
2011-04-12  7:19 Petteri Räty
2011-04-12  7:19 Petteri Räty
2011-04-11  6:50 Petteri Räty
2011-04-11  6:50 Petteri Räty
2011-04-11  6:50 Petteri Räty
2011-04-11  6:50 Petteri Räty
2011-04-11  5:21 Petteri Räty
2011-04-11  5:21 Petteri Räty
2011-04-11  5:21 Petteri Räty
2011-04-11  5:21 Petteri Räty
2011-04-09  6:27 Petteri Räty
2011-04-09  6:27 Petteri Räty
2011-04-09  6:27 Petteri Räty
2011-04-08 14:26 Petteri Räty
2011-04-07 16:45 Petteri Räty
2011-04-07  7:48 Petteri Räty
2011-04-06  7:43 Petteri Räty
2011-03-30 12:48 Petteri Räty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=167e235cabb2528bc53e9d975053018c6b53fc04.betelgeuse@gentoo \
    --to=betelgeuse@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox