mirror of
https://github.com/c3d/DB48X-on-DM42.git
synced 2024-09-28 03:20:53 +02:00
parser: Deal with negation more "normally", parse -a²
correctly
We were treating negation in a special way in the expression parser. As a result, `-a²` was parsed as `(-a)²` instead of `-(a²)`. Treat negation like a normal prefix, generating an object, which makes it possible to deal with precedence the right way. Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
parent
a83a6057b7
commit
83d6536626
1 changed files with 7 additions and 10 deletions
17
src/list.cc
17
src/list.cc
|
@ -73,7 +73,6 @@ object::result list::list_parse(id type,
|
|||
object_g postfix = nullptr;
|
||||
object_g obj = nullptr;
|
||||
object_g xroot_arg = nullptr;
|
||||
bool negate = false;
|
||||
int precedence = p.precedence;
|
||||
int lowest = precedence;
|
||||
uint arity = 0;
|
||||
|
@ -188,10 +187,13 @@ object::result list::list_parse(id type,
|
|||
// Check to see if we have a sign
|
||||
else if (cp == '-' || cp == '+')
|
||||
{
|
||||
if (cp == '-')
|
||||
negate = !negate;
|
||||
s = utf8_next(s);
|
||||
continue;
|
||||
if (cp == '+')
|
||||
{
|
||||
s = utf8_next(s);
|
||||
continue;
|
||||
}
|
||||
obj = static_object(ID_neg);
|
||||
length = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -343,11 +345,6 @@ object::result list::list_parse(id type,
|
|||
obj = prefix;
|
||||
prefix = nullptr;
|
||||
}
|
||||
else if (negate)
|
||||
{
|
||||
obj = command::static_object(ID_neg);
|
||||
negate = false;
|
||||
}
|
||||
else if (postfix)
|
||||
{
|
||||
obj = postfix;
|
||||
|
|
Loading…
Reference in a new issue