summaryrefslogtreecommitdiffstatshomepage
path: root/py/compile.c
diff options
context:
space:
mode:
authorDamien <damien.p.george@gmail.com>2013-12-12 15:24:38 +0000
committerDamien <damien.p.george@gmail.com>2013-12-12 15:24:38 +0000
commite388f1034e98f5066954c2a01477c199e2c76a42 (patch)
treea80801816f64c33b77f9c8a53b9eace1050da2b8 /py/compile.c
parent02f8941bf6992a3100216f192a3a37c56fce102f (diff)
downloadmicropython-e388f1034e98f5066954c2a01477c199e2c76a42.tar.gz
micropython-e388f1034e98f5066954c2a01477c199e2c76a42.zip
py: fix bug with doc string not recognised after first newline of file.
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/py/compile.c b/py/compile.c
index f777675632..5fbf623b29 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -2646,10 +2646,21 @@ void check_for_doc_string(compiler_t *comp, py_parse_node_t pn) {
// look for the first statement
if (PY_PARSE_NODE_IS_STRUCT_KIND(pn, PN_expr_stmt)) {
- // fall through
+ // a statement; fall through
} else if (PY_PARSE_NODE_IS_STRUCT_KIND(pn, PN_file_input_2)) {
- pn = ((py_parse_node_struct_t*)pn)->nodes[0];
+ // file input; find the first non-newline node
+ py_parse_node_struct_t *pns = (py_parse_node_struct_t*)pn;
+ int num_nodes = PY_PARSE_NODE_STRUCT_NUM_NODES(pns);
+ for (int i = 0; i < num_nodes; i++) {
+ pn = pns->nodes[i];
+ if (!(PY_PARSE_NODE_IS_LEAF(pn) && PY_PARSE_NODE_LEAF_KIND(pn) == PY_PARSE_NODE_TOKEN && PY_PARSE_NODE_LEAF_ARG(pn) == PY_TOKEN_NEWLINE)) {
+ // not a newline, so this is the first statement; finish search
+ break;
+ }
+ }
+ // if we didn't find a non-newline then it's okay to fall through; pn will be a newline and so doc-string test below will fail gracefully
} else if (PY_PARSE_NODE_IS_STRUCT_KIND(pn, PN_suite_block_stmts)) {
+ // a list of statements; get the first one
pn = ((py_parse_node_struct_t*)pn)->nodes[0];
} else {
return;