Groups the parts of the formula that must be evaluated first into parentheses

@param string $formula
@param string $opt
542652
private function group(&$formula, $opt = 'init') {
        if ($opt == 'init') {
            // Numbers in E notation
            $formula = preg_replace_callback('/[\d\.]+( )?[eE]( )?[\+\-]?( )?[\d\.]+ /',
                    [$this, 'match'], $formula);
            // Variables
            if (count($this->variables) > 0) {
            	$valid_variables = implode("|", $this->valid_variables);
                $formula = preg_replace_callback('/[\+\-\*\/\^ ]('.$valid_variables.')[ \+\-\*\/\^]/',
                        [$this, 'match1'], $formula);
            }
        } else {
            // Functions
            $valid_functions = implode("|", $this->valid_functions);
            $formula = preg_replace_callback('/('.$valid_functions.')( )?[\+\-]?( )?[\d\.eEINF]+ /',
                    [$this, 'match2'], $formula);
        }
    }
1032838
function _advance()
	{
		$i = $this->_current_char;
		$formula_length = strlen($this->_formula);
		// eat up white spaces
		if ($i < $formula_length) {
			while ($this->_formula{$i} == " ") {
				++$i;
			}

			if ($i < ($formula_length - 1)) {
				$this->_lookahead = $this->_formula{$i+1};
			}
			$token = '';
		}

		while ($i < $formula_length) {
			$token .= $this->_formula{$i};

			if ($i < ($formula_length - 1)) {
				$this->_lookahead = $this->_formula{$i+1};
			} else {
				$this->_lookahead = '';
			}

			if ($this->_match($token) != '') {
				//if ($i < strlen($this->_formula) - 1) {
				//    $this->_lookahead = $this->_formula{$i+1};
				//}
				$this->_current_char = $i + 1;
				$this->_current_token = $token;
				return 1;
			}

			if ($i < ($formula_length - 2)) {
				$this->_lookahead = $this->_formula{$i+2};
			} else { // if we run out of characters _lookahead becomes empty
				$this->_lookahead = '';
			}
			++$i;
		}
		//die("Lexical error ".$this->_current_char);
	}
137843
private Formula distribute(final Formula f1, final Formula f2) {
    if (this.handler != null)
      this.proceed = this.handler.performedDistribution();
    if (this.proceed) {
      final FormulaFactory f = f1.factory();
      if (f1.type() == FType.OR || f2.type() == FType.OR) {
        final LinkedHashSet<Formula> nops = new LinkedHashSet<>();
        for (final Formula op : f1.type() == FType.OR ? f1 : f2) {
          final Formula distribute = this.distribute(op, f1.type() == FType.OR ? f2 : f1);
          if (!this.proceed)
            return null;
          nops.add(distribute);
        }
        return f.or(nops);
      }
      final Formula clause = f.and(f1, f2);
      if (this.handler != null)
        proceed = this.handler.createdClause(clause);
      return clause;
    }
    return null;
  }
748439
private function processOptionals(array &$expression, Call $call, CompilationContext $context)
    {
        $flags = null;
        $offset = null;

        $offsetParamOffset = 4;
        if (isset($expression['parameters'][4]) && 'int' === $expression['parameters'][4]['parameter']['type']) {
            $offset = $expression['parameters'][4]['parameter']['value'].' ';
            unset($expression['parameters'][4]);
        }

        if (isset($expression['parameters'][3]) && 'int' === $expression['parameters'][3]['parameter']['type']) {
            $flags = $expression['parameters'][3]['parameter']['value'].' ';
            $offsetParamOffset = 3;
            unset($expression['parameters'][3]);
        }

        try {
            $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);

            if (null === $offset && isset($resolvedParams[$offsetParamOffset])) {
                $context->headersManager->add('kernel/operators');
                $offset = 'zephir_get_intval('.$resolvedParams[$offsetParamOffset].') ';
            }

            if (null === $flags && isset($resolvedParams[3])) {
                $context->headersManager->add('kernel/operators');
                $flags = 'zephir_get_intval('.$resolvedParams[3].') ';
            }
        } catch (Exception $e) {
            throw new CompilerException($e->getMessage(), $expression, $e->getCode(), $e);
        }

        if (null === $flags) {
            $flags = '0 ';
        }

        if (null === $offset) {
            $offset = '0 ';
        }

        return [$flags, $offset];
    }
445996
public static void checkOptional(OptionSet options, String opt1, String opt2) {
        List<String> opts = Lists.newArrayList();
        opts.add(opt1);
        opts.add(opt2);
        checkOptional(options, opts);
    }
