private static InvalidExpression ParseInvalid(ErrorCode code, IEnumerator <IToken> tokens) { var expr = new InvalidExpression(code, tokens.Current); tokens.NextNonIgnorable(); return(expr); }
/// <summary> /// Visits an invalid expression. /// </summary> public override void Visit(InvalidExpression expression) { if (Within(expression)) { AddExpressionKeywords(); } }
private BlockStatement ParseBlockStatement(IEnumerator <IToken> tokens) { var start = tokens.Current.Start; var current = tokens.NextNonIgnorable().Current; var statements = new List <IStatement>(); while (current.Type != TokenType.CloseScope) { if (current.Type == TokenType.End) { var invalid = new InvalidExpression(ErrorCode.BlockNotTerminated, current); var statement = new SimpleStatement(invalid, current.End); statements.Add(statement); break; } statements.Add(ParseNextStatement(tokens)); current = tokens.Current; } var end = tokens.Current.End; tokens.NextNonIgnorable(); return(new BlockStatement(statements.ToArray(), start, end)); }
private IStatement ParseExpectedStatement(IEnumerator <IToken> tokens) { var token = tokens.Current; if (token.Type == TokenType.End) { var invalid = new InvalidExpression(ErrorCode.StatementExpected, token); return(new SimpleStatement(invalid, token.End)); } return(ParseNextStatement(tokens)); }
private IStatement ParseAfterCondition(IEnumerator <IToken> tokens) { var token = tokens.Current; if (token.Type != TokenType.CloseGroup) { var invalid = new InvalidExpression(ErrorCode.BracketNotTerminated, token); return(new SimpleStatement(invalid, token.End)); } return(ParseExpectedStatement(tokens.NextNonIgnorable())); }
private IStatement ParseAfterMatch(IEnumerator <IToken> tokens) { var token = tokens.Current; if (token.Type != TokenType.CloseGroup) { var invalid = new InvalidExpression(ErrorCode.BracketNotTerminated, token); return(new SimpleStatement(invalid, token.End)); } token = tokens.NextNonIgnorable().Current; if (token.Type == TokenType.End) { var invalid = new InvalidExpression(ErrorCode.StatementExpected, token); return(new SimpleStatement(invalid, token.End)); } else if (token.Type != TokenType.OpenScope) { var invalid = new InvalidExpression(ErrorCode.BracketExpected, token); return(new SimpleStatement(invalid, token.End)); } var start = tokens.Current.Start; token = tokens.NextNonIgnorable().Current; var statements = new List <IStatement>(); while (token.Type != TokenType.CloseScope) { if (token.Type == TokenType.End) { var invalid = new InvalidExpression(ErrorCode.BlockNotTerminated, token); var statement = new SimpleStatement(invalid, token.End); statements.Add(statement); break; } else { var expr = ParsePrimary(tokens); var block = ParseBlockStatement(tokens); var stmt = new CaseStatement(expr, block); statements.Add(stmt); } token = tokens.Current; } var end = tokens.Current.End; tokens.NextNonIgnorable(); return(new BlockStatement(statements.ToArray(), start, end)); }
private static void CheckProperlyTerminated(IEnumerator <IToken> tokens, ref IExpression expr) { if (tokens.Current.Type == TokenType.SemiColon) { tokens.NextNonIgnorable(); } else { var invalid = new InvalidExpression(ErrorCode.TerminatorExpected, tokens.Current); expr = new BinaryExpression.Multiply(expr, invalid); } }
private static void WriteInvalidExpression(InvalidExpression node, IndentedTextWriter writer) { if (node.Expression == null) { writer.WriteInvalid("!!"); } else { writer.WriteInvalid("!"); node.Expression.WriteTo(writer); writer.WriteInvalid("!"); } }
public static bool TryTransformGetFixedArrayLength(this GetProperty s, Log log, ref Expression result) { var fat = s.Property.DeclaringType as FixedArrayType; if (fat != null && s.Property.UnoName == "Length") { if (fat.OptionalSize != null) { result = fat.OptionalSize; } else { log.Error(s.Source, ErrorCode.E0000, "Cannot get length of 'fixed' array with unknown size"); result = new InvalidExpression(); } return(true); } return(false); }
/// <summary> /// Visits an invalid expression. /// </summary> public virtual void Visit(InvalidExpression expression) { }
void ITreeWalker.Visit(InvalidExpression expression) { Header("Expression/Invalid"); }
void ITreeWalker.Visit(InvalidExpression expression) { expression.Validate(this); }