public XmlParser(XmlRootState rootState, bool buildTree) { RootState = rootState; CurrentState = rootState; previousState = rootState; BuildTree = buildTree; Reset(); }
public XmlParser(XmlRootState rootState, bool buildTree) { this.rootState = rootState; this.currentState = rootState; this.previousState = rootState; this.buildTree = buildTree; Reset(); }
protected XmlParser(XmlRootState rootState) { RootState = rootState; Context = new XmlParserContext { CurrentStateLength = 0, CurrentState = rootState, PreviousState = rootState, KeywordBuilder = new StringBuilder(), Nodes = new NodeStack() }; Context.Nodes.Push(RootState.CreateDocument()); }
/// <summary> /// Advances the parser to end the node at the current position and gets that node's path. /// </summary> /// <param name="parser">A spine parser. Its state will be modified.</param> /// <param name="text">The text snapshot corresponding to the parser.</param> /// <returns></returns> public static List <XObject> AdvanceToNodeEndAndGetNodePath(this XmlSpineParser parser, ITextSource text, int maximumReadahead = DEFAULT_READAHEAD_LIMIT) { var context = parser.GetContext(); int startOffset = parser.Position; int startDepth = parser.Spine.Count; //if in potential start of a state, advance into the next state var end = Math.Min(text.Length - context.Position, maximumReadahead) + context.Position; if (parser.Position < end && (XmlRootState.IsNotFree(context) || (context.CurrentState is XmlRootState && text[parser.Position] == '<'))) { do { parser.Push(text[parser.Position]); } while (parser.Position < end && XmlRootState.IsNotFree(context)); //if it transitioned to another state, eat until we get a new node on the stack if (parser.Position < end && !(context.CurrentState is XmlRootState) && context.Nodes.Count <= startDepth) { parser.Push(text[parser.Position]); } } var path = parser.Spine.ToNodePath(); // make sure the leaf node is ended if (path.Count > 0) { var leaf = path[path.Count - 1]; if (!(leaf is XDocument)) { AdvanceUntilEnded(parser, leaf, text, maximumReadahead - (parser.Position - startOffset)); } //the leaf node might have a child that's a better match for the offset if (leaf is XContainer c && c.FindAtOffset(startOffset) is XObject o) { path.Add(o); } } return(path); }
XmlParser(XmlParser copyFrom) { buildTree = false; rootState = copyFrom.rootState; currentState = copyFrom.currentState; previousState = copyFrom.previousState; position = copyFrom.position; previousLineEnd = copyFrom.location; location = copyFrom.location; stateTag = copyFrom.stateTag; keywordBuilder = new StringBuilder(copyFrom.keywordBuilder.ToString()); currentStateLength = copyFrom.currentStateLength; //clone the node stack var l = new List <XObject> (CopyXObjects(copyFrom.nodes)); l.Reverse(); nodes = new NodeStack(l); }
/// <summary> /// Efficiently creates a spine parser using information from an existing document. The position of /// the parser is not guaranteed but will not exceed <paramref name="maximumPosition" />. /// </summary> /// <returns></returns> public static XmlSpineParser FromDocumentPosition(XmlRootState stateMachine, XDocument xdocument, int maximumPosition) => xdocument.FindAtOrBeforeOffset(maximumPosition) is XObject obj &&
public XmlSpineParser(XmlParserContext context, XmlRootState rootState) : base(context, rootState) { Debug.Assert(!context.BuildTree); }
public XmlSpineParser(XmlRootState rootState) : base(rootState) { }
public XmlTreeParser(XmlRootState rootState) : base(rootState) { Context.BuildTree = true; Context.Diagnostics = new List <XmlDiagnosticInfo> (); }
protected XmlParser(XmlParserContext context, XmlRootState rootState) { Context = context; RootState = rootState; }