340561
public function whereOr($field, $opt=null, $value=null) {
        if ( $field instanceof \Closure ) {
            $this->sqlBuilder->sqlAppend(" OR (");
            $this->sqlBuilder->enterClosure();
            call_user_func($field);
            $this->sqlBuilder->addWhere(") ");
        } else {
            $this->sqlBuilder->addWhere($field, $opt, $value, 'OR');
        }
        return $this;
    }
1028477
function (args) {
      args = args || [];
      var str = args[0];

      if (str) {
        str = str.toUpperCase();
        if (instance.formulas[str]) {
          return ((typeof instance.formulas[str] === 'function') ? instance.formulas[str].apply(this, args) : instance.formulas[str]);
        }
      }

      throw Error('NAME');
    }
1058419
protected function setOption($opt)
    {
        if ($this->checkDiscription($opt)) {
            $this->advanceOpt($opt);
        } else {
            $this->simpleOpt($opt);
        }
    }
845989
private function opt($o) {
		if (is_numeric($o)) {
			return "--$o";
		}
		if ($o{0} !== '-') {
			if (strlen($o) > 1) {
				$o = "-$o";
			}
			$o = "-$o";
		}
		return $o;
	}
334306
private void addClauseSetWithRelaxation(final Variable relaxationVar, final Formula formula) {
        switch (formula.type()) {
            case TRUE:
                break;
            case FALSE:
            case LITERAL:
            case OR:
                this.addClauseWithRelaxation(relaxationVar, formula);
                break;
            case AND:
                for (final Formula op : formula) { this.addClauseWithRelaxation(relaxationVar, op); }
                break;
            default:
                throw new IllegalArgumentException("Input formula ist not a valid CNF: " + formula);
        }
    }
398741
public static function compile(Compiler $compiler, $equation, $format = '', $assign = '', array $rest = array())
    {
        /*
         * Holds the allowed function, characters, operators and constants
         */
        $allowed = array(
            '0',
            '1',
            '2',
            '3',
            '4',
            '5',
            '6',
            '7',
            '8',
            '9',
            '+',
            '-',
            '/',
            '*',
            '.',
            ' ',
            '<<',
            '>>',
            '%',
            '&',
            '^',
            '|',
            '~',
            'abs(',
            'ceil(',
            'floor(',
            'exp(',
            'log10(',
            'cos(',
            'sin(',
            'sqrt(',
            'tan(',
            'M_PI',
            'INF',
            'M_E',
        );

        /*
         * Holds the functions that can accept multiple arguments
         */
        $funcs = array(
            'round(',
            'log(',
            'pow(',
            'max(',
            'min(',
            'rand(',
        );

        $equation = $equationSrc = str_ireplace(array(
            'pi',
            'M_PI()',
            'inf',
            ' e '
        ),
            array(
                'M_PI',
                'M_PI',
                'INF',
                ' M_E '
            ),
            $equation);

        $delim      = $equation[0];
        $open       = $delim . '.';
        $close      = '.' . $delim;
        $equation   = substr($equation, 1, - 1);
        $out        = '';
        $ptr        = 1;
        $allowcomma = 0;
        while (strlen($equation) > 0) {
            $substr = substr($equation, 0, $ptr);
            if (array_search($substr, $allowed) !== false) {
                // allowed string
                $out .= $substr;
                $equation = substr($equation, $ptr);
                $ptr      = 0;
            } elseif (array_search($substr, $funcs) !== false) {
                // allowed func
                $out .= $substr;
                $equation = substr($equation, $ptr);
                $ptr      = 0;
                ++ $allowcomma;
                if ($allowcomma === 1) {
                    $allowed[] = ',';
                }
            } elseif (isset($rest[$substr])) {
                // variable
                $out .= $rest[$substr];
                $equation = substr($equation, $ptr);
                $ptr      = 0;
            } elseif ($substr === $open) {
                // pre-replaced variable
                preg_match('#.*\((?:[^()]*?|(?R))\)' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m);
                if (empty($m)) {
                    preg_match('#.*?' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m);
                }
                $out .= substr($m[0], 0, - 2);
                $equation = substr($equation, strlen($m[0]) + 2);
                $ptr      = 0;
            } elseif ($substr === '(') {
                // opening parenthesis
                if ($allowcomma > 0) {
                    ++ $allowcomma;
                }

                $out .= $substr;
                $equation = substr($equation, $ptr);
                $ptr      = 0;
            } elseif ($substr === ')') {
                // closing parenthesis
                if ($allowcomma > 0) {
                    -- $allowcomma;
                    if ($allowcomma === 0) {
                        array_pop($allowed);
                    }
                }

                $out .= $substr;
                $equation = substr($equation, $ptr);
                $ptr      = 0;
            } elseif ($ptr >= strlen($equation)) {
                // parse error if we've consumed the entire equation without finding anything valid
                throw new CompilationException($compiler,
                    'Math : Syntax error or variable undefined in equation ' . $equationSrc . ' at ' . $substr);
            } else {
                // nothing special, advance
                ++ $ptr;
            }
        }
        if ($format !== '\'\'') {
            $out = 'sprintf(' . $format . ', ' . $out . ')';
        }
        if ($assign !== '\'\'') {
            return '($this->assignInScope(' . $out . ', ' . $assign . '))';
        }

        return '(' . $out . ')';
    }
