Allow empty parens for function0.

This commit is contained in:
Lewis Van Winkle
2016-02-23 17:29:03 -06:00
parent d9138d4bff
commit 681fb9aa0f
2 changed files with 10 additions and 2 deletions

View File

@@ -219,7 +219,7 @@ TinyExpr parses the following grammar:
<term> = <factor> {("*" | "/" | "%") <factor>} <term> = <factor> {("*" | "/" | "%") <factor>}
<factor> = <power> {"^" <power>} <factor> = <power> {"^" <power>}
<power> = {("-" | "+")} <base> <power> = {("-" | "+")} <base>
<base> = <constant> | <variable> | <function-1> <power> | <function-2> "(" <expr> "," <expr> ")" | "(" <list> ")" <base> = <constant> | <variable> | <function-0> {"(" ")"} | <function-1> <power> | <function-2> "(" <expr> "," <expr> ")" | "(" <list> ")"
In addition, whitespace between tokens is ignored. In addition, whitespace between tokens is ignored.

View File

@@ -205,7 +205,7 @@ static te_expr *expr(state *s);
static te_expr *power(state *s); static te_expr *power(state *s);
static te_expr *base(state *s) { static te_expr *base(state *s) {
/* <base> = <constant> | <variable> | <function-1> <power> | <function-2> "(" <expr> "," <expr> ")" | "(" <list> ")" */ /* <base> = <constant> | <variable> | <function-0> {"(" ")"} | <function-1> <power> | <function-2> "(" <expr> "," <expr> ")" | "(" <list> ")" */
te_expr *ret; te_expr *ret;
switch (s->type) { switch (s->type) {
@@ -225,6 +225,14 @@ static te_expr *base(state *s) {
ret = new_expr(TE_FUNCTION0, 0, 0); ret = new_expr(TE_FUNCTION0, 0, 0);
ret->f0 = s->f0; ret->f0 = s->f0;
next_token(s); next_token(s);
if (s->type == TOK_OPEN) {
next_token(s);
if (s->type != TOK_CLOSE) {
s->type = TOK_ERROR;
} else {
next_token(s);
}
}
break; break;
case TOK_FUNCTION1: case TOK_FUNCTION1: