add comments

Fri, 16 Mar 2018 11:55:58 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 16 Mar 2018 11:55:58 +0200
changeset 1289
ec5a38d19cf5
parent 1288
d1e45f90654b
child 1290
8db26042f3d1

add comments

src/parser.cpp file | annotate | diff | comparison | revisions
--- a/src/parser.cpp	Fri Mar 16 11:50:35 2018 +0200
+++ b/src/parser.cpp	Fri Mar 16 11:55:58 2018 +0200
@@ -25,15 +25,28 @@
 #include "linetypes/quadrilateral.h"
 #include "linetypes/triangle.h"
 
+/*
+ * Constructs an LDraw parser
+ */
 Parser::Parser(QIODevice& device, QObject* parent) :
 	QObject {parent},
 	device {device} {}
 
+/*
+ * Reads a single line from the device.
+ */
 QString Parser::readLine()
 {
 	return QString::fromUtf8(this->device.readLine()).simplified();
 }
 
+/*
+ * Parses a single line of the header.
+ * Possible parse results:
+ *   · ParseSuccess: the header line was parsed successfully.
+ *   · ParseFailure: the header line was parsed incorrectly and needs to be handled otherwise.
+ *   · StopParsing: the line does not belong in the header and header parsing needs to stop.
+ */
 Parser::HeaderParseResult Parser::parseHeaderLine(LDHeader& header, const QString& line)
 {
 	if (line.isEmpty())
@@ -182,6 +195,10 @@
 	}
 }
 
+/*
+ * Parses the header from the device given at construction and returns
+ * the resulting header structure.
+ */
 LDHeader Parser::parseHeader()
 {
 	LDHeader header = {};
@@ -202,10 +219,12 @@
 
 				if (result == ParseFailure)
 				{
+					// Failed to parse this header line, add it as a comment into the body later.
 					this->bag.append(line);
 				}
 				else if (result == StopParsing)
 				{
+					// Header parsing stops, add this line to the body.
 					this->bag.append(line);
 					break;
 				}
@@ -220,6 +239,9 @@
 	return header;
 }
 
+/*
+ * Parses the model body into the given model.
+ */
 void Parser::parseBody(Model& model)
 {
 	bool invertNext = false;
@@ -300,7 +322,14 @@
 	return {tokens[n].toDouble(), tokens[n + 1].toDouble(), tokens[n + 2].toDouble()};
 }
 
-// TODO: rewrite this using regular expressions
+/*
+ * Parses the given model body line and inserts the result into the given model.
+ * The resulting object is also returned.
+ *
+ * If an error happens, an error object is created. Result is guaranteed to be a valid pointer.
+ *
+ * TODO: rewrite this using regular expressions
+ */
 LDObject* Parser::parseFromString(Model& model, int position, QString line)
 {
 	if (position == EndOfModel)

mercurial