summaryrefslogtreecommitdiffstatshomepage
path: root/py/parse.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-02-13 02:29:46 +0000
committerDamien George <damien.p.george@gmail.com>2015-02-13 02:29:46 +0000
commitdfe944c3e5c2a7fa04c3416266728ffce6332bf8 (patch)
treea004a0ae2dd3a70335c5238c418bd9fe61dd549a /py/parse.c
parent8dfbd2d5894c98bd7b48e3e69bec0216d06ebb47 (diff)
downloadmicropython-dfe944c3e5c2a7fa04c3416266728ffce6332bf8.tar.gz
micropython-dfe944c3e5c2a7fa04c3416266728ffce6332bf8.zip
py: Expose compile.c:list_get as mp_parse_node_extract_list.
Diffstat (limited to 'py/parse.c')
-rw-r--r--py/parse.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/py/parse.c b/py/parse.c
index 4ea0362d2b..6223968f5d 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -199,6 +199,25 @@ void mp_parse_node_free(mp_parse_node_t pn) {
}
}
+int mp_parse_node_extract_list(mp_parse_node_t *pn, mp_uint_t pn_kind, mp_parse_node_t **nodes) {
+ if (MP_PARSE_NODE_IS_NULL(*pn)) {
+ *nodes = NULL;
+ return 0;
+ } else if (MP_PARSE_NODE_IS_LEAF(*pn)) {
+ *nodes = pn;
+ return 1;
+ } else {
+ mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)(*pn);
+ if (MP_PARSE_NODE_STRUCT_KIND(pns) != pn_kind) {
+ *nodes = pn;
+ return 1;
+ } else {
+ *nodes = pns->nodes;
+ return MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
+ }
+ }
+}
+
#if MICROPY_DEBUG_PRINTERS
void mp_parse_node_print(mp_parse_node_t pn, mp_uint_t indent) {
if (MP_PARSE_NODE_IS_STRUCT(pn)) {