private string CreateUnexpectedMessage(AphidToken token) { return(string.Format( "Unexpected {0} ({1}) at offset {2}", token.TokenType, token.Lexeme, token.Index)); }
public void GetCodeExcerptTest03() { string s; AphidToken aphidToken = default(AphidToken); s = this.GetCodeExcerptTest("\t", in aphidToken, 0); Assert.AreEqual <string>((string)null, s); }
public AphidParserException(AphidToken unexpectedToken, AphidTokenType expectedToken) { UnexpectedToken = unexpectedToken; ExpectedToken = expectedToken; _message = string.Format( "{0}; expected {1}.", CreateUnexpectedMessage(unexpectedToken), expectedToken); }
public bool NextToken() { _tokenIndex++; if (_tokenIndex < _tokens.Count) { CurrentToken = _tokens[_tokenIndex]; return(true); } CurrentToken = AphidToken.GetNone(CurrentToken.Index + CurrentToken.Lexeme.Length); return(false); }
private bool NextToken() { _tokenIndex++; if (_tokenIndex < _tokens.Count) { _currentToken = _tokens[_tokenIndex]; return(true); } else { _currentToken = default(AphidToken); return(false); } }
static string GetCodeExcerpt(string code, AphidToken token) { var matches = Regex.Matches(code, @"(\r\n)|\r|\n").OfType <Match>().ToArray(); var firstAfter = matches.FirstOrDefault(x => x.Index > token.Index); int line; if (firstAfter != null) { line = Array.IndexOf(matches, firstAfter); } else { line = matches.Count(); } var lines = code.Replace("\r\n", "\n").Replace('\r', '\n').Replace("\n", "\r\n").Split(new[] { "\r\n" }, StringSplitOptions.None); var loc = lines[line]; return(string.Format("({0}) {1}", line, loc)); }
private static AphidExpression ParseCore(string expression) { var fixedExpression = expression; List <AphidToken> tokens; AphidToken lastToken = default; int state, offset = 0; do { tokens = AphidLexer.GetTokens(fixedExpression); state = 0; for (var i = 0; i < tokens.Count; i++) { lastToken = tokens[i]; if (lastToken.TokenType == _tickType) { offset = lastToken.Index; fixedExpression = fixedExpression.Remove(offset, 1).Insert(offset, "'"); if (++state == 2) { break; } } } if (state == 1) { throw new AphidParserException( $"Unterminated string beginning at {expression.Substring(offset)}") { UnexpectedToken = lastToken, }; } }while (state != 0); return(AphidParser.ParseExpression(tokens, expression)); }
public AphidParserException(AphidToken token) { Token = token; }
private TextCellType GetTokenColor(AphidToken t) { switch (t.TokenType) { case AphidTokenType.String: case AphidTokenType.Number: case AphidTokenType.HexNumber: return(TextCellType.Literal); case AphidTokenType.Identifier: return(TextCellType.Identifier); case AphidTokenType.breakKeyword: case AphidTokenType.catchKeyword: case AphidTokenType.defaultKeyword: case AphidTokenType.definedKeyword: case AphidTokenType.deleteKeyword: case AphidTokenType.elseKeyword: case AphidTokenType.extendKeyword: case AphidTokenType.falseKeyword: case AphidTokenType.finallyKeyword: case AphidTokenType.forKeyword: case AphidTokenType.ifKeyword: case AphidTokenType.inKeyword: case AphidTokenType.nullKeyword: case AphidTokenType.retKeyword: case AphidTokenType.switchKeyword: case AphidTokenType.thisKeyword: case AphidTokenType.trueKeyword: case AphidTokenType.tryKeyword: case AphidTokenType.whileKeyword: case AphidTokenType.functionOperator: case AphidTokenType.LoadLibraryOperator: case AphidTokenType.LoadScriptOperator: case AphidTokenType.PatternMatchingOperator: return(TextCellType.Keyword); case AphidTokenType.AdditionOperator: case AphidTokenType.AndOperator: case AphidTokenType.AssignmentOperator: case AphidTokenType.BinaryAndOperator: case AphidTokenType.BinaryOrOperator: case AphidTokenType.ColonOperator: case AphidTokenType.ComplementOperator: case AphidTokenType.DecrementOperator: case AphidTokenType.DivisionEqualOperator: case AphidTokenType.DivisionOperator: case AphidTokenType.EqualityOperator: case AphidTokenType.GreaterThanOperator: case AphidTokenType.GreaterThanOrEqualOperator: case AphidTokenType.IncrementOperator: case AphidTokenType.LessThanOperator: case AphidTokenType.LessThanOrEqualOperator: case AphidTokenType.MinusEqualOperator: case AphidTokenType.MinusOperator: case AphidTokenType.ModulusEqualOperator: case AphidTokenType.ModulusOperator: case AphidTokenType.MultiplicationEqualOperator: case AphidTokenType.MultiplicationOperator: case AphidTokenType.NotEqualOperator: case AphidTokenType.NotOperator: case AphidTokenType.OrEqualOperator: case AphidTokenType.OrOperator: case AphidTokenType.PipelineOperator: case AphidTokenType.PlusEqualOperator: case AphidTokenType.XorEqualOperator: case AphidTokenType.XorOperator: case AphidTokenType.MemberOperator: return(TextCellType.Operator); case AphidTokenType.LeftBrace: case AphidTokenType.RightBrace: case AphidTokenType.LeftBracket: case AphidTokenType.RightBracket: case AphidTokenType.LeftParenthesis: case AphidTokenType.RightParenthesis: return(TextCellType.Delimiter); case AphidTokenType.Comment: return(TextCellType.Comment); default: return(TextCellType.Text); } }
public AphidParserException(AphidToken unexpectedToken) { UnexpectedToken = unexpectedToken; _message = CreateUnexpectedMessage(unexpectedToken) + "."; }
public InterpreterException(string message, AphidToken token) { Message = message; Token = token; }