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.

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