Commit c6e6ce73 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Gestion des sous-expressions

parent b556cf60
Loading
Loading
Loading
Loading
Loading
+49 −15
Original line number Diff line number Diff line
@@ -303,13 +303,14 @@ class Formule
            if ($c >= $i) {
                $match = true;
                foreach ($filters as $name => $value) {
                    if ($term[$name] !== $value) {
                    if (!isset($term[$name]) || $term[$name] !== $value) {
                        $match = false;
                    }
                    if ($match) return $c;
                }
            }
        }

        return null;
    }

@@ -317,9 +318,16 @@ class Formule

    private function analyseExpr(array &$expr, int $i)
    {
        while( ($i = $this->searchExpr($expr, $i, ['type' => 'function'])) !== null ){
            $this->buildFunction($expr, $i);
            $i++;
        $c = $i;
        while (($c = $this->searchExpr($expr, $c, ['type' => 'function'])) !== null) {
            $this->buildFunction($expr, $c);
            $c++;
        }

        $c = $i;
        while (($c = $this->searchExpr($expr, $c, ['type' => 'sep', 'name' => '('])) !== null) {
            $this->buildExpr($expr, $c);
            $c++;
        }
    }

@@ -341,11 +349,9 @@ class Formule
                break;
            } elseif ($t['type'] === 'sep' && $t['name'] === ';' && $t['level'] === $level) {
                $currentExpr++;
                
            } else {
                $exprs[$currentExpr][] = $t;
            }
            //  if ()
        }

        for ($e = 0; $e <= $currentExpr; $e++) {
@@ -357,6 +363,34 @@ class Formule



    private function buildExpr(array &$expr, int $i)
    {
        $level    = $expr[$i]['level'];
        $sousExpr = [];
        $end      = count($expr);

        unset($expr[$i]); // on supprime la parenthèse ouvrante
        for ($c = $i + 1; $c < $end; $c++) {
            $t = $expr[$c];
            unset($expr[$c]);
            if ($t['type'] === 'sep' && $t['name'] === ')' && $t['level'] === $level) {
                // fin de la fonction
                break;
            } else {
                $sousExpr[] = $t;
            }
        }

        $this->analyseExpr($sousExpr, 0);
        $expr[$i] = [
            'type' => 'expr',
            'expr' => $sousExpr,
        ];
        $expr     = array_values($expr);
    }



    public function displayExprs()
    {
        echo '<div style="clear:both">';