-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.cpp
More file actions
108 lines (104 loc) · 3.2 KB
/
Copy pathparser.cpp
File metadata and controls
108 lines (104 loc) · 3.2 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright (c) 2017 Billy Carlyle, Stephan Kreutzer
*
* This file is part of NTL.
*
* NTL is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NTL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NTL. If not, see <http://www.gnu.org/licenses/>.
*/
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <regex>
#include "parser.h"
#include "render.h"
#include "equation.h"
using namespace std;
//Initialize regular expressions
const regex newLineEx("//");
const regex highlightEx("::(.*)::");
const regex titleEx("#t (.*)");
const regex listTitleEx("#l(.*)");
const regex listItemEx("^ (.*)");
const regex lineEx("#b");
const regex equationEx("#e (.*)");
const regex regularLineEx("(.*)");
smatch matchTitle;
smatch matchNewLine;
smatch matchListTitle;
smatch matchListItem;
smatch matchHighlight;
smatch matchDrawLine;
smatch matchEquation;
smatch matchRegularLine;
int equationNumber = 0;
void parser(char* filePath){
vector<string> words;
vector<string> lines;
string inLine;
string word;
string space = " ";
size_t pos = 0;
bool newPara = true;
ifstream inFile(filePath);
// Open input file
if(inFile.is_open()){
while(getline(inFile,inLine)){
lines.push_back(inLine);
if(regex_search(inLine, matchTitle, titleEx)){
cout << "Title is " << matchTitle.str(1) << endl;
InitDocument((matchTitle.str(1)+".pdf").c_str());
DrawTitle(matchTitle.str(1));
}else if(regex_search(inLine, matchDrawLine, lineEx)){
cout << "Line detected" << endl;
DrawBreak();
}else if(regex_search(inLine, matchListItem, listItemEx)){
cout << "Item: " << matchListItem.str(1) << endl;
DrawListItem(matchListItem.str(1));
}else if(regex_search(inLine, matchHighlight, highlightEx)){
cout << "Highlighted text: " << matchHighlight.str(1) << endl;
DrawHighlighted(matchHighlight.str(1), true);
}else if(regex_search(inLine, matchEquation, equationEx)){
cout << "Equation in LaTeX: " << matchEquation.str(1) << endl;
InitializeTexDocument(equationNumber, matchEquation.str(1));
equationNumber++;
}else if(regex_search(inLine, matchRegularLine, regularLineEx)){
cout << "Regular line detected" << endl;
while((pos = inLine.find(space)) != string::npos){
word = inLine.substr(0, pos);
if(word != "//"){
DrawParagraph(word, newPara);
if(newPara == true)
newPara = false;
}else{
newPara = true;
}
inLine.erase(0, pos + space.length());
}
if(inLine != "//" && !inLine.empty()){
DrawParagraph(inLine, newPara);
}
else{
newPara = true;
}
}else if(regex_search(inLine, matchNewLine, newLineEx)){
newPara = true;
}
}
CloseDocument();
inFile.close();
}else{
cout << "Error loading file" << endl;
}
}