added regular expressions for the parser

Mon, 23 Sep 2019 14:06:36 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 23 Sep 2019 14:06:36 +0300
changeset 4
68988ebc2a68
parent 3
55a55a9ec2c2
child 5
593a658cba8e

added regular expressions for the parser

src/parser.cpp file | annotate | diff | comparison | revisions
--- a/src/parser.cpp	Sun Sep 22 11:51:41 2019 +0300
+++ b/src/parser.cpp	Mon Sep 23 14:06:36 2019 +0300
@@ -262,6 +262,52 @@
 	}
 }
 
+namespace
+{
+	namespace regexes
+	{
+		static const QRegExp comment {R"(^\s*0\s*\/\/\s*(.+)$)"};
+		static const QRegExp metacommand {R"(^\s*0\s*(.+)$)"};
+		static const QRegExp edgeline
+		{
+			R"(^\s*2)" // starting 2-token
+			R"(\s+(\d+))" // colour
+			R"(((?:\s+[^\s]+){3}))" // 1st vertex
+			R"(((?:\s+[^\s]+){3}))" // 2nd vertex
+			R"(\s*$)" // end
+		};
+		static const QRegExp triangle
+		{
+			R"(^\s*3)" // starting 3-token
+			R"(\s+(\d+))" // colour
+			R"(((?:\s+[^\s]+){3}))" // 1st vertex
+			R"(((?:\s+[^\s]+){3}))" // 2nd vertex
+			R"(((?:\s+[^\s]+){3}))" // 3rd vertex
+			R"(\s*$)" // end
+		};
+		static const QRegExp quadrilateral
+		{
+			R"(^\s*4)" // starting 4-token
+			R"(\s+(\d+))" // colour
+			R"(((?:\s+[^\s]+){3}))" // 1st vertex
+			R"(((?:\s+[^\s]+){3}))" // 2nd vertex
+			R"(((?:\s+[^\s]+){3}))" // 3rd vertex
+			R"(((?:\s+[^\s]+){3}))" // 4th vertex
+			R"(\s*$)" // end
+		};
+		static const QRegExp conditionaledge
+		{
+			R"(^\s*5)" // starting 5-token
+			R"(\s+(\d+))" // colour
+			R"(((?:\s+[^\s]+){3}))" // 1st vertex
+			R"(((?:\s+[^\s]+){3}))" // 2nd vertex
+			R"(((?:\s+[^\s]+){3}))" // 1st control point
+			R"(((?:\s+[^\s]+){3}))" // 2nd control point
+			R"(\s*$)" // end
+		};
+	}
+}
+
 modelobjects::BaseObject* Parser::parseFromString(
 	Model::EditContext& editor,
 	const QString& line)

mercurial