Ejemplo n.º 1
0
 /// <summary>Add a NAMED record with a name of a next state record to link to</summary>
 /// <param name="name">Record's name to be added to the name cross reference list</param>
 /// <param name="record">Record to be saved</param>
 /// <param name="linkToName">Name of record to link to</param>
 public void AddNextStateRecord(string name, NextStateRec record, string linkToName)
 {
     //NextStateFunc.AddNextStateRecord(record, null);
     m_recNameXRef.Add(name, record);
     //m_unLnkdRecordList.Add(record, linkToName);
     throw new NotImplementedException("Needs completing!");
 }
Ejemplo n.º 2
0
        internal void LinkAlternate(NextStateRec alt)
        {
            if (Alternate != null)
            {
                throw new InvalidOperationException($"Can only set Alternate State Once! Alternate has already been set.\n\tAlternate={Alternate}\n\tLinkNext={alt}");
            }

            Alternate = alt;
        }
Ejemplo n.º 3
0
        // Link the next NSRecord to the end of the list, returning the object that contains this next Record
        internal void LinkNext(NextStateRec next)
        {
            if (Sequence != null)
            {
                throw new InvalidOperationException($"Can only set Next State Once! Sequence has already been set.\n\tSequence={Sequence}\n\tLinkNext={next}");
            }

            Sequence = next;
        }
Ejemplo n.º 4
0
        public NextStateBuilder(NextStateRec startState, NextStateFunc.ActionDelegte action)
            : this(startState)
        {
            if (action is null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            NextStateFunc.Action += action;
        }
Ejemplo n.º 5
0
        public NextStateBuilder(NextStateRec startState)
        {
            if (startState is null)
            {
                throw new ArgumentNullException(nameof(startState));
            }

            NextStateFunc = new NextStateFunc(startState);
            m_recNameXRef.Add(startState.Name, startState);
        }
Ejemplo n.º 6
0
 /// <summary>Resolves those records that do not yet have a NextState recorded</summary>
 /// <remarks>Where a record is added, but the NextState is not yet added, then its NestState's name is recorded.
 /// This methods resolves these unlimked records after all records have been recorded and their objects created</remarks>
 public void ResolveUnlinkedRecords()
 {
     foreach (KeyValuePair <NextStateRec, Link2Ref> item in m_unLnkdRecordList)
     {
         NextStateRec record = item.Key;
         NextStateRec next   = m_recNameXRef[item.Value.Name];
         throw new NotImplementedException("Needs completing!");
         // NextStateFunc.AddRecordNextLink(record, next);
     }
 }
Ejemplo n.º 7
0
 /// <summary>Add a record with a name of a next state record to link to</summary>
 /// <param name="record">Record to be saved</param>
 /// <param name="linkToName">Name of record to link to</param>
 public void AddNSRecordRef(NextStateRec record, string linkToName, bool isAlternate)
 {
     if (m_recNameXRef.ContainsKey(linkToName))
     {
         // gramma has been already defined -can be linked as required
         NextStateRec link = m_recNameXRef[linkToName];
         if (isAlternate)
         {
             record.LinkAlternate(link);
         }
         else
         {
             record.LinkNext(link);
         }
     }
     else
     {
         m_unLnkdRecordList.Add(record, new Link2Ref(linkToName, isAlternate));       // Gramma not yet defined, add to list to be resovled later
     }
 }
Ejemplo n.º 8
0
        public static NextStateRec CreateTokenRef(string name, TokenRef.Type type, ParseResponse response)
        {
            NextStateRec nsRec;

            switch (type)
            {
            case TokenRef.Type.Null:
                throw new FormatException($"SourceObject Type {type.ToString()} is valid BUT NOT in the context as a Next State Token Ref!");

            case TokenRef.Type.Empty:
                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateEmpty(), null, response);
                break;

            case TokenRef.Type.Identifier:
                if (!(name is null))
                {
                    throw new ArgumentNullException(nameof(name), $"NextStateRecords can not contain Identifier Tokens with predefined names -{nameof(name)} must be set to 'null', not '{name}'!");
                }

                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateIdentifier(), response);
                break;

            case TokenRef.Type.Keyword:
                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateKeyword(name), name, response);
                break;

            case TokenRef.Type.Operator:
                nsRec = new NextStateRec(Type.TokenRef, TokenRef.CreateOperator(name), name, response);
                break;

            case TokenRef.Type.Error:
                throw new NotImplementedException("Error types yet to be implemented!");

            default:
                throw InvalidEnumValueException.InvalidArgument(typeof(TokenRef.Type), type, nameof(name));
            }

            return(nsRec);
        }
