More complete tokenizer

This commit is contained in:
Ryan Shepherd 2018-10-08 15:04:42 -04:00
parent 5c9e3c91d5
commit 15ae3dafdb
2 changed files with 21 additions and 2 deletions

View File

@ -252,9 +252,26 @@ sub EvalString {
#LogData(DEBUG, "Val is '$val'");
# Tokenize
my @tokens = split(/\s+/,$val);
# Pretokenize quoted strings
my @pretokens;
$val=~s/\\"/\x01/g;
while(my($start,$quote,$left)=$val=~/^(.*?)(".*?")(.*)$/) {
push @pretokens, $start if($start);
push @pretokens, $quote;
$val = $left;
}
push @pretokens, $val if($val);
# Tokenize
my @tokens;
foreach my $token (@pretokens) {
$token=~s/\x01/\\"/g;
if(IsString($token)) {
push @tokens, $token;
} else {
push @tokens, split(/\s+/, $token);
}
}
#for(my $i=0;$i<@tokens-0;$i++) { LogData(DEBUG, "Pass 1 Token [%i], '%s'", $i, $tokens[$i]); }

View File

@ -26,5 +26,7 @@ ok( PerlRPG::Script::IsString(5)==0, "'5' is not a string");
ok( EvalString("\"[TestVar]\"") eq '3', "\"[TestVar]\" is 3");
ok( EvalString("3 + 3") == 6, "\"3 + 3\" == 6");
ok( EvalString("lc('FoO') . uc('FoO')") eq 'fooFOO', "String function test");
SetGameVar("TestVar", "\"FoO\"");
ok( EvalString("uc(\" [TestVar] \")") eq ' FOO ', "Complex string function test");
done_testing();