aboutsummaryrefslogtreecommitdiffstats
path: root/parser.cpp
blob: 76da588bc61653dfedd2d49a1cf6c9d2c338f2ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "parser.h"
#include <string>
#include <vector>
#include "token.h"

Parser::Parser(std::string& input) {
    std::vector<Token> result;

    bool isString = false;
    std::string tmp;
    for (auto& c : input) {
        if (c == '"' && !isString) {
            isString = true;
            continue;
        }

        if (c == '"' && isString) {
            Token token(tmp, true);
            result.push_back(token);
            tmp = "";
            isString = false;
            continue;
        }

        if (!isString) {
            std::string parsed(1, c);
            Token token(parsed, false);
            result.push_back(token);
        }
        else {
            tmp += c;
        }
    }
}