本文整理汇总了C++中Tokenizer::advIf方法的典型用法代码示例。如果您正苦于以下问题:C++ Tokenizer::advIf方法的具体用法?C++ Tokenizer::advIf怎么用?C++ Tokenizer::advIf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokenizer
的用法示例。
在下文中一共展示了Tokenizer::advIf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readConfigFile
// -----------------------------------------------------------------------------
// Reads and parses the SLADE configuration file
// -----------------------------------------------------------------------------
void readConfigFile()
{
// Open SLADE.cfg
Tokenizer tz;
if (!tz.openFile(App::path("slade3.cfg", App::Dir::User)))
return;
// Go through the file with the tokenizer
while (!tz.atEnd())
{
// If we come across a 'cvars' token, read in the cvars section
if (tz.advIf("cvars", 2))
{
// Keep reading name/value pairs until we hit the ending '}'
while (!tz.checkOrEnd("}"))
{
CVar::set(tz.current().text, tz.peek().text);
tz.adv(2);
}
tz.adv(); // Skip ending }
}
// Read base resource archive paths
if (tz.advIf("base_resource_paths", 2))
{
while (!tz.checkOrEnd("}"))
{
archive_manager.addBaseResourcePath(tz.current().text);
tz.adv();
}
tz.adv(); // Skip ending }
}
// Read recent files list
if (tz.advIf("recent_files", 2))
{
while (!tz.checkOrEnd("}"))
{
archive_manager.addRecentFile(tz.current().text);
tz.adv();
}
tz.adv(); // Skip ending }
}
// Read keybinds
if (tz.advIf("keys", 2))
KeyBind::readBinds(tz);
// Read nodebuilder paths
if (tz.advIf("nodebuilder_paths", 2))
{
while (!tz.checkOrEnd("}"))
{
NodeBuilders::addBuilderPath(tz.current().text, tz.peek().text);
tz.adv(2);
}
tz.adv(); // Skip ending }
}
// Read game exe paths
if (tz.advIf("executable_paths", 2))
{
while (!tz.checkOrEnd("}"))
{
Executables::setGameExePath(tz.current().text, tz.peek().text);
tz.adv(2);
}
tz.adv(); // Skip ending }
}
// Read window size/position info
if (tz.advIf("window_info", 2))
Misc::readWindowInfo(tz);
// Next token
tz.adv();
}
}
示例2: parseZMapInfo
// -----------------------------------------------------------------------------
// Parses ZMAPINFO-format definitions in [entry]
// -----------------------------------------------------------------------------
bool MapInfo::parseZMapInfo(ArchiveEntry* entry)
{
Tokenizer tz;
tz.setReadLowerCase(true);
tz.openMem(entry->data(), entry->name());
while (!tz.atEnd())
{
// Include
if (tz.check("include"))
{
// Get entry at include path
auto include_entry = entry->parent()->entryAtPath(tz.next().text);
if (!include_entry)
{
Log::warning(
"Warning - Parsing ZMapInfo \"{}\": Unable to include \"{}\" at line {}",
entry->name(),
tz.current().text,
tz.lineNo());
}
else if (!parseZMapInfo(include_entry))
return false;
}
// Map
else if (tz.check("map") || tz.check("defaultmap") || tz.check("adddefaultmap"))
{
if (!parseZMap(tz, tz.current().text))
return false;
}
// DoomEdNums
else if (tz.check("doomednums"))
{
if (!parseDoomEdNums(tz))
return false;
}
// Unknown block (skip it)
else if (tz.check("{"))
{
Log::warning(2, "Warning - Parsing ZMapInfo \"{}\": Skipping {{}} block", entry->name());
tz.adv();
tz.skipSection("{", "}");
continue;
}
// Unknown
else
{
Log::warning(2, R"(Warning - Parsing ZMapInfo "{}": Unknown token "{}")", entry->name(), tz.current().text);
}
tz.adv();
}
Log::info(2, "Parsed ZMapInfo entry {} successfully", entry->name());
return true;
}
// -----------------------------------------------------------------------------
// Parses a ZMAPINFO map definition of [type] beginning at the current token in
// tokenizer [tz]
// -----------------------------------------------------------------------------
bool MapInfo::parseZMap(Tokenizer& tz, std::string_view type)
{
// TODO: Handle adddefaultmap
auto map = default_map_;
// Normal map, get lump/name/etc
tz.adv();
if (type == "map")
{
// Entry name should be just after map keyword
map.entry_name = tz.current().text;
// Parse map name
tz.adv();
if (tz.check("lookup"))
{
map.lookup_name = true;
map.name = tz.next().text;
}
else
{
map.lookup_name = false;
map.name = tz.current().text;
}
tz.adv();
}
if (!tz.advIf("{"))
//.........这里部分代码省略.........
示例3: parse
// -----------------------------------------------------------------------------
// Parses a ZScript 'statement'. This isn't technically correct but suits our
// purposes well enough
//
// tokens
// {
// block[0].tokens
// {
// block[0].block[0].tokens;
// ...
// }
//
// block[1].tokens;
// ...
// }
// -----------------------------------------------------------------------------
bool ParsedStatement::parse(Tokenizer& tz)
{
// Check for unexpected token
if (tz.check('}'))
{
tz.adv();
return false;
}
line = tz.lineNo();
// Tokens
bool in_initializer = false;
while (true)
{
// End of statement (;)
if (tz.advIf(';'))
return true;
// DB comment
if (tz.current().text.StartsWith(db_comment))
{
tokens.push_back(tz.current().text);
tokens.push_back(tz.getLine());
return true;
}
if (tz.check('}'))
{
// End of array initializer
if (in_initializer)
{
in_initializer = false;
tokens.emplace_back("}");
tz.adv();
continue;
}
// End of statement
return true;
}
if (tz.atEnd())
{
Log::debug(S_FMT("Failed parsing zscript statement/block beginning line %u", line));
return false;
}
// Beginning of block
if (tz.advIf('{'))
break;
// Array initializer: ... = { ... }
if (tz.current().text.Cmp("=") == 0 && tz.peek() == '{')
{
tokens.emplace_back("=");
tokens.emplace_back("{");
tz.adv(2);
in_initializer = true;
continue;
}
tokens.push_back(tz.current().text);
tz.adv();
}
// Block
while (true)
{
if (tz.advIf('}'))
return true;
if (tz.atEnd())
{
Log::debug(S_FMT("Failed parsing zscript statement/block beginning line %u", line));
return false;
}
block.push_back({});
block.back().entry = entry;
if (!block.back().parse(tz) || block.back().tokens.empty())
block.pop_back();
}
}