public Slice(SliceExpression expr) : this() { if (expr.SliceStart != null) _lower = Convert(expr.SliceStart); if (expr.SliceStop != null) _upper = Convert(expr.SliceStop); if (expr.StepProvided && expr.SliceStep != null) _step = Convert(expr.SliceStep); }
// dict_display: '{' [key_datum_list] '}' // key_datum_list: key_datum (',' key_datum)* [","] // key_datum: expression ':' expression private Expression FinishDictValue() { SourceLocation oStart = GetStart(); SourceLocation oEnd = GetEnd(); List<SliceExpression> l = new List<SliceExpression>(); bool prevAllow = _allowIncomplete; try { _allowIncomplete = true; while (true) { if (MaybeEat(TokenKind.RightBrace)) { break; } Expression e1 = ParseExpression(); Eat(TokenKind.Colon); Expression e2 = ParseExpression(); SliceExpression se = new SliceExpression(e1, e2, null, false); se.SetLoc(e1.Start, e2.End); l.Add(se); if (!MaybeEat(TokenKind.Comma)) { Eat(TokenKind.RightBrace); break; } } } finally { _allowIncomplete = prevAllow; } SourceLocation cStart = GetStart(); SourceLocation cEnd = GetEnd(); _sink.MatchPair(new SourceSpan(oStart, oEnd), new SourceSpan(cStart, cEnd), 1); SliceExpression[] exprs = l.ToArray(); DictionaryExpression ret = new DictionaryExpression(exprs); ret.SetLoc(oStart, cEnd); return ret; }
public override void PostWalk(SliceExpression node) { var parent = tree.Peek(); if (parent is IndexExpression) { return; } List<string> parts = new List<string>(); if (node.SliceStop != null) { parts.Add(Content()); } if (node.SliceStep != null) { parts.Add(Content()); } if (node.SliceStart != null) { parts.Add(Content()); } parts.Reverse(); Content(String.Join(": ", parts)); CommonPostWalk(node); }
public override bool Walk(SliceExpression node) { node.Parent = _currentScope; return base.Walk(node); }
// SliceExpression public bool Walk(SliceExpression node) { return Process(node); }
public override bool Walk(SliceExpression node) { var parent = tree.Peek(); if (parent is IndexExpression) { return true; } CommonWalk(node); return true; }
internal override AstExpression Revert() { AstExpression index = null; if (slice is Index) index = expr.Revert(((Index)slice).value); else if (slice is Slice) { Slice concreteSlice = (Slice)slice; AstExpression start = null; if (concreteSlice.lower != null) start = expr.Revert(concreteSlice.lower); AstExpression stop = null; if (concreteSlice.upper != null) stop = expr.Revert(concreteSlice.upper); AstExpression step = null; bool stepProvided = false; if (concreteSlice.step != null) { stepProvided = true; if (concreteSlice.step is Name && ((Name)concreteSlice.step).id == "None") { // pass } else { step = expr.Revert(concreteSlice.step); } } index = new SliceExpression(start, stop, step, stepProvided); } else if (slice is Ellipsis) { index = new ConstantExpression(PythonOps.Ellipsis); } else if (slice is ExtSlice) { index = new TupleExpression(true, ((ExtSlice)slice).Revert()); } else { Debug.Assert(false, "Unexpected type when converting Subscript: " + slice.GetType()); } return new IndexExpression(expr.Revert(value), index); }
private Expression FinishSlice(Expression e0, Location start) { Expression e1 = null; Expression e2 = null; Token t = PeekToken(); switch (t.Kind) { case TokenKind.Comma: case TokenKind.RightBracket: break; case TokenKind.Colon: NextToken(); e2 = ParseSliceEnd(); break; default: e1 = ParseTest(); if (MaybeEat(TokenKind.Colon)) { e2 = ParseSliceEnd(); } break; } SliceExpression ret = new SliceExpression(e0, e1, e2); ret.SetLoc(GetExternal(), start, GetEnd()); return ret; }
internal override AstExpression Revert() { SliceExpression[] e = new SliceExpression[values.Count]; for (int i = 0; i < values.Count; i++) { e[i] = new SliceExpression( expr.Revert(keys[i]), expr.Revert(values[i]), null, false); } return new DictionaryExpression(e); }
internal Slice(SliceExpression expr) : this() { if (expr.SliceStart != null) _lower = Convert(expr.SliceStart); if (expr.SliceStop != null) _upper = Convert(expr.SliceStop); if (expr.StepProvided) if (expr.SliceStep != null) _step = Convert(expr.SliceStep); // [x:y:z] else _step = new Name("None", Load.Instance); // [x:y:] }
public override bool Walk(SliceExpression node) { node.Parent = _currentScope; return(base.Walk(node)); }
public virtual void PostWalk(SliceExpression node) { }
// SliceExpression public virtual bool Walk(SliceExpression node) { return true; }
private Expression FinishSlice(Expression e0, int start) { Expression e1 = null; Expression e2 = null; bool stepProvided = false; switch (PeekToken().Kind) { case TokenKind.Comma: case TokenKind.RightBracket: break; case TokenKind.Colon: // x[?::?] stepProvided = true; NextToken(); e2 = ParseSliceEnd(); break; default: // x[?:val:?] e1 = ParseExpression(); if (MaybeEat(TokenKind.Colon)) { stepProvided = true; e2 = ParseSliceEnd(); } break; } SliceExpression ret = new SliceExpression(e0, e1, e2, stepProvided); ret.SetLoc(_globalParent, start, GetEnd()); return ret; }
public void PostWalk(SliceExpression node) { PostProcess(node); }
// dict_display: '{' [dictorsetmaker] '}' // dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) | // (test (comp_for | (',' test)* [','])) ) private Expression FinishDictOrSetValue() { var oStart = GetStart(); var oEnd = GetEnd(); List<SliceExpression> dictMembers = null; List<Expression> setMembers = null; bool prevAllow = _allowIncomplete; try { _allowIncomplete = true; while (true) { if (MaybeEat(TokenKind.RightBrace)) { // empty dict literal break; } bool first = false; Expression e1 = ParseExpression(); if (MaybeEat(TokenKind.Colon)) { // dict literal if (setMembers != null) { ReportSyntaxError("invalid syntax"); } else if (dictMembers == null) { dictMembers = new List<SliceExpression>(); first = true; } Expression e2 = ParseExpression(); if (PeekToken(Tokens.KeywordForToken)) { if (!first) { ReportSyntaxError("invalid syntax"); } return FinishDictComp(e1, e2, oStart, oEnd); } SliceExpression se = new SliceExpression(e1, e2, null, false); se.SetLoc(_globalParent, e1.StartIndex, e2.EndIndex); dictMembers.Add(se); } else { // set literal if (dictMembers != null) { ReportSyntaxError("invalid syntax"); } else if (setMembers == null) { setMembers = new List<Expression>(); first = true; } if (PeekToken(Tokens.KeywordForToken)) { if (!first) { ReportSyntaxError("invalid syntax"); } return FinishSetComp(e1, oStart, oEnd); } // error recovery if (setMembers != null) { setMembers.Add(e1); } } if (!MaybeEat(TokenKind.Comma)) { Eat(TokenKind.RightBrace); break; } } } finally { _allowIncomplete = prevAllow; } var cStart = GetStart(); var cEnd = GetEnd(); if (_sink != null) { _sink.MatchPair( new SourceSpan(_tokenizer.IndexToLocation(oStart), _tokenizer.IndexToLocation(oEnd)), new SourceSpan(_tokenizer.IndexToLocation(cStart), _tokenizer.IndexToLocation(cEnd)), 1 ); } if (dictMembers != null || setMembers == null) { SliceExpression[] exprs; if (dictMembers != null) { exprs = dictMembers.ToArray(); } else { exprs = new SliceExpression[0]; } DictionaryExpression ret = new DictionaryExpression(exprs); ret.SetLoc(_globalParent, oStart, cEnd); return ret; } else { SetExpression ret = new SetExpression(setMembers.ToArray()); ret.SetLoc(_globalParent, oStart, cEnd); return ret; } }
public string Visit(PyAst.SliceExpression node) => throw CreateNotImplementedEx();