diff options
author | Adrian Thurston <thurston@complang.org> | 2009-03-01 02:42:25 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2009-03-01 02:42:25 +0000 |
commit | f067b4e5d7039c37e6cfb199d442862c0819b889 (patch) | |
tree | e7fb0ce1ce3456b4d839dbc6dab7f73afef546de | |
parent | 208a0090dd0f6c12776eeb032f4f06f25f630a79 (diff) | |
download | colm-f067b4e5d7039c37e6cfb199d442862c0819b889.tar.gz |
Include captured attributes in constructor patterns and add them to the
construced tree at runtime.
-rw-r--r-- | colm/pdabuild.cpp | 19 | ||||
-rw-r--r-- | colm/tree.cpp | 13 |
2 files changed, 32 insertions, 0 deletions
diff --git a/colm/pdabuild.cpp b/colm/pdabuild.cpp index d824c7d5..d22a7db3 100644 --- a/colm/pdabuild.cpp +++ b/colm/pdabuild.cpp @@ -1569,6 +1569,9 @@ void mapNodes( Program *prg, int &count, Kid *kid ) count += 1; ignore = ignore->next; } + + count += prg->rtd->lelInfo[kid->tree->id].numCaptureAttr; + mapNodes( prg, count, tree_child( prg, kid->tree ) ); mapNodes( prg, count, kid->next ); } @@ -1590,6 +1593,7 @@ void fillNodes( Program *prg, Bindings &bindings, long &bindId, node.length = string_length( kid->tree->tokdata ); node.data = string_data( kid->tree->tokdata ); + /* Ignore items. */ Kid *ignore = tree_ignore( prg, kid->tree ); node.ignore = ignore == 0 ? -1 : ind; @@ -1606,6 +1610,21 @@ void fillNodes( Program *prg, Bindings &bindings, long &bindId, ignore = ignore->next; } + /* The captured attributes. */ + for ( int i = 0; i < prg->rtd->lelInfo[kid->tree->id].numCaptureAttr; i++ ) { + CaptureAttr *cap = prg->rtd->captureAttr + + prg->rtd->lelInfo[kid->tree->id].captureAttr + i; + + Tree *attr = get_attr( kid->tree, cap->offset ); + + PatReplNode &node = nodes[ind++]; + memset( &node, 0, sizeof(PatReplNode) ); + + node.id = attr->id; + node.length = string_length( attr->tokdata ); + node.data = string_data( attr->tokdata ); + } + node.stop = kid->tree->flags & AF_TERM_DUP; /* Recurse. */ diff --git a/colm/tree.cpp b/colm/tree.cpp index 42bcec9b..434a34f6 100644 --- a/colm/tree.cpp +++ b/colm/tree.cpp @@ -259,6 +259,19 @@ Tree *construct_replacement_tree( Tree **bindings, Program *prg, long pat ) tree->child = kid_list_concat( attrs, kid_list_concat( ignore, child ) ); + + for ( int i = 0; i < lelInfo[tree->id].numCaptureAttr; i++ ) { + long ci = pat+1+i; + CaptureAttr *ca = prg->rtd->captureAttr + lelInfo[tree->id].captureAttr + i; + Tree *attr = prg->treePool.allocate(); + attr->id = nodes[ci].id; + attr->refs = 1; + attr->tokdata = nodes[ci].length == 0 ? 0 : + string_alloc_const( prg, + nodes[ci].data, nodes[ci].length ); + + set_attr( tree, ca->offset, attr ); + } } return tree; |