summaryrefslogtreecommitdiff
path: root/hscript/script.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-06 19:19:23 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-06 19:19:23 -0500
commit6fe1d4ea7c32a7c20a40d9bc7887b5a7d665ed8c (patch)
treef37b5e810010aec70cd68ae40942fd696b264ca0 /hscript/script.cc
parent7bcadd4ac91d4694700d9d173233a2b234d1799d (diff)
downloadhorizon-6fe1d4ea7c32a7c20a40d9bc7887b5a7d665ed8c.tar.gz
horizon-6fe1d4ea7c32a7c20a40d9bc7887b5a7d665ed8c.tar.bz2
horizon-6fe1d4ea7c32a7c20a40d9bc7887b5a7d665ed8c.tar.xz
horizon-6fe1d4ea7c32a7c20a40d9bc7887b5a7d665ed8c.zip
hscript: Factor parser errors to a macro; check key validity
Diffstat (limited to 'hscript/script.cc')
-rw-r--r--hscript/script.cc35
1 files changed, 28 insertions, 7 deletions
diff --git a/hscript/script.cc b/hscript/script.cc
index e7746bc..0e72c81 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -52,6 +52,21 @@ const Script *Script::load(std::string path, ScriptOptions opts) {
return Script::load(file, opts);
}
+/*! Determines if the specified +key+ has been defined in this version of
+ * HorizonScript.
+ */
+bool is_key(std::string key) {
+ return true;
+}
+
+#define PARSER_ERROR(err_str) \
+ any_error = true;\
+ output_error("installfile:" + std::to_string(lineno),\
+ err_str, "", (opts.test(Pretty)));\
+ if(!opts.test(ScriptOptionFlags::KeepGoing)) {\
+ break;\
+ }
+
const Script *Script::load(std::istream &sstream, ScriptOptions opts) {
Script *the_script = new Script;
@@ -68,6 +83,7 @@ const Script *Script::load(std::istream &sstream, ScriptOptions opts) {
}
const std::string line(nextline);
+ std::string key;
std::string::size_type start, key_end, value_begin;
start = line.find_first_not_of(delim);
if(start == std::string::npos) {
@@ -77,15 +93,20 @@ const Script *Script::load(std::istream &sstream, ScriptOptions opts) {
key_end = line.find_first_of(delim, start);
value_begin = line.find_first_not_of(delim, key_end);
+ key = line.substr(start, key_end);
if(key_end == std::string::npos || value_begin == std::string::npos) {
/* Key without value */
- any_error = true;
- output_error("installfile:" + std::to_string(lineno),
- "key '" + line.substr(start, key_end) +
- "' has no value",
- "", (opts.test(Pretty)));
- if(!opts.test(ScriptOptionFlags::KeepGoing)) {
- break;
+ PARSER_ERROR("key '" + key + "' has no value")
+ }
+
+ if(!is_key(line.substr(start, key_end))) {
+ /* Invalid key */
+ if(opts.test(StrictMode)) {
+ PARSER_ERROR("key '" + key + "' is not defined")
+ } else {
+ output_warning("installfile:" + std::to_string(lineno),
+ "key '" + key + "' is not defined", "",
+ opts.test(Pretty));
}
}
}