/Parser/Python.asdl

http://unladen-swallow.googlecode.com/ · Unknown · 112 lines · 87 code · 25 blank · 0 comment · 0 complexity · 9aaca7720890e6ca4b32a6fadf71c2ee MD5 · raw file

  1. -- ASDL's five builtin types are identifier, int, string, object, bool
  2. module Python version "$Revision: 62047 $"
  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. | ListComp(expr elt, comprehension* generators)
  48. | GeneratorExp(expr elt, comprehension* generators)
  49. -- the grammar constrains where yield expressions can occur
  50. | Yield(expr? value)
  51. -- need sequences for compare to distinguish between
  52. -- x < 4 < 3 and (x < 4) < 3
  53. | Compare(expr left, cmpop* ops, expr* comparators)
  54. | Call(expr func, expr* args, keyword* keywords,
  55. expr? starargs, expr? kwargs)
  56. | Repr(expr value)
  57. | Num(object n) -- a number as a PyObject.
  58. | Str(string s) -- need to specify raw, unicode, etc?
  59. -- other literals? bools?
  60. -- the following expression can appear in assignment context
  61. | Attribute(expr value, identifier attr, expr_context ctx)
  62. | Subscript(expr value, slice slice, expr_context ctx)
  63. | Name(identifier id, expr_context ctx)
  64. | List(expr* elts, expr_context ctx)
  65. | Tuple(expr* elts, expr_context ctx)
  66. -- col_offset is the byte offset in the utf8 string the parser uses
  67. attributes (int lineno, int col_offset)
  68. expr_context = Load | Store | Del | AugLoad | AugStore | Param
  69. slice = Ellipsis | Slice(expr? lower, expr? upper, expr? step)
  70. | ExtSlice(slice* dims)
  71. | Index(expr value)
  72. boolop = And | Or
  73. operator = Add | Sub | Mult | Div | Mod | Pow | LShift
  74. | RShift | BitOr | BitXor | BitAnd | FloorDiv
  75. unaryop = Invert | Not | UAdd | USub
  76. cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
  77. comprehension = (expr target, expr iter, expr* ifs)
  78. -- not sure what to call the first argument for raise and except
  79. excepthandler = ExceptHandler(expr? type, expr? name, stmt* body)
  80. attributes (int lineno, int col_offset)
  81. arguments = (expr* args, identifier? vararg,
  82. identifier? kwarg, expr* defaults)
  83. -- keyword arguments supplied to call
  84. keyword = (identifier arg, expr value)
  85. -- import name with optional 'as' alias.
  86. alias = (identifier name, identifier? asname)
  87. }