<commit_before>-----------------------------------------------------------------------
--  EL.Expressions -- Expression Nodes
--  Copyright (C) 2009, 2010 <NAME>
--  Written by <NAME> (<EMAIL>)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
with EL.Beans;
with EL.Variables;
with EL.Beans.Methods;
with Util.Strings;
package body EL.Expressions.Nodes is

   use EL.Variables;
   use Util.Concurrent;

   --  ------------------------------
   --  Evaluate a node on a given context.
   --  ------------------------------
   function Get_Value (Expr    : ELUnary;
                       Context : ELContext'Class) return Object is
      Value : constant Object := Expr.Node.Get_Value (Context);
   begin
      case Expr.Kind is
      when EL_NOT =>
         return To_Object (not To_Boolean (Value));

      when EL_MINUS =>
         return -Value;

      when EL_EMPTY =>
         return To_Object (Is_Empty (Value));

      when others =>
         return Value;
      end case;
   end Get_Value;

   --  ------------------------------
   --  Reduce the expression by eliminating variables which are known
   --  and computing constant expressions.  Returns either a new expression
   --  tree or a constant value.
   --  ------------------------------
   overriding
   function Reduce (Expr    : ELUnary;
                    Context : ELContext'Class) return Reduction is<commit_msg>Catch the No_Variable exception and if the operation is EL_EMPTY, makes sure it returns True and the exception is blocked. For other operations, raise the exception as this is an error.<commit_after>-----------------------------------------------------------------------
--  EL.Expressions -- Expression Nodes
--  Copyright (C) 2009, 2010 <NAME>
--  Written by <NAME> (<EMAIL>)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
with EL.Beans;
with EL.Variables;
with EL.Beans.Methods;
with Util.Strings;
package body EL.Expressions.Nodes is

   use EL.Variables;
   use Util.Concurrent;

   --  ------------------------------
   --  Evaluate a node on a given context.
   --  ------------------------------
   function Get_Value (Expr    : ELUnary;
                       Context : ELContext'Class) return Object is
   begin
      declare
         Value : constant Object := Expr.Node.Get_Value (Context);
      begin
         case Expr.Kind is
         when EL_NOT =>
            return To_Object (not To_Boolean (Value));

         when EL_MINUS =>
            return -Value;

         when EL_EMPTY =>
            return To_Object (Is_Empty (Value));

         when others =>
            return Value;
         end case;
      end;

   exception
      when EL.Variables.No_Variable =>
         --  If we can't find the variable, empty predicate must return true.
         if Expr.Kind = EL_EMPTY then
            return To_Object (True);
         end if;

         --  For others, this is an error.
         raise;
   end Get_Value;

   --  ------------------------------
   --  Reduce the expression by eliminating variables which are known
   --  and computing constant expressions.  Returns either a new expression
   --  tree or a constant value.
   --  ------------------------------
   overriding
   function Reduce (Expr    : ELUnary;
                    Context : ELContext'Class) return Reduction is
{'fraction_non_alphanumeric': 0.18740365558247082, 'fraction_numerical': 0.005285179475886369, 'mean_word_length': 1.6013745704467355, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4598766', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1096, 'n_words': 446}