MCPcopy Create free account
hub / github.com/Gusabary/FlowChar / scan

Method scan

src/codeParser.cpp:22–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22void CodeParser::scan() {
23 char c;
24 std::string str;
25 std::pair<int, int> cntPos = std::make_pair<int, int>(1, 0);
26 while (this->fs.get(c))
27 {
28 // update current position
29 if (c == '\n') {
30 cntPos.first++;
31 cntPos.second = 0;
32 }
33 else {
34 cntPos.second++;
35 }
36
37 if (Token::delimiters.find(c) != Token::delimiters.end()) {
38 // c is a delimiter
39 // first erase trailing space
40 str.erase(str.find_last_not_of(' ') + 1);
41
42 if (str == Token::iftoken)
43 {
44 this->tokenList.push_back(new IfToken(cntPos));
45 }
46 else if (str == Token::elsetoken) {
47 this->tokenList.push_back(new ElseToken(cntPos));
48 }
49 else if (str == Token::whiletoken) {
50 this->tokenList.push_back(new WhileToken(cntPos));
51 }
52 else if (!str.empty()) {
53 // cond or simple stm
54 if (c == Token::rparen) {
55 // cond
56 this->tokenList.push_back(new CondToken(str, cntPos));
57 }
58 else {
59 // simple stm
60 this->tokenList.push_back(new StmToken(str, cntPos));
61 }
62 }
63
64 if (c == Token::lbrace) {
65 this->tokenList.push_back(new LBraceToken(cntPos));
66 }
67 else if (c == Token::rbrace) {
68 this->tokenList.push_back(new RBraceToken(cntPos));
69 }
70 str.clear();
71 }
72 else {
73 if (Token::whitespaces.find(c) == Token::whitespaces.end()) {
74 // c is not a whitespace
75 str += c;
76 }
77 else if (c == Token::space && !str.empty()) {
78 // ignore leading space
79 str += c;

Callers 1

mainFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected