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.

115 lines
4.2 KiB

  1. -- ASDL's five builtin types are identifier, int, string, object, bool
  2. module Python version "$Revision$"
  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)
  11. | ClassDef(identifier name, expr* bases, stmt* body, expr* decorator_list)
  12. | Return(expr? value)
  13. | Delete(expr* targets)
  14. | Assign(expr* targets, expr value)
  15. | AugAssign(expr target, operator op, expr value)
  16. -- not sure if bool is allowed, can always use int
  17. | Print(expr? dest, expr* values, bool nl)
  18. -- use 'orelse' because else is a keyword in target languages
  19. | For(expr target, expr iter, stmt* body, stmt* orelse)
  20. | While(expr test, stmt* body, stmt* orelse)
  21. | If(expr test, stmt* body, stmt* orelse)
  22. | With(expr context_expr, expr? optional_vars, stmt* body)
  23. -- 'type' is a bad name
  24. | Raise(expr? type, expr? inst, expr? tback)
  25. | TryExcept(stmt* body, excepthandler* handlers, stmt* orelse)
  26. | TryFinally(stmt* body, stmt* finalbody)
  27. | Assert(expr test, expr? msg)
  28. | Import(alias* names)
  29. | ImportFrom(identifier? module, alias* names, int? level)
  30. -- Doesn't capture requirement that locals must be
  31. -- defined if globals is
  32. -- still supports use as a function!
  33. | Exec(expr body, expr? globals, expr? locals)
  34. | Global(identifier* names)
  35. | Expr(expr value)
  36. | Pass | Break | Continue
  37. -- XXX Jython will be different
  38. -- col_offset is the byte offset in the utf8 string the parser uses
  39. attributes (int lineno, int col_offset)
  40. -- BoolOp() can use left & right?
  41. expr = BoolOp(boolop op, expr* values)
  42. | BinOp(expr left, operator op, expr right)
  43. | UnaryOp(unaryop op, expr operand)
  44. | Lambda(arguments args, expr body)
  45. | IfExp(expr test, expr body, expr orelse)
  46. | Dict(expr* keys, expr* values)
  47. | Set(expr* elts)
  48. | ListComp(expr elt, comprehension* generators)
  49. | SetComp(expr elt, comprehension* generators)
  50. | DictComp(expr key, expr value, comprehension* generators)
  51. | GeneratorExp(expr elt, comprehension* generators)
  52. -- the grammar constrains where yield expressions can occur
  53. | Yield(expr? value)
  54. -- need sequences for compare to distinguish between
  55. -- x < 4 < 3 and (x < 4) < 3
  56. | Compare(expr left, cmpop* ops, expr* comparators)
  57. | Call(expr func, expr* args, keyword* keywords,
  58. expr? starargs, expr? kwargs)
  59. | Repr(expr value)
  60. | Num(object n) -- a number as a PyObject.
  61. | Str(string s) -- need to specify raw, unicode, etc?
  62. -- other literals? bools?
  63. -- the following expression can appear in assignment context
  64. | Attribute(expr value, identifier attr, expr_context ctx)
  65. | Subscript(expr value, slice slice, expr_context ctx)
  66. | Name(identifier id, expr_context ctx)
  67. | List(expr* elts, expr_context ctx)
  68. | Tuple(expr* elts, expr_context ctx)
  69. -- col_offset is the byte offset in the utf8 string the parser uses
  70. attributes (int lineno, int col_offset)
  71. expr_context = Load | Store | Del | AugLoad | AugStore | Param
  72. slice = Ellipsis | Slice(expr? lower, expr? upper, expr? step)
  73. | ExtSlice(slice* dims)
  74. | Index(expr value)
  75. boolop = And | Or
  76. operator = Add | Sub | Mult | Div | Mod | Pow | LShift
  77. | RShift | BitOr | BitXor | BitAnd | FloorDiv
  78. unaryop = Invert | Not | UAdd | USub
  79. cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
  80. comprehension = (expr target, expr iter, expr* ifs)
  81. -- not sure what to call the first argument for raise and except
  82. excepthandler = ExceptHandler(expr? type, expr? name, stmt* body)
  83. attributes (int lineno, int col_offset)
  84. arguments = (expr* args, identifier? vararg,
  85. identifier? kwarg, expr* defaults)
  86. -- keyword arguments supplied to call
  87. keyword = (identifier arg, expr value)
  88. -- import name with optional 'as' alias.
  89. alias = (identifier name, identifier? asname)
  90. }