summaryrefslogtreecommitdiff
path: root/src/recursivedescent.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/recursivedescent.cc')
-rw-r--r--src/recursivedescent.cc100
1 files changed, 32 insertions, 68 deletions
diff --git a/src/recursivedescent.cc b/src/recursivedescent.cc
index b734779..7753c91 100644
--- a/src/recursivedescent.cc
+++ b/src/recursivedescent.cc
@@ -11,27 +11,22 @@
#include "imapparser.h"
#include "iodevice.h"
#include "iofactory.h"
-#include "operators.h"
-#include "session.h"
#include <cctype>
#include <iomanip>
#include <iostream>
#include <stack>
-using namespace Binc;
using std::string;
using ParseResult = Binc::Parser::ParseResult;
-constexpr auto ERROR = Parser::ParseResult::ERROR;
-constexpr auto REJECT = Parser::ParseResult::REJECT;
-constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
-constexpr auto TIMEOUT = Parser::ParseResult::TIMEOUT;
+constexpr auto ERROR = ParseResult::ERROR;
+constexpr auto REJECT = ParseResult::REJECT;
+constexpr auto ACCEPT = ParseResult::ACCEPT;
+constexpr auto TIMEOUT = ParseResult::TIMEOUT;
-ParseResult Binc::expectThisString(const string &s_in)
+ParseResult Binc::Parser::expectThisString(const string &s_in)
{
- Session &session = Session::getInstance();
-
char c;
bool match = true;
@@ -58,10 +53,8 @@ ParseResult Binc::expectThisString(const string &s_in)
}
}
-ParseResult Binc::expectDateTime(string &s_in)
+ParseResult Binc::Parser::expectDateTime(string &s_in)
{
- Session &session = Session::getInstance();
-
if (expectThisString("\"") != ACCEPT) return REJECT;
unsigned int digit1, digit2;
@@ -204,10 +197,8 @@ ParseResult Binc::expectDateTime(string &s_in)
return ACCEPT;
}
-ParseResult Binc::expectTime(string &s_in)
+ParseResult Binc::Parser::expectTime(string &s_in)
{
- Session &session = Session::getInstance();
-
unsigned int c, t;
ParseResult res;
if ((res = expectDigit(t)) != ACCEPT) return res;
@@ -278,10 +269,8 @@ ParseResult Binc::expectTime(string &s_in)
return ACCEPT;
}
-ParseResult Binc::expectZone(string &s_in)
+ParseResult Binc::Parser::expectZone(string &s_in)
{
- Session &session = Session::getInstance();
-
ParseResult res;
if ((res = expectThisString("-")) == ACCEPT)
s_in += "-";
@@ -326,7 +315,7 @@ ParseResult Binc::expectZone(string &s_in)
return ACCEPT;
}
-ParseResult Binc::expectListWildcards(int &c_in)
+ParseResult Binc::Parser::expectListWildcards(int &c_in)
{
ParseResult res;
if ((res = expectThisString("%")) == ACCEPT) {
@@ -340,7 +329,7 @@ ParseResult Binc::expectListWildcards(int &c_in)
}
}
-ParseResult Binc::expectListMailbox(string &s_in)
+ParseResult Binc::Parser::expectListMailbox(string &s_in)
{
ParseResult res;
if ((res = expectString(s_in)) == ACCEPT) return ACCEPT;
@@ -364,10 +353,8 @@ ParseResult Binc::expectListMailbox(string &s_in)
return res;
}
-ParseResult Binc::expectFlag(std::vector<string> &v_in)
+ParseResult Binc::Parser::expectFlag(std::vector<string> &v_in)
{
- Session &session = Session::getInstance();
-
ParseResult res;
string flag;
if ((res = expectThisString("\\Answered")) == ACCEPT) {
@@ -399,10 +386,8 @@ ParseResult Binc::expectFlag(std::vector<string> &v_in)
return ACCEPT;
}
-ParseResult Binc::expectDate(string &s_in)
+ParseResult Binc::Parser::expectDate(string &s_in)
{
- Session &session = Session::getInstance();
-
ParseResult res;
bool quoted = false;
if ((res = expectThisString("\"")) == ACCEPT) quoted = true;
@@ -513,7 +498,7 @@ ParseResult Binc::expectDate(string &s_in)
return ACCEPT;
}
-ParseResult Binc::expectCRLF()
+ParseResult Binc::Parser::expectCRLF()
{
ParseResult res;
if ((res = expectCR()) == ACCEPT && (res = expectLF()) == ACCEPT)
@@ -522,10 +507,8 @@ ParseResult Binc::expectCRLF()
return res;
}
-ParseResult Binc::expectCR()
+ParseResult Binc::Parser::expectCR()
{
- Session &session = Session::getInstance();
-
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
@@ -542,10 +525,8 @@ ParseResult Binc::expectCR()
}
}
-ParseResult Binc::expectLF()
+ParseResult Binc::Parser::expectLF()
{
- Session &session = Session::getInstance();
-
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
@@ -562,10 +543,8 @@ ParseResult Binc::expectLF()
}
}
-ParseResult Binc::expectTagChar(int &c_in)
+ParseResult Binc::Parser::expectTagChar(int &c_in)
{
- Session &session = Session::getInstance();
-
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
@@ -672,7 +651,7 @@ ParseResult Binc::expectTagChar(int &c_in)
return REJECT;
}
-ParseResult Binc::expectTag(string &s_in)
+ParseResult Binc::Parser::expectTag(string &s_in)
{
string tag;
int tagchar;
@@ -710,10 +689,8 @@ ParseResult Binc::expectTag(string &s_in)
return ACCEPT;
}
-ParseResult Binc::expectSPACE()
+ParseResult Binc::Parser::expectSPACE()
{
- Session &session = Session::getInstance();
-
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
@@ -730,13 +707,13 @@ ParseResult Binc::expectSPACE()
}
}
-ParseResult Binc::expectMailbox(string &s_in)
+ParseResult Binc::Parser::expectMailbox(string &s_in)
{
return expectAstring(s_in);
}
// FIXME: This rule is wrong.
-ParseResult Binc::expectAstring(string &s_in)
+ParseResult Binc::Parser::expectAstring(string &s_in)
{
ParseResult res;
if ((res = expectAtom(s_in)) == ACCEPT) return ACCEPT;
@@ -746,10 +723,8 @@ ParseResult Binc::expectAstring(string &s_in)
return res;
}
-ParseResult Binc::expectAtomChar(int &c_in)
+ParseResult Binc::Parser::expectAtomChar(int &c_in)
{
- Session &session = Session::getInstance();
-
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
@@ -856,7 +831,7 @@ ParseResult Binc::expectAtomChar(int &c_in)
return REJECT;
}
-ParseResult Binc::expectAtom(string &s_in)
+ParseResult Binc::Parser::expectAtom(string &s_in)
{
string atom;
int atomchar;
@@ -875,7 +850,7 @@ ParseResult Binc::expectAtom(string &s_in)
return ACCEPT;
}
-ParseResult Binc::expectString(string &s_in)
+ParseResult Binc::Parser::expectString(string &s_in)
{
ParseResult res;
if ((res = expectQuoted(s_in)) == ACCEPT) return ACCEPT;
@@ -885,7 +860,7 @@ ParseResult Binc::expectString(string &s_in)
return res;
}
-ParseResult Binc::expectQuoted(string &s_in)
+ParseResult Binc::Parser::expectQuoted(string &s_in)
{
string quoted;
int quotedchar;
@@ -905,10 +880,8 @@ ParseResult Binc::expectQuoted(string &s_in)
return ACCEPT;
}
-ParseResult Binc::expectQuotedChar(int &c_in)
+ParseResult Binc::Parser::expectQuotedChar(int &c_in)
{
- Session &session = Session::getInstance();
-
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
@@ -1069,10 +1042,8 @@ ParseResult Binc::expectQuotedChar(int &c_in)
return REJECT;
}
-ParseResult Binc::expectLiteral(string &s_in)
+ParseResult Binc::Parser::expectLiteral(string &s_in)
{
- Session &session = Session::getInstance();
-
string literal;
ParseResult res;
@@ -1124,7 +1095,7 @@ ParseResult Binc::expectLiteral(string &s_in)
return ACCEPT;
}
-ParseResult Binc::expectNumber(unsigned int &i_in)
+ParseResult Binc::Parser::expectNumber(unsigned int &i_in)
{
i_in = 0;
unsigned int n;
@@ -1141,10 +1112,8 @@ ParseResult Binc::expectNumber(unsigned int &i_in)
return ACCEPT;
}
-ParseResult Binc::expectDigit(unsigned int &i_in)
+ParseResult Binc::Parser::expectDigit(unsigned int &i_in)
{
- Session &session = Session::getInstance();
-
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
@@ -1165,10 +1134,8 @@ ParseResult Binc::expectDigit(unsigned int &i_in)
return ACCEPT;
}
-ParseResult Binc::expectDigitNZ(unsigned int &i_in)
+ParseResult Binc::Parser::expectDigitNZ(unsigned int &i_in)
{
- Session &session = Session::getInstance();
-
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
@@ -1218,9 +1185,8 @@ ParseResult Binc::expectDigitNZ(unsigned int &i_in)
return ACCEPT;
}
-ParseResult Binc::expectSet(SequenceSet &s_in)
+ParseResult Binc::Parser::expectSet(SequenceSet &s_in)
{
- Session &session = Session::getInstance();
unsigned int seqnum = (unsigned int)-1;
ParseResult res;
@@ -1257,10 +1223,8 @@ ParseResult Binc::expectSet(SequenceSet &s_in)
return ACCEPT;
}
-ParseResult Binc::expectSequenceNum(unsigned int &i_in)
+ParseResult Binc::Parser::expectSequenceNum(unsigned int &i_in)
{
- Session &session = Session::getInstance();
-
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
@@ -1282,7 +1246,7 @@ ParseResult Binc::expectSequenceNum(unsigned int &i_in)
return ACCEPT;
}
-ParseResult Binc::expectNZNumber(unsigned int &i_in)
+ParseResult Binc::Parser::expectNZNumber(unsigned int &i_in)
{
unsigned int c;
ParseResult res;