|
42 | 42 |
|
43 | 43 | // TODO this class has to be moved to impl package and from this package we need to do api. |
44 | 44 |
|
| 45 | +import static com.oracle.graal.python.pegparser.AbstractParser.EMPTY_ARG_ARRAY; |
| 46 | +import static com.oracle.graal.python.pegparser.AbstractParser.EMPTY_EXPR_ARRAY; |
| 47 | + |
45 | 48 | import java.math.BigInteger; |
46 | 49 | import java.util.Arrays; |
47 | 50 |
|
|
51 | 54 | import com.oracle.graal.python.pegparser.sst.AliasTy; |
52 | 55 | import com.oracle.graal.python.pegparser.sst.ArgTy; |
53 | 56 | import com.oracle.graal.python.pegparser.sst.ArgumentsTy; |
| 57 | +import com.oracle.graal.python.pegparser.sst.BoolOpTy; |
| 58 | +import com.oracle.graal.python.pegparser.sst.CmpOpTy; |
54 | 59 | import com.oracle.graal.python.pegparser.sst.ComprehensionTy; |
55 | 60 | import com.oracle.graal.python.pegparser.sst.ConstantValue; |
56 | 61 | import com.oracle.graal.python.pegparser.sst.ExceptHandlerTy; |
57 | 62 | import com.oracle.graal.python.pegparser.sst.ExprContextTy; |
58 | 63 | import com.oracle.graal.python.pegparser.sst.ExprTy; |
59 | | -import com.oracle.graal.python.pegparser.sst.BoolOpTy; |
60 | | -import com.oracle.graal.python.pegparser.sst.CmpOpTy; |
61 | | -import com.oracle.graal.python.pegparser.sst.StmtTy.AsyncFunctionDef; |
62 | | -import com.oracle.graal.python.pegparser.sst.StmtTy.FunctionDef; |
63 | | -import com.oracle.graal.python.pegparser.sst.WithItemTy; |
64 | | -import com.oracle.graal.python.pegparser.sst.UnaryOpTy; |
65 | | -import com.oracle.graal.python.pegparser.sst.OperatorTy; |
66 | 64 | import com.oracle.graal.python.pegparser.sst.KeywordTy; |
| 65 | +import com.oracle.graal.python.pegparser.sst.MatchCaseTy; |
67 | 66 | import com.oracle.graal.python.pegparser.sst.ModTy; |
| 67 | +import com.oracle.graal.python.pegparser.sst.OperatorTy; |
| 68 | +import com.oracle.graal.python.pegparser.sst.PatternTy; |
68 | 69 | import com.oracle.graal.python.pegparser.sst.StmtTy; |
69 | 70 | import com.oracle.graal.python.pegparser.sst.StringLiteralUtils; |
| 71 | +import com.oracle.graal.python.pegparser.sst.UnaryOpTy; |
| 72 | +import com.oracle.graal.python.pegparser.sst.WithItemTy; |
70 | 73 | import com.oracle.graal.python.pegparser.tokenizer.SourceRange; |
71 | 74 |
|
72 | | -import static com.oracle.graal.python.pegparser.AbstractParser.EMPTY_ARG_ARRAY; |
73 | | -import static com.oracle.graal.python.pegparser.AbstractParser.EMPTY_EXPR_ARRAY; |
74 | | - |
75 | 75 | public class NodeFactory { |
76 | 76 | public StmtTy createAnnAssignment(ExprTy target, ExprTy annotation, ExprTy rhs, boolean isSimple, SourceRange sourceRange) { |
77 | 77 | return new StmtTy.AnnAssign(target, annotation, rhs, isSimple, sourceRange); |
@@ -399,12 +399,12 @@ public StmtTy createFunctionDef(String name, ArgumentsTy args, StmtTy[] body, Ex |
399 | 399 | } |
400 | 400 |
|
401 | 401 | public StmtTy createFunctionDefWithDecorators(StmtTy funcDef, ExprTy[] decorators) { |
402 | | - if (funcDef instanceof AsyncFunctionDef) { |
| 402 | + if (funcDef instanceof StmtTy.AsyncFunctionDef) { |
403 | 403 | StmtTy.AsyncFunctionDef f = (StmtTy.AsyncFunctionDef) funcDef; |
404 | | - return new AsyncFunctionDef(f.name, f.args, f.body, decorators, f.returns, f.typeComment, f.getSourceRange()); |
| 404 | + return new StmtTy.AsyncFunctionDef(f.name, f.args, f.body, decorators, f.returns, f.typeComment, f.getSourceRange()); |
405 | 405 | } |
406 | 406 | StmtTy.FunctionDef f = (StmtTy.FunctionDef) funcDef; |
407 | | - return new FunctionDef(f.name, f.args, f.body, decorators, f.returns, f.typeComment, f.getSourceRange()); |
| 407 | + return new StmtTy.FunctionDef(f.name, f.args, f.body, decorators, f.returns, f.typeComment, f.getSourceRange()); |
408 | 408 | } |
409 | 409 |
|
410 | 410 | public StmtTy createAsyncFunctionDef(String name, ArgumentsTy args, StmtTy[] body, ExprTy returns, String typeComment, SourceRange sourceRange) { |
@@ -523,4 +523,44 @@ public ExprTy createGetAttribute(ExprTy receiver, String name, SourceRange sourc |
523 | 523 | public ExprTy.Name createVariable(String name, SourceRange sourceRange) { |
524 | 524 | return createVariable(name, sourceRange, ExprContextTy.Load); |
525 | 525 | } |
| 526 | + |
| 527 | + public StmtTy createMatch(ExprTy subject, MatchCaseTy[] cases, SourceRange sourceRange) { |
| 528 | + return new StmtTy.Match(subject, cases, sourceRange); |
| 529 | + } |
| 530 | + |
| 531 | + public MatchCaseTy createMatchCase(PatternTy pattern, ExprTy guard, StmtTy[] body, SourceRange sourceRange) { |
| 532 | + return new MatchCaseTy(pattern, guard, body, sourceRange); |
| 533 | + } |
| 534 | + |
| 535 | + public PatternTy createMatchValue(ExprTy value, SourceRange sourceRange) { |
| 536 | + return new PatternTy.MatchValue(value, sourceRange); |
| 537 | + } |
| 538 | + |
| 539 | + public PatternTy createMatchSingleton(ConstantValue value, SourceRange sourceRange) { |
| 540 | + return new PatternTy.MatchSingleton(value, sourceRange); |
| 541 | + } |
| 542 | + |
| 543 | + public PatternTy createMatchSequence(PatternTy[] patterns, SourceRange sourceRange) { |
| 544 | + return new PatternTy.MatchSequence(patterns, sourceRange); |
| 545 | + } |
| 546 | + |
| 547 | + public PatternTy createMatchMapping(ExprTy[] keys, PatternTy[] patterns, String rest, SourceRange sourceRange) { |
| 548 | + return new PatternTy.MatchMapping(keys, patterns, rest, sourceRange); |
| 549 | + } |
| 550 | + |
| 551 | + public PatternTy createMatchClass(ExprTy cls, PatternTy[] patterns, String[] kwdAttrs, PatternTy[] kwdPatterns, SourceRange sourceRange) { |
| 552 | + return new PatternTy.MatchClass(cls, patterns, kwdAttrs, kwdPatterns, sourceRange); |
| 553 | + } |
| 554 | + |
| 555 | + public PatternTy createMatchStar(String name, SourceRange sourceRange) { |
| 556 | + return new PatternTy.MatchStar(name, sourceRange); |
| 557 | + } |
| 558 | + |
| 559 | + public PatternTy createMatchAs(PatternTy pattern, String name, SourceRange sourceRange) { |
| 560 | + return new PatternTy.MatchAs(pattern, name, sourceRange); |
| 561 | + } |
| 562 | + |
| 563 | + public PatternTy createMatchOr(PatternTy[] patterns, SourceRange sourceRange) { |
| 564 | + return new PatternTy.MatchOr(patterns, sourceRange); |
| 565 | + } |
526 | 566 | } |
0 commit comments