public void PostWalk(Arg node) { PostProcess(node); }
// Arg public bool Walk(Arg node) { return Process(node); }
public string Visit(PyAst.Arg node) => (node.Name is null ? "" : node.Name + " = ") + Visit(node.Expression);
public CallExpression(Expression target, Arg[] args) { _target = target; _args = args; }
// arglist: // expression rest_of_arguments // expression "=" expression rest_of_arguments // expression "for" gen_expr_rest // private Arg[] FinishArgListOrGenExpr() { Arg a = null; if (_sink != null) { _sink.StartParameters(GetSourceSpan()); } Token t = PeekToken(); if (t.Kind != TokenKind.RightParenthesis && t.Kind != TokenKind.Multiply && t.Kind != TokenKind.Power) { var start = GetStart(); Expression e = ParseExpression(); if (e is ErrorExpression) { return null; } if (MaybeEat(TokenKind.Assign)) { // Keyword argument a = FinishKeywordArgument(e); if (a == null) { // Error recovery a = new Arg(e); a.SetLoc(_globalParent, e.StartIndex, GetEnd()); } } else if (PeekToken(Tokens.KeywordForToken)) { // Generator expression a = new Arg(ParseGeneratorExpression(e)); Eat(TokenKind.RightParenthesis); a.SetLoc(_globalParent, start, GetEnd()); if (_sink != null) { _sink.EndParameters(GetSourceSpan()); } return new Arg[1] { a }; // Generator expression is the argument } else { a = new Arg(e); a.SetLoc(_globalParent, e.StartIndex, e.EndIndex); } // Was this all? // if (MaybeEat(TokenKind.Comma)) { if (_sink != null) { _sink.NextParameter(GetSourceSpan()); } } else { Eat(TokenKind.RightParenthesis); a.SetLoc(_globalParent, start, GetEnd()); if (_sink != null) { _sink.EndParameters(GetSourceSpan()); } return new Arg[1] { a }; } } return FinishArgumentList(a); }
private void CheckUniqueArgument(List<Arg> names, Arg arg) { if (arg != null && arg.Name != null) { for (int i = 0; i < names.Count; i++) { if (names[i].Name == arg.Name) { ReportSyntaxError(IronPython.Resources.DuplicateKeywordArg); } } } }
// Arg public virtual bool Walk(Arg node) { return false; }
public override void PostWalk(Arg node) { CommonPostWalk(node); }
//arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) //argument: [test '='] test # Really [keyword '='] test private Arg[] FinishArgumentList(Arg first) { const TokenKind terminator = TokenKind.RightParenthesis; List<Arg> l = new List<Arg>(); Dictionary<SymbolId, SymbolId> names = new Dictionary<SymbolId, SymbolId>(); if (first != null) { l.Add(first); CheckUniqueArgument(names, first); } // Parse remaining arguments while (true) { if (MaybeEat(terminator)) { break; } Location start = GetStart(); Arg a; if (MaybeEat(TokenKind.Multiply)) { Expression t = ParseTest(); a = new Arg(SymbolTable.Star, t); } else if (MaybeEat(TokenKind.Power)) { Expression t = ParseTest(); a = new Arg(SymbolTable.StarStar, t); } else { Expression e = ParseTest(); if (MaybeEat(TokenKind.Assign)) { a = FinishKeywordArgument(e); CheckUniqueArgument(names, a); } else { a = new Arg(e); } } a.SetLoc(GetExternal(), start, GetEnd()); l.Add(a); if (MaybeEat(TokenKind.Comma)) { context.Sink.NextParameter(GetSpan()); } else { Eat(terminator); break; } } context.Sink.EndParameters(GetSpan()); Arg[] ret = l.ToArray(); return ret; }
private Arg FinishKeywordArgument(Expression t) { NameExpression n = t as NameExpression; if (n == null) { ReportSyntaxError("expected name"); Arg arg = new Arg(SymbolTable.StringToId(""), t); arg.SetLoc(GetExternal(), t.Start, t.End); return arg; } else { Expression val = ParseTest(); Arg arg = new Arg(n.Name, val); arg.SetLoc(GetExternal(), n.Start, val.End); return arg; } }
// arglist ::= // test rest_of_arguments // test "=" test rest_of_arguments // test "for" gen_expr_rest // private Arg[] FinishArgListOrGenExpr() { Arg a = null; context.Sink.StartParameters(GetSpan()); Token t = PeekToken(); if (t.Kind != TokenKind.RightParenthesis && t.Kind != TokenKind.Multiply && t.Kind != TokenKind.Power) { Location start = GetStart(); Expression e = ParseTest(); if (MaybeEat(TokenKind.Assign)) { // Keyword argument a = FinishKeywordArgument(e); if (a == null) { // Error recovery a = new Arg(e); a.SetLoc(GetExternal(), e.Start, GetEnd()); } } else if (PeekToken(Tokens.KeywordForToken)) { // Generator expression a = new Arg(ParseGeneratorExpression(e)); Eat(TokenKind.RightParenthesis); a.SetLoc(GetExternal(), start, GetEnd()); context.Sink.EndParameters(GetSpan()); return new Arg[1] { a }; // Generator expression is the argument } else { a = new Arg(e); a.SetLoc(GetExternal(), e.Start, e.End); } // Was this all? // if (MaybeEat(TokenKind.Comma)) { context.Sink.NextParameter(GetSpan()); } else { Eat(TokenKind.RightParenthesis); a.SetLoc(GetExternal(), start, GetEnd()); context.Sink.EndParameters(GetSpan()); return new Arg[1] { a }; } } return FinishArgumentList(a); }
private void CheckUniqueArgument(Dictionary<SymbolId, SymbolId> names, Arg arg) { if (arg != null && arg.Name != SymbolTable.Empty) { SymbolId name = arg.Name; if (names.ContainsKey(name)) { ReportSyntaxError("duplicate keyword argument"); } names[name] = name; } }
private void CheckUniqueArgument(Dictionary<SymbolId, SymbolId> names, Arg arg) { if (arg != null && arg.Name != SymbolId.Empty) { SymbolId name = arg.Name; if (names.ContainsKey(name)) { ReportSyntaxError(IronPython.Resources.DuplicateKeywordArg); } names[name] = name; } }
private Arg FinishKeywordArgument(Expression t) { NameExpression n = t as NameExpression; if (n == null) { ReportSyntaxError(IronPython.Resources.ExpectedName); Arg arg = new Arg(null, t); arg.SetLoc(t.Start, t.End); return arg; } else { Expression val = ParseExpression(); Arg arg = new Arg(SymbolTable.IdToString(n.Name), val); arg.SetLoc(n.Start, val.End); return arg; } }
// Arg public virtual bool Walk(Arg node) { return true; }
public override bool Walk(Arg node) { if (!String.IsNullOrWhiteSpace(node.Name)) { sink.Add(src, "Named parameters are not supported.", node.Span, NAMED_PARAMETER, Severity.FatalError); } CommonWalk(node); return true; }
public virtual void PostWalk(Arg node) { }
private void CheckUniqueArgument(Dictionary<string, string> names, Arg arg) { if (arg != null && arg.Name != null) { string name = arg.Name; if (names.ContainsKey(name)) { ReportSyntaxError(IronPython.Resources.DuplicateKeywordArg); } names[name] = name; } }
// Arg public override bool Walk(Arg node) { node.Parent = _currentScope; return base.Walk(node); }
private Arg FinishKeywordArgument(Expression t) { NameExpression n = t as NameExpression; if (n == null) { ReportSyntaxError(IronPython.Resources.ExpectedName); Arg arg = new Arg(null, t); arg.SetLoc(_globalParent, t.StartIndex, t.EndIndex); return arg; } else { Expression val = ParseExpression(); Arg arg = new Arg(n.Name, val); arg.SetLoc(_globalParent, n.StartIndex, val.EndIndex); return arg; } }
public CallExpression(Expression target, Arg[] args, bool hasArgsTuple, bool hasKeywordDictionary, int keywordCount, int extraArgs) { this.target = target; this.args = args; this.hasArgsTuple = hasArgsTuple; this.hasKeywordDict = hasKeywordDictionary; this.keywordCount = keywordCount; this.extraArgs = extraArgs; }
//arglist: (argument ',')* (argument [',']| '*' expression [',' '**' expression] | '**' expression) //argument: [expression '='] expression # Really [keyword '='] expression private Arg[] FinishArgumentList(Arg first) { const TokenKind terminator = TokenKind.RightParenthesis; List<Arg> l = new List<Arg>(); if (first != null) { l.Add(first); } // Parse remaining arguments while (true) { if (MaybeEat(terminator)) { break; } var start = GetStart(); Arg a; if (MaybeEat(TokenKind.Multiply)) { Expression t = ParseExpression(); a = new Arg("*", t); } else if (MaybeEat(TokenKind.Power)) { Expression t = ParseExpression(); a = new Arg("**", t); } else { Expression e = ParseExpression(); if (MaybeEat(TokenKind.Assign)) { a = FinishKeywordArgument(e); CheckUniqueArgument(l, a); } else { a = new Arg(e); } } a.SetLoc(_globalParent, start, GetEnd()); l.Add(a); if (MaybeEat(TokenKind.Comma)) { if (_sink != null) { _sink.NextParameter(GetSourceSpan()); } } else { Eat(terminator); break; } } if (_sink != null) { _sink.EndParameters(GetSourceSpan()); } Arg[] ret = l.ToArray(); return ret; }
public override bool Walk(Arg node) { writer.WriteLine("Arg: " + node.Name.ToString()); return base.Walk(node); }