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.

125 lines
4.7 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
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. | FormattedValue(expr value, int? conversion, expr? format_spec)
  64. | JoinedStr(expr* values)
  65. | Bytes(bytes s)
  66. | NameConstant(singleton value)
  67. | Ellipsis
  68. -- the following expression can appear in assignment context
  69. | Attribute(expr value, identifier attr, expr_context ctx)
  70. | Subscript(expr value, slice slice, expr_context ctx)
  71. | Starred(expr value, expr_context ctx)
  72. | Name(identifier id, expr_context ctx)
  73. | List(expr* elts, expr_context ctx)
  74. | Tuple(expr* elts, expr_context ctx)
  75. -- col_offset is the byte offset in the utf8 string the parser uses
  76. attributes (int lineno, int col_offset)
  77. expr_context = Load | Store | Del | AugLoad | AugStore | Param
  78. slice = Slice(expr? lower, expr? upper, expr? step)
  79. | ExtSlice(slice* dims)
  80. | Index(expr value)
  81. boolop = And | Or
  82. operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
  83. | RShift | BitOr | BitXor | BitAnd | FloorDiv
  84. unaryop = Invert | Not | UAdd | USub
  85. cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
  86. comprehension = (expr target, expr iter, expr* ifs)
  87. excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
  88. attributes (int lineno, int col_offset)
  89. arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults,
  90. arg? kwarg, expr* defaults)
  91. arg = (identifier arg, expr? annotation)
  92. attributes (int lineno, int col_offset)
  93. -- keyword arguments supplied to call (NULL identifier for **kwargs)
  94. keyword = (identifier? arg, expr value)
  95. -- import name with optional 'as' alias.
  96. alias = (identifier name, identifier? asname)
  97. withitem = (expr context_expr, expr? optional_vars)
  98. }