summaryrefslogtreecommitdiff
path: root/src/parser.cc
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-01-04 16:29:36 -0500
committerAdrian Thurston <thurston@complang.org>2015-01-04 16:29:36 -0500
commit4070e94fcedeffc25128c2f613ee6aec687eae72 (patch)
treead3b5335d5f9cc493c0f24cd50f22170f3768a76 /src/parser.cc
parent07547abf01f117076f36587f462a68dae0959b11 (diff)
downloadcolm-4070e94fcedeffc25128c2f613ee6aec687eae72.tar.gz
push towards embedded list elements
Diffstat (limited to 'src/parser.cc')
-rw-r--r--src/parser.cc57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/parser.cc b/src/parser.cc
index 25595f9d..9119a341 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -15,6 +15,58 @@
using std::endl;
+void BaseParser::listElDef( String name )
+{
+ /*
+ * The unique type. This is a def with a single empty form.
+ */
+ ObjectDef *objectDef = ObjectDef::cons( ObjectDef::UserType,
+ name, pd->nextObjectId++ );
+
+ LelDefList *defList = new LelDefList;
+
+ Production *prod = BaseParser::production( InputLoc(),
+ new ProdElList, String(), false, 0, 0 );
+ prodAppend( defList, prod );
+
+ NtDef *ntDef = NtDef::cons( name, curNspace(), curStruct(), false );
+ BaseParser::cflDef( ntDef, objectDef, defList );
+
+ /*
+ * List element with the same name as containing context.
+ */
+ NamespaceQual *nspaceQual = NamespaceQual::cons( curNspace() );
+ String id = curStruct()->objectDef->name;
+ RepeatType repeatType = RepeatNone;
+ TypeRef *objTr = TypeRef::cons( InputLoc(), nspaceQual, id, repeatType );
+ TypeRef *elTr = TypeRef::cons( InputLoc(), TypeRef::ListEl, 0, objTr, 0 );
+
+ ObjectField *of = ObjectField::cons( InputLoc(),
+ ObjectField::UserFieldType, elTr, name );
+ contextVarDef( InputLoc(), of );
+}
+
+void BaseParser::argvDecl()
+{
+ String structName = "argv_el";
+ structHead( internal, structName, ObjectDef::StructType );
+
+ /* First the argv value. */
+ String name = "value";
+ String type = "str";
+ NamespaceQual *nspaceQual = NamespaceQual::cons( curNspace() );
+ TypeRef *typeRef = TypeRef::cons( internal, nspaceQual, type, RepeatNone );
+ ObjectField *objField = ObjectField::cons( internal,
+ ObjectField::StructFieldType, typeRef, name );
+ contextVarDef( objField->loc, objField );
+
+ /* Now the list element. */
+ listElDef( "el" );
+
+ structStack.pop();
+ namespaceStack.pop();
+}
+
void BaseParser::init()
{
/* Set up the root namespace. */
@@ -55,6 +107,8 @@ void BaseParser::init()
pd->declareBaseLangEls();
pd->initUniqueTypes();
+ argvDecl();
+
/* Internal variables. */
addArgvList();
}
@@ -315,7 +369,8 @@ void BaseParser::literalDef( const InputLoc &loc, const String &data,
void BaseParser::addArgvList()
{
- TypeRef *typeRef = TypeRef::cons( internal, pd->uniqueTypeStr );
+ NamespaceQual *nspaceQual = NamespaceQual::cons( curNspace() );
+ TypeRef *typeRef = TypeRef::cons( internal, nspaceQual, "argv_el", RepeatNone );
pd->argvTypeRef = TypeRef::cons( internal, TypeRef::List, 0, typeRef, 0 );
}