Skip to content

Commit 07c3b0d

Browse files
committed
Fixed issue #6
Allow function calls as the first event block action
1 parent 36e0123 commit 07c3b0d

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ bar", 127 } } }, // Newline
566566
{ "if 1 == 1 then $a = 1; $b = 2; $aa = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.1; $bb = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.2; $cc = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.3; $dd = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.4; $dd = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.5; $ee = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.6; $ff = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.7; $ff = round($a / (($b * 230) + 50) * 10) / 10; $b = 2.8; $gg = round($a / (($b * 230) + 50) * 10) / 10; end", { "[1]$a = 1[1]$b = 2.8[1]$aa = 0[1]$bb = 0[1]$cc = 0[1]$dd = 0[1]$ee = 0[1]$ff = 0[1]$gg = 0", 710 }, { "[1]$a = 1[1]$b = 2.8[1]$aa = 0[1]$bb = 0[1]$cc = 0[1]$dd = 0[1]$ee = 0[1]$ff = 0[1]$gg = 0", 710 }, 0 },
567567
{ "on foo then coalesce(10, 5); $a = 1; $b = 2; if $c == 12 && $d == 0 then $e = 1; end", { "[1]$a = 1[1]$b = 2[1]$e = 1", 263 }, { "[1]$a = 1[1]$b = 2", 263 }, 0 },
568568

569+
{ "on foo($a, $b) then print($a); $b = 1; end", { "[1]$a = NULL[1]$b = 1", 158 }, { "[1]$a = NULL[1]$b = 1", 158 }, 0 },
570+
{ "on foo then print($a); $b = 1; end", { "[1]$b = 1", 150 }, { "[1]$b = 1", 150 }, 0 },
571+
{ "on sub2($a) then print($a); $b = $a; end if 1 == 1 then print($a); sub2(2); end", { { "[1]$a = NULL[1]$b = NULL", 159 }, { "[1]$a = 2[1]$b = 2", 215 } }, { { "[1]$a = NULL[1]$b = NULL", 128 },{ "[1]$a = 2[1]$b = 2", 215 } }, 0 },
572+
{ "on sub2($a) then print($a); $c = $a + 1; end on sub1($a) then print($a); sub2($a + 1); $b = $a - 1; end if 1 == 1 then sub1(1); end", { { "[1]$a = NULL[1]$c = NULL", 167 }, { "[1]$a = NULL[1]$c = NULL[2]$a = NULL[2]$b = NULL", 271 }, { "[1]$a = 2[1]$c = 3[2]$a = 1[2]$b = 0", 271 } }, { { "[1]$a = NULL[1]$c = NULL", 128 }, { "[1]$a = NULL[1]$c = NULL[2]$a = NULL[2]$b = NULL", 196 }, { "[1]$a = 2[1]$c = 3[2]$a = 1[2]$b = 0", 196 } }, 0 },
569573
/*
570574
* Invalid rules
571575
*/
@@ -673,6 +677,9 @@ static int8_t is_event(char *text, uint16_t size) {
673677
if(size == 3 &&
674678
(strnicmp(text, "foo", 3) == 0 || strnicmp(text, "bar", 3) == 0)) {
675679
return 0;
680+
} else if(size == 4 &&
681+
(strnicmp(text, "sub1", 4) == 0 || strnicmp(text, "sub2", 4) == 0)) {
682+
return 0;
676683
}
677684
return -1;
678685
}

src/rules/rules.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,6 +3184,7 @@ static int16_t rule_create(char **text, struct rules_t *obj) {
31843184
case TIF:
31853185
case TSEMICOLON:
31863186
case TTHEN:
3187+
case TFUNCTION:
31873188
case TVAR: {
31883189
} break;
31893190
default: {
@@ -3851,9 +3852,15 @@ static int16_t rule_create(char **text, struct rules_t *obj) {
38513852
}
38523853

38533854
if(type == VPTR && in_child == -1) {
3854-
go = TIF;
3855-
ret = LPAREN;
3856-
pos+=2;
3855+
if(pos == 0) {
3856+
go = TIF;
3857+
ret = LPAREN;
3858+
pos+=2;
3859+
} else {
3860+
go = TIF;
3861+
ret = LPAREN;
3862+
pos++;
3863+
}
38573864
} else if(type == TFUNCTION || type == TEVENT) {
38583865
ret = LPAREN;
38593866
go = type;

0 commit comments

Comments
 (0)