From 3279566244f192a41a412a0ac667bea438bf3ac9 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 9 Nov 2014 16:51:36 -0500 Subject: [PATCH] CLI - Modify ::disqualifyOnlyParenOps to count sugared operators. - Labelled '(' and ')' as circumflex operators, thanks awwaiid. --- src/CLI.cpp | 16 ++++++++++++++-- src/Eval.cpp | 8 ++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index f0b4eaa43..7309b4f27 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -666,7 +666,7 @@ void CLI::addArg (const std::string& arg) if (disqualifyInsufficientTerms (lexemes) || disqualifyNoOps (lexemes) || -// disqualifyOnlyParenOps (lexemes) || + disqualifyOnlyParenOps (lexemes) || disqualifyFirstLastBinary (lexemes) || disqualifySugarFree (lexemes)) { @@ -2357,10 +2357,12 @@ bool CLI::disqualifyOnlyParenOps ( const std::vector >& lexemes) const { int opCount = 0; + int opSugarCount = 0; int opParenCount = 0; std::vector >::const_iterator l; for (l = lexemes.begin (); l != lexemes.end (); ++l) + { if (l->second == Lexer::typeOperator) { ++opCount; @@ -2370,7 +2372,17 @@ bool CLI::disqualifyOnlyParenOps ( ++opParenCount; } - return opCount == opParenCount; + else if (isTag (l->first) || + isUUIDList (l->first) || + isUUID (l->first) || + isIDSequence (l->first) || + isID (l->first) || + isPattern (l->first) || + isAttribute (l->first)) + ++opSugarCount; + } + + return opCount == opParenCount && ! opSugarCount; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Eval.cpp b/src/Eval.cpp index 884fd34cd..912086105 100644 --- a/src/Eval.cpp +++ b/src/Eval.cpp @@ -45,8 +45,8 @@ static struct { std::string op; int precedence; - char type; - char associativity; + char type; // b=binary, u=unary, c=circumfix + char associativity; // l=left, r=right, _=? } operators[] = { // Operator Precedence Type Associativity @@ -83,8 +83,8 @@ static struct { "or", 4, 'b', 'l' }, // Disjunction { "xor", 3, 'b', 'l' }, // Disjunction - { "(", 0, '_', 'l' }, // Precedence start - { ")", 0, '_', 'l' }, // Precedence end + { "(", 0, 'c', '_' }, // Precedence start + { ")", 0, 'c', '_' }, // Precedence end }; #define NUM_OPERATORS (sizeof (operators) / sizeof (operators[0]))