156168
public function getReplacements(Formula $formula)
    {
        $result = array();

        $start = $this->getOption('separator_start');
        $end   = $this->getOption('separator_end');

        if (preg_match_all('/'. $start . '(.+?)' . $end . '/is', $this->prepare($formula->formula), $matches)) {
            $result = array_merge($result, $matches[1]);
        }

        foreach ($formula->getSubFormulas() as $key => $subformula) {
            $result = array_merge($result, $this->getReplacements($subformula));
            unset($result[array_search($key, $result)]);
        }

        return array_unique($result);
    }
1305592
private function extract($opts) {
    if (!empty($opts) && is_array($opts)) {
      isset($opts['query']) && $this->setQueryString($opts['query']);
      isset($opts['indexes']) && $this->addIndex($opts['indexes']);
      isset($opts['fetch_field']) && $this->addFetchFields($opts['fetch_field']);
      isset($opts['format']) && $this->setFormat($opts['format']);
      isset($opts['formula_name']) && $this->setFormulaName($opts['formula_name']);
      isset($opts['summary']) && $this->summary = $opts['summary'];
      isset($opts['start']) && $this->setStartHit($opts['start']);
      isset($opts['hits']) && $this->setHits((int) $opts['hits']);
      isset($opts['sort']) && $this->sort = $opts['sort'];
      isset($opts['filter']) && $this->addFilter($opts['filter']);
      isset($opts['aggregate']) && $this->aggregate = $opts['aggregate'];
      isset($opts['distinct']) && $this->distinct = $opts['distinct'];
      isset($opts['kvpair']) && $this->setPair($opts['kvpair']);
      isset($opts['rerankSize']) && $this->addRerankSize($opts['rerankSize']);
    }
  }
279088
public function do_option($opt, $value)
    {
        switch ($opt) {
            case 'interactive':
                $this->interactive = true;
                break;
            case 'dry-run':
                $this->verbose = true;
                $this->nowrite = true;
                $this->dryrun = true;
                $this->trace = true;
                break;
            case 'help':
                $this->help();
                exit();
            case 'libdir':
                set_include_path($value.PATH_SEPARATOR.get_include_path());
                break;
            case 'nosearch':
                $this->nosearch = true;
                break;
            case 'prereqs':
                $this->show_prereqs = true;
                break;
            case 'quiet':
                $this->verbose = false;
                break;
            case 'pakefile':
                $this->PAKEFILES = array($value);
                break;
            case 'require':
                require $value;
                break;
            case 'import':
                pake_import($value);
                break;
            case 'tasks':
                $this->show_tasks = true;
                break;
            case 'trace':
                $this->trace = true;
                $this->verbose = true;
                break;
            case 'usage':
                $this->usage();
                exit();
            case 'verbose':
                $this->verbose = true;
                break;
            case 'force-tty':
                define('PAKE_FORCE_TTY', true);
                break;
            case 'full-width':
                $this->full_width = true;
                break;
            case 'version':
                $this->showVersion();
                exit();
            default:
                throw new pakeException('Unknown option: '.$opt);
        }
    }
1010276
public function prepare(&$formulaString)
    {
        $start = $this->getOption('separator_start');
        $end   = $this->getOption('separator_end');

        $formulaString = preg_replace(sprintf('/%s[ ]+/', $start), $start, $formulaString);
        $formulaString = preg_replace(sprintf('/[ ]+%s+/', $end), $end, $formulaString);

        return $formulaString;
    }
