summaryrefslogtreecommitdiff
path: root/colm
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-03-01 02:45:37 +0000
committerAdrian Thurston <thurston@complang.org>2013-03-01 02:45:37 +0000
commitc5696e8f85dc40b1c548f5547604d5029b60b1a4 (patch)
tree47797ce3b6dc5e047189d1295298135572491f26 /colm
parent9cc679f29b46fd95daa4b65e107b66cd3423fbbb (diff)
downloadcolm-c5696e8f85dc40b1c548f5547604d5029b60b1a4.tar.gz
collect RE captures into tokenDef during a declare walk
Diffstat (limited to 'colm')
-rw-r--r--colm/declare.cc51
-rw-r--r--colm/lmparse.kh2
-rw-r--r--colm/lmparse.kl20
-rw-r--r--colm/parsetree.h8
4 files changed, 40 insertions, 41 deletions
diff --git a/colm/declare.cc b/colm/declare.cc
index 36a8ff31..cdd279a5 100644
--- a/colm/declare.cc
+++ b/colm/declare.cc
@@ -24,51 +24,56 @@
#include <iostream>
#include <assert.h>
-void LexJoin::varDecl( Compiler *pd, ObjectDef *objectDef )
+void LexJoin::varDecl( Compiler *pd, TokenDef *tokenDef )
{
- expr->varDecl( pd, objectDef );
+ expr->varDecl( pd, tokenDef );
}
-void LexExpression::varDecl( Compiler *pd, ObjectDef *objectDef )
+void LexExpression::varDecl( Compiler *pd, TokenDef *tokenDef )
{
switch ( type ) {
case OrType: case IntersectType: case SubtractType:
case StrongSubtractType:
- expression->varDecl( pd, objectDef );
- term->varDecl( pd, objectDef );
+ expression->varDecl( pd, tokenDef );
+ term->varDecl( pd, tokenDef );
break;
case TermType:
- term->varDecl( pd, objectDef );
+ term->varDecl( pd, tokenDef );
break;
case BuiltinType:
break;
}
}
-void LexTerm::varDecl( Compiler *pd, ObjectDef *objectDef )
+void LexTerm::varDecl( Compiler *pd, TokenDef *tokenDef )
{
switch ( type ) {
case ConcatType:
case RightStartType:
case RightFinishType:
case LeftType:
- term->varDecl( pd, objectDef );
- factorAug->varDecl( pd, objectDef );
+ term->varDecl( pd, tokenDef );
+ factorAug->varDecl( pd, tokenDef );
break;
case FactorAugType:
- factorAug->varDecl( pd, objectDef );
+ factorAug->varDecl( pd, tokenDef );
break;
}
}
-void LexFactorAug::varDecl( Compiler *pd, ObjectDef *objectDef )
+void LexFactorAug::varDecl( Compiler *pd, TokenDef *tokenDef )
{
for ( ReCaptureVect::Iter re = reCaptureVect; re.lte(); re++ ) {
- if ( objectDef->checkRedecl( re->objField->name ) != 0 )
- error(re->objField->loc) << "label name \"" << re->objField->name << "\" already in use" << endp;
+ if ( tokenDef->objectDef->checkRedecl( re->objField->name ) != 0 ) {
+ error(re->objField->loc) << "label name \"" <<
+ re->objField->name << "\" already in use" << endp;
+ }
/* Insert it into the map. */
- objectDef->insertField( re->objField->name, re->objField );
+ tokenDef->objectDef->insertField( re->objField->name, re->objField );
+
+ /* Store it in the TokenDef. */
+ tokenDef->reCaptureVect.append( *re );
}
}
@@ -77,9 +82,25 @@ void Compiler::varDeclaration()
for ( NamespaceList::Iter n = namespaceList; n.lte(); n++ ) {
for ( TokenDefListNs::Iter tok = n->tokenDefList; tok.lte(); tok++ ) {
if ( tok->join != 0 )
- tok->join->varDecl( this, tok->objectDef );
+ tok->join->varDecl( this, tok );
}
}
+
+ /* FIXME: declare RE captures in token generation actions. */
+#if 0
+ /* Add captures to the local frame. We Depend on these becoming the
+ * first local variables so we can compute their location. */
+
+ /* Make local variables corresponding to the local capture vector. */
+ for ( ReCaptureVect::Iter c = reCaptureVect; c.lte(); c++ )
+ {
+ ObjectField *objField = ObjectField::cons( c->objField->loc,
+ c->objField->typeRef, c->objField->name );
+
+ /* Insert it into the field map. */
+ pd->curLocalFrame->insertField( objField->name, objField );
+ }
+#endif
}
LangEl *declareLangEl( Compiler *pd, Namespace *nspace, const String &data, LangEl::Type type )
diff --git a/colm/lmparse.kh b/colm/lmparse.kh
index c32c4251..49b2c5da 100644
--- a/colm/lmparse.kh
+++ b/colm/lmparse.kh
@@ -81,8 +81,6 @@ struct ColmParser
NamespaceVect namespaceStack;
ContextStack contextStack;
- ReCaptureVect reCaptureVect;
-
/* Lexical feedback. */
bool enterRl;
diff --git a/colm/lmparse.kl b/colm/lmparse.kl
index 67608321..c7287711 100644
--- a/colm/lmparse.kl
+++ b/colm/lmparse.kl
@@ -232,8 +232,6 @@ void ColmParser::tokenDef( const InputLoc &loc, String name, LexJoin *join, Obje
* make other tokens */
addRegularDef( loc, namespaceStack.top(), name, join );
}
-
- reCaptureVect.empty();
}
void ColmParser::zeroDef( const InputLoc &loc, const String &data,
@@ -343,20 +341,6 @@ ObjectDef *ColmParser::blockOpen()
"local", pd->nextObjectId++ );
pd->curLocalFrame = frame;
-
- /* Add captures to the local frame. We Depend on these becoming the
- * first local variables so we can compute their location. */
-
- /* Make local variables corresponding to the local capture vector. */
- for ( ReCaptureVect::Iter c = reCaptureVect; c.lte(); c++ )
- {
- ObjectField *objField = ObjectField::cons( c->objField->loc,
- c->objField->typeRef, c->objField->name );
-
- /* Insert it into the field map. */
- pd->curLocalFrame->insertField( objField->name, objField );
- }
-
return frame;
}
@@ -533,7 +517,6 @@ LexFactorAug *ColmParser::lexFactorLabel( const InputLoc &loc, const String &dat
factorAug->actions.append( ParserAction( loc, at_start, 0, enter ) );
factorAug->actions.append( ParserAction( loc, at_leave, 0, leave ) );
- reCaptureVect.append( ReCapture( enter, leave, objField ) );
factorAug->reCaptureVect.append( ReCapture( enter, leave, objField ) );
return factorAug;
@@ -1930,9 +1913,6 @@ rl_def:
final {
/* Generic creation of machine for instantiation and assignment. */
addRegularDef( $2->loc, namespaceStack.top(), $2->data, $5->join );
-
- if ( reCaptureVect.length() > 0 )
- error($1->loc) << "rl definitions cannot capture vars" << endl;
};
type class token_data
diff --git a/colm/parsetree.h b/colm/parsetree.h
index 5e9a4fd9..f75d7193 100644
--- a/colm/parsetree.h
+++ b/colm/parsetree.h
@@ -822,7 +822,7 @@ struct LexJoin
/* Tree traversal. */
FsmGraph *walk( Compiler *pd );
void makeNameTree( Compiler *pd );
- void varDecl( Compiler *pd, ObjectDef *objectDef );
+ void varDecl( Compiler *pd, TokenDef *tokenDef );
/* Data. */
LexExpression *expr;
@@ -881,7 +881,7 @@ struct LexExpression
/* Tree traversal. */
FsmGraph *walk( Compiler *pd, bool lastInSeq = true );
void makeNameTree( Compiler *pd );
- void varDecl( Compiler *pd, ObjectDef *objectDef );
+ void varDecl( Compiler *pd, TokenDef *tokenDef );
/* Node data. */
LexExpression *expression;
@@ -938,7 +938,7 @@ struct LexTerm
FsmGraph *walk( Compiler *pd, bool lastInSeq = true );
void makeNameTree( Compiler *pd );
- void varDecl( Compiler *pd, ObjectDef *objectDef );
+ void varDecl( Compiler *pd, TokenDef *tokenDef );
LexTerm *term;
LexFactorAug *factorAug;
@@ -967,7 +967,7 @@ struct LexFactorAug
/* Tree traversal. */
FsmGraph *walk( Compiler *pd );
void makeNameTree( Compiler *pd );
- void varDecl( Compiler *pd, ObjectDef *objectDef );
+ void varDecl( Compiler *pd, TokenDef *tokenDef );
void assignActions( Compiler *pd, FsmGraph *graph, int *actionOrd );