/// <summary> /// Handles colored text start. colored text contains a token which has to be a 6character long hex string. If the value is off, black is used. /// </summary> private void HandleColoredTextStart() { NonTerminal current = _parseTree[_nonTerminalIndex]; string defaultColor = "000000"; NonTerminalType endType = NonTerminalType.ColoredTextEnd; // current contains the tokens. A color start nonterminal always contains the following tokens // 0 1 2 3 // [color value = string ] string colorValueAsString = StripFromQuotes(current.Tokens[3].LiteralMatchedTokenText); if (colorValueAsString.Length != 6) { colorValueAsString = defaultColor; } _outputWriter.WriteStartElement("color"); _outputWriter.WriteAttributeString("value", colorValueAsString); _nonTerminalIndex++; // as the text inside a formatted text block has limited scope, we have to call a special handler. InnerFormattedTextHandler(endType); // done _outputWriter.WriteEndElement(); }
/// <summary> /// Handles sized text start. Sized text contains a token which has to be a 1 character long string. If the value is wrong, 3 (default) is used /// </summary> private void HandleSizedTextStart() { NonTerminal current = _parseTree[_nonTerminalIndex]; string defaultSize = "3"; NonTerminalType endType = NonTerminalType.SizedTextEnd; // current contains the tokens. A sized text start nonterminal always contains the following tokens // 0 1 2 3 // [size value = string ] string sizedValueAsString = StripFromQuotes(current.Tokens[3].LiteralMatchedTokenText); if ((sizedValueAsString.Length != 1) && !Char.IsDigit(sizedValueAsString, 0)) { sizedValueAsString = defaultSize; } _outputWriter.WriteStartElement("size"); _outputWriter.WriteAttributeString("value", sizedValueAsString); _nonTerminalIndex++; // as the text inside a formatted text block has limited scope, we have to call a special handler. InnerFormattedTextHandler(endType); // done _outputWriter.WriteEndElement(); }
/// <summary> /// Handles all nonterminals from the current position. This routine will /// return when the passed in nonterminal is seen. The passed in nonterminal is the current nonterminal after this routine ends. /// </summary> /// <param name="endType">The nonterminal type which marks the end of the tokenstream to walk.</param> private void InnerGeneralTextHandler(NonTerminalType endType) { while ((_nonTerminalIndex < _parseTree.Count) && (_parseTree[_nonTerminalIndex].Type != endType)) { GeneralTextNTHandler(); _nonTerminalIndex++; } }
/// <summary> /// Handles code text start. /// </summary> private void HandleCodeTextStart() { NonTerminal current = _parseTree[_nonTerminalIndex]; NonTerminalType endType = NonTerminalType.CodeTextEnd; _outputWriter.WriteStartElement("code"); _nonTerminalIndex++; // as the text inside a formatted text block has limited scope, we have to call a special handler. InnerLiteralTextHandler(endType, true); // done _outputWriter.WriteEndElement(); }
/// <summary> /// Handles simply formatted text start. Simple formatted text is text surrounded with bold,italic, striked or underlined. /// </summary> private void HandleSimpleFormattedTextStart() { NonTerminal current = _parseTree[_nonTerminalIndex]; string tag = string.Empty; NonTerminalType endType = NonTerminalType.BoldTextEnd; switch (current.Type) { case NonTerminalType.BoldTextStart: tag = "bold"; endType = NonTerminalType.BoldTextEnd; break; case NonTerminalType.ItalicTextStart: tag = "italic"; endType = NonTerminalType.ItalicTextEnd; break; case NonTerminalType.StrikedTextStart: tag = "striked"; endType = NonTerminalType.StrikedTextEnd; break; case NonTerminalType.UnderlinedTextStart: tag = "underlined"; endType = NonTerminalType.UnderlinedTextEnd; break; default: // error return; } _outputWriter.WriteStartElement(tag); _nonTerminalIndex++; // as the text inside a formatted text block has limited scope, we have to call a special handler. InnerFormattedTextHandler(endType); // done _outputWriter.WriteEndElement(); }
/// <summary> /// Handles all nonterminals from the current position. This routine will /// return when the passed in nonterminal is seen. The passed in nonterminal is the current nonterminal after this routine ends. /// </summary> /// <param name="endType">The nonterminal type which marks the end of the tokenstream to walk.</param> /// <param name="allowCrLf">If set to true, CrLf tokens are handled, otherwise skipped as normal text</param> /// <remarks>Routine used to handle the nonterminals inside code text and other nonterminals which only allow literal text inside themselves. /// This is done in a separate loop because not all nonterminals can be located inside code text for example, see syntaxis</remarks> private void InnerLiteralTextHandler(NonTerminalType endType, bool allowCrLf) { while ((_nonTerminalIndex < _parseTree.Count) && (_parseTree[_nonTerminalIndex].Type != endType)) { if (allowCrLf) { switch (_parseTree[_nonTerminalIndex].Type) { case NonTerminalType.CRLF: HandleCrLf(); break; case NonTerminalType.Tab: HandleTab(); break; default: HandleLiteralText(false); break; } } else { switch (_parseTree[_nonTerminalIndex].Type) { case NonTerminalType.Tab: HandleTab(); break; default: HandleLiteralText(false); break; } } _nonTerminalIndex++; } }
/// <summary> /// CTor /// </summary> /// <param name="typeOfNonTerminal">The type of this nonterminal</param> public NonTerminal(NonTerminalType typeOfNonTerminal) { _type = typeOfNonTerminal; _tokens = new List <IToken>(); }
/// <summary> /// CTor /// </summary> /// <param name="typeOfNonTerminal">The type of this nonterminal</param> public NonTerminal(NonTerminalType typeOfNonTerminal) { _type = typeOfNonTerminal; _tokens = new List<IToken>(); }
public LL1StackElement(bool flag, NonTerminalType nonTerminalType, int productionNum) : this(productionNum) { this.Flag = flag; this.NonTerminalType = nonTerminalType; }
/// <summary> /// Handles all nonterminals from the current position. This routine will /// return when the passed in nonterminal is seen. The passed in nonterminal is the current nonterminal after this routine ends. /// </summary> /// <param name="endType">The nonterminal type which marks the end of the tokenstream to walk.</param> /// <param name="allowCrLf">If set to true, CrLf tokens are handled, otherwise skipped as normal text</param> /// <remarks>Routine used to handle the nonterminals inside code text and other nonterminals which only allow literal text inside themselves. /// This is done in a separate loop because not all nonterminals can be located inside code text for example, see syntaxis</remarks> private void InnerLiteralTextHandler(NonTerminalType endType, bool allowCrLf) { while((_nonTerminalIndex < _parseTree.Count) && (_parseTree[_nonTerminalIndex].Type != endType)) { if(allowCrLf) { switch(_parseTree[_nonTerminalIndex].Type) { case NonTerminalType.CRLF: HandleCrLf(); break; case NonTerminalType.Tab: HandleTab(); break; default: HandleLiteralText(false); break; } } else { switch(_parseTree[_nonTerminalIndex].Type) { case NonTerminalType.Tab: HandleTab(); break; default: HandleLiteralText(false); break; } } _nonTerminalIndex++; } }
/// <summary> /// Handles all nonterminals from the current position. This routine will /// return when the passed in nonterminal is seen. The passed in nonterminal is the current nonterminal after this routine ends. /// </summary> /// <param name="endType">The nonterminal type which marks the end of the tokenstream to walk.</param> private void InnerGeneralTextHandler(NonTerminalType endType) { while((_nonTerminalIndex < _parseTree.Count)&&(_parseTree[_nonTerminalIndex].Type != endType)) { GeneralTextNTHandler(); _nonTerminalIndex++; } }
/// <summary> /// Gets the start NT stack for the nonterminal type passed in. If the stack isn't available, a new one is created. /// </summary> /// <param name="ntType">Type of the nt.</param> /// <returns></returns> private Stack<NonTerminal> GetStartNTStack(NonTerminalType ntType) { Stack<NonTerminal> toReturn = null; if(!_startNTStacks.TryGetValue(ntType, out toReturn)) { // create a new one toReturn = new Stack<NonTerminal>(); _startNTStacks.Add(ntType, toReturn); } return toReturn; }