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
commit208a0090dd0f6c12776eeb032f4f06f25f630a79 (patch)
tree61b41bf3d9deb8afcb3ff5a6b966bfed9f927b44
parent2c21e2cd0340f2a777530da692bc0669bc8dc1bd (diff)
downloadcolm-208a0090dd0f6c12776eeb032f4f06f25f630a79.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--colm/fsmrun.cpp20
-rw-r--r--colm/lmparse.kl2
-rw-r--r--colm/parsetree.h6
-rw-r--r--colm/pdabuild.cpp25
-rw-r--r--colm/pdacodegen.cpp19
-rw-r--r--colm/pdarun.h5
6 files changed, 60 insertions, 17 deletions
diff --git a/colm/fsmrun.cpp b/colm/fsmrun.cpp
index 0f20b8cc..fc9c45d2 100644
--- a/colm/fsmrun.cpp
+++ b/colm/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/colm/lmparse.kl b/colm/lmparse.kl
index b796318e..04e64d65 100644
--- a/colm/lmparse.kl
+++ b/colm/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/colm/parsetree.h b/colm/parsetree.h
index ece6ac5f..86f81e7f 100644
--- a/colm/parsetree.h
+++ b/colm/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/colm/pdabuild.cpp b/colm/pdabuild.cpp
index 07449330..d824c7d5 100644
--- a/colm/pdabuild.cpp
+++ b/colm/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/colm/pdacodegen.cpp b/colm/pdacodegen.cpp
index 34d79061..04a980ba 100644
--- a/colm/pdacodegen.cpp
+++ b/colm/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/colm/pdarun.h b/colm/pdarun.h
index 528f7073..30f5b0d2 100644
--- a/colm/pdarun.h
+++ b/colm/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;