summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2009-02-28 04:18:09 +0000
committerAdrian Thurston <thurston@complang.org>2009-02-28 04:18:09 +0000
commit7da1f291953309a5bb152535a2a8d3330c330761 (patch)
tree2cc2e0460b7ae9fca94451f72b0f0fb0aa3edbdf
parentf899c2a23ca8c8abda70ded884e839187e190bee (diff)
downloadcolm-7da1f291953309a5bb152535a2a8d3330c330761.tar.gz
Capture info now propagated to the runtime data. In make token, the LEL's list
of captures is used to create the attributes. No longer relying on the end markers. That scheme was wrong since the index of the end marker can't correctly correspond to the attribute offset, otherwise there could be interference among tokens.
-rw-r--r--fsmrun.cpp20
-rw-r--r--lmparse.kl2
-rw-r--r--parsetree.h6
-rw-r--r--pdabuild.cpp25
-rw-r--r--pdacodegen.cpp19
-rw-r--r--pdarun.h5
6 files changed, 60 insertions, 17 deletions
diff --git a/fsmrun.cpp b/fsmrun.cpp
index 0f20b8cc..fc9c45d2 100644
--- a/fsmrun.cpp
+++ b/fsmrun.cpp
@@ -511,15 +511,17 @@ Kid *FsmRun::makeToken( int id, Head *tokdata, bool namedLangEl, int bindId )
/* No children and ignores get added later. */
input->tree->child = attrs;
-// /* Set attributes for the labelled components. */
-// for ( int i = 0; i < 32; i++ ) {
-// if ( mark_leave[i] != 0 ) {
-// Head *data = string_alloc_new( prg,
-// mark_enter[i], mark_leave[i] - mark_enter[i] );
-// set_attr( input->tree, i, construct_string( prg, data ) );
-// tree_upref( get_attr( input->tree, i ) );
-// }
-// }
+ LangElInfo *lelInfo = parser->tables->rtd->lelInfo;
+ if ( lelInfo[id].numCaptureAttr > 0 ) {
+ for ( int i = 0; i < lelInfo[id].numCaptureAttr; i++ ) {
+ CaptureAttr *ca = &parser->tables->rtd->captureAttr[lelInfo[id].captureAttr + i];
+ Head *data = string_alloc_new( prg,
+ mark[ca->mark_enter], mark[ca->mark_leave] - mark[ca->mark_enter] );
+ Tree *string = construct_string( prg, data );
+ set_attr( input->tree, ca->offset, string );
+ tree_upref( string );
+ }
+ }
/* If the item is bound then store it in the bindings array. */
if ( bindId > 0 ) {
diff --git a/lmparse.kl b/lmparse.kl
index b796318e..04e64d65 100644
--- a/lmparse.kl
+++ b/lmparse.kl
@@ -1650,7 +1650,7 @@ factor_with_label:
$$->factorWithAug->actions.append( ParserAction( $1->loc, at_start, 0, enter ) );
$$->factorWithAug->actions.append( ParserAction( $1->loc, at_leave, 0, leave ) );
- reCaptureVect.append( ReCapture( objField, enter, leave ) );
+ reCaptureVect.append( ReCapture( enter, leave, objField ) );
};
nonterm factor_with_ep
diff --git a/parsetree.h b/parsetree.h
index ece6ac5f..86f81e7f 100644
--- a/parsetree.h
+++ b/parsetree.h
@@ -273,12 +273,12 @@ struct NamespaceQual
struct ReCapture
{
- ReCapture( ObjField *objField, Action *markEnter, Action *markLeave )
- : objField(objField), markEnter(markEnter), markLeave(markLeave) {}
+ ReCapture( Action *markEnter, Action *markLeave, ObjField *objField )
+ : markEnter(markEnter), markLeave(markLeave), objField(objField) {}
- ObjField *objField;
Action *markEnter;
Action *markLeave;
+ ObjField *objField;
};
typedef Vector<ReCapture> ReCaptureVect;
diff --git a/pdabuild.cpp b/pdabuild.cpp
index 07449330..d824c7d5 100644
--- a/pdabuild.cpp
+++ b/pdabuild.cpp
@@ -1506,7 +1506,29 @@ void ParseData::makeRuntimeData()
runtimeData->litlen[el->value] = el->key.length();
}
- /* FIXME: Captured attributes go here. */
+ /* Captured attributes. Loop over tokens and count first. */
+ long numCapturedAttr = 0;
+ for ( RegionList::Iter reg = regionList; reg.lte(); reg++ ) {
+ for ( TokenDefList::Iter td = reg->tokenDefList; td.lte(); td++ )
+ numCapturedAttr += td->reCaptureVect.length();
+ }
+ runtimeData->captureAttr = new CaptureAttr[numCapturedAttr];
+ runtimeData->numCapturedAttr = numCapturedAttr;
+
+ count = 0;
+ for ( RegionList::Iter reg = regionList; reg.lte(); reg++ ) {
+ for ( TokenDefList::Iter td = reg->tokenDefList; td.lte(); td++ ) {
+ runtimeData->lelInfo[td->token->id].captureAttr = count;
+ runtimeData->lelInfo[td->token->id].numCaptureAttr = td->reCaptureVect.length();
+ for ( ReCaptureVect::Iter c = td->reCaptureVect; c.lte(); c++ ) {
+ runtimeData->captureAttr[count].mark_enter = c->markEnter->markId;
+ runtimeData->captureAttr[count].mark_leave = c->markLeave->markId;
+ runtimeData->captureAttr[count].offset = c->objField->offset;
+
+ count += 1;
+ }
+ }
+ }
runtimeData->fsmTables = fsmTables;
runtimeData->pdaTables = pdaTables;
@@ -1520,7 +1542,6 @@ void ParseData::makeRuntimeData()
runtimeData->eofLelIds[lel->parserId] = lel->eofLel->id;
}
}
-
runtimeData->globalSize = globalObjectDef->size();
diff --git a/pdacodegen.cpp b/pdacodegen.cpp
index 34d79061..04a980ba 100644
--- a/pdacodegen.cpp
+++ b/pdacodegen.cpp
@@ -193,7 +193,11 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable
out << runtimeData->lelInfo[i].genericId << ", ";
- out << runtimeData->lelInfo[i].markId;
+ out << runtimeData->lelInfo[i].markId << ", ";
+
+ out << runtimeData->lelInfo[i].captureAttr << ", ";
+
+ out << runtimeData->lelInfo[i].numCaptureAttr;
out << " }";
@@ -370,6 +374,16 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable
}
out << "};\n\n";
+ out << "CaptureAttr captureAttr[] = {\n";
+ for ( long i = 0; i < runtimeData->numCapturedAttr; i++ ) {
+ out << "\t{ " <<
+ runtimeData->captureAttr[i].mark_enter << ", " <<
+ runtimeData->captureAttr[i].mark_leave << ", " <<
+ runtimeData->captureAttr[i].offset << " },\n";
+ }
+
+ out << "};\n\n";
+
out <<
"RuntimeData main_runtimeData = \n"
"{\n"
@@ -405,6 +419,9 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable
" " << literals() << ",\n"
" " << runtimeData->numLiterals << ",\n"
"\n"
+ " captureAttr,\n"
+ " " << runtimeData->numCapturedAttr << ",\n"
+ "\n"
" &fsmTables_start,\n"
" &pid_0_pdaTables,\n"
" startStates, eofLelIds, " << runtimeData->numParsers << ",\n"
diff --git a/pdarun.h b/pdarun.h
index 528f7073..30f5b0d2 100644
--- a/pdarun.h
+++ b/pdarun.h
@@ -354,6 +354,8 @@ struct LangElInfo
long termDupId;
long genericId;
long markId;
+ long captureAttr;
+ long numCaptureAttr;
};
struct ObjFieldInfo
@@ -428,7 +430,8 @@ struct RuntimeData
Head **literals;
long numLiterals;
-// CaptureAttr *captureAttr;
+ CaptureAttr *captureAttr;
+ long numCapturedAttr;
FsmTables *fsmTables;
PdaTables *pdaTables;