public PeekToken Peek(PeekToken peekToken) { int oldIndex = _index; _index = peekToken.TokenIndex; if (_index >= _inputString.Length) { _index = oldIndex; return(null); } foreach (KeyValuePair <Tokens, string> pair in _tokens) { var r = new Regex(pair.Value); Match m = r.Match(_inputString, _index); if (m.Success && m.Index == _index) { _index += m.Length; var pt = new PeekToken(_index, new Token(pair.Key, m.Value)); _index = oldIndex; return(pt); } } var pt2 = new PeekToken(_index + 1, new Token(Tokens.UNDEFINED, string.Empty)); _index = oldIndex; return(pt2); }
internal static string GetStringExpression(this TokenParser parser) { string retval = ""; int parens = 0; parser.SkipWhiteSpace(); PeekToken pToken = parser.Peek(); while (pToken != null && pToken.TokenPeek.TokenName != TokenParser.Tokens.NEWLINE) { if (pToken.TokenPeek.TokenName == TokenParser.Tokens.STRING || pToken.TokenPeek.TokenName == TokenParser.Tokens.PLUS || pToken.TokenPeek.TokenName == TokenParser.Tokens.STRINGLABEL) { retval = retval + pToken.TokenPeek.TokenValue; parser.GetToken(); parser.SkipWhiteSpace(); pToken = parser.Peek(); continue; } if (pToken.TokenPeek.TokenName == TokenParser.Tokens.LPAREN) { parens++; retval = retval + pToken.TokenPeek.TokenValue; parser.GetToken(); parser.SkipWhiteSpace(); pToken = parser.Peek(); continue; } if (pToken.TokenPeek.TokenName == TokenParser.Tokens.RPAREN) { parens--; retval = retval + pToken.TokenPeek.TokenValue; parser.GetToken(); if (parens == 0) { break; } } if (pToken.TokenPeek.TokenName == TokenParser.Tokens.COLON && parens == 0) { break; } parser.SkipWhiteSpace(); parser.GetToken(); parser.SkipWhiteSpace(); pToken = parser.Peek(); } return(retval); }