home readme diff tree note docs

0commit 80f04b134ae32ad8a9d526007b33dd02f6600f05
1Author: Mason Wright <mason@lakefox.net>
2Date:   Fri Jun 20 19:09:22 2025 -0600
3
4    Made a makefile
5
6diff --git a/Makefile b/Makefile
7new file mode 100644
8index 0000000..634834e
9--- /dev/null
10+++ b/Makefile
11@@ -0,0 +1,18 @@
12+# --- Variables ---
13+CCFLAGS = -Wall -Wextra -std=c++23
14+CC = clang++
15+
16+main: main.cc build/grim.o build/parser.o
17+	${CC} ${CCFLAGS} main.cc -Iinclude/ build/grim.o build/parser.o -o main
18+
19+grim: src/grim.cc include/grim.h
20+	${CC} ${CCFLAGS} -Iinclude/ -c src/grim.cc -o build/grim.o
21+
22+parser: src/parser.cc include/parser.h
23+	${CC} ${CCFLAGS} -Iinclude/ -c src/parser.cc -o build/parser.o
24+
25+clean:
26+	rm -f main build/*.o
27+
28+run:
29+	clear && ./main
30diff --git a/build/grim.o b/build/grim.o
31new file mode 100644
32index 0000000..5227626
33Binary files /dev/null and b/build/grim.o differ
34diff --git a/build/main b/build/main
35new file mode 100755
36index 0000000..4405023
37Binary files /dev/null and b/build/main differ
38diff --git a/build/parser.o b/build/parser.o
39new file mode 100644
40index 0000000..4be662f
41Binary files /dev/null and b/build/parser.o differ
42diff --git a/include/element.h b/include/grim.h
43similarity index 98%
44rename from include/element.h
45rename to include/grim.h
46index 83d5155..0919017 100644
47--- a/include/element.h
48+++ b/include/grim.h
49@@ -1,6 +1,6 @@
50-// Node.h
51-#ifndef ELEMENT_H
52-#define ELEMENT_H
53+// Grim.h
54+#ifndef GRIM_H
55+#define GRIM_H
56 
57 #include <string>
58 #include <vector>
59diff --git a/main b/main
60index 6f01d7a..f4d8f51 100755
61Binary files a/main and b/main differ
62diff --git a/main.cc b/main.cc
63index f51d773..4cca14d 100755
64--- a/main.cc
65+++ b/main.cc
66@@ -1,38 +1,38 @@
67 #include <iostream>
68 #include <fstream>
69 #include <memory>
70-#include "element.h"
71-#include "parser.h" 
72+#include "include/grim.h"
73+#include "include/parser.h" 
74 
75 int main() {
76-    // // Option 1: Parse from a file
77-    // std::ifstream inputFile("./index.html");
78-    // if (!inputFile.is_open()) {
79-    //     std::cerr << "Error: Could not open index.html" << std::endl;
80-    //     return 1;
81-    // }
82-    //
83-    // std::unique_ptr<Node> document = parseStream(inputFile);
84-    // inputFile.close(); // Close the file after parsing
85+    // Option 1: Parse from a file
86+    std::ifstream inputFile("./index.html");
87+    if (!inputFile.is_open()) {
88+        std::cerr << "Error: Could not open index.html" << std::endl;
89+        return 1;
90+    }
91+
92+    std::unique_ptr<Node> document = parseStream(inputFile);
93+    inputFile.close(); // Close the file after parsing
94     //
95     // // Option 2: Parse from a string (for testing)
96     // // std::string html_content = "<div>Hello <b>world</b>!</div><p>Another paragraph.</p>";
97     // // std::stringstream ss(html_content);
98     // // std::unique_ptr<Node> document = parseStream(ss);
99     //
100-    // // Print the parsed document tree
101-    // if (document) {
102-    //     document->print();
103-    // } else {
104-    //     std::cout << "Document parsing failed or resulted in an empty document." << std::endl;
105-    // }
106+    // Print the parsed document tree
107+    if (document) {
108+        document->print();
109+    } else {
110+        std::cout << "Document parsing failed or resulted in an empty document." << std::endl;
111+    }
112 
113 	
114-	std::ifstream inputFile("./style.css");
115-
116-	parseCSS(inputFile);
117-
118-	inputFile.close();
119+	// std::ifstream inputFile("./style.css");
120+	//
121+	// // parseCSS(inputFile);
122+	//
123+	// inputFile.close();
124 
125 	return 0;
126 }
127diff --git a/make.sh b/make.sh
128deleted file mode 100755
129index 5498ebc..0000000
130--- a/make.sh
131+++ /dev/null
132@@ -1 +0,0 @@
133-clang++ -I./include main.cc src/element.cc src/parser.cc -std=c++23 -o main
134diff --git a/src/element.cc b/src/grim.cc
135similarity index 94%
136rename from src/element.cc
137rename to src/grim.cc
138index 5c7f76a..4f968f3 100755
139--- a/src/element.cc
140+++ b/src/grim.cc
141@@ -1,4 +1,4 @@
142-#include "element.h"
143+#include "grim.h"
144 #include <iostream>
145 #include <sstream>
146 #include <algorithm>
147@@ -170,7 +170,7 @@ struct Style {
148 	std::string selector;
149 	// Index of when it was added (for cascading)
150 	int index;
151-}
152+};
153 
154 // struct BaseParts {
155 // 	std::string tagName;
156@@ -201,9 +201,14 @@ class StyleHandler {
157 			std::vector<std::string> parts;
158 			std::string word;
159 
160-			for (int s = 0; s < selector.length(); s++) {
161+			for (size_t s = 0; s < selector.length(); s++) {
162 				// Start parsing if we see a comma or the end of the selector
163+				word += selector[s];
164+
165 				if (selector[s] == ',' || s == selector.length()-1) {
166+					if (selector[s] == ',') {
167+						word.pop_back(); // Remove the trailing comma
168+					}
169 					// Break the tag and add the right most parts to parts
170 					for (int i = word.length()-1; i > -1; i--) {
171 						if (
172@@ -256,17 +261,15 @@ class StyleHandler {
173 					if (part != "") {
174 						parts.push_back(part);
175 					}
176-				} else {
177-					word += selector[s];
178 				}
179 			}
180 
181 			std::vector<std::string> deduplicated;
182 
183-			for (int p1 = 0; p1 < parts.size(); p1++) {
184+			for (size_t p1 = 0; p1 < parts.size(); p1++) {
185 				bool matches = false;
186 
187-				for (int p2 = p1+1; p2 < parts.size(); p2++) {
188+				for (size_t p2 = p1+1; p2 < parts.size(); p2++) {
189 					if (parts[p1] == parts[p2]) {
190 						matches = true;
191 					}
192@@ -282,9 +285,14 @@ class StyleHandler {
193 	public:
194 		void add(Style style) {
195 			styles.push_back(std::move(style));
196-			basemap[styles.back().selector] = styles.size() - 1; // Store the index
197+			if (basemap.find(styles.back().selector) != basemap.end()) {
198+				basemap[styles.back().selector].push_back(styles.size()-1);
199+			} else {
200+				std::vector<size_t> bm = {styles.size() - 1};
201+				basemap[styles.back().selector] = bm;
202+			}
203 			// Give the properties a cascade index
204 			styles.back().index = currentIndex++;
205 		}
206 
207-}
208+};
209diff --git a/src/parser.cc b/src/parser.cc
210index 9017b6c..2bfc103 100644
211--- a/src/parser.cc
212+++ b/src/parser.cc
213@@ -1,4 +1,4 @@
214-#include "element.h" 
215+#include "grim.h" 
216 #include <iostream>
217 #include <fstream>
218 #include <sstream>
219@@ -162,7 +162,7 @@ std::unique_ptr<Node> parseStream(std::istream& inputStream) {
220 				if (token.length() > 0) {
221 					bool empty = true;
222 					bool closingTag = false;
223-					for (int i = 0; i < token.length(); i++) {
224+					for (size_t i = 0; i < token.length(); i++) {
225 						auto c = token[i];
226 						if (std::isspace(c)) {
227 							continue;