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.

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