Skip to content

Commit

Permalink
Scripting|libcore|ScriptedInfo: Processing attributes of script blocks
Browse files Browse the repository at this point in the history
Also, cleaned up things a little by making some of the common strings
public static members of ScriptedInfo.
  • Loading branch information
skyjake committed Aug 16, 2015
1 parent 672f3f7 commit 0506414
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 23 deletions.
7 changes: 7 additions & 0 deletions doomsday/sdk/libcore/include/de/scriptsys/scriptedinfo.h
Expand Up @@ -228,6 +228,13 @@ class DENG2_PUBLIC ScriptedInfo
*/
static StringList sortRecordsBySource(Record::Subrecords const &subrecs);

public:
static String const SCRIPT;
static String const BLOCK_GROUP;

/// Name of a special variable where the source location of a record is stored.
static String const VAR_SOURCE;

private:
DENG2_PRIVATE(d)
};
Expand Down
11 changes: 8 additions & 3 deletions doomsday/sdk/libcore/src/data/info.cpp
Expand Up @@ -395,7 +395,8 @@ success:;

//qDebug() << "now at" << content.substr(endPos - 15, endPos) << "^" << content.substr(endPos);

return InfoValue(content.substr(startPos, lex.pos() - 1), InfoValue::Script);
// Whitespace is removed from beginning and end.
return InfoValue(content.substr(startPos, lex.pos() - 1).trimmed(), InfoValue::Script);
}

/**
Expand Down Expand Up @@ -501,9 +502,13 @@ success:;
DENG2_ASSERT(blockType != ")");

String blockName;
if(peekToken() != "(" && peekToken() != "{")

if(!scriptBlockTypes.contains(blockType)) // script blocks are never named
{
blockName = parseValue();
if(peekToken() != "(" && peekToken() != "{")
{
blockName = parseValue();
}
}

if(!implicitBlockType.isEmpty() && blockName.isEmpty() &&
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libcore/src/data/infobank.cpp
Expand Up @@ -13,7 +13,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/InfoBank"
Expand All @@ -40,7 +40,7 @@ DENG2_PIMPL_NOREF(InfoBank)

void parsedNamedBlock(String const &, Record &block)
{
if(block.gets("__type__") != "group")
if(block.gets("__type__") != ScriptedInfo::BLOCK_GROUP)
{
block.addBoolean(VAR_NOT_IN_BANK, true);
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libcore/src/filesys/package.cpp
Expand Up @@ -40,7 +40,7 @@ String Package::Asset::absolutePath(String const &name) const
// For the context, we'll accept either the variable's own record or the package
// metadata.
Record const *context = &accessedRecord().parentRecordForMember(name);
if(!context->has("__source__"))
if(!context->has(ScriptedInfo::VAR_SOURCE))
{
context = &accessedRecord();
}
Expand Down Expand Up @@ -349,5 +349,5 @@ Time Package::containerOfFileModifiedAt(File const &file)
if(!c) return file.status().modifiedAt;
return c->status().modifiedAt;
}

} // namespace de
60 changes: 44 additions & 16 deletions doomsday/sdk/libcore/src/scriptsys/scriptedinfo.cpp
Expand Up @@ -27,14 +27,16 @@

namespace de {

static String const BLOCK_GROUP = "group";
String const ScriptedInfo::SCRIPT = "script";
String const ScriptedInfo::BLOCK_GROUP = "group";
String const ScriptedInfo::VAR_SOURCE = "__source__";

static String const BLOCK_NAMESPACE = "namespace";
static String const BLOCK_SCRIPT = "script";
static String const KEY_SCRIPT = "script";
static String const BLOCK_SCRIPT = ScriptedInfo::SCRIPT;
static String const KEY_SCRIPT = ScriptedInfo::SCRIPT;
static String const KEY_INHERITS = "inherits";
static String const KEY_CONDITION = "condition";
static String const VAR_BLOCK_TYPE = "__type__";
static String const VAR_SOURCE = "__source__";
static String const VAR_SCRIPT = "__script%1__";

DENG2_PIMPL(ScriptedInfo)
Expand Down Expand Up @@ -263,6 +265,8 @@ DENG2_PIMPL(ScriptedInfo)
}
}

bool const isScriptBlock = (block.blockType() == BLOCK_SCRIPT);

// Script blocks are executed now. This includes only the unqualified script
// blocks that have only a single "script" key in them.
if(isUnqualifiedScriptBlock(block))
Expand Down Expand Up @@ -292,15 +296,16 @@ DENG2_PIMPL(ScriptedInfo)
}
LOG_SCR_XVERBOSE("Namespace set to '%s' on line %i") << currentNamespace << block.lineNumber();
}
else if(!block.name().isEmpty() || block.blockType() == BLOCK_SCRIPT)
else if(!block.name().isEmpty() || isScriptBlock)
{
// Determine the full variable name of the record of this block.
String varName;
if(block.blockType() == BLOCK_SCRIPT)

// Determine the full variable name of the record of this block.
if(isScriptBlock)
{
// Qualified scripts get automatically generated names.
Record const &parentRecord = ns[variableName(*block.parent())];
varName = varName.concatenateMember(chooseScriptName(parentRecord));
String const parentVarName = variableName(*block.parent());
varName = parentVarName.concatenateMember(chooseScriptName(ns[parentVarName]));
}
else
{
Expand All @@ -321,24 +326,47 @@ DENG2_PIMPL(ScriptedInfo)
// Also store source location in a special variable.
blockRecord.addText(VAR_SOURCE, block.sourceLocation());

if(!block.name().isEmpty())
if(!isScriptBlock)
{
DENG2_FOR_PUBLIC_AUDIENCE2(NamedBlock, i)
{
i->parsedNamedBlock(varName, blockRecord);
}
}
else
{
// Add the extra attributes of script blocks.
// These are not processed as regular subelements because the
// path of the script record is not directly determined by the parent
// blocks (see above; chooseScriptName()).
for(auto const *elem : block.contents().values())
{
if(elem->isKey())
{
auto const &key = elem->as<Info::KeyElement>();
if(key.name() != KEY_CONDITION)
{
blockRecord.addText(key.name(), key.value());
}
}
}
}
}

foreach(Info::Element const *sub, block.contentsInOrder())
// Continue processing elements contained in the block (unless this is
// script block).
if(!isScriptBlock)
{
// Handle special elements.
if(sub->name() == KEY_CONDITION || sub->name() == KEY_INHERITS)
foreach(Info::Element const *sub, block.contentsInOrder())
{
// Already handled.
continue;
// Handle special elements.
if(sub->name() == KEY_CONDITION || sub->name() == KEY_INHERITS)
{
// Already handled.
continue;
}
processElement(sub);
}
processElement(sub);
}

// Continue with the old namespace after the block.
Expand Down

0 comments on commit 0506414

Please sign in to comment.