private void serachForParent(LaTeXElement element, LaTeXElementParser parser) { var parentFound = false; for (var i = _parserList.Count - 2; i > -1; i--) { try { _parserList[i].SetChildElement(_elementsList[i], element); parentFound = true; _elementsList.RemoveRange(i + 1, _elementsList.Count - i - 1); _parserList.RemoveRange(i + 1, _parserList.Count - i - 1); addElementAndParserToTracking(element, parser); break; } catch (ArgumentException) { } catch (NotSupportedException) { } } if (!parentFound) { _parserList.Clear(); _elementsList.Clear(); addElementToList(element, parser); } }
private void addElementAndParserToTracking(LaTeXElement element, LaTeXElementParser parser) { if (parser != null) { _parserList.Add(parser); _elementsList.Add(element); } }
private void backofElement(LaTeXElementParser parser) { var searchingForType = parser.GetEmptyElement().GetType(); for (var i = _elementsList.Count - 1; i >= 0; i--) { if (_elementsList[i].GetType() == searchingForType) { var remoevEl = _elementsList.Count - i - 1; _elementsList.RemoveRange(i, remoevEl); _parserList.RemoveRange(i, remoevEl); break; } } }
private void setElementToParent(LaTeXElement element, LaTeXElementParser parser) { try { setElementToClosestParent(element, parser); } catch (ArgumentException) { serachForParent(element, parser); } catch (NotSupportedException) { serachForParent(element, parser); } }
private void setElementInHierarchy(LaTeXElement element, LaTeXElementParser parser) { if (element != null && _elements.Count == 0) { addElementToList(element, parser); } else if (element != null) { setElementToParent(element, parser); } else { backofElement(parser); } }
/// <summary> /// Creates a new pair /// </summary> /// <param name="element">The element of the pair</param> /// <param name="parser">The parser for the element</param> public LaTeXElementElementParserPair(LaTeXElement element, LaTeXElementParser parser) { Element = element; Parser = parser; }
private void setElementToClosestParent(LaTeXElement element, LaTeXElementParser parser) { _parserList[_parserList.Count - 1].SetChildElement(_elementsList[_elementsList.Count - 1], element); addElementAndParserToTracking(element, parser); }
private void addElementToList(LaTeXElement element, LaTeXElementParser parser) { _elements.Add(element); addElementAndParserToTracking(element, parser); }
private LaTeXElement parseElement(StringBuilder code, LaTeXElementParser parser) { var element = _textParser.CodeStartsWithText(code) ? _textParser.ParseCode(code) : parser.ParseCode(code); return(element); }
private bool codeCantBeProcessed(StringBuilder code, LaTeXElementParser parser) { return(parser == null && !_textParser.CodeStartsWithText(code)); }