src/parser.cpp

changeset 340
e17e07661f4c
parent 335
c5830bce1c23
child 358
ef90ed0a5720
equal deleted inserted replaced
339:4787d05e9c89 340:e17e07661f4c
20 #include <QIODevice> 20 #include <QIODevice>
21 #include "src/ldrawalgorithm.h" 21 #include "src/ldrawalgorithm.h"
22 #include "src/model.h" 22 #include "src/model.h"
23 #include "src/parser.h" 23 #include "src/parser.h"
24 24
25 #define NUMBER_REGEX R"([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+)))" 25 #define NUMBER_REGEX R"(([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))))"
26 #define SPACE_REGEX R"(\s+)" 26 #define SPACE_REGEX R"(\s+)"
27 #define VEC3_REGEX "(" NUMBER_REGEX SPACE_REGEX NUMBER_REGEX SPACE_REGEX NUMBER_REGEX ")" 27 #define VEC3_REGEX NUMBER_REGEX SPACE_REGEX NUMBER_REGEX SPACE_REGEX NUMBER_REGEX
28 #define TWO_VECTORS VEC3_REGEX SPACE_REGEX VEC3_REGEX 28 #define TWO_VECTORS VEC3_REGEX SPACE_REGEX VEC3_REGEX
29 #define THREE_VECTORS TWO_VECTORS SPACE_REGEX VEC3_REGEX 29 #define THREE_VECTORS TWO_VECTORS SPACE_REGEX VEC3_REGEX
30 #define FOUR_VECTORS THREE_VECTORS SPACE_REGEX VEC3_REGEX 30 #define FOUR_VECTORS THREE_VECTORS SPACE_REGEX VEC3_REGEX
31 31
32 static const auto& exprs() 32 static const auto& exprs()
62 template<Attribute Attrib, typename T, Attribute... Attribs> 62 template<Attribute Attrib, typename T, Attribute... Attribs>
63 QString attrib(const LineType<T, Attribs...>& parsed) 63 QString attrib(const LineType<T, Attribs...>& parsed)
64 { 64 {
65 const int index = attribIndex<LineType<T, Attribs...>, Attrib>; 65 const int index = attribIndex<LineType<T, Attribs...>, Attrib>;
66 const TextRange& range = parsed.positions[index]; 66 const TextRange& range = parsed.positions[index];
67 const QString content = parsed.content;
67 return parsed.content.mid(range.start, range.length); 68 return parsed.content.mid(range.start, range.length);
68 } 69 }
69 70
70 template<Attribute X, Attribute Y, Attribute Z, typename T, Attribute... Attribs> 71 template<Attribute X, Attribute Y, Attribute Z, typename T, Attribute... Attribs>
71 glm::vec3 vectorAttrib(const LineType<T, Attribs...>& parsed) 72 glm::vec3 vectorAttrib(const LineType<T, Attribs...>& parsed)
101 parsed->positions[i] = { 102 parsed->positions[i] = {
102 .start = match.capturedStart(i + 1), 103 .start = match.capturedStart(i + 1),
103 .length = match.capturedLength(i + 1), 104 .length = match.capturedLength(i + 1),
104 }; 105 };
105 } 106 }
107 parsed->content = match.captured(0);
106 return parsed; 108 return parsed;
107 }; 109 };
108 if (auto line1Match = tryRe(exprs().subfileRe)) { 110 if (auto line1Match = tryRe(exprs().subfileRe)) {
109 LineType1* const parsed = init(LineType1{}, *line1Match); 111 LineType1* const parsed = init(LineType1{}, *line1Match);
110 parsed->value = { 112 parsed->value = {

mercurial