| rest25/reference/toplevel_components.rst => rest262/reference/toplevel_components.rst | ||
|---|---|---|
| 61 | .. _file-input: | |
| 62 | ||
| 63 | File input | |
| 64 | ========== | |
| 65 | ||
| 66 | All input read from non-interactive files has the same form: | |
| 67 | ||
| 68 | .. productionlist:: | |
| n | 69- | file_input: (NEWLINE \| `statement`)\* |
| n | 69+ | file_input: (NEWLINE | `statement`)* |
| 70 | ||
| 71 | This syntax is used in the following situations: | |
| 72 | ||
| 73 | * when parsing a complete Python program (from a file or from a string); | |
| 74 | ||
| 75 | * when parsing a module; | |
| 76 | ||
| 77 | * when parsing a string passed to the :keyword:`exec` statement; | |
| 80 | .. _interactive: | |
| 81 | ||
| 82 | Interactive input | |
| 83 | ================= | |
| 84 | ||
| 85 | Input in interactive mode is parsed using the following grammar: | |
| 86 | ||
| 87 | .. productionlist:: | |
| n | 88- | interactive_input: [`stmt_list`] NEWLINE \| `compound_stmt` NEWLINE |
| n | 88+ | interactive_input: [`stmt_list`] NEWLINE | `compound_stmt` NEWLINE |
| 89 | ||
| 90 | Note that a (top-level) compound statement must be followed by a blank line in | |
| 91 | interactive mode; this is needed to help the parser detect the end of the input. | |
| 92 | ||
| 93 | ||
| 94 | .. _expression-input: | |
| 95 | ||
| 96 | Expression input | |
| 99 | .. index:: single: input | |
| 100 | ||
| 101 | .. index:: builtin: eval | |
| 102 | ||
| 103 | There are two forms of expression input. Both ignore leading whitespace. The | |
| 104 | string argument to :func:`eval` must have the following form: | |
| 105 | ||
| 106 | .. productionlist:: | |
| t | 107- | eval_input: `expression_list` NEWLINE\* |
| t | 107+ | eval_input: `expression_list` NEWLINE* |
| 108 | ||
| 109 | .. index:: builtin: input | |
| 110 | ||
| 111 | The input line read by :func:`input` must have the following form: | |
| 112 | ||
| 113 | .. productionlist:: | |
| 114 | input_input: `expression_list` NEWLINE | |
| 115 | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||