private InputElement MakeInputElement(InputElementTag tag) { var res = new InputElement (new Location(fileName, startPos, startLine, startColumn, currentPos, currentLine, currentColumn), tag, sb.ToString()); sb = new StringBuilder(); startPos = currentPos; startLine = currentLine; startColumn = currentColumn; if (IsSignificantTag(tag)) { lastSignificantTag = tag; wasInExpressionContext = false; } return res; }
private void PopClosePunctuator(InputElement closeElem) { if (openPunctuators.Count == 0) { var openStr = default(string); switch (closeElem.Tag) { case InputElementTag.RParen: openStr = "("; break; case InputElementTag.RBrace: openStr = "{"; break; case InputElementTag.RSquare: openStr = "["; break; default: throw new InvalidOperationException("not a bracket"); } throw MsgError("punctuator", String.Format("no opening '{0}' to match closing '{1}'", openStr, closeElem.Value)); } else { var openElem = openPunctuators[openPunctuators.Count - 1]; openPunctuators.RemoveAt(openPunctuators.Count - 1); if (closeElem.Tag == InputElementTag.RParen && openElem.Tag == InputElementTag.LParen || closeElem.Tag == InputElementTag.RBrace && openElem.Tag == InputElementTag.LBrace || closeElem.Tag == InputElementTag.RSquare && openElem.Tag == InputElementTag.LSquare) return; throw MsgError ("punctuator", String.Format("closing '{0}' does not match opening '{1}' at ({2}, {3})", closeElem.Value, openElem.Value, openElem.Loc.StartLine, openElem.Loc.StartColumn)); } }
private void PushOpenPunctuator(InputElement openElem) { openPunctuators.Add(openElem); }
private void Regurgitate(InputElement ie) { lookahead.Push(ie); }
public Parser(Lexer lexer) { this.lexer = lexer; lookahead = new Seq<InputElement>(); lastLineTerminator = null; pendingComments = null; pendingCommentsLoc = null; }