private Token ProduceToken(Stack<Token> groupStack, LookAheadBuffer lookAheadBuffer) { while (true) { Token read = LookAheadDFA(lookAheadBuffer); if (read.Type == SymbolType.GroupStart && (groupStack.Count == 0 || groupStack.Peek().Group.Nesting.Contains(read.Group.TableIndex))) { lookAheadBuffer.Consume(read.Data.Length); read.EndPosition = lookAheadBuffer.Position; groupStack.Push(read); } else if (groupStack.Count == 0) { //The token is ready to be analyzed. lookAheadBuffer.Consume(read.Data.Length); read.EndPosition = lookAheadBuffer.Position; return read; } else if (Object.ReferenceEquals(groupStack.Peek().Group.End, read.Symbol)) { //End the current group Token pop = groupStack.Pop(); if (pop.Group.Ending == GroupEndingMode.Closed) { pop.Data += read.Data; lookAheadBuffer.Consume(read.Data.Length); read.EndPosition = lookAheadBuffer.Position; } //We are out of the group. Return pop'd token (which contains all the group text) if (groupStack.Count == 0) { //Change symbol to parent pop.Symbol = pop.Group.Container; return pop; } else { groupStack.Peek().Data += pop.Data; } } else if (read.Type == SymbolType.End) { return read; } else { //We are in a group, Append to the Token on the top of the stack. //Take into account the Token group mode Token top = groupStack.Peek(); if (top.Group.Advance == GroupAdvanceMode.Token) { // Append all text top.Data += read.Data; lookAheadBuffer.Consume(read.Data.Length); } else { // Append one character top.Data += read.Data[0].ToString(); lookAheadBuffer.Consume(1); } read.EndPosition = lookAheadBuffer.Position; } } }
private Token ProduceToken(Stack <Token> groupStack, LookAheadBuffer lookAheadBuffer) { while (true) { Token read = LookAheadDFA(lookAheadBuffer); if (read.Type == SymbolType.GroupStart && (groupStack.Count == 0 || groupStack.Peek().Group.Nesting.Contains(read.Group.TableIndex))) { lookAheadBuffer.Consume(read.Data.Length); read.EndPosition = lookAheadBuffer.Position; groupStack.Push(read); } else if (groupStack.Count == 0) { //The token is ready to be analyzed. lookAheadBuffer.Consume(read.Data.Length); read.EndPosition = lookAheadBuffer.Position; return(read); } else if (Object.ReferenceEquals(groupStack.Peek().Group.End, read.Symbol)) { //End the current group Token pop = groupStack.Pop(); if (pop.Group.Ending == GroupEndingMode.Closed) { pop.Data += read.Data; lookAheadBuffer.Consume(read.Data.Length); read.EndPosition = lookAheadBuffer.Position; } //We are out of the group. Return pop'd token (which contains all the group text) if (groupStack.Count == 0) { //Change symbol to parent pop.Symbol = pop.Group.Container; return(pop); } else { groupStack.Peek().Data += pop.Data; } } else if (read.Type == SymbolType.End) { return(read); } else { //We are in a group, Append to the Token on the top of the stack. //Take into account the Token group mode Token top = groupStack.Peek(); if (top.Group.Advance == GroupAdvanceMode.Token) { // Append all text top.Data += read.Data; lookAheadBuffer.Consume(read.Data.Length); } else { // Append one character top.Data += read.Data[0].ToString(); lookAheadBuffer.Consume(1); } read.EndPosition = lookAheadBuffer.Position; } } }