diff options
-rw-r--r-- | utils/cli/ledgersmb_cli.pl | 34 | ||||
-rw-r--r-- | utils/cli/sample.lsmb | 13 |
2 files changed, 30 insertions, 17 deletions
diff --git a/utils/cli/ledgersmb_cli.pl b/utils/cli/ledgersmb_cli.pl index 995682b1..d279e958 100644 --- a/utils/cli/ledgersmb_cli.pl +++ b/utils/cli/ledgersmb_cli.pl @@ -30,12 +30,12 @@ $form = new Form; $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 @@ $syntax = << '_END_SYNTAX_'; | 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 @@ $syntax = << '_END_SYNTAX_'; { 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 @@ $syntax = << '_END_SYNTAX_'; { 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 @@ _END_SYNTAX_ $::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 if_handler { sub login { $myconfig = new LedgerSMB::User "${LedgerSMB::Sysconfig::memberfile}", "$form->{login}"; + $form->db_init($myconfig); } sub load_mod { @@ -142,6 +155,7 @@ sub load_mod { my $scriptparse = new Parse::RecDescent($syntax); while ($line = <>){ + $line =~ s/#.*$//; # strip comments $scriptparse->startrule($line); } diff --git a/utils/cli/sample.lsmb b/utils/cli/sample.lsmb index 62b67fb0..6344c89f 100644 --- a/utils/cli/sample.lsmb +++ b/utils/cli/sample.lsmb @@ -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 |