You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.6 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. -- ASDL's six builtin types are identifier, int, string, bytes, object, singleton
  2. module Python
  3. {
  4. mod = Module(stmt* body)
  5. | Interactive(stmt* body)
  6. | Expression(expr body)
  7. -- not really an actual node but useful in Jython's typesystem.
  8. | Suite(stmt* body)
  9. stmt = FunctionDef(identifier name, arguments args,
  10. stmt* body, expr* decorator_list, expr? returns)
  11. | AsyncFunctionDef(identifier name, arguments args,
  12. stmt* body, expr* decorator_list, expr? returns)
  13. | ClassDef(identifier name,
  14. expr* bases,
  15. keyword* keywords,
  16. stmt* body,
  17. expr* decorator_list)
  18. | Return(expr? value)
  19. | Delete(expr* targets)
  20. | Assign(expr* targets, expr value)
  21. | AugAssign(expr target, operator op, expr value)
  22. -- use 'orelse' because else is a keyword in target languages
  23. | For(expr target, expr iter, stmt* body, stmt* orelse)
  24. | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse)
  25. | While(expr test, stmt* body, stmt* orelse)
  26. | If(expr test, stmt* body, stmt* orelse)
  27. | With(withitem* items, stmt* body)
  28. | AsyncWith(withitem* items, stmt* body)
  29. | Raise(expr? exc, expr? cause)
  30. | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
  31. | Assert(expr test, expr? msg)
  32. | Import(alias* names)
  33. | ImportFrom(identifier? module, alias* names, int? level)
  34. | Global(identifier* names)
  35. | Nonlocal(identifier* names)
  36. | Expr(expr value)
  37. | Pass | Break | Continue
  38. -- XXX Jython will be different
  39. -- col_offset is the byte offset in the utf8 string the parser uses
  40. attributes (int lineno, int col_offset)
  41. -- BoolOp() can use left & right?
  42. expr = BoolOp(boolop op, expr* values)
  43. | BinOp(expr left, operator op, expr right)
  44. | UnaryOp(unaryop op, expr operand)
  45. | Lambda(arguments args, expr body)
  46. | IfExp(expr test, expr body, expr orelse)
  47. | Dict(expr* keys, expr* values)
  48. | Set(expr* elts)
  49. | ListComp(expr elt, comprehension* generators)
  50. | SetComp(expr elt, comprehension* generators)
  51. | DictComp(expr key, expr value, comprehension* generators)
  52. | GeneratorExp(expr elt, comprehension* generators)
  53. -- the grammar constrains where yield expressions can occur
  54. | Await(expr value)
  55. | Yield(expr? value)
  56. | YieldFrom(expr value)
  57. -- need sequences for compare to distinguish between
  58. -- x < 4 < 3 and (x < 4) < 3
  59. | Compare(expr left, cmpop* ops, expr* comparators)
  60. | Call(expr func, expr* args, keyword* keywords)
  61. | Num(object n) -- a number as a PyObject.
  62. | Str(string s) -- need to specify raw, unicode, etc?
  63. | Bytes(bytes s)
  64. | NameConstant(singleton value)
  65. | Ellipsis
  66. -- the following expression can appear in assignment context
  67. | Attribute(expr value, identifier attr, expr_context ctx)
  68. | Subscript(expr value, slice slice, expr_context ctx)
  69. | Starred(expr value, expr_context ctx)
  70. | Name(identifier id, expr_context ctx)
  71. | List(expr* elts, expr_context ctx)
  72. | Tuple(expr* elts, expr_context ctx)
  73. -- col_offset is the byte offset in the utf8 string the parser uses
  74. attributes (int lineno, int col_offset)
  75. expr_context = Load | Store | Del | AugLoad | AugStore | Param
  76. slice = Slice(expr? lower, expr? upper, expr? step)
  77. | ExtSlice(slice* dims)
  78. | Index(expr value)
  79. boolop = And | Or
  80. operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
  81. | RShift | BitOr | BitXor | BitAnd | FloorDiv
  82. unaryop = Invert | Not | UAdd | USub
  83. cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
  84. comprehension = (expr target, expr iter, expr* ifs)
  85. excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
  86. attributes (int lineno, int col_offset)
  87. arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults,
  88. arg? kwarg, expr* defaults)
  89. arg = (identifier arg, expr? annotation)
  90. attributes (int lineno, int col_offset)
  91. -- keyword arguments supplied to call (NULL identifier for **kwargs)
  92. keyword = (identifier? arg, expr value)
  93. -- import name with optional 'as' alias.
  94. alias = (identifier name, identifier? asname)
  95. withitem = (expr context_expr, expr? optional_vars)
  96. }