1009591
void setOption(String[] opt) {
	if(!matchOption(opt[0], "hide") && optionLength(opt[0]) > opt.length) {
	    System.err.println("Skipping option '" + opt[0] + "', missing argument");
	    return;
	}
	boolean dash = opt[0].length() > 1 && opt[0].charAt(0) == '-';
	boolean positive = !(opt[0].length() > 1 && opt[0].charAt(dash ? 1 : 0) == '!');
	
	if(matchOption(opt[0], "qualify", true)) {
	    showQualified = positive;
	} else if(matchOption(opt[0], "qualifyGenerics", true)) {
	    showQualifiedGenerics = positive;
	} else if(matchOption(opt[0], "hideGenerics", true)) {
	    hideGenerics = positive;
	} else if(matchOption(opt[0], "horizontal", true)) {
	    horizontal = positive;
	} else if(matchOption(opt[0], "attributes", true)) {
	    showAttributes = positive;
	} else if(matchOption(opt[0], "enumconstants", true)) {
	    showEnumConstants = positive;
	} else if(matchOption(opt[0], "operations", true)) {
	    showOperations = positive;
	} else if(matchOption(opt[0], "enumerations", true)) {
	    showEnumerations = positive;
	} else if(matchOption(opt[0], "constructors", true)) {
	    showConstructors = positive;
	} else if(matchOption(opt[0], "visibility", true)) {
	    showVisibility = positive;
	} else if(matchOption(opt[0], "types", true)) {
	    showType = positive;
	} else if(matchOption(opt[0], "autoSize", true)) {
	    autoSize = positive;
	} else if(matchOption(opt[0], "commentname", true)) {
	    showComment = positive;
	} else if(matchOption(opt[0], "all")) {
	    setAll();
	} else if(matchOption(opt[0], "bgcolor", true)) {
	    bgColor = positive ? opt[1] : null;
	} else if(matchOption(opt[0], "edgecolor", true)) {
	    edgeColor = positive ? opt[1] : "black";
	} else if(matchOption(opt[0], "edgefontcolor", true)) {
	    edgeFontColor = positive ? opt[1] : "black";
	} else if(matchOption(opt[0], "edgefontname", true)) {
	    edgeFontName = positive ? opt[1] : Font.DEFAULT_FONT;
	} else if(matchOption(opt[0], "edgefontsize", true)) {
	    edgeFontSize = positive ? Double.parseDouble(opt[1]) : 10;
	} else if(matchOption(opt[0], "nodefontcolor", true)) {
	    nodeFontColor = positive ? opt[1] : "black";
	} else if(matchOption(opt[0], "nodefontname", true)) {
	    nodeFontName = positive ? opt[1] : Font.DEFAULT_FONT;
	} else if(matchOption(opt[0], "nodefontabstractitalic", true)) {
	    nodeFontAbstractItalic = positive;
	} else if(matchOption(opt[0], "nodefontsize", true)) {
	    nodeFontSize = positive ? Double.parseDouble(opt[1]) : 10;
	} else if(matchOption(opt[0], "nodefontclassname", true)) {
	    nodeFontClassName = positive ? opt[1] : null;
	} else if(matchOption(opt[0], "nodefontclasssize", true)) {
	    nodeFontClassSize = positive ? Double.parseDouble(opt[1]) : -1;
	} else if(matchOption(opt[0], "nodefonttagname", true)) {
	    nodeFontTagName = positive ? opt[1] : null;
	} else if(matchOption(opt[0], "nodefonttagsize", true)) {
	    nodeFontTagSize = positive ? Double.parseDouble(opt[1]) : -1;
	} else if(matchOption(opt[0], "nodefontpackagename", true)) {
	    nodeFontPackageName = positive ? opt[1] : null;
	} else if(matchOption(opt[0], "nodefontpackagesize", true)) {
	    nodeFontPackageSize = positive ? Double.parseDouble(opt[1]) : -1;
	} else if(matchOption(opt[0], "nodefillcolor", true)) {
	    nodeFillColor = positive ? opt[1] : null;
	} else if(matchOption(opt[0], "shape", true)) {
	    shape = positive ? Shape.of(opt[1]) : Shape.CLASS;
	} else if(matchOption(opt[0], "output", true)) {
	    outputFileName = positive ? opt[1] : "graph.dot";
	} else if(matchOption(opt[0], "outputencoding", true)) {
	    outputEncoding = positive ? opt[1] : "ISO-8859-1";
	} else if(matchOption(opt[0], "hide", true)) {
	    if (positive) {
		if (opt.length == 1) {
		    hidePatterns.clear();
		    hidePatterns.add(allPattern);
		} else {
		    try {
			hidePatterns.add(Pattern.compile(opt[1]));
		    } catch (PatternSyntaxException e) {
			System.err.println("Skipping invalid pattern " + opt[1]);
		    }
		}
	    } else
		hidePatterns.clear();
	} else if(matchOption(opt[0], "include", true)) {
	    if (positive) {
		try {
		    includePatterns.add(Pattern.compile(opt[1]));
		} catch (PatternSyntaxException e) {
		    System.err.println("Skipping invalid pattern " + opt[1]);
		}
	    } else
		includePatterns.clear();
	} else if(matchOption(opt[0], "apidocroot", true)) {
	    apiDocRoot = positive ? fixApiDocRoot(opt[1]) : null;
	} else if(matchOption(opt[0], "apidocmap", true)) {
	    if (positive)
		setApiDocMapFile(opt[1]);
	    else
		apiDocMap.clear();
	} else if(matchOption(opt[0], "noguillemot", true)) {
	    guilOpen = positive ? "&lt;&lt;" : "\u00ab";
	    guilClose = positive ? "&gt;&gt;" : "\u00bb";
	} else if (matchOption(opt[0], "view", true)) {
	    viewName = positive ? opt[1] : null;
	} else if (matchOption(opt[0], "views", true)) {
	    findViews = positive;
	} else if (matchOption(opt[0], "d", true)) {
	    outputDirectory = positive ? opt[1] : null;
	} else if(matchOption(opt[0], "inferrel", true)) {
	    inferRelationships = positive;
	} else if(matchOption(opt[0], "inferreltype", true)) {
	    if (positive) {
		try {
		    inferRelationshipType = RelationType.valueOf(opt[1].toUpperCase());
		} catch(IllegalArgumentException e) {
		    System.err.println("Unknown association type " + opt[1]);
		}
	    } else 
		inferRelationshipType = RelationType.NAVASSOC;
	} else if(matchOption(opt[0], "inferdepvis", true)) {
	    if (positive) {
		try {
		    Visibility vis = Visibility.valueOf(opt[1].toUpperCase());
		    inferDependencyVisibility = vis;
		} catch(IllegalArgumentException e) {
		    System.err.println("Ignoring invalid visibility specification for " +
			    "dependency inference: " + opt[1]);
		}
	    } else
		inferDependencyVisibility = Visibility.PRIVATE;
	} else if(matchOption(opt[0], "collapsible", true)) {
	    collapsibleDiagrams = positive;
	} else if(matchOption(opt[0], "inferdep", true)) {
	    inferDependencies = positive;
	} else if(matchOption(opt[0], "inferdepinpackage", true)) {
	    inferDepInPackage = positive;
	} else if (matchOption(opt[0], "hideprivateinner", true)) {
	    hidePrivateInner = positive;
	} else if(matchOption(opt[0], "useimports", true)) {
	    useImports = positive;
	} else if (matchOption(opt[0], "collpackages", true)) {
	    if (positive) {
		try {
		    collPackages.add(Pattern.compile(opt[1]));
		} catch (PatternSyntaxException e) {
		    System.err.println("Skipping invalid pattern " + opt[1]);
		}
	    } else
		collPackages.clear();
	} else if (matchOption(opt[0], "compact", true)) {
	    compact = positive;
	} else if (matchOption(opt[0], "postfixpackage", true)) {
	    postfixPackage = positive;
	} else if (matchOption(opt[0], "link")) {
	    addApiDocRoots(opt[1]);
	} else if (matchOption(opt[0], "linkoffline")) {
	    addApiDocRootsOffline(opt[1], opt[2]);
	} else if(matchOption(opt[0], "contextPattern")) {
	    RelationDirection d; RelationType rt;
	    try {
		d = RelationDirection.valueOf(opt[2].toUpperCase());
		if(opt[1].equalsIgnoreCase("all")) {
		    contextRelationPattern = new RelationPattern(d);
		} else {
		    rt = RelationType.valueOf(opt[1].toUpperCase());
		    contextRelationPattern.addRelation(rt, d);
		}
	    } catch(IllegalArgumentException e) {
		
	    }
		
	} else if (matchOption(opt[0], "nodesep", true)) {
	    try {
		nodeSep = positive ? Double.parseDouble(opt[1]) : 0.25;
	    } catch (NumberFormatException e) {
		System.err.println("Skipping invalid nodesep " + opt[1]);
	    }
	} else if (matchOption(opt[0], "ranksep", true)) {
	    try {
		rankSep = positive ? Double.parseDouble(opt[1]) : 0.5;
	    } catch (NumberFormatException e) {
		System.err.println("Skipping invalid ranksep " + opt[1]);
	    }
	} else if (matchOption(opt[0], "dotexecutable")) {
	    dotExecutable = opt[1];
	} else
	    ; // Do nothing, javadoc will handle the option or complain, if needed.
    }
636766
public function ormClearCacheResult($opt = ['flush' => false])
    {
        $validOpts = ['flush'];
        $command = new Command\ClearCache\ResultCommand;

        $this->runDoctrineCommand($command, $opt, $validOpts);
    }