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: scripts/, bashast/
Date: Tue, 12 Apr 2011 18:29:22 +0000 (UTC)	[thread overview]
Message-ID: <5b7cec85d9adeaee707cb3e74122c70aa96c6518.betelgeuse@gentoo> (raw)

commit:     5b7cec85d9adeaee707cb3e74122c70aa96c6518
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 12 07:19:42 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Apr 12 12:08:11 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=5b7cec85

Implement array element reference for string

Now we can refer an array element as a string value.

---
 bashast/libbashWalker.g       |   96 ++++++++++++++++++++++++-----------------
 scripts/var_def.ebuild        |    3 +-
 scripts/var_def.ebuild.result |    3 +-
 3 files changed, 60 insertions(+), 42 deletions(-)

diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 33c18a6..1061c3f 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -45,11 +45,23 @@ start: list|EOF;
 
 list: ^(LIST var_def+);
 
-name	returns[std::string libbash_value]:
+name_base	returns[std::string libbash_value]:
 	NAME {$libbash_value = walker->get_string($NAME);}
 	|	LETTER {$libbash_value = walker->get_string($LETTER);}
 	|	'_' {$libbash_value="_";};
 
+name	returns[std::string libbash_value, unsigned index]
+@init {
+	$index = 0;
+}:
+	^(libbash_name=name_base value=arithmetics){
+		$index = value;
+		$libbash_value = libbash_name;
+	}
+	|libbash_name=name_base{
+		$libbash_value = libbash_name;
+	};
+
 num returns[std::string libbash_value]
 options{ k=1; }:
 	DIGIT { $libbash_value = walker->get_string($DIGIT); }
@@ -60,14 +72,14 @@ var_def
 	std::map<int, std::string> values;
 	int index = 0;
 }:
