aboutsummaryrefslogtreecommitdiffstats
path: root/libalee/parser.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-10-13 10:13:31 -0400
committerClyne Sullivan <clyne@bitgloo.com>2023-10-13 10:13:31 -0400
commitf7a9103bbef39b7f6c5909d7f74fa2aea4b81fe1 (patch)
treed0cedbfaa20a205c05951977173667273e33e134 /libalee/parser.cpp
parent15c0c2f789902ac764919913e123466ac46e4746 (diff)
more refactoring, object organization
Diffstat (limited to 'libalee/parser.cpp')
-rw-r--r--libalee/parser.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/libalee/parser.cpp b/libalee/parser.cpp
index 2b1d8e1..da7ae0b 100644
--- a/libalee/parser.cpp
+++ b/libalee/parser.cpp
@@ -20,14 +20,14 @@
#include "ctype.hpp"
#include "parser.hpp"
+#include <algorithm>
+#include <cstring>
+
Error Parser::parse(State& state, const char *str)
{
auto addr = Dictionary::Input;
- Cell len = 0;
- for (auto ptr = str; *ptr; ++ptr)
- ++len;
-
+ const auto len = static_cast<Cell>(std::strlen(str));
state.dict.write(addr, 0);
state.dict.write(Dictionary::SourceLen, len);
@@ -43,15 +43,12 @@ Error Parser::parse(State& state, const char *str)
Error Parser::parseSource(State& state)
{
- auto word = state.dict.input();
- while (word.size() > 0) {
- if (auto ret = parseWord(state, word); ret != Error::none)
- return ret;
+ auto err = Error::none;
- word = state.dict.input();
- }
+ while (err == Error::none && state.dict.hasInput())
+ err = parseWord(state, state.dict.input());
- return Error::none;
+ return err;
}
Error Parser::parseWord(State& state, Word word)