// SliceExpression public override bool Walk(SliceExpression node) { return(ShouldWalkWorker(node)); }
// SliceExpression public bool Walk(SliceExpression node) { return(Process(node)); }
public void PostWalk(SliceExpression node) { PostProcess(node); }
public override QlExpression VisitSelect_core(QlParser.Select_coreContext context) { QlExpression take = null; QlToken takeToken = null; QlExpression skip = null; QlToken skipToken = null; List <ColumnNameExpression> columns = null; for (int i = 0; i < context.ChildCount; i++) { var child = context.GetChild(i); var terminal = child as TerminalNodeImpl; if (terminal != null) { if (string.Equals(terminal.GetText(), KEYWORD_TOP, StringComparison.OrdinalIgnoreCase)) { if (i < context.ChildCount - 1) { takeToken = context.ToQlToken(); take = Visit(context.GetChild(++i)); } } if (string.Equals(terminal.GetText(), KEYWORD_SKIP, StringComparison.OrdinalIgnoreCase)) { if (i < context.ChildCount - 1) { skipToken = context.ToQlToken(); skip = Visit(context.GetChild(++i)); } } } var col = child as QlParser.Result_columnContext; if (col != null) { var column = (ColumnNameExpression)Visit(col); if (column != null) { if (columns == null) { columns = new List <ColumnNameExpression>(); } columns.Add(column); } } } var result = Visit(context.GetRuleContext <QlParser.Table_or_subqueryContext>(0)); var expWhere = context.GetRuleContext <QlParser.Where_exprContext>(0); if (expWhere != null) { result = new FilterExpression(Visit(expWhere), result, context.ToQlToken()); } if (columns != null) { result = new MapExpression(result, columns, new QlToken(string.Join(",", columns.Select(c => c.ParseToken.Text)), columns.Min(c => c.ParseToken.Line), columns.Min(c => c.ParseToken.Position))); } if (skip != null) { result = new SliceExpression(result, EJournalExpressionType.Skip, skip, skipToken); } if (take != null) { result = new SliceExpression(result, EJournalExpressionType.Take, take, takeToken); } return(result); }
public override void PostWalk(SliceExpression node) { }
// SliceExpression public override bool Walk(SliceExpression node) { return false; }
// SliceExpression public virtual bool Walk(SliceExpression node) { return true; }
public static ExpressionTerm create_slice_expression(SliceExpression expr) { return(new ExpressionTerm(Type.SliceExpression, expr)); }
// SliceExpression public override bool Walk(SliceExpression node) { return(Location >= node.StartIndex && Location <= node.EndIndex); }
// SliceExpression public override bool Walk(SliceExpression node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
/// <summary> /// Add the token at "token_list[index]" to "source_expression_terms", and /// advance the index. /// </summary> /// <param name="start_index">the very first index of the expression within token_list</param> /// <param name="end_index">how far can the expression continue</param> void process_expression_term(TokenList token_list, ref int index, List <ExpressionTerm> source_expression_terms, int start_index, int end_index) { var token = token_list[index]; if (token.type == TokenType.Identifier) { // check for "identifier [ x ]" case if (index + 3 <= end_index && token_list[index + 1].type == TokenType.Left_Bracket) { // slice expression // find the end ']' character int end_bracket = token_list.find_ending_token(index + 1); if (end_bracket < 0 || end_bracket > end_index) { throw new Exception("Unable to find the ending ']' while processing the " + "bracket notation for \"" + token.ToString() + "\"."); } // continue looking for more '[' - to handle cases like x[1][2] while (end_bracket + 1 < token_list.Count && token_list[end_bracket + 1].type == TokenType.Left_Bracket) { end_bracket = token_list.find_ending_token(end_bracket + 1); if (end_bracket < 0 || end_bracket > end_index) { throw new Exception("Unable to find the ending ']' while processing the " + "bracket notation for \"" + token.ToString() + "\"."); } } var slice_expr = new SliceExpression(token_list, index, end_bracket); source_expression_terms.Add(ExpressionTerm.create_slice_expression(slice_expr)); index = end_bracket + 1; } else { // stand alone identifier source_expression_terms.Add(ExpressionTerm.create_identifier((string)token.value)); index++; } } else if (token.type == TokenType.Integer) { source_expression_terms.Add(ExpressionTerm.create_value(new DynamicValue((int)token.value))); index++; } else if (token.type == TokenType.Double) { source_expression_terms.Add(ExpressionTerm.create_value(new DynamicValue((double)token.value))); index++; } else if (token.type == TokenType.String) { // check for "string [ x ]" case if (index + 3 <= end_index && token_list[index + 1].type == TokenType.Left_Bracket) { // slice expression // find the end ']' character int end_bracket = token_list.find_ending_token(index + 1); if (end_bracket < index || end_bracket > end_index) { throw new Exception("Unable to find the ending ']' while processing the " + "bracket notation for \"" + token.ToString() + "\"."); } var slice_expr = new SliceExpression(token_list, index, end_bracket); source_expression_terms.Add(ExpressionTerm.create_slice_expression(slice_expr)); index = end_bracket + 1; } else { // stand alone string source_expression_terms.Add(ExpressionTerm.create_value(new StringValue((string)token.value))); index++; } } else if (token.type == TokenType.None) { source_expression_terms.Add(ExpressionTerm.create_value(NoneValue.NONE)); index++; } else if (token.type == TokenType.True) { source_expression_terms.Add(ExpressionTerm.create_value(new DynamicValue(true))); index++; } else if (token.type == TokenType.False) { source_expression_terms.Add(ExpressionTerm.create_value(new DynamicValue(false))); index++; } else if (token.type == TokenType.Left_Bracket) { // find the end bracket, but it has to be "end_index" or earlier int end_bracket_index = token_list.find_token_outside_of_paren( TokenType.Right_Bracket, index + 1, end_index); if (end_bracket_index == -1) { throw new Exception("Unable to find the ending ']' in the phrase \"" + token_list.ToString(index, end_index) + "\"."); } var list_expression = new ListExpression(token_list, index, end_bracket_index); source_expression_terms.Add(ExpressionTerm.create_list_expression(list_expression)); index = end_bracket_index + 1; } else if (token.type == TokenType.Left_Brace) { // find the end '}' int end_brace_index = token_list.find_token_outside_of_paren( TokenType.Right_Brace, index + 1, end_index); if (end_brace_index == -1) { throw new Exception("Unable to find the ending '}' in the phrase \"" + token_list.ToString(index, end_index) + "\"."); } var dict_expression = new DictionaryExpression(token_list, index, end_brace_index); source_expression_terms.Add(ExpressionTerm.create_dict_expression(dict_expression)); index = end_brace_index + 1; } else { // token must be a supported operator var op = Operator.parse_token(token); if (op != null) { // detect redundant +, as in 2 + + 3 if (op.type == OperatorType.Add) { if (index == start_index || is_active_operator(token_list[index - 1])) { // skip over the redundant '+' index++; return; } } // detect negation -, as in 2 + - 3 if (op.type == OperatorType.Subtract) { if ((index == start_index) || is_active_operator(token_list[index - 1])) { op = Operator.Constants.Negate; } } source_expression_terms.Add(ExpressionTerm.create_operator(op)); index++; } else { // op == null case, unable to convert "token" to "op" throw new Exception("Source code error on line # " + (line_number + 1) + ". Unsupported operator \"" + token.ToString() + "\"."); } } }
private List <Inferred> InferSliceExpression(SliceExpression node, Scope scope) { Debug.Print("Not implemented: InferSliceExpressionIn"); return(null); }
public virtual void Accept(SliceExpression slice) { }
public override void visit_slice_expression(SliceExpression expr) { expr.accept_children(this); }
public override void PostWalk(SliceExpression node) { PostWalkWorker(node); }
// SliceExpression public virtual bool Walk(SliceExpression node) { return(true); }
public override bool Walk(SliceExpression node) { return(UpdateLineInfo(node, true)); }
public virtual void PostWalk(SliceExpression node) { }
// SliceExpression public override bool Walk(SliceExpression node) { return(false); }
/// <summary> /// Visit operation called for array slice expressions. /// /// <param name="expr">an array slice expression</param> /// </summary> public virtual void visit_slice_expression(SliceExpression expr) { }