[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [461] trunk/utils/cli



Revision: 461
          http://svn.sourceforge.net/ledger-smb/?rev=461&view=rev
Author:   einhverfr
Date:     2006-11-01 22:18:13 -0800 (Wed, 01 Nov 2006)

Log Message:
-----------
Mostly working CLI script host.

Modified Paths:
--------------
    trunk/utils/cli/ledgersmb_cli.pl
    trunk/utils/cli/sample.lsmb

Modified: trunk/utils/cli/ledgersmb_cli.pl
===================================================================
--- trunk/utils/cli/ledgersmb_cli.pl	2006-11-02 04:53:42 UTC (rev 460)
+++ trunk/utils/cli/ledgersmb_cli.pl	2006-11-02 06:18:13 UTC (rev 461)
@@ -30,12 +30,12 @@
 $syntax = << '_END_SYNTAX_';
 
 	KEY : /\w[a-z0-9_]*/i
-	FNKEY : /\w[a-z0-9_]*/i
-	MODSTR: /\w[a-z0-9_:]*/i
+	MODSTR : /\w[a-z0-9_]*/i
+	FNKEY : /(?:\w|:)+/
 	OP       : m([-+*/%])
 	NUMBER : /[+-]?\d*\.?\d+/
 
-	ARGSTR : /\w[a-z0-9_,\s]*/i 
+	ARGS : /(\w[a-z0-9_]*,?\s?)+/i 
 
 	expression : NUMBER OP expression
               { return main::expression(@item) }
@@ -45,13 +45,13 @@
               | KEY
 
 	assign_instruction : KEY "=" expression
-		{ ${main::stackref}->{$item{key}} = $item{expression} }
+		{ main::assignval($item{KEY}, $item{expression}) }
 
-	call_and_assign : /call/i FNKEY(ARGSTR) /into/i KEY
+	call_and_assign : /call/i FNKEY '(' ARGS ')' /into/i KEY
 		{ main::call_and_assign($item{FNKEY}, $item{ARGSTR}, $item{KEY}) }	
 
-	call : /call/i FNKEY(ARGSTR)
-		{ main::call($item{FNKEY}, $item{ARGSTR}) }
+	FUNCTIONCALL : /call/i FNKEY '(' ARGS ')'
+		{ main::call($item{FNKEY}, $item{ARGS})}
 
 	for : /for/i KEY
 		{ main::push_loop($item{KEY}) }
@@ -60,7 +60,7 @@
 		{ main::pop_loop() }
 
 	if : /^\s*if/i KEY
-		{ main::if_handler($item{KEY} }
+		{ main::if_handler($item{KEY}) }
 
 	# IF is terminated by END IF or FI on its own line
 
@@ -68,11 +68,11 @@
 		{ main::login() }
 
 	module : /module/i MODSTR
-		{ main::load_mod($item{MODSTR} }
+		{ main::load_mod($item{MODSTR}) }
 
 	instruction : assign_instruction
 		| call_and_assign
-		| call
+		| FUNCTIONCALL
 		| for
 		| done
 		| if
@@ -85,9 +85,21 @@
  $::RD_HINT = 1;
  $::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error
  $::RD_WARN   = 1; # Enable warnings. This will warn on unused rules &c.`
+#$::RD_TRACE = 1;
 my $stackref;
 my @loopstack;
 
+push @loopstack, $form;
+
+sub assignval {
+	my ($key, $value) = @_;
+	if ($key =~ /^ENV:/i){
+		$ENV{$key} = $value;
+	} else {
+		%{$loopstack[$#loopstack - 1]}->{$key} = $value;
+	}
+}
+
 sub expression {
 	shift;
 	my ($lhs,$op,$rhs) = @_;
@@ -131,6 +143,7 @@
 sub login {
 	$myconfig = new LedgerSMB::User 
 		"${LedgerSMB::Sysconfig::memberfile}", "$form->{login}";
+	$form->db_init($myconfig);
 }
 
 sub load_mod {
@@ -142,6 +155,7 @@
 my $scriptparse = new Parse::RecDescent($syntax);
 
 while ($line = <>){
+	$line =~ s/#.*$//; # strip comments
 	$scriptparse->startrule($line);
 }
 

Modified: trunk/utils/cli/sample.lsmb
===================================================================
--- trunk/utils/cli/sample.lsmb	2006-11-02 04:53:42 UTC (rev 460)
+++ trunk/utils/cli/sample.lsmb	2006-11-02 06:18:13 UTC (rev 461)
@@ -1,7 +1,6 @@
-# THe below line shows how to set the PGUSER environment variable
-ENV:PGUSER=postgres
-login=demo # set username
-password=demo # set password
-LOGIN
-MODULE AR # load AR
-CALL AR::transactions(\%$form);
+ENV:PGUSER = postgres # how to set an environment variable
+login = demo  # How to set a form variable
+password = demo  
+LOGIN # Log in
+MODULE AR  # Load a module
+CALL AR::transactions(form, user) # call a function


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.