protected SourceSnippet(SourceObject start, SourceObject end, SourceStruct.Type type) { OfType = type; Name = ""; // name maybe set by inherited class Sequence = start; End = end; }
protected SourceSnippet(string name, SourceObject start, SourceObject end, SourceStruct.Type type) { OfType = type; Name = name; Sequence = start; End = end; }
public SourceObject(string text, TokenRef.Type type) { OfType = type; Text = text; Sequence = null; Previous = null; }
protected SourceSnippet(string name, SourceStruct.Type type, SourceObject start) { OfType = type; Name = name; // name maybe set by inherited class Sequence = start; End = null; // designates an empty Struct -e.g. a QName without a Namespace }
public void LinkNext(SourceObject srcObj) { if (Sequence == null) { Sequence = srcObj; srcObj.Previous = this; } else { Sequence.LinkNext(srcObj); // find the current end of the list } }
public static SourceStruct Build(SourceFile srcFile) { SourceObject start = srcFile.Sequence; // the start object in a sequence of Struct objects to process SourceObject next = start; // the next object to process SourceStruct first = null; // the 1st struct built upon this call SourceStruct previous, build = null; ParseResponse response = NextStateFunc.GoToNextState(next); do { } while (response != ParseResponse.Null); return(first); }
private static SourceStruct.Type IdentifyType(ref SourceObject next, out SourceObject end) { SourceStruct.Type ofType = SourceStruct.Type.Identifying; // if not changed, this value indicates that could not be identified switch (next.OfType) { case TokenRef.Type.Keyword when next.Text == "using": ofType = SourceStruct.Type.Using; break; default: throw new InvalidOperationException($"Could not identify {next.ToString()}!"); } end = next.Sequence; return(ofType); }
public void InsertNextLink(SourceObject srcObj) { if (Sequence == null) { Sequence = srcObj; // at the end of the list -add object here srcObj.Previous = this; } else { srcObj.Previous = this; SourceObject oldNext = Sequence; Sequence = srcObj; srcObj.LinkNext(oldNext); // find the current end of the inserted list and link the old next object there to complete Sequence } }
/// <summary>Build the SourceStruct using the SoucreObject sequence from a SourceFile</summary> /// <param name="lastSrcStruct">Ref: loaded with the last SourceStruct created previously or null if none. Gets set to the last created this call</param> /// <param name="srcFile">The SourceFile to use for building the SourceStruct from</param> /// <returns>The 1st SourceStruct created by this call ...</returns> internal SourceStruct Build(ref SourceStruct lastSrcStruct, SourceFile srcFile) { BuildInstr instr = BuildInstr.Continue; // continue until a struct is identified SourceObject start = srcFile.Sequence; // the start object in a sequence of Struct objects to process SourceObject next = start; // the next object to process SourceStruct first = null; // the 1st struct built upon this call SourceStruct previous, build = null; NextStateFunc.BeginParse(); while (next != null) { ParseResponse response = NextStateFunc.GoToNextState(next); switch (response) { case ParseResponse.Accept: if (first == null) { first = build; } break; case ParseResponse.Resume: break; case ParseResponse.Next: case ParseResponse.Call: next = next.Sequence; break; default: throw new InvalidEnumValueException(typeof(ParseResponse), response); } } // TODO: add check for source file completion, i.e. nothing left on the stack return(first); }
protected SourceStruct(SourceObject start, Type type, SourceFile srcFile) : base(start, type) { Next = null; File = srcFile; }
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); }