Example #1
0
        public JsonReader(TextReader reader, Relaxations relax = Relaxations.AllowAll) {
            this.Position = -1;
            this.Line = -1;
            this.reader = reader;
            this.relax = relax;

            this.stateStack.Push(StateModel.Start);
        }
Example #2
0
        public JsonReader(TextReader reader, Relaxations relax = Relaxations.AllowAll)
        {
            this.Position = -1;
            this.Line     = -1;
            this.reader   = reader;
            this.relax    = relax;

            this.stateStack.Push(StateModel.Start);
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RelaxItem"/> class.
 /// </summary>
 /// <param name="RelaxationType">Type of the relaxation.</param>
 /// <param name="NumberAllowed">The number allowed.</param>
 /// <param name="GraphElement">The graph element.</param>
 /// <param name="Datum">The datum.</param>
 public RelaxItem(Relaxations RelaxationType, int NumberAllowed, graphElement GraphElement = null, string Datum = null)
 {
     this.GraphElement   = GraphElement;
     this.RelaxationType = RelaxationType;
     bothRevokeAndImpose = RelaxationType.ToString().EndsWith("_Altered");
     if (bothRevokeAndImpose)
     {
         prefixForAltered = RelaxationType.ToString().Replace("_Altered", "");
     }
     this.Datum         = Datum;
     this.NumberAllowed = NumberAllowed;
     if (GraphElement != null)
     {
         AppliesTo = (RelaxAppliesTo)Enum.Parse(typeof(RelaxAppliesTo), GraphElement.GetType().BaseType.Name, true);
     }
     else if (RelaxationType == Relaxations.Additional_Functions_Revoked ||
              RelaxationType == Relaxations.Contains_All_Global_Labels_Revoked ||
              RelaxationType == Relaxations.Ordered_Global_Labels_Revoked ||
              RelaxationType == Relaxations.Global_Label_Revoked ||
              RelaxationType == Relaxations.Negate_Global_Label_Revoked ||
              RelaxationType == Relaxations.Induced_Revoked ||
              RelaxationType == Relaxations.Shape_Restriction_Revoked)
     {
         AppliesTo = RelaxAppliesTo.graph;
     }
     else if (RelaxationType == Relaxations.Direction_Is_Equal_Revoked ||
              RelaxationType == Relaxations.Null_Means_Null_Revoked)
     {
         AppliesTo = RelaxAppliesTo.arc;
     }
     else if (RelaxationType == Relaxations.Strict_Degree_Match_Revoked ||
              RelaxationType == Relaxations.HyperArc_Preclusion_Revoked)
     {
         AppliesTo = RelaxAppliesTo.node;
     }
     else if (RelaxationType == Relaxations.Strict_Node_Count_Revoked)
     {
         AppliesTo = RelaxAppliesTo.hyperarc;
     }
     else
     {
         AppliesTo = RelaxAppliesTo.element;
     }
 }
Example #4
0
 internal bool Matches(Relaxations rType, graphElement g = null, string datum = "")
 {
     if ((!string.IsNullOrWhiteSpace(Datum)) && (Datum != datum))
     {
         return(false);
     }
     if (NumberAllowed <= 0)
     {
         return(false);
     }
     if (RelaxationType == Relaxations.Any)
     {
         return(true);
     }
     if (bothRevokeAndImpose)
     {
         if (!rType.ToString().StartsWith(prefixForAltered))
         {
             return(false);
         }
     }
     else if (RelaxationType != rType)
     {
         return(false);
     }
     if (g == null)
     {
         return(true);
     }
     if (GraphElement != null)
     {
         return(GraphElement == g);
     }
     /* in the remaining cases, g is not null, but GraphElement is, so we need to look at "Applies To" */
     if (AppliesTo == RelaxAppliesTo.element)
     {
         return(true);
     }
     return((g is node && AppliesTo == RelaxAppliesTo.node) ||
            (g is arc && AppliesTo == RelaxAppliesTo.arc) ||
            (g is hyperarc && AppliesTo == RelaxAppliesTo.hyperarc));
 }
Example #5
0
        public static void Check(string json, ReaderExpect[] expects, Relaxations? relax = null) {
            var pos = 0;
            using (var reader = relax.HasValue ? new JsonReader(json, relax.Value) : new JsonReader(json)) {
                while (reader.Read()) {
                    var expect = expects[pos++];
                    Assert.AreEqual(expect.Value, reader.Value, string.Format("{0}-Value:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.Quote, reader.Quote, string.Format("{0}-Quote:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.Type, reader.Type, string.Format("{0}-Type:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.Token, reader.Token, string.Format("{0}-Token:{1}", pos, expect.AssertMessage));

                    Assert.AreEqual(expect.IsStrict, reader.IsStrict, string.Format("{0}-IsStrict:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.IsHexNumber, reader.IsHexNumber, string.Format("{0}-IsHexNumber:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.IsOctalNumber, reader.IsOctalNumber, string.Format("{0}-IsOctalNumber:{1}", pos, expect.AssertMessage));
                    Assert.AreEqual(expect.HasLastComma, reader.HasLastComma, string.Format("{0}-HasLastComma:{1}", pos, expect.AssertMessage));

                    if (expect.Pos.HasValue) {
                        Assert.AreEqual(expect.Pos.Value, reader.Position, string.Format("{0}-Pos:{1}", pos, expect.AssertMessage));
                    }
                    if (expect.Line.HasValue) {
                        Assert.AreEqual(expect.Line.Value, reader.Line, string.Format("{0}-Line:{1}", pos, expect.AssertMessage));
                    }
                }
            }
        }
Example #6
0
 public JsonReader(string json, Relaxations relax = Relaxations.AllowAll)
     : this(new StringReader(json), relax) {
 }
Example #7
0
 public JsonReader(string json, Relaxations relax = Relaxations.AllowAll)
     : this(new StringReader(json), relax)
 {
 }