-	^(EQUALS libbash_name=name libbash_value=word){
+	^(EQUALS libbash_name=name_base libbash_value=word){
 		walker->define(libbash_name, libbash_value);
 	}
-	|^(EQUALS libbash_name=name ^(ARRAY (
-									(libbash_string=string_expr
-									|^(EQUALS value=arithmetics { index = value; } libbash_string=string_expr))
-									{ values[index++] = libbash_string; })*
-								 )){
+	|^(EQUALS libbash_name=name_base ^(ARRAY (
+										(libbash_string=string_expr
+										|^(EQUALS value=arithmetics { index = value; } libbash_string=string_expr))
+										{ values[index++] = libbash_string; })*
+									 )){
 		walker->define(libbash_name, values);
 	};
 
@@ -91,11 +103,15 @@ any_string returns[std::string libbash_value]
 	any_token=. { $libbash_value = walker->get_string(any_token); };
 
 //Allowable variable names in the variable expansion
-var_name returns[std::string libbash_value]
-@after {
-	$libbash_value = walker->get_string($var_name.start);
+var_name returns[std::string libbash_value, unsigned index]
+@init {
+	$var_name.index = 0;
 }:
-	num|name;
+	libbash_string=num { $libbash_value = libbash_string; }
+	|name {
+		$libbash_value = $name.libbash_value;
+		$index = $name.index;
+	};
 
 var_expansion returns[std::string libbash_value]:
 	^(USE_DEFAULT var_name libbash_word=word) {
@@ -127,7 +143,7 @@ word returns[std::string libbash_value]:
 
 //variable reference
 var_ref returns[std::string libbash_value]:
-	^(VAR_REF libbash_name=name) { $libbash_value = walker->resolve<std::string>(libbash_name); }
+	^(VAR_REF name) { $libbash_value = walker->resolve<std::string>($name.libbash_value, $name.index); }
 	|^(VAR_REF libbash_string=var_expansion) { $libbash_value = libbash_string; };
 
 // shell arithmetic
@@ -157,45 +173,45 @@ arithmetics returns[int value]
 	|^(ARITHMETIC_CONDITION cnd=arithmetics l=arithmetics r=arithmetics){
 		$value = walker->arithmetic_condition(cnd, l, r);
 	}
-	|^(VAR_REF libbash_name=name) {
-		$value = walker->resolve<int>(libbash_name);
+	|^(VAR_REF name) {
+		$value = walker->resolve<int>($name.libbash_value);
 	}
-	|^(PRE_INCR ^(VAR_REF libbash_name=name)){ $value = walker->pre_incr(libbash_name); }
-	|^(PRE_DECR ^(VAR_REF libbash_name=name)){ $value = walker->pre_decr(libbash_name); }
-	|^(POST_INCR ^(VAR_REF libbash_name=name)){ $value = walker->post_incr(libbash_name); }
-	|^(POST_DECR ^(VAR_REF libbash_name=name)){ $value = walker->post_decr(libbash_name); }
-	|^(EQUALS libbash_name=name l=arithmetics) {
-		$value = walker->set_value(libbash_name, l);
+	|^(PRE_INCR ^(VAR_REF name)){ $value = walker->pre_incr($name.libbash_value); }
+	|^(PRE_DECR ^(VAR_REF name)){ $value = walker->pre_decr($name.libbash_value); }
+	|^(POST_INCR ^(VAR_REF name)){ $value = walker->post_incr($name.libbash_value); }
+	|^(POST_DECR ^(VAR_REF name)){ $value = walker->post_decr($name.libbash_value); }
+	|^(EQUALS name l=arithmetics) {
+		$value = walker->set_value($name.libbash_value, l);
 	}
-	|^(MUL_ASSIGN libbash_name=name l=arithmetics) {
-		$value = walker->assign(&interpreter::multiply, libbash_name, l);
+	|^(MUL_ASSIGN name l=arithmetics) {
+		$value = walker->assign(&interpreter::multiply, $name.libbash_value, l);
 	}
-	|^(DIVIDE_ASSIGN libbash_name=name l=arithmetics) {
-		$value = walker->assign(&interpreter::divide, libbash_name, l);
+	|^(DIVIDE_ASSIGN name l=arithmetics) {
+		$value = walker->assign(&interpreter::divide, $name.libbash_value, l);
 	}
-	|^(MOD_ASSIGN libbash_name=name l=arithmetics) {
-		$value = walker->assign(&interpreter::mod, libbash_name, l);
+	|^(MOD_ASSIGN name l=arithmetics) {
+		$value = walker->assign(&interpreter::mod, $name.libbash_value, l);
 	}
-	|^(PLUS_ASSIGN libbash_name=name l=arithmetics) {
-		$value = walker->assign(&interpreter::plus, libbash_name, l);
+	|^(PLUS_ASSIGN name l=arithmetics) {
+		$value = walker->assign(&interpreter::plus, $name.libbash_value, l);
 	}
-	|^(MINUS_ASSIGN libbash_name=name l=arithmetics) {
-		$value = walker->assign(&interpreter::minus, libbash_name, l);
+	|^(MINUS_ASSIGN name l=arithmetics) {
+		$value = walker->assign(&interpreter::minus, $name.libbash_value, l);
 	}
-	|^(LSHIFT_ASSIGN libbash_name=name l=arithmetics) {
-		$value = walker->assign(&interpreter::left_shift, libbash_name, l);
+	|^(LSHIFT_ASSIGN name l=arithmetics) {
+		$value = walker->assign(&interpreter::left_shift, $name.libbash_value, l);
 	}
-	|^(RSHIFT_ASSIGN libbash_name=name l=arithmetics) {
-		$value = walker->assign(&interpreter::right_shift, libbash_name, l);
+	|^(RSHIFT_ASSIGN name l=arithmetics) {
+		$value = walker->assign(&interpreter::right_shift, $name.libbash_value, l);
 	}
-	|^(AND_ASSIGN libbash_name=name l=arithmetics) {
-		$value = walker->assign(&interpreter::bitwiseand, libbash_name, l);
+	|^(AND_ASSIGN name l=arithmetics) {
+		$value = walker->assign(&interpreter::bitwiseand, $name.libbash_value, l);
 	}
-	|^(XOR_ASSIGN libbash_name=name l=arithmetics) {
-		$value = walker->assign(&interpreter::bitwisexor, libbash_name, l);
+	|^(XOR_ASSIGN name l=arithmetics) {
+		$value = walker->assign(&interpreter::bitwisexor, $name.libbash_value, l);
 	}
-	|^(OR_ASSIGN libbash_name=name l=arithmetics) {
-		$value = walker->assign(&interpreter::bitwiseor, libbash_name, l);
+	|^(OR_ASSIGN name l=arithmetics) {
+		$value = walker->assign(&interpreter::bitwiseor, $name.libbash_value, l);
 	}
 	| NUMBER { $value = walker->parse_int($NUMBER);}
 	| DIGIT { $value = walker->parse_int($DIGIT);}

diff --git a/scripts/var_def.ebuild b/scripts/var_def.ebuild
index 3dfeb80..a621409 100644
--- a/scripts/var_def.ebuild
+++ b/scripts/var_def.ebuild
@@ -12,4 +12,5 @@ DEPEND="${RDEPEND}
 		dev-util/pkgconfig"
 MY_PATCH=ldflags.patch
 PATCH=("1.patch" 2.patch)
-ARRAY=(1 2 3 [5]=4)
+ARRAY=(1 2 3 [5]=4 5)
+ARRAY_LAST=${ARRAY[6]}

diff --git a/scripts/var_def.ebuild.result b/scripts/var_def.ebuild.result
index 3e19cdb..b563a56 100644
--- a/scripts/var_def.ebuild.result
+++ b/scripts/var_def.ebuild.result
@@ -1,4 +1,5 @@
-ARRAY=1 2 3 4
+ARRAY=1 2 3 4 5
+ARRAY_LAST=5
 DEPEND=dev-db/sqlite:3
 		dev-util/pkgconfig
 DESCRIPTION=SunPinyin is a SLM (Statistical Language Model) based IME



             reply	other threads:[~2011-04-12 18:30 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-12 18:29 Petteri Räty [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-08-19 15:23 [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/ Petteri Räty
2012-08-19 14:54 Petteri Räty
2012-08-19 14:54 Petteri Räty
2012-08-19 14:29 Petteri Räty
2012-08-07  2:38 Mu Qiao
2012-08-07  2:38 Mu Qiao
2012-08-07  2:38 Mu Qiao
2012-07-29 12:46 Petteri Räty
2012-07-29 12:45 Petteri Räty
2012-07-08  9:44 Petteri Räty
2012-07-08  9:31 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
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-07-20 13:08 Petteri Räty
2011-06-25 10:30 Petteri Räty
2011-06-25 10:30 Petteri Räty
2011-06-25 10:30 Petteri Räty
2011-06-25 10:05 Petteri Räty
2011-06-25 10:05 Petteri Räty
2011-06-19 19:15 Petteri Räty
2011-06-18  9:55 Petteri Räty
2011-06-16 16:53 Petteri Räty
2011-06-16 16:53 Petteri Räty
2011-06-11  8:52 Petteri Räty
2011-06-11  8:52 Petteri Räty
2011-06-09 11:46 Petteri Räty
2011-06-09  8:15 Petteri Räty
2011-06-09  7:27 Petteri Räty
2011-06-03 12:43 Petteri Räty
2011-06-01 12:19 Petteri Räty
2011-05-29 11:20 Petteri Räty
2011-05-29 11:20 Petteri Räty
2011-05-29 11:20 Petteri Räty
2011-05-28 13:11 Petteri Räty
2011-05-28 13:11 Petteri Räty
2011-05-24 14:50 Petteri Räty
2011-05-24 14:50 Petteri Räty
2011-05-24 14:50 Petteri Räty
2011-05-23 14:39 Petteri Räty
2011-05-22 21:00 Petteri Räty
2011-05-12 14:06 Petteri Räty
2011-05-12 14:06 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-11  7:19 Petteri Räty
2011-05-06 10:29 Petteri Räty
2011-04-27 15:11 Petteri Räty
2011-04-27 15:11 Petteri Räty
2011-04-20 14:04 Petteri Räty
2011-04-14  4:50 Petteri Räty
2011-04-12 18:29 Petteri Räty
2011-04-04 16:09 Petteri Räty
2011-04-03 13:09 Petteri Räty
2011-04-03 10:16 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=5b7cec85d9adeaee707cb3e74122c70aa96c6518.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