| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
4 files changed, 431 insertions, 6 deletions
| diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java b/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java new file mode 100644 index 0000000..25b85c8 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java @@ -0,0 +1,88 @@ +package tonkadur.fate.v1.lang.instruction; + +import tonkadur.error.ErrorManager; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.error.InvalidTypeException; + +import tonkadur.fate.v1.lang.type.CollectionType; +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.ValueNode; + +public class Clear extends InstructionNode +{ +   /***************************************************************************/ +   /**** MEMBERS **************************************************************/ +   /***************************************************************************/ +   protected final ValueNode collection; + +   /***************************************************************************/ +   /**** PROTECTED ************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ +   protected Clear +   ( +      final Origin origin, +      final ValueNode collection +   ) +   { +      super(origin); + +      this.collection = collection; +   } + +   /***************************************************************************/ +   /**** PUBLIC ***************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ +   public static Clear build +   ( +      final Origin origin, +      final ValueNode collection +   ) +   throws InvalidTypeException +   { +      if +      ( +         !Type.COLLECTION_TYPES.contains(collection.get_type().get_base_type()) +      ) +      { +         ErrorManager.handle +         ( +            new InvalidTypeException +            ( +               collection.get_origin(), +               collection.get_type(), +               Type.COLLECTION_TYPES +            ) +         ); +      } + +      return new Clear(origin, collection); +   } + +   /**** Accessors ************************************************************/ + +   /**** Misc. ****************************************************************/ +   @Override +   public String toString () +   { +      final StringBuilder sb = new StringBuilder(); + +      sb.append(origin.toString()); +      sb.append("(Clear"); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("collection:"); +      sb.append(System.lineSeparator()); +      sb.append(collection.toString()); + +      sb.append(")"); + +      return sb.toString(); +   } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java new file mode 100644 index 0000000..937138c --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java @@ -0,0 +1,148 @@ +package tonkadur.fate.v1.lang.instruction; + +import tonkadur.error.ErrorManager; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.error.ConflictingTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; +import tonkadur.fate.v1.error.InvalidTypeException; + +import tonkadur.fate.v1.lang.type.CollectionType; +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.ValueNode; + +public class RemoveAllOfElement extends InstructionNode +{ +   /***************************************************************************/ +   /**** MEMBERS **************************************************************/ +   /***************************************************************************/ +   protected final ValueNode element; +   protected final ValueNode collection; + +   /***************************************************************************/ +   /**** PROTECTED ************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ +   protected RemoveAllOfElement +   ( +      final Origin origin, +      final ValueNode element, +      final ValueNode collection +   ) +   { +      super(origin); + +      this.collection = collection; +      this.element = element; +   } + +   /***************************************************************************/ +   /**** PUBLIC ***************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ +   public static RemoveAllOfElement build +   ( +      final Origin origin, +      final ValueNode element, +      final ValueNode collection +   ) +   throws +      InvalidTypeException, +      ConflictingTypeException, +      IncomparableTypeException +   { +      final Type hint; +      final Type collection_type; +      final CollectionType collection_true_type; +      final Type collection_element_type; + +      collection_type = collection.get_type(); + +      if +      ( +         !Type.COLLECTION_TYPES.contains(collection_type.get_base_type()) +         || !(collection_type instanceof CollectionType) +      ) +      { +         ErrorManager.handle +         ( +            new InvalidTypeException +            ( +               collection.get_origin(), +               collection.get_type(), +               Type.COLLECTION_TYPES +            ) +         ); +      } + +      collection_true_type = (CollectionType) collection_type; +      collection_element_type = collection_true_type.get_content_type(); + +      if (element.get_type().can_be_used_as(collection_element_type)) +      { +         return new RemoveAllOfElement(origin, element, collection); +      } + +      ErrorManager.handle +      ( +         new ConflictingTypeException +         ( +            element.get_origin(), +            element.get_type(), +            collection_element_type +         ) +      ); + +      hint = +         (Type) element.get_type().generate_comparable_to +         ( +            collection_element_type +         ); + +      if (hint.equals(Type.ANY)) +      { +         ErrorManager.handle +         ( +            new IncomparableTypeException +            ( +               element.get_origin(), +               element.get_type(), +               collection_element_type +            ) +         ); +      } + +      return new RemoveAllOfElement(origin, element, collection); +   } + +   /**** Accessors ************************************************************/ + +   /**** Misc. ****************************************************************/ +   @Override +   public String toString () +   { +      final StringBuilder sb = new StringBuilder(); + +      sb.append(origin.toString()); +      sb.append("(RemoveAllOfElement"); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("element:"); +      sb.append(System.lineSeparator()); +      sb.append(element.toString()); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("collection:"); +      sb.append(System.lineSeparator()); +      sb.append(collection.toString()); + +      sb.append(")"); + +      return sb.toString(); +   } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java new file mode 100644 index 0000000..c05ed5e --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java @@ -0,0 +1,148 @@ +package tonkadur.fate.v1.lang.instruction; + +import tonkadur.error.ErrorManager; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.error.ConflictingTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; +import tonkadur.fate.v1.error.InvalidTypeException; + +import tonkadur.fate.v1.lang.type.CollectionType; +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.ValueNode; + +public class RemoveElement extends InstructionNode +{ +   /***************************************************************************/ +   /**** MEMBERS **************************************************************/ +   /***************************************************************************/ +   protected final ValueNode element; +   protected final ValueNode collection; + +   /***************************************************************************/ +   /**** PROTECTED ************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ +   protected RemoveElement +   ( +      final Origin origin, +      final ValueNode element, +      final ValueNode collection +   ) +   { +      super(origin); + +      this.collection = collection; +      this.element = element; +   } + +   /***************************************************************************/ +   /**** PUBLIC ***************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ +   public static RemoveElement build +   ( +      final Origin origin, +      final ValueNode element, +      final ValueNode collection +   ) +   throws +      InvalidTypeException, +      ConflictingTypeException, +      IncomparableTypeException +   { +      final Type hint; +      final Type collection_type; +      final CollectionType collection_true_type; +      final Type collection_element_type; + +      collection_type = collection.get_type(); + +      if +      ( +         !Type.COLLECTION_TYPES.contains(collection_type.get_base_type()) +         || !(collection_type instanceof CollectionType) +      ) +      { +         ErrorManager.handle +         ( +            new InvalidTypeException +            ( +               collection.get_origin(), +               collection.get_type(), +               Type.COLLECTION_TYPES +            ) +         ); +      } + +      collection_true_type = (CollectionType) collection_type; +      collection_element_type = collection_true_type.get_content_type(); + +      if (element.get_type().can_be_used_as(collection_element_type)) +      { +         return new RemoveElement(origin, element, collection); +      } + +      ErrorManager.handle +      ( +         new ConflictingTypeException +         ( +            element.get_origin(), +            element.get_type(), +            collection_element_type +         ) +      ); + +      hint = +         (Type) element.get_type().generate_comparable_to +         ( +            collection_element_type +         ); + +      if (hint.equals(Type.ANY)) +      { +         ErrorManager.handle +         ( +            new IncomparableTypeException +            ( +               element.get_origin(), +               element.get_type(), +               collection_element_type +            ) +         ); +      } + +      return new RemoveElement(origin, element, collection); +   } + +   /**** Accessors ************************************************************/ + +   /**** Misc. ****************************************************************/ +   @Override +   public String toString () +   { +      final StringBuilder sb = new StringBuilder(); + +      sb.append(origin.toString()); +      sb.append("(RemoveElement"); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("element:"); +      sb.append(System.lineSeparator()); +      sb.append(element.toString()); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("collection:"); +      sb.append(System.lineSeparator()); +      sb.append(collection.toString()); + +      sb.append(")"); + +      return sb.toString(); +   } +} diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index fbb1d2d..bcda80d 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -456,24 +456,61 @@ returns [InstructionNode result]     | ADD_KW WS+ value WS+ value_reference WS* R_PAREN     { -      /* TODO */ +      $result = +         AddElement.build +         ( +            CONTEXT.get_origin_at +            ( +               ($ADD_KW.getLine()), +               ($ADD_KW.getCharPositionInLine()) +            ), +            ($value.result), +            ($value_reference.result) +         );     }     | REMOVE_ONE_KW WS+ value WS+ value_reference WS* R_PAREN     { -      /* TODO */ +      $result = +         RemoveElement.build +         ( +            CONTEXT.get_origin_at +            ( +               ($REMOVE_ONE_KW.getLine()), +               ($REMOVE_ONE_KW.getCharPositionInLine()) +            ), +            ($value.result), +            ($value_reference.result) +         );     }     | REMOVE_ALL_KW WS+ value WS+ value_reference WS* R_PAREN     { -      /* TODO */ +      $result = +         RemoveAllOfElement.build +         ( +            CONTEXT.get_origin_at +            ( +               ($REMOVE_ALL_KW.getLine()), +               ($REMOVE_ALL_KW.getCharPositionInLine()) +            ), +            ($value.result), +            ($value_reference.result) +         );     }     | CLEAR_KW WS+ value_reference WS* R_PAREN     { -      /* TODO */ - -      $result = null; +      $result = +         Clear.build +         ( +            CONTEXT.get_origin_at +            ( +               ($CLEAR_KW.getLine()), +               ($CLEAR_KW.getCharPositionInLine()) +            ), +            ($value_reference.result) +         );     }     | SET_KW WS+ value WS+ value_reference WS* R_PAREN @@ -586,6 +623,10 @@ returns [InstructionNode result]        $result = null;     }  ; +catch [final Throwable e] +{ +   throw new ParseCancellationException(e); +}  instr_cond_list  returns [List<Cons<ValueNode,InstructionNode>> result] | 