Ejemplo n.º 9
0
 /// <summary>Add the Allternative NextState to an NS record</summary>
 /// <param name="record">Record to receive link to the Alternative NS Record</param>
 /// <param name="altNextState">The Next stae record to be linked as Alternative to record</param>
 public void AddAlternativeNSRecord(NextStateRec record, NextStateRec altNextState)
 {
     record.LinkAlternate(altNextState);
 }
Ejemplo n.º 10
0
 /// <summary>Add the Sequence NextState to an NS record</summary>
 /// <param name="record">Record to receive link to the Sequence NS Record</param>
 /// <param name="nextState">The Next stae record to be linked to record</param>
 public void AddSequenceNSRecord(NextStateRec record, NextStateRec nextState)
 {
     record.LinkNext(nextState);
 }
Ejemplo n.º 11
0
 public void SetNextStateStartRecord(NextStateRec startRec)
 {
     NextStateFunc.StartState = startRec;
     m_recNameXRef.Add(startRec.Name, startRec);
 }
Ejemplo n.º 12
0
 /// <summary>Add a NAMED record with a next state record supplied</summary>
 /// <param name="name">Record's name to be added to the name cross reference list</param>
 /// <param name="record">Record to be saved</param>
 /// <param name="nextState">The Next stae record to be linked to record</param>
 public void AddNextStateRecord(string name, NextStateRec record, NextStateRec nextState)
 {
     //NextStateFunc.AddNextStateRecord(record, nextState);
     m_recNameXRef.Add(name, record);
     throw new NotImplementedException("Needs completing!");
 }
Ejemplo n.º 13
0
 public void AddNSRecordRef(string name, NextStateRec record)
 {
     m_recNameXRef.Add(name, record);
 }
Ejemplo n.º 14
0
        public ParseResponse GoToNextState(SourceObject next)
        {
            ParseResponse response = ParseResponse.Null;
            NextStateRec  state    = CurrentState;
            TokenRef      token    = TokenRef.Create(next.OfType, next.Text);

            do
            {
                Debug.WriteIf(state != null, $"{{{token}}} against {{{state.Token}}}", "Check");

                if (state == null)
                {
                    response = ParseResponse.Reject;
                    Debug.WriteLine(" -Match! Response = Reject");
                }

                else if (token == state.Token)
                {
                    response = state.Response;
                    Debug.WriteLine(" -Match! Response = " + response);
                }

                else if (state.Token.OfType == TokenRef.Type.Empty)
                {
                    response = state.Response;
                    Debug.WriteLine(" -Match on Empty! Response = " + response);
                }

                else if (state.Token.OfType == TokenRef.Type.Null)
                {
                    if (state.Response == ParseResponse.Next)
                    {
                        state    = state.Sequence;
                        response = ParseResponse.Null;
                    }
                    else
                    {
                        response = state.Response;
                    }

                    Debug.WriteLine(" -Special Response = " + response);
                }

                else
                {
                    Debug.WriteLine(" -NO Match! Check Next");
                    state = state.Sequence;
                }
            } while (response == ParseResponse.Null);

            // Determine next state based on response
            Debug.Write($"{{{state.Token }}} -> ", "Result");
            switch (response)
            {
            case ParseResponse.Next:
                CurrentState = state.Sequence;
                break;

            default:
                throw new InvalidEnumValueException(typeof(ParseResponse), response);
            }

            Debug.WriteLine($"{{{CurrentState.Token}}} -Response {response}!");

            return(response);
        }
Ejemplo n.º 15
0
 public NextStateFunc(NextStateRec startState)
 {
     StartState   = startState ?? throw new ArgumentNullException(nameof(startState));
     CurrentState = startState;
 }
Ejemplo n.º 16
0
 public NextStateFunc(NextStateRec startState, ActionDelegte action)
 {
     StartState   = startState ?? throw new ArgumentNullException(nameof(startState));
     CurrentState = startState;
     Action       = action ?? throw new ArgumentNullException(nameof(action